diff --git a/app/controllers/post_histories_controller.rb b/app/controllers/post_histories_controller.rb index 0d99079d9..a4f0055ad 100644 --- a/app/controllers/post_histories_controller.rb +++ b/app/controllers/post_histories_controller.rb @@ -1,6 +1,6 @@ class PostHistoriesController < ApplicationController def index @search = PostHistory.search(params[:search]) - @histories = @search.paginate(:page => params[:page], :per_page => 20) + @histories = @search.paginate(:page => params[:page], :per_page => 20, :order => "updated_at DESC") end end diff --git a/app/models/post_history.rb b/app/models/post_history.rb index 0b2059daf..e0b899f35 100644 --- a/app/models/post_history.rb +++ b/app/models/post_history.rb @@ -51,9 +51,13 @@ class PostHistory < ActiveRecord::Base hash["updated_at"] end - def updater_id + def user_id hash["user_id"] end + + def presenter + @presenter ||= PostHistoryRevisionPresenter.new(self) + end end before_validation :initialize_revisions, :on => :create diff --git a/app/presenters/post_history_presenter.rb b/app/presenters/post_history_presenter.rb deleted file mode 100644 index 89c30c29e..000000000 --- a/app/presenters/post_history_presenter.rb +++ /dev/null @@ -1,19 +0,0 @@ -class PostHistoryPresenter < Presenter - attr_reader :revision - - def initialize(revision) - @revision = revision - end - - def changes - - end - - def updated_at - revision["updated_at"] - end - - def updater_name - User.id_to_name(revision["user_id"].to_i) - end -end diff --git a/app/presenters/post_history_revision_presenter.rb b/app/presenters/post_history_revision_presenter.rb new file mode 100644 index 000000000..c2defe7ac --- /dev/null +++ b/app/presenters/post_history_revision_presenter.rb @@ -0,0 +1,25 @@ +class PostHistoryRevisionPresenter < Presenter + attr_reader :revision + + def initialize(revision) + @revision = revision + end + + def changes + html = [] + html << revision.diff[:del].map {|x| "#{h(x)}"} + html << revision.diff[:add].map {|x| "#{h(x)}"} + html << "source:#{h(revision.diff[:source])}" if revision.diff[:source].present? + html << "rating:#{h(revision.diff[:rating])}" if revision.diff[:rating].present? + html << "parent:#{revision.diff[:parent_id]}" if revision.diff[:parent_id].present? + html.join(" ").html_safe + end + + def updated_at + Time.parse(revision.updated_at) + end + + def updater_name + User.id_to_name(revision.user_id) + end +end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 44f372c76..44f5a0d76 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -10,6 +10,7 @@ class PostPresenter < Presenter html << %{} html << %{} html << %{} + html.html_safe end def initialize(post) diff --git a/app/presenters/presenter.rb b/app/presenters/presenter.rb index 3a294dcb4..03b4b4eba 100644 --- a/app/presenters/presenter.rb +++ b/app/presenters/presenter.rb @@ -1,4 +1,12 @@ class Presenter + def self.h(s) + CGI.escapeHTML(s) + end + + def self.u(s) + URI.escape(s) + end + def h(s) CGI.escapeHTML(s) end diff --git a/app/views/post_histories/index.html.erb b/app/views/post_histories/index.html.erb index 3d52de02e..e4015e144 100644 --- a/app/views/post_histories/index.html.erb +++ b/app/views/post_histories/index.html.erb @@ -9,25 +9,27 @@
- +
- + <% history.each_revision do |revision| %> - + <% end %>
Changes Date UpdaterChanges
<%= revision.presenter.changes %> <%= revision.presenter.updated_at %> <%= revision.presenter.updater_name %><%= revision.presenter.changes %>
+ +
<% end %> diff --git a/app/views/posts/partials/common/_secondary_links.html.erb b/app/views/posts/partials/common/_secondary_links.html.erb index ec115e295..70bca6994 100644 --- a/app/views/posts/partials/common/_secondary_links.html.erb +++ b/app/views/posts/partials/common/_secondary_links.html.erb @@ -5,7 +5,7 @@
  • Popular
  • Favorites
  • Subscriptions
  • -
  • Changes
  • +
  • <%= link_to "Changes", post_histories_path %>
  • Approvals
  • Moderate
  • Help
  • diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index d721c5d18..ce1c090f3 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -10,6 +10,6 @@ (<%= post.image_width %>x<%= post.image_height %>) <% end %> -
  • <%= link_to "Tag History", post_versions_path(:post_id => post) %>
  • -
  • <%= link_to "Note History", note_versions_path(:post_id => post) %>
  • +
  • <%= link_to "Tag History", post_histories_path(:search => {:post_id_eq => post.id}) %>
  • +
  • <%= link_to "Note History", note_versions_path(:search => {:post_id_eq => post.id}) %>
  • \ No newline at end of file diff --git a/public/javascripts/compiled/default.js b/public/javascripts/compiled/default.js index 8d6c902be..18f6dffcb 100644 --- a/public/javascripts/compiled/default.js +++ b/public/javascripts/compiled/default.js @@ -785,8 +785,10 @@ $(document).ready(function() { // Cookie.put('hide-upgrade-account', '1', 7); // }); - // Style button spans - + // Table striping + $("table.striped tbody tr:even").addClass("even"); + $("table.striped tbody tr:odd").addClass("odd"); + // Comment listing $(".comment-section form").hide(); $(".comment-section input.expand-comment-response").click(function() { diff --git a/public/javascripts/src/app/application.js b/public/javascripts/src/app/application.js index 895519b9f..2f97c255e 100644 --- a/public/javascripts/src/app/application.js +++ b/public/javascripts/src/app/application.js @@ -6,8 +6,10 @@ $(document).ready(function() { // Cookie.put('hide-upgrade-account', '1', 7); // }); - // Style button spans - + // Table striping + $("table.striped tbody tr:even").addClass("even"); + $("table.striped tbody tr:odd").addClass("odd"); + // Comment listing $(".comment-section form").hide(); $(".comment-section input.expand-comment-response").click(function() { diff --git a/public/stylesheets/compiled/default.css b/public/stylesheets/compiled/default.css index 24997f587..508a96022 100644 --- a/public/stylesheets/compiled/default.css +++ b/public/stylesheets/compiled/default.css @@ -123,6 +123,11 @@ span.link { table tfoot { margin-top: 2em; } +table.striped tbody tr:hover { + background-color: #FFE; } +table.striped tr.even { + background-color: #EEE; } + div#notice { margin: 1em; padding: 1em; @@ -269,6 +274,24 @@ div.posts section#content menu#post-sections { div.posts section#content menu#post-sections li.active a { color: black; } +/*** Post Histories ***/ +div.post_histories div.index div.post { + margin-bottom: 2em; } + div.post_histories div.index div.post div.preview { + width: 20%; + float: left; } + div.post_histories div.index div.post div.history { + width: 70%; + float: left; } + div.post_histories div.index div.post div.history table { + width: 100%; } + div.post_histories div.index div.post div.history ins { + color: green; + text-decoration: none; } + div.post_histories div.index div.post div.history del { + color: red; + text-decoration: line-through; } + /*** Comments ***/ div.comment-response > div { margin-top: 1em; } diff --git a/public/stylesheets/src/default.scss b/public/stylesheets/src/default.scss index fe2996345..d7b4a567c 100644 --- a/public/stylesheets/src/default.scss +++ b/public/stylesheets/src/default.scss @@ -159,6 +159,18 @@ table tfoot { margin-top: 2em; } +table.striped { + tbody { + tr:hover { + background-color: #FFE; + } + } + + tr.even { + background-color: #EEE; + } +} + div#notice { margin: 1em; padding: 1em; @@ -421,6 +433,40 @@ div.posts { } +/*** Post Histories ***/ +div.post_histories { + div.index { + div.post { + margin-bottom: 2em; + + div.preview { + width: 20%; + float: left; + } + + div.history { + width: 70%; + float: left; + + table { + width: 100%; + } + + ins { + color: green; + text-decoration: none; + } + + del { + color: red; + text-decoration: line-through; + } + } + } + } +} + + /*** Comments ***/ div.comment-response { }