diff --git a/app/helpers/note_versions_helper.rb b/app/helpers/note_versions_helper.rb index c29996ef0..e020b5c45 100644 --- a/app/helpers/note_versions_helper.rb +++ b/app/helpers/note_versions_helper.rb @@ -1,34 +1,23 @@ 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) - previous = note_version.previous - if previous.nil? - return "" - end - - html = "" - if note_version.body == previous.body - html += '(body not changed)' - end - - html.html_safe - end - def note_version_position_diff(note_version) previous = note_version.previous - html = "#{note_version.width}x#{note_version.height}" - html += " #{note_version.x},#{note_version.y}" + 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 + else + "#{previous.x},#{previous.y} -> " + html + end + end + + def note_version_size_diff(note_version) + previous = note_version.previous + + html = "#{note_version.width}x#{note_version.height}" + if previous.nil? html else - html = '' + html + '' - html.html_safe + "#{previous.width}x#{previous.height} -> " + html end end end diff --git a/app/models/note_version.rb b/app/models/note_version.rb index 3cc1c56ea..0e65e5738 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -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 diff --git a/app/views/note_versions/_listing.html.erb b/app/views/note_versions/_listing.html.erb index eb95d5c6e..8449b678d 100644 --- a/app/views/note_versions/_listing.html.erb +++ b/app/views/note_versions/_listing.html.erb @@ -1,35 +1,39 @@ -
+
<%= 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? %> - (deleted) - <% 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| %> + <% t.column "Size (WxH)", width: "5%", column: "size" do |note_version| %> + <%= note_version_size_diff(note_version) %> + <% end %> + <% t.column "Changes", width: "3%" do |note_version| %> + <%= status_diff_html(note_version) %> + <% end %> + <% t.column "Updated", width: "10%" do |note_version| %> +
+ <%= compact_time note_version.updated_at %> +
+ by <%= link_to_user note_version.updater %> + <%= link_to "»", note_versions_path(search: params[:search].merge({ updater_id: note_version.updater_id })) %> <% end %> - <% t.column "Date", width: "10%" do |note_version| %> - <%= compact_time note_version.updated_at %> - <% 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 %>