post histories finished
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
25
app/presenters/post_history_revision_presenter.rb
Normal file
25
app/presenters/post_history_revision_presenter.rb
Normal file
@@ -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| "<del>#{h(x)}</del>"}
|
||||
html << revision.diff[:add].map {|x| "<ins>#{h(x)}</ins>"}
|
||||
html << "<ins>source:#{h(revision.diff[:source])}</ins>" if revision.diff[:source].present?
|
||||
html << "<ins>rating:#{h(revision.diff[:rating])}</ins>" if revision.diff[:rating].present?
|
||||
html << "<ins>parent:#{revision.diff[:parent_id]}</ins>" 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
|
||||
@@ -10,6 +10,7 @@ class PostPresenter < Presenter
|
||||
html << %{<img src="#{post.preview_file_url}">}
|
||||
html << %{</a>}
|
||||
html << %{</article>}
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
def initialize(post)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,25 +9,27 @@
|
||||
</div>
|
||||
|
||||
<div class="history">
|
||||
<table>
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Changes</th>
|
||||
<th>Date</th>
|
||||
<th>Updater</th>
|
||||
<th>Changes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% history.each_revision do |revision| %>
|
||||
<tr>
|
||||
<td><%= revision.presenter.changes %></td>
|
||||
<td><%= revision.presenter.updated_at %></td>
|
||||
<td><%= revision.presenter.updater_name %></td>
|
||||
<td><%= revision.presenter.changes %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<li>Popular</li>
|
||||
<li>Favorites</li>
|
||||
<li>Subscriptions</li>
|
||||
<li>Changes</li>
|
||||
<li><%= link_to "Changes", post_histories_path %></li>
|
||||
<li>Approvals</li>
|
||||
<li>Moderate</li>
|
||||
<li>Help</li>
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
(<%= post.image_width %>x<%= post.image_height %>)
|
||||
<% end %>
|
||||
</li>
|
||||
<li><%= link_to "Tag History", post_versions_path(:post_id => post) %></li>
|
||||
<li><%= link_to "Note History", note_versions_path(:post_id => post) %></li>
|
||||
<li><%= link_to "Tag History", post_histories_path(:search => {:post_id_eq => post.id}) %></li>
|
||||
<li><%= link_to "Note History", note_versions_path(:search => {:post_id_eq => post.id}) %></li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user