Commit d8fd1c21 authored by BrokenEagle's avatar BrokenEagle

Revise display on note versions index

- Body now uses the diff builder to highlight changes
-- A generalized diff-body class was added instead of something specific
- The status changes are now verbalized instead of being shown with styles
- The position and sizes are now split up
-- Changes directly reference the previous version
- The date and user columns were combined
-- This is more in line with other indexes, plus it saves space
parent 154849a5
module NoteVersionsHelper
def note_versions_listing_type
((params.dig(:search, :post_id).present? || params.dig(:search, :note_id).present?) && CurrentUser.is_member?) ? :revert : :standard
end
def note_version_body_diff_info(note_version)
def note_version_position_diff(note_version)
previous = note_version.previous
if previous.nil?
return ""
end
html = ""
if note_version.body == previous.body
html += '<span class="inactive">(body not changed)</span>'
html = "#{note_version.x},#{note_version.y}"
if previous.nil?
html
else
"#{previous.x},#{previous.y} -> " + html
end
html.html_safe
end
def note_version_position_diff(note_version)
def note_version_size_diff(note_version)
previous = note_version.previous
html = "#{note_version.width}x#{note_version.height}"
html += " #{note_version.x},#{note_version.y}"
if previous.nil?
html
elsif note_version.x == previous.x && note_version.y == previous.y && note_version.width == previous.width && note_version.height == previous.height
html
else
html = '<span style="text-decoration: underline;">' + html + '</span>'
html.html_safe
"#{previous.width}x#{previous.height} -> " + html
end
end
end
......@@ -18,4 +18,30 @@ class NoteVersion < ApplicationRecord
end
@previous.first
end
def self.status_fields
{
body: "Body",
was_moved: "Moved",
was_resized: "Resized",
was_deleted: "Deleted",
was_undeleted: "Undeleted",
}
end
def was_moved
x != previous.x || y != previous.y
end
def was_resized
width != previous.width || height != previous.height
end
def was_deleted
!is_active && previous.is_active
end
def was_undeleted
is_active && !previous.is_active
end
end
<div id="p-<%= note_versions_listing_type %>-listing">
<div id="p-<%= listing_type(:post_id, :note_id) %>-listing">
<%= table_for @note_versions, {class: "striped autofit", width: "100%"} do |t| %>
<% t.column "Post", width: "5%" do |note_version| %>
<%= link_to note_version.post_id, post_path(note_version.post_id) %>
<% if !params.dig(:search, :post_id).present? %>
<%= link_to "»", note_versions_path(search: {post_id: note_version.post_id}) %>
<%= link_to "»", note_versions_path(search: {post_id: note_version.post_id}, anchor: "note-version-#{note_version.id}") %>
<% end %>
<% end %>
<% t.column "Note", width: "5%" do |note_version| %>
<%= link_to "#{note_version.note_id}.#{note_version.version}", post_path(note_version.post_id, anchor: "note-#{note_version.note_id}") %>
<% if !params.dig(:search, :note_id).present? %>
<%= link_to "»", note_versions_path(search: {note_id: note_version.note_id}) %>
<%= link_to "»", note_versions_path(search: {note_id: note_version.note_id}, anchor: "note-version-#{note_version.id}") %>
<% end %>
<% end %>
<% t.column "Body", td: {class: "col-expand"} do |note_version| %>
<%= h(note_version.body) %>
<% unless note_version.is_active? %>
<span class="inactive">(deleted)</span>
<% end %>
<%= note_version_body_diff_info(note_version) %>
<% t.column "Body", td: {class: "col-expand diff-body"} do |note_version| %>
<%= diff_body_html(note_version, note_version.previous, :body) %>
<% end %>
<% t.column "Position", width: "5%" do |note_version| %>
<% t.column "Position (X,Y)", width: "5%", column: "position" do |note_version| %>
<%= note_version_position_diff(note_version) %>
<% end %>
<% t.column "Edited By", width: "10%" do |note_version| %>
<%= link_to_user note_version.updater %>
<% t.column "Size (WxH)", width: "5%", column: "size" do |note_version| %>
<%= note_version_size_diff(note_version) %>
<% end %>
<% t.column "Date", width: "10%" do |note_version| %>
<%= compact_time note_version.updated_at %>
<% t.column "Changes", width: "3%" do |note_version| %>
<%= status_diff_html(note_version) %>
<% end %>
<% t.column "Updated", width: "10%" do |note_version| %>
<div>
<%= compact_time note_version.updated_at %>
</div>
by
<%= link_to_user note_version.updater %>
<%= link_to "»", note_versions_path(search: params[:search].merge({ updater_id: note_version.updater_id })) %>
<% end %>
<% if note_versions_listing_type == :revert %>
<% if listing_type(:post_id, :note_id) == :revert %>
<% t.column column: "control", width: "7%" do |note_version| %>
<%= link_to "Revert to", revert_note_path(note_version.note_id, :version_id => note_version.id), :remote => true, :method => :put, :data => {:confirm => "Are you sure you want to revert to this version?"} %>
<% end %>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment