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:
@@ -1,21 +1,4 @@
|
||||
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)
|
||||
new_names = new_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"])
|
||||
end
|
||||
|
||||
def wiki_body_diff(thispage, otherpage)
|
||||
pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
|
||||
DiffBuilder.new(thispage.body, otherpage.body, pattern).build
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
div#c-wiki-page-versions {
|
||||
#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);
|
||||
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);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.wiki-other-names-diff-list .obsolete {
|
||||
ul.wiki-other-names-diff-list li.obsolete {
|
||||
text-decoration: dotted underline;
|
||||
}
|
||||
|
||||
span.paragraph-mark {
|
||||
opacity: 0.25;
|
||||
}
|
||||
}
|
||||
|
||||
#a-index {
|
||||
|
||||
@@ -29,6 +29,28 @@ class WikiPageVersion < ApplicationRecord
|
||||
@previous.first
|
||||
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
|
||||
Tag.category_for(title)
|
||||
end
|
||||
|
||||
@@ -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 %>
|
||||
<%= table_for @wiki_page_versions, width: "100%" do |t| %>
|
||||
<% 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) %>
|
||||
<% 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| %>
|
||||
<%= radio_button_tag "thispage", wiki_page_version.id, (i == 1) %>
|
||||
<% end %>
|
||||
@@ -21,10 +21,10 @@
|
||||
<%= link_to "»", wiki_page_versions_path(search: { wiki_page_id: wiki_page_version.wiki_page_id }) %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% t.column "Status", width: "5%" do |wiki_page_version| %>
|
||||
<%= wiki_page_version_status_diff(wiki_page_version) %>
|
||||
<% t.column "Changes", width: "5%" do |wiki_page_version| %>
|
||||
<%= status_diff_html(wiki_page_version) %>
|
||||
<% 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) %>
|
||||
by
|
||||
<%= link_to_user wiki_page_version.updater %>
|
||||
@@ -32,7 +32,7 @@
|
||||
<% 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" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<%= wiki_other_names_diff(@thispage, @otherpage) %>
|
||||
|
||||
<div>
|
||||
<%= wiki_body_diff(@thispage, @otherpage) %>
|
||||
<div class="diff-body">
|
||||
<%= diff_body_html(@thispage, @otherpage, :body) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user