diff --git a/app/helpers/note_versions_helper.rb b/app/helpers/note_versions_helper.rb new file mode 100644 index 000000000..e007faba1 --- /dev/null +++ b/app/helpers/note_versions_helper.rb @@ -0,0 +1,30 @@ +module NoteVersionsHelper + 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}" + 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 = '' + html + '' + html.html_safe + end + end +end diff --git a/app/models/note_version.rb b/app/models/note_version.rb index 02c6d92d8..5bbfadc81 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -28,6 +28,10 @@ class NoteVersion < ActiveRecord::Base self.updater_ip_addr = CurrentUser.ip_addr end + def previous + NoteVersion.where("note_id = ? and created_at < ?", note_id, created_at).order("created_at desc").first + end + def updater_name User.id_to_name(updater_id) end diff --git a/app/views/note_versions/index.html.erb b/app/views/note_versions/index.html.erb index eafb61a5c..ccbda932a 100644 --- a/app/views/note_versions/index.html.erb +++ b/app/views/note_versions/index.html.erb @@ -9,6 +9,7 @@ Post Note Body + Position <% if CurrentUser.is_janitor? %> IP Address <% end %> @@ -30,6 +31,10 @@ <% unless note_version.is_active? %> (deleted) <% end %> + <%= note_version_body_diff_info(note_version) %> + + + <%= note_version_position_diff(note_version) %> <% if CurrentUser.is_janitor? %>