diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a68e056f2..d79308cab 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -39,6 +39,10 @@ class ApplicationController < ActionController::Base
super
end
+ def set_version_comparison
+ params[:type] = %w[previous subsequent current].include?(params[:type]) ? params[:type] : "previous"
+ end
+
def model_name
controller_name.classify
end
diff --git a/app/controllers/artist_commentary_versions_controller.rb b/app/controllers/artist_commentary_versions_controller.rb
index cee5140c2..49a497a4f 100644
--- a/app/controllers/artist_commentary_versions_controller.rb
+++ b/app/controllers/artist_commentary_versions_controller.rb
@@ -2,6 +2,7 @@ class ArtistCommentaryVersionsController < ApplicationController
respond_to :html, :xml, :json
def index
+ set_version_comparison
@commentary_versions = ArtistCommentaryVersion.paginated_search(params)
@commentary_versions = @commentary_versions.includes(:updater, post: :uploader) if request.format.html?
diff --git a/app/controllers/artist_versions_controller.rb b/app/controllers/artist_versions_controller.rb
index 54262e560..1c2efa6c9 100644
--- a/app/controllers/artist_versions_controller.rb
+++ b/app/controllers/artist_versions_controller.rb
@@ -2,6 +2,7 @@ class ArtistVersionsController < ApplicationController
respond_to :html, :xml, :json
def index
+ set_version_comparison
@artist_versions = ArtistVersion.paginated_search(params)
@artist_versions = @artist_versions.includes(:updater, artist: :urls) if request.format.html?
diff --git a/app/controllers/note_versions_controller.rb b/app/controllers/note_versions_controller.rb
index a5b224d8d..b217925f6 100644
--- a/app/controllers/note_versions_controller.rb
+++ b/app/controllers/note_versions_controller.rb
@@ -2,6 +2,7 @@ class NoteVersionsController < ApplicationController
respond_to :html, :xml, :json
def index
+ set_version_comparison
@note_versions = NoteVersion.paginated_search(params)
@note_versions = @note_versions.includes(:updater) if request.format.html?
diff --git a/app/controllers/pool_versions_controller.rb b/app/controllers/pool_versions_controller.rb
index f4bc9967f..13a68bd79 100644
--- a/app/controllers/pool_versions_controller.rb
+++ b/app/controllers/pool_versions_controller.rb
@@ -4,6 +4,7 @@ class PoolVersionsController < ApplicationController
around_action :set_timeout
def index
+ set_version_comparison
@pool_versions = PoolVersion.paginated_search(params)
@pool_versions = @pool_versions.includes(:updater, :pool) if request.format.html?
@@ -19,7 +20,8 @@ class PoolVersionsController < ApplicationController
if params[:other_id]
@other_version = PoolVersion.find(params[:other_id])
else
- @other_version = @pool_version.previous
+ set_version_comparison
+ @other_version = @pool_version.send(params[:type])
end
end
diff --git a/app/controllers/post_versions_controller.rb b/app/controllers/post_versions_controller.rb
index 278ab643a..71d3e77cc 100644
--- a/app/controllers/post_versions_controller.rb
+++ b/app/controllers/post_versions_controller.rb
@@ -6,6 +6,7 @@ class PostVersionsController < ApplicationController
respond_to :js, only: [:undo]
def index
+ set_version_comparison
@post_versions = PostVersion.paginated_search(params)
if request.format.html?
diff --git a/app/controllers/wiki_page_versions_controller.rb b/app/controllers/wiki_page_versions_controller.rb
index 7293f72a9..ac9873514 100644
--- a/app/controllers/wiki_page_versions_controller.rb
+++ b/app/controllers/wiki_page_versions_controller.rb
@@ -3,6 +3,7 @@ class WikiPageVersionsController < ApplicationController
layout "sidebar"
def index
+ set_version_comparison
@wiki_page_versions = WikiPageVersion.paginated_search(params)
@wiki_page_versions = @wiki_page_versions.includes(:updater) if request.format.html?
@@ -16,15 +17,20 @@ class WikiPageVersionsController < ApplicationController
def diff
if params[:thispage].blank? || params[:otherpage].blank?
- redirect_back fallback_location: wiki_pages_path, notice: "You must select two versions to diff"
- return
- end
-
- @thispage = WikiPageVersion.find(params[:thispage])
- @otherpage = WikiPageVersion.find(params[:otherpage])
-
- if @thispage.id < @otherpage.id
- @thispage, @otherpage = @otherpage, @thispage
+ page_id = params[:thispage] || params[:otherpage]
+ if page_id.blank?
+ redirect_back fallback_location: wiki_pages_path, notice: "You must select at least one version to diff"
+ return
+ end
+ set_version_comparison
+ @thispage = WikiPageVersion.find(page_id)
+ @otherpage = @thispage.send(params[:type])
+ else
+ @thispage = WikiPageVersion.find(params[:thispage])
+ @otherpage = WikiPageVersion.find(params[:otherpage])
+ if @thispage.id < @otherpage.id
+ @thispage, @otherpage = @otherpage, @thispage
+ end
end
respond_with([@thispage, @otherpage])
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0548842b6..dc1080b8a 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -5,37 +5,45 @@ module ApplicationHelper
(fields.reduce(false) { |acc, field| acc || params.dig(:search, field).present? } && (!member_check || CurrentUser.is_member?) ? types[0] : types[1])
end
- def diff_list_html(new, old, latest, ul_class: ["diff-list"], li_class: [])
- diff = SetDiff.new(new, old, latest)
+ def diff_list_html(this_list, other_list, ul_class: ["diff-list"], li_class: [])
+ diff = SetDiff.new(this_list, other_list)
render "diff_list", diff: diff, ul_class: ul_class, li_class: li_class
end
- def diff_name_html(this_name, prev_name)
+ def diff_name_html(this_name, other_name)
pattern = Regexp.new('.')
- DiffBuilder.new(this_name, prev_name, pattern).build
+ DiffBuilder.new(this_name, other_name, pattern).build
end
- def diff_body_html(record, previous, field)
- return h(record[field]).gsub(/\r?\n/, '¶
').html_safe if previous.blank?
+ def diff_body_html(record, other, field)
+ if record.blank? || other.blank?
+ diff_record = other.presence || record
+ return h(diff_record[field]).gsub(/\r?\n/, '¶
').html_safe
+ end
pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
- DiffBuilder.new(record[field], previous[field], pattern).build
+ DiffBuilder.new(record[field], other[field], pattern).build
end
- def status_diff_html(record)
- previous = record.previous
+ def status_diff_html(record, type)
+ other = record.send(type)
- return "New" if previous.blank?
+ if other.blank?
+ return type == "previous" ? "New" : ""
+ end
statuses = []
record.class.status_fields.each do |field, status|
if record.has_attribute?(field)
- statuses += [status] if record[field] != previous[field]
+ statuses += [status] if record[field] != other[field]
else
- statuses += [status] if record.send(field)
+ statuses += [status] if record.send(field, type)
end
end
- statuses.join("
").html_safe
+
+ altered = record.updater_id != other.updater_id
+
+ %(
Showing differences between <%= compact_time @pool_version.updated_at %> (<%= link_to_user @pool_version.updater %>) and <%= compact_time @other_version.updated_at %> (<%= link_to_user @other_version.updater %>)
+ <% if @pool_version.id != @other_version.id %> +Showing differences between <%= compact_time @pool_version.updated_at %> (<%= link_to_user @pool_version.updater %>) and <%= compact_time @other_version.updated_at %> (<%= link_to_user @other_version.updater %>)
- <% if @pool_version.description != @other_version.description %> -No changes to description.
+ <% end %> <% else %> -No changes to description.
+Version is latest!
<% end %> + <% else %> +No versions to compare!
<% end %>Showing differences between <%= compact_time @thispage.updated_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.updated_at %> (<%= link_to_user @otherpage.updater %>)
- - <% if wiki_version_show_other_names(@thispage, @otherpage) %> -<%= wiki_version_other_names_diff(@thispage, @otherpage) %>
- <% else %> -No changes to other names.
+ <% if params[:type].present? %> + <%= render "versions/types" %> <% end %> - <% if @thispage.body != @otherpage.body %> -Showing differences between <%= compact_time @thispage.updated_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.updated_at %> (<%= link_to_user @otherpage.updater %>)
+ + <% if wiki_version_show_other_names(@thispage, @otherpage) %> +<%= wiki_version_other_names_diff(@thispage, @otherpage) %>
+ <% else %> +No changes to other names.
+ <% end %> + + <% if @thispage.body != @otherpage.body %> +No changes to body.
+ <% end %> + <% else %> +Version is latest!
+ <% end %> <% else %> -No changes to body.
+No versions to compare!
<% end %> <% end %> diff --git a/app/views/wiki_page_versions/index.html.erb b/app/views/wiki_page_versions/index.html.erb index 33613d14f..382ecf479 100644 --- a/app/views/wiki_page_versions/index.html.erb +++ b/app/views/wiki_page_versions/index.html.erb @@ -3,6 +3,8 @@ <% content_for(:content) do %>