/post_versions: unify standard and revert listings.

This commit is contained in:
evazion
2019-09-28 12:53:45 -05:00
parent 62ec679bfb
commit 609a440d1c
4 changed files with 9 additions and 67 deletions

View File

@@ -1,4 +1,8 @@
module PostVersionsHelper
def post_version_listing
params.dig(:search, :post_id).present? ? :revert : :standard
end
def post_version_diff(post_version)
diff = post_version.diff(post_version.previous)
html = '<span class="diff-list">'

View File

@@ -1,4 +1,4 @@
<div id="p-standard-listing">
<div id="p-<%= post_version_listing %>-listing">
<table class="striped autofit">
<thead>
<tr>
@@ -51,6 +51,9 @@
<% if post_version.can_undo?(CurrentUser.user) %>
<%= link_to "Undo", undo_post_version_path(post_version), method: :put, remote: true, class: "post-version-undo-link" %>
<% end %>
<% if post_version_listing == :revert && post_version.can_revert_to?(CurrentUser.user) %>
| <%= link_to "Revert to", revert_post_path(post_version.post_id, version_id: post_version.id), method: :put, remote: true %>
<% end %>
</td>
</tr>
<% end %>

View File

@@ -1,60 +0,0 @@
<div id="p-revert-listing">
<table class="striped autofit">
<thead>
<tr>
<% if CurrentUser.user.is_builder? %>
<th class="post-version-select-column">
<label><input type="checkbox" id="post-version-select-all-checkbox" class="post-version-select-checkbox"></label>
</th>
<% end %>
<th width="5%">Post</th>
<th width="15%">Date</th>
<th width="10%">User</th>
<th width="5%">Rating</th>
<th width="5%">Parent</th>
<% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th>
<% end %>
<th>Tags</th>
<% if CurrentUser.is_member? %>
<th width="7%"></th>
<% end %>
</tr>
</thead>
<tbody>
<% @post_versions.each do |post_version| %>
<tr id="post-version-<%= post_version.id %>" data-post-version-id="<%= post_version.id %>">
<% if CurrentUser.user.is_builder? %>
<td class="post-version-select-column">
<input type="checkbox" class="post-version-select-checkbox" <%= "disabled" unless post_version.can_undo?(CurrentUser.user) %>>
</td>
<% end %>
<td><%= link_to("#{post_version.post_id}.#{post_version.id}", post_path(post_version.post_id)) %></td>
<td><%= compact_time(post_version.updated_at) %></td>
<td>
<% if post_version.updater %>
<%= link_to_user(post_version.updater) %>
<% end %>
</td>
<td><%= post_version.rating %></td>
<td><%= post_version.parent_id %></td>
<% if CurrentUser.is_moderator? %>
<td>
<%= link_to_ip post_version.updater_ip_addr %>
</td>
<% end %>
<td class="col-expand"><%= post_version_diff(post_version) %></td>
<td>
<% if post_version.can_undo?(CurrentUser.user) %>
<%= link_to "Undo", undo_post_version_path(post_version), method: :put, remote: true, class: "post-version-undo-link" %> |
<% end %>
<% if post_version.can_revert_to?(CurrentUser.user) %>
<%= link_to "Revert to", revert_post_path(post_version.post_id, version_id: post_version.id), method: :put, remote: true %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@@ -7,12 +7,7 @@
<% if @post_versions.length == 0 %>
<%= render "post_sets/blank" %>
<% else %>
<% if params.dig(:search, :post_id).present? %>
<%= render "revert_listing" %>
<% else %>
<%= render "standard_listing" %>
<% end %>
<%= render "listing" %>
<%= numbered_paginator(@post_versions) %>
<% end %>
</div>