post histories finished

This commit is contained in:
albert
2010-11-06 12:16:24 -04:00
parent f3b4312ef3
commit 190beedb7a
13 changed files with 125 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
class PostHistoriesController < ApplicationController class PostHistoriesController < ApplicationController
def index def index
@search = PostHistory.search(params[:search]) @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
end end

View File

@@ -51,9 +51,13 @@ class PostHistory < ActiveRecord::Base
hash["updated_at"] hash["updated_at"]
end end
def updater_id def user_id
hash["user_id"] hash["user_id"]
end end
def presenter
@presenter ||= PostHistoryRevisionPresenter.new(self)
end
end end
before_validation :initialize_revisions, :on => :create before_validation :initialize_revisions, :on => :create

View File

@@ -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

View 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

View File

@@ -10,6 +10,7 @@ class PostPresenter < Presenter
html << %{<img src="#{post.preview_file_url}">} html << %{<img src="#{post.preview_file_url}">}
html << %{</a>} html << %{</a>}
html << %{</article>} html << %{</article>}
html.html_safe
end end
def initialize(post) def initialize(post)

View File

@@ -1,4 +1,12 @@
class Presenter class Presenter
def self.h(s)
CGI.escapeHTML(s)
end
def self.u(s)
URI.escape(s)
end
def h(s) def h(s)
CGI.escapeHTML(s) CGI.escapeHTML(s)
end end

View File

@@ -9,25 +9,27 @@
</div> </div>
<div class="history"> <div class="history">
<table> <table class="striped">
<thead> <thead>
<tr> <tr>
<th>Changes</th>
<th>Date</th> <th>Date</th>
<th>Updater</th> <th>Updater</th>
<th>Changes</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% history.each_revision do |revision| %> <% history.each_revision do |revision| %>
<tr> <tr>
<td><%= revision.presenter.changes %></td>
<td><%= revision.presenter.updated_at %></td> <td><%= revision.presenter.updated_at %></td>
<td><%= revision.presenter.updater_name %></td> <td><%= revision.presenter.updater_name %></td>
<td><%= revision.presenter.changes %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="clearfix"></div>
</div> </div>
<% end %> <% end %>
</div> </div>

View File

@@ -5,7 +5,7 @@
<li>Popular</li> <li>Popular</li>
<li>Favorites</li> <li>Favorites</li>
<li>Subscriptions</li> <li>Subscriptions</li>
<li>Changes</li> <li><%= link_to "Changes", post_histories_path %></li>
<li>Approvals</li> <li>Approvals</li>
<li>Moderate</li> <li>Moderate</li>
<li>Help</li> <li>Help</li>

View File

@@ -10,6 +10,6 @@
(<%= post.image_width %>x<%= post.image_height %>) (<%= post.image_width %>x<%= post.image_height %>)
<% end %> <% end %>
</li> </li>
<li><%= link_to "Tag History", post_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(:post_id => post) %></li> <li><%= link_to "Note History", note_versions_path(:search => {:post_id_eq => post.id}) %></li>
</ul> </ul>

View File

@@ -785,8 +785,10 @@ $(document).ready(function() {
// Cookie.put('hide-upgrade-account', '1', 7); // 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 listing
$(".comment-section form").hide(); $(".comment-section form").hide();
$(".comment-section input.expand-comment-response").click(function() { $(".comment-section input.expand-comment-response").click(function() {

View File

@@ -6,8 +6,10 @@ $(document).ready(function() {
// Cookie.put('hide-upgrade-account', '1', 7); // 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 listing
$(".comment-section form").hide(); $(".comment-section form").hide();
$(".comment-section input.expand-comment-response").click(function() { $(".comment-section input.expand-comment-response").click(function() {

View File

@@ -123,6 +123,11 @@ span.link {
table tfoot { table tfoot {
margin-top: 2em; } margin-top: 2em; }
table.striped tbody tr:hover {
background-color: #FFE; }
table.striped tr.even {
background-color: #EEE; }
div#notice { div#notice {
margin: 1em; margin: 1em;
padding: 1em; padding: 1em;
@@ -269,6 +274,24 @@ div.posts section#content menu#post-sections {
div.posts section#content menu#post-sections li.active a { div.posts section#content menu#post-sections li.active a {
color: black; } 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 ***/ /*** Comments ***/
div.comment-response > div { div.comment-response > div {
margin-top: 1em; } margin-top: 1em; }

View File

@@ -159,6 +159,18 @@ table tfoot {
margin-top: 2em; margin-top: 2em;
} }
table.striped {
tbody {
tr:hover {
background-color: #FFE;
}
}
tr.even {
background-color: #EEE;
}
}
div#notice { div#notice {
margin: 1em; margin: 1em;
padding: 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 ***/ /*** Comments ***/
div.comment-response { div.comment-response {
} }