diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 63a9f6f63..900b79f8f 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -243,7 +243,7 @@ div#c-posts { margin-top: 0.5em; } - #pool-nav, #search-seq-nav, #nav-help { + #pool-nav, #search-seq-nav { li { position: relative; text-align: center; diff --git a/app/controllers/post_versions_controller.rb b/app/controllers/post_versions_controller.rb index 89a606214..ddf634239 100644 --- a/app/controllers/post_versions_controller.rb +++ b/app/controllers/post_versions_controller.rb @@ -13,4 +13,12 @@ class PostVersionsController < ApplicationController def search end + + def undo + @post_version = PostVersion.find(params[:id]) + @post_version.undo! + respond_with(@post_version) do |format| + format.js + end + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 030b6a288..cb4acf487 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -14,9 +14,7 @@ class PostsController < ApplicationController respond_with(@posts) do |format| format.atom format.xml do - render :xml => @posts.to_xml(:root => "posts") {|builder| - builder.tag!("total-count", @posts.total_count) - } + render :xml => @posts.to_xml(:root => "posts") end end end diff --git a/app/models/post_version.rb b/app/models/post_version.rb index 1af723881..017a5a348 100644 --- a/app/models/post_version.rb +++ b/app/models/post_version.rb @@ -112,4 +112,31 @@ class PostVersion < ActiveRecord::Base def truncated_source source.gsub(/^http:\/\//, "").sub(/\/.+/, "") end + + def undo + changes = diff(previous) + added = changes[:added_tags] - changes[:obsolete_added_tags] + removed = changes[:removed_tags] - changes[:obsolete_removed_tags] + + added.each do |tag| + if tag =~ /^source:/ + post.source = "" + else + escaped_tag = Regexp.escape(tag) + post.tag_string = post.tag_string.sub(/(?:\A| )#{escaped_tag}(?:\Z| )/, " ").strip + end + end + removed.each do |tag| + if tag =~ /^source:(.+)$/ + post.source = $1 + else + post.tag_string = "#{post.tag_string} #{tag}".strip + end + end + end + + def undo! + undo + post.save! + end end diff --git a/app/views/post_versions/_listing.html.erb b/app/views/post_versions/_listing.html.erb index e716a6626..fbb61dc26 100644 --- a/app/views/post_versions/_listing.html.erb +++ b/app/views/post_versions/_listing.html.erb @@ -36,6 +36,9 @@