Rework wiki page versions index/diff views

- Changed to using the diff-body CSS class
-- Removed unnecessary elements from the CSS style file
- Does a symmetric difference on the array fields to detect differences
- Add more descriptors to the status/changes column
- Specifically add <br> to statuses to cause line breaks
This commit is contained in:
BrokenEagle
2020-02-08 06:56:01 +00:00
parent ede7167bb8
commit de1324098d
5 changed files with 33 additions and 37 deletions

View File

@@ -1,21 +1,4 @@
module WikiPageVersionsHelper module WikiPageVersionsHelper
def wiki_page_versions_listing_type
params.dig(:search, :wiki_page_id).present? ? :page : :global
end
def wiki_page_version_status_diff(wiki_page_version)
cur = wiki_page_version
prev = wiki_page_version.previous
return "New" if prev.blank?
status = []
status += ["Renamed"] if cur.title != prev.title
status += ["Deleted"] if cur.is_deleted? && !prev.is_deleted?
status += ["Undeleted"] if !cur.is_deleted? && prev.is_deleted?
status.join(" ")
end
def wiki_other_names_diff(new_version, old_version) def wiki_other_names_diff(new_version, old_version)
new_names = new_version.other_names new_names = new_version.other_names
old_names = old_version.other_names old_names = old_version.other_names
@@ -23,9 +6,4 @@ module WikiPageVersionsHelper
diff_list_html(new_names, old_names, latest_names, ul_class: ["wiki-other-names-diff-list list-inline"], li_class: ["wiki-other-name"]) diff_list_html(new_names, old_names, latest_names, ul_class: ["wiki-other-names-diff-list list-inline"], li_class: ["wiki-other-name"])
end end
def wiki_body_diff(thispage, otherpage)
pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
DiffBuilder.new(thispage.body, otherpage.body, pattern).build
end
end end

View File

@@ -1,22 +1,18 @@
div#c-wiki-page-versions { div#c-wiki-page-versions {
#a-diff { #a-diff {
del, .wiki-other-names-diff-list .removed { ul.wiki-other-names-diff-list li.removed {
background: var(--wiki-page-versions-diff-del-background); background: var(--wiki-page-versions-diff-del-background);
text-decoration: none; text-decoration: none;
} }
ins, .wiki-other-names-diff-list .added { ul.wiki-other-names-diff-list li.added {
background: var(--wiki-page-versions-diff-ins-background); background: var(--wiki-page-versions-diff-ins-background);
text-decoration: none; text-decoration: none;
} }
.wiki-other-names-diff-list .obsolete { ul.wiki-other-names-diff-list li.obsolete {
text-decoration: dotted underline; text-decoration: dotted underline;
} }
span.paragraph-mark {
opacity: 0.25;
}
} }
#a-index { #a-index {

View File

@@ -29,6 +29,28 @@ class WikiPageVersion < ApplicationRecord
@previous.first @previous.first
end end
def self.status_fields
{
body: "Body",
other_names_changed: "OtherNames",
title: "Renamed",
was_deleted: "Deleted",
was_undeleted: "Undeleted",
}
end
def other_names_changed
((other_names - previous.other_names) | (previous.other_names - other_names)).length > 0
end
def was_deleted
is_deleted && !previous.is_deleted
end
def was_undeleted
!is_deleted && previous.is_deleted
end
def category_name def category_name
Tag.category_for(title) Tag.category_for(title)
end end

View File

@@ -1,11 +1,11 @@
<div id="p-<%= wiki_page_versions_listing_type %>-listing"> <div id="p-<%= listing_type(:wiki_page_id, member_check: false, types: [:page, :global]) %>-listing">
<%= form_tag(diff_wiki_page_versions_path, :method => :get) do %> <%= form_tag(diff_wiki_page_versions_path, :method => :get) do %>
<%= table_for @wiki_page_versions, width: "100%" do |t| %> <%= table_for @wiki_page_versions, width: "100%" do |t| %>
<% t.column column: "diff", width: "3%" do |wiki_page_version, i| %> <% t.column column: "diff", width: "3%" do |wiki_page_version, i| %>
<%= link_to_if wiki_page_version.previous.present?, "diff", diff_wiki_page_versions_path(otherpage: wiki_page_version.previous.try(:id), thispage: wiki_page_version.id) %> <%= link_to_if wiki_page_version.previous.present?, "diff", diff_wiki_page_versions_path(otherpage: wiki_page_version.previous.try(:id), thispage: wiki_page_version.id) %>
<% end %> <% end %>
<% if wiki_page_versions_listing_type == :page %> <% if listing_type(:wiki_page_id, member_check: false, types: [:page, :global]) == :page %>
<% t.column column: "this-page", width: "2%" do |wiki_page_version, i| %> <% t.column column: "this-page", width: "2%" do |wiki_page_version, i| %>
<%= radio_button_tag "thispage", wiki_page_version.id, (i == 1) %> <%= radio_button_tag "thispage", wiki_page_version.id, (i == 1) %>
<% end %> <% end %>
@@ -21,10 +21,10 @@
<%= link_to "»", wiki_page_versions_path(search: { wiki_page_id: wiki_page_version.wiki_page_id }) %> <%= link_to "»", wiki_page_versions_path(search: { wiki_page_id: wiki_page_version.wiki_page_id }) %>
</span> </span>
<% end %> <% end %>
<% t.column "Status", width: "5%" do |wiki_page_version| %> <% t.column "Changes", width: "5%" do |wiki_page_version| %>
<%= wiki_page_version_status_diff(wiki_page_version) %> <%= status_diff_html(wiki_page_version) %>
<% end %> <% end %>
<% t.column "Last edited", width: "26%" do |wiki_page_version| %> <% t.column "Updated", width: "26%" do |wiki_page_version| %>
<%= compact_time(wiki_page_version.updated_at) %> <%= compact_time(wiki_page_version.updated_at) %>
by by
<%= link_to_user wiki_page_version.updater %> <%= link_to_user wiki_page_version.updater %>
@@ -32,7 +32,7 @@
<% end %> <% end %>
<% end %> <% end %>
<% if wiki_page_versions_listing_type == :page %> <% if listing_type(:wiki_page_id, member_check: false, types: [:page, :global]) == :page %>
<%= submit_tag "Diff" %> <%= submit_tag "Diff" %>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -10,7 +10,7 @@
<%= wiki_other_names_diff(@thispage, @otherpage) %> <%= wiki_other_names_diff(@thispage, @otherpage) %>
<div> <div class="diff-body">
<%= wiki_body_diff(@thispage, @otherpage) %> <%= diff_body_html(@thispage, @otherpage, :body) %>
</div> </div>
<% end %> <% end %>