diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7a63cdd95..6c4a0673d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -40,6 +40,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/reports_controller.rb b/app/controllers/reports_controller.rb
deleted file mode 100644
index cf8b4f65c..000000000
--- a/app/controllers/reports_controller.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class ReportsController < ApplicationController
- respond_to :html, :xml, :json
-
- def upload_tags
- @user = User.find(params[:user_id])
- @upload_reports = Reports::UploadTags.includes(versions: { post: :versions }).for_user(params[:user_id]).order("id desc").paginate(params[:page], :limit => params[:limit])
- respond_with(@upload_reports)
- end
-end
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 8a5af6ace..dc1080b8a 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -5,32 +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_body_html(record, previous, field)
- return h(record[field]).gsub(/\r?\n/, '¶
').html_safe if previous.blank?
-
- pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
- DiffBuilder.new(record[field], previous[field], pattern).build
+ def diff_name_html(this_name, other_name)
+ pattern = Regexp.new('.')
+ DiffBuilder.new(this_name, other_name, pattern).build
end
- def status_diff_html(record)
- previous = record.previous
+ 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
- return "New" if previous.blank?
+ pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
+ DiffBuilder.new(record[field], other[field], pattern).build
+ end
+
+ def status_diff_html(record, type)
+ other = record.send(type)
+
+ 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
+
+ %(
#{statuses.join("
")}
).html_safe
end
def wordbreakify(string)
@@ -39,6 +52,18 @@ module ApplicationHelper
raw(wordbreaked_string)
end
+ def version_type_links(params)
+ html = []
+ %w[previous subsequent current].each do |type|
+ if type == params[:type]
+ html << %(#{type})
+ else
+ html << tag.li(link_to(type, params.except(:controller, :action).merge(type: type).permit!))
+ end
+ end
+ html.join(" | ").html_safe
+ end
+
def nav_link_to(text, url, **options)
klass = options.delete(:class)
diff --git a/app/helpers/artist_commentary_versions_helper.rb b/app/helpers/artist_commentary_versions_helper.rb
new file mode 100644
index 000000000..30d05befc
--- /dev/null
+++ b/app/helpers/artist_commentary_versions_helper.rb
@@ -0,0 +1,10 @@
+module ArtistCommentaryVersionsHelper
+ def commentary_version_field_diff(commentary_version, type, field)
+ other = commentary_version.send(params[:type])
+ if type == "previous"
+ diff_body_html(commentary_version, other, field)
+ else
+ diff_body_html(other, commentary_version, field)
+ end
+ end
+end
diff --git a/app/helpers/artist_versions_helper.rb b/app/helpers/artist_versions_helper.rb
index 1f55b471e..3e5a366f6 100644
--- a/app/helpers/artist_versions_helper.rb
+++ b/app/helpers/artist_versions_helper.rb
@@ -1,17 +1,66 @@
module ArtistVersionsHelper
- def artist_version_other_names_diff(artist_version)
- new_names = artist_version.other_names
- old_names = artist_version.previous.try(:other_names)
- latest_names = artist_version.artist.other_names
+ def artist_version_other_names_diff(artist_version, type)
+ other = artist_version.send(type)
+ this_names = artist_version.other_names
+ if other.present?
+ other_names = other.other_names
+ elsif type == "subsequent"
+ other_names = this_names
+ else
+ other_names = []
+ end
- diff_list_html(new_names, old_names, latest_names)
+ if type == "previous"
+ diff_list_html(this_names, other_names)
+ else
+ diff_list_html(other_names, this_names)
+ end
end
- def artist_version_urls_diff(artist_version)
- new_urls = artist_version.urls
- old_urls = artist_version.previous.try(:urls)
- latest_urls = artist_version.artist.urls.map(&:to_s)
+ def artist_version_urls_diff(artist_version, type)
+ other = artist_version.send(type)
+ this_urls = artist_version.urls
+ if other.present?
+ other_urls = other.urls
+ elsif type == "subsequent"
+ other_urls = this_urls
+ else
+ other_urls = []
+ end
- diff_list_html(new_urls, old_urls, latest_urls)
+ if type == "previous"
+ diff_list_html(this_urls, other_urls)
+ else
+ diff_list_html(other_urls, this_urls)
+ end
+ end
+
+ def artist_version_name_diff(artist_version, type)
+ other = artist_version.send(type)
+ if other.present? && (artist_version.name != other.name)
+ if type == "previous"
+ name_diff = diff_name_html(artist_version.name, other.name)
+ else
+ name_diff = diff_name_html(other.name, artist_version.name)
+ end
+ %(
Rename:
#{name_diff}).html_safe
+ else
+ ""
+ end
+ end
+
+ def artist_version_group_name_diff(artist_version, type)
+ other = artist_version.send(type)
+ if artist_version.group_name.present? || (other.present? && other.group_name.present?)
+ other_group_name = (other.present? ? other.group_name : artist_version.group_name)
+ if type == "previous"
+ group_name_diff = diff_name_html(artist_version.group_name, other_group_name)
+ else
+ group_name_diff = diff_name_html(other_group_name, artist_version.group_name)
+ end
+ %(Group:
#{group_name_diff}
).html_safe
+ else
+ ""
+ end
end
end
diff --git a/app/helpers/note_versions_helper.rb b/app/helpers/note_versions_helper.rb
index f2fc16377..e3a29b1fa 100644
--- a/app/helpers/note_versions_helper.rb
+++ b/app/helpers/note_versions_helper.rb
@@ -1,23 +1,36 @@
module NoteVersionsHelper
- def note_version_position_diff(note_version)
- previous = note_version.previous
+ def note_version_position_diff(note_version, type)
+ other = note_version.send(type)
html = "#{note_version.x},#{note_version.y}"
- if previous.nil? || (note_version.x == previous.x && note_version.y == previous.y)
+ if other.nil? || (note_version.x == other.x && note_version.y == other.y)
html
+ elsif type == "previous"
+ "#{other.x},#{other.y} -> " + html
else
- "#{previous.x},#{previous.y} -> " + html
+ html + " -> #{other.x},#{other.y}"
end
end
- def note_version_size_diff(note_version)
- previous = note_version.previous
+ def note_version_size_diff(note_version, type)
+ other = note_version.send(type)
html = "#{note_version.width}x#{note_version.height}"
- if previous.nil? || (note_version.width == previous.width && note_version.height == previous.height)
+ if other.nil? || (note_version.width == other.width && note_version.height == other.height)
html
+ elsif type == "previous"
+ "#{other.width}x#{other.height} -> " + html
else
- "#{previous.width}x#{previous.height} -> " + html
+ html + " -> #{other.width}x#{other.height}"
+ end
+ end
+
+ def note_version_body_diff(note_version, type)
+ other = note_version.send(params[:type])
+ if type == "previous"
+ diff_body_html(note_version, other, :body)
+ else
+ diff_body_html(other, note_version, :body)
end
end
end
diff --git a/app/helpers/pool_versions_helper.rb b/app/helpers/pool_versions_helper.rb
new file mode 100644
index 000000000..71cf87c7f
--- /dev/null
+++ b/app/helpers/pool_versions_helper.rb
@@ -0,0 +1,40 @@
+module PoolVersionsHelper
+ def pool_version_show_diff(pool_version, type)
+ other = pool_version.send(type)
+ other.present? && pool_version.description != other.description
+ end
+
+ def pool_version_name_diff(pool_version, type)
+ other = pool_version.send(type)
+ if other.present? && (pool_version.name != other.name)
+ if type == "previous"
+ name_diff = diff_name_html(pool_version.name, other.name)
+ else
+ name_diff = diff_name_html(other.name, pool_version.name)
+ end
+ %(
Rename:
#{name_diff}).html_safe
+ else
+ ""
+ end
+ end
+
+ def pool_version_post_diff(pool_version, type)
+ other = pool_version.send(type)
+ diff = {}
+
+ if other.present? && type == "previous"
+ diff[:added_post_ids] = pool_version.post_ids - other.post_ids
+ diff[:removed_post_ids] = other.post_ids - pool_version.post_ids
+ elsif other.present?
+ diff[:added_post_ids] = other.post_ids - pool_version.post_ids
+ diff[:removed_post_ids] = pool_version.post_ids - other.post_ids
+ elsif type == "previous"
+ diff[:added_post_ids] = pool_version.added_post_ids
+ diff[:removed_post_ids] = pool_version.removed_post_ids
+ else
+ return ""
+ end
+
+ render "pool_versions/diff", diff: diff
+ end
+end
diff --git a/app/helpers/post_versions_helper.rb b/app/helpers/post_versions_helper.rb
index 062deebf4..a4d8f1144 100644
--- a/app/helpers/post_versions_helper.rb
+++ b/app/helpers/post_versions_helper.rb
@@ -1,19 +1,41 @@
module PostVersionsHelper
- def post_version_diff(post_version)
- diff = post_version.diff(post_version.previous)
+ def post_version_diff(post_version, type)
+ other = post_version.send(type)
+
+ this_tags = post_version.tag_array
+ this_tags << "rating:#{post_version.rating}" if post_version.rating.present?
+ this_tags << "parent:#{post_version.parent_id}" if post_version.parent_id.present?
+ this_tags << "source:#{post_version.source}" if post_version.source.present?
+
+ other_tags = other.present? ? other.tag_array : []
+ if other.present?
+ other_tags << "rating:#{other.rating}" if other.rating.present?
+ other_tags << "parent:#{other.parent_id}" if other.parent_id.present?
+ other_tags << "source:#{other.source}" if other.source.present?
+ elsif type == "subsequent"
+ other_tags = this_tags
+ end
+
+ if type == "previous"
+ added_tags = this_tags - other_tags
+ removed_tags = other_tags - this_tags
+ else
+ added_tags = other_tags - this_tags
+ removed_tags = this_tags - other_tags
+ end
+ unchanged_tags = this_tags & other_tags
+
html = ''
- diff[:added_tags].each do |tag|
- prefix = diff[:obsolete_added_tags].include?(tag) ? '+' : '+'
- html << prefix + link_to(wordbreakify(tag), posts_path(:tags => tag)) + ''
+ added_tags.each do |tag|
+ html << '+' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + ''
html << " "
end
- diff[:removed_tags].each do |tag|
- prefix = diff[:obsolete_removed_tags].include?(tag) ? '-' : '-'
- html << prefix + link_to(wordbreakify(tag), posts_path(:tags => tag)) + ''
+ removed_tags.each do |tag|
+ html << '-' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + ''
html << " "
end
- diff[:unchanged_tags].each do |tag|
+ unchanged_tags.each do |tag|
html << '' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + ''
html << " "
end
diff --git a/app/helpers/wiki_page_versions_helper.rb b/app/helpers/wiki_page_versions_helper.rb
index 0dd614045..11123d929 100644
--- a/app/helpers/wiki_page_versions_helper.rb
+++ b/app/helpers/wiki_page_versions_helper.rb
@@ -1,9 +1,31 @@
module WikiPageVersionsHelper
- def wiki_other_names_diff(new_version, old_version)
- new_names = new_version.other_names
- old_names = old_version.other_names
- latest_names = new_version.wiki_page.other_names
+ def wiki_version_show_diff(wiki_page_version, type)
+ other = wiki_page_version.send(type)
+ other.present? && ((wiki_page_version.body != other.body) || wiki_page_version.other_names_changed(type))
+ end
- diff_list_html(new_names, old_names, latest_names, ul_class: ["wiki-other-names-diff-list list-inline"], li_class: ["wiki-other-name"])
+ def wiki_version_show_other_names(this_version, other_version)
+ ((this_version.other_names - other_version.other_names) | (other_version.other_names - this_version.other_names)).length.positive?
+ end
+
+ def wiki_version_other_names_diff(this_version, other_version)
+ this_names = this_version.other_names
+ other_names = other_version.other_names
+
+ diff_list_html(this_names, other_names, ul_class: ["wiki-other-names-diff-list list-inline"], li_class: ["wiki-other-name"])
+ end
+
+ def wiki_version_title_diff(wiki_page_version, type)
+ other = wiki_page_version.send(type)
+ if other.present? && (wiki_page_version.title != other.title)
+ if type == "previous"
+ name_diff = diff_name_html(wiki_page_version.title, other.title)
+ else
+ name_diff = diff_name_html(other.title, wiki_page_version.title)
+ end
+ %((Rename: #{name_diff})).html_safe
+ else
+ ""
+ end
end
end
diff --git a/app/javascript/src/styles/base/040_colors.css b/app/javascript/src/styles/base/040_colors.css
index 1b7c51541..beef5495a 100644
--- a/app/javascript/src/styles/base/040_colors.css
+++ b/app/javascript/src/styles/base/040_colors.css
@@ -89,8 +89,6 @@
--diff-list-added-color: green;
--diff-list-removed-color: red;
- --diff-list-obsolete-added-color: darkGreen;
- --diff-list-obsolete-removed-color: darkRed;
--wiki-page-versions-diff-del-background: #FCC;
--wiki-page-versions-diff-ins-background: #CFC;
@@ -301,8 +299,6 @@ body[data-current-user-theme="dark"] {
--diff-list-added-color: var(--green-1);
--diff-list-removed-color: var(--red-1);
- --diff-list-obsolete-added-color: var(--green-3);
- --diff-list-obsolete-removed-color: var(--red-3);
--dtext-blockquote-background: var(--grey-3);
--dtext-blockquote-border: 1px solid var(--grey-4);
diff --git a/app/javascript/src/styles/common/diffs.scss b/app/javascript/src/styles/common/diffs.scss
index f126b2e6d..e8d7c9a61 100644
--- a/app/javascript/src/styles/common/diffs.scss
+++ b/app/javascript/src/styles/common/diffs.scss
@@ -5,20 +5,12 @@
margin-right: 0.5em;
}
- .added.obsolete, .added.obsolete a {
- color: var(--diff-list-obsolete-added-color);
- }
-
.removed, .removed a {
color: var(--diff-list-removed-color);
text-decoration: line-through;
margin-right: 0.5em;
}
- .removed.obsolete, .removed.obsolete a {
- color: var(--diff-list-obsolete-removed-color);
- }
-
ins, ins a {
color: var(--diff-list-added-color);
text-decoration: none;
@@ -30,14 +22,6 @@
text-decoration: line-through;
margin-right: 0.5em;
}
-
- ins.obsolete, ins.obsolete a {
- color: var(--diff-list-obsolete-added-color);
- }
-
- del.obsolete, del.obsolete a {
- color: var(--diff-list-obsolete-removed-color);
- }
}
.diff-body {
diff --git a/app/javascript/src/styles/common/versions.scss b/app/javascript/src/styles/common/versions.scss
index 5913cc2b1..5f37cf45e 100644
--- a/app/javascript/src/styles/common/versions.scss
+++ b/app/javascript/src/styles/common/versions.scss
@@ -3,7 +3,7 @@ body.a-index {
display: flex;
table.striped {
- flex: 1;
+ flex: 1;
}
}
@@ -11,3 +11,15 @@ body.a-index {
margin-top: 2em;
}
}
+
+div#version-comparisons {
+ margin-bottom: 1em;
+
+ span {
+ font-weight: bold;
+ }
+
+ ul#version-comparisons-list, ul#version-comparisons-list li {
+ display: inline;
+ }
+}
diff --git a/app/javascript/src/styles/specific/wiki_page_versions.scss b/app/javascript/src/styles/specific/wiki_page_versions.scss
index c83da2c0f..15f895024 100644
--- a/app/javascript/src/styles/specific/wiki_page_versions.scss
+++ b/app/javascript/src/styles/specific/wiki_page_versions.scss
@@ -9,10 +9,6 @@ div#c-wiki-page-versions {
background: var(--wiki-page-versions-diff-ins-background);
text-decoration: none;
}
-
- ul.wiki-other-names-diff-list li.obsolete {
- text-decoration: dotted underline;
- }
}
#a-index {
diff --git a/app/logical/reports/upload_tags.rb b/app/logical/reports/upload_tags.rb
deleted file mode 100644
index d49996079..000000000
--- a/app/logical/reports/upload_tags.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-module Reports
- class UploadTags < ::Post
- def readonly?
- true
- end
-
- def api_attributes
- [:id, :uploader_id, :uploader_tags, :added_tags, :removed_tags]
- end
-
- def uploader_tags_array
- @uploader_tags ||= begin
- uploader_versions = versions.where(updater_id: uploader_id)
- tags = []
- uploader_versions.each do |version|
- tags += version.changes[:added_tags]
- tags -= version.changes[:removed_tags]
- end
- tags.uniq.sort
- end
- end
-
- def current_tags_array
- latest_tags = tag_array
- latest_tags << "rating:#{rating}" if rating.present?
- latest_tags << "parent:#{parent_id}" if parent_id.present?
- latest_tags << "source:#{source}" if source.present?
- latest_tags
- end
-
- def added_tags_array
- current_tags_array - uploader_tags_array
- end
-
- def removed_tags_array
- uploader_tags_array - current_tags_array
- end
-
- def uploader_tags
- uploader_tags_array.join(' ')
- end
-
- def added_tags
- added_tags_array.join(' ')
- end
-
- def removed_tags
- removed_tags_array.join(' ')
- end
- end
-end
diff --git a/app/logical/set_diff.rb b/app/logical/set_diff.rb
index 3bc4b288e..8688b1f05 100644
--- a/app/logical/set_diff.rb
+++ b/app/logical/set_diff.rb
@@ -1,14 +1,12 @@
class SetDiff
- attr_reader :additions, :removals, :added, :removed, :obsolete_added, :obsolete_removed, :changed, :unchanged
+ attr_reader :additions, :removals, :added, :removed, :changed, :unchanged
- def initialize(new, old, latest)
- new, old, latest = new.to_a, old.to_a, latest.to_a
+ def initialize(this_list, other_list)
+ this, other = this_list.to_a, other_list.to_a
- @additions = new - old
- @removals = old - new
- @unchanged = new & old
- @obsolete_added = additions - latest
- @obsolete_removed = removals & latest
+ @additions = this - other
+ @removals = other - this
+ @unchanged = this & other
@added, @removed, @changed = changes(additions, removals)
end
diff --git a/app/models/artist_commentary_version.rb b/app/models/artist_commentary_version.rb
index 1fab760bb..d052810e8 100644
--- a/app/models/artist_commentary_version.rb
+++ b/app/models/artist_commentary_version.rb
@@ -15,6 +15,20 @@ class ArtistCommentaryVersion < ApplicationRecord
@previous.first
end
+ def subsequent
+ @subsequent ||= begin
+ ArtistCommentaryVersion.where("post_id = ? and updated_at > ?", post_id, updated_at).order("updated_at asc").limit(1).to_a
+ end
+ @subsequent.first
+ end
+
+ def current
+ @current ||= begin
+ ArtistCommentaryVersion.where("post_id = ?", post_id).order("updated_at desc").limit(1).to_a
+ end
+ @current.first
+ end
+
def self.status_fields
{
original_title: "OrigTitle",
diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb
index 411f1436f..bcd08fa2b 100644
--- a/app/models/artist_version.rb
+++ b/app/models/artist_version.rb
@@ -30,6 +30,20 @@ class ArtistVersion < ApplicationRecord
@previous.first
end
+ def subsequent
+ @subsequent ||= begin
+ ArtistVersion.where("artist_id = ? and created_at > ?", artist_id, created_at).order("created_at asc").limit(1).to_a
+ end
+ @subsequent.first
+ end
+
+ def current
+ @previous ||= begin
+ ArtistVersion.where("artist_id = ?", artist_id).order("created_at desc").limit(1).to_a
+ end
+ @previous.first
+ end
+
def self.status_fields
{
name: "Renamed",
@@ -43,28 +57,50 @@ class ArtistVersion < ApplicationRecord
}
end
- def other_names_changed
- ((other_names - previous.other_names) | (previous.other_names - other_names)).length > 0
+ def other_names_changed(type)
+ other = self.send(type)
+ ((other_names - other.other_names) | (other.other_names - other_names)).length.positive?
end
- def urls_changed
- ((urls - previous.urls) | (previous.urls - urls)).length > 0
+ def urls_changed(type)
+ other = self.send(type)
+ ((urls - other.urls) | (other.urls - urls)).length.positive?
end
- def was_deleted
- is_deleted && !previous.is_deleted
+ def was_deleted(type)
+ other = self.send(type)
+ if type == "previous"
+ is_deleted && !other.is_deleted
+ else
+ !is_deleted && other.is_deleted
+ end
end
- def was_undeleted
- !is_deleted && previous.is_deleted
+ def was_undeleted(type)
+ other = self.send(type)
+ if type == "previous"
+ !is_deleted && other.is_deleted
+ else
+ is_deleted && !other.is_deleted
+ end
end
- def was_banned
- is_banned && !previous.is_banned
+ def was_banned(type)
+ other = self.send(type)
+ if type == "previous"
+ is_banned && !other.is_banned
+ else
+ !is_banned && other.is_banned
+ end
end
- def was_unbanned
- !is_banned && previous.is_banned
+ def was_unbanned(type)
+ other = self.send(type)
+ if type == "previous"
+ !is_banned && other.is_banned
+ else
+ is_banned && !other.is_banned
+ end
end
def self.available_includes
diff --git a/app/models/note_version.rb b/app/models/note_version.rb
index 5d1f19f6c..d8655f995 100644
--- a/app/models/note_version.rb
+++ b/app/models/note_version.rb
@@ -14,11 +14,25 @@ class NoteVersion < ApplicationRecord
def previous
@previous ||= begin
- NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").limit(1).to_a
+ NoteVersion.where("note_id = ? and version < ?", note_id, version).order("updated_at desc").limit(1).to_a
end
@previous.first
end
+ def subsequent
+ @subsequent ||= begin
+ NoteVersion.where("note_id = ? and version > ?", note_id, version).order("updated_at asc").limit(1).to_a
+ end
+ @subsequent.first
+ end
+
+ def current
+ @current ||= begin
+ NoteVersion.where("note_id = ?", note_id).order("updated_at desc").limit(1).to_a
+ end
+ @current.first
+ end
+
def self.status_fields
{
body: "Body",
@@ -29,20 +43,32 @@ class NoteVersion < ApplicationRecord
}
end
- def was_moved
- x != previous.x || y != previous.y
+ def was_moved(type)
+ other = self.send(type)
+ x != other.x || y != other.y
end
- def was_resized
- width != previous.width || height != previous.height
+ def was_resized(type)
+ other = self.send(type)
+ width != other.width || height != other.height
end
- def was_deleted
- !is_active && previous.is_active
+ def was_deleted(type)
+ other = self.send(type)
+ if type == "previous"
+ !is_active && other.is_active
+ else
+ is_active && !other.is_active
+ end
end
- def was_undeleted
- is_active && !previous.is_active
+ def was_undeleted(type)
+ other = self.send(type)
+ if type == "previous"
+ is_active && !other.is_active
+ else
+ !is_active && other.is_active
+ end
end
def self.available_includes
diff --git a/app/models/pool_version.rb b/app/models/pool_version.rb
index 5e9f18342..598c03108 100644
--- a/app/models/pool_version.rb
+++ b/app/models/pool_version.rb
@@ -89,23 +89,6 @@ class PoolVersion < ApplicationRecord
normalize_name(name).mb_chars.downcase
end
- def build_diff(other = previous)
- diff = {}
-
- if other.nil?
- diff[:added_post_ids] = added_post_ids
- diff[:removed_post_ids] = removed_post_ids
- diff[:added_desc] = description
- else
- diff[:added_post_ids] = post_ids - other.post_ids
- diff[:removed_post_ids] = other.post_ids - post_ids
- diff[:added_desc] = description
- diff[:removed_desc] = other.description
- end
-
- diff
- end
-
def previous
@previous ||= begin
PoolVersion.where("pool_id = ? and version < ?", pool_id, version).order("version desc").limit(1).to_a
@@ -113,8 +96,23 @@ class PoolVersion < ApplicationRecord
@previous.first
end
+ def subsequent
+ @subsequent ||= begin
+ PoolVersion.where("pool_id = ? and version > ?", pool_id, version).order("version asc").limit(1).to_a
+ end
+ @subsequent.first
+ end
+
+ def current
+ @current ||= begin
+ PoolVersion.where("pool_id = ?", pool_id).order("version desc").limit(1).to_a
+ end
+ @current.first
+ end
+
def self.status_fields
{
+ posts_changed: "Posts",
name: "Renamed",
description: "Description",
was_deleted: "Deleted",
@@ -124,24 +122,45 @@ class PoolVersion < ApplicationRecord
}
end
- def was_deleted
- is_deleted && !previous.is_deleted
+ def posts_changed(type)
+ other = self.send(type)
+ ((post_ids - other.post_ids) | (other.post_ids - post_ids)).length.positive?
end
- def was_undeleted
- !is_deleted && previous.is_deleted
+ def was_deleted(type)
+ other = self.send(type)
+ if type == "previous"
+ is_deleted && !other.is_deleted
+ else
+ !is_deleted && other.is_deleted
+ end
end
- def was_activated
- is_active && !previous.is_active
+ def was_undeleted(type)
+ other = self.send(type)
+ if type == "previous"
+ !is_deleted && other.is_deleted
+ else
+ is_deleted && !other.is_deleted
+ end
end
- def was_deactivated
- !is_active && previous.is_active
+ def was_activated(type)
+ other = self.send(type)
+ if type == "previous"
+ is_active && !other.is_active
+ else
+ !is_active && other.is_active
+ end
end
- def text_field_changed
- previous.present? && (name_changed || description_changed)
+ def was_deactivated(type)
+ other = self.send(type)
+ if type == "previous"
+ !is_active && other.is_active
+ else
+ is_active && !other.is_active
+ end
end
def pretty_name
diff --git a/app/models/post_version.rb b/app/models/post_version.rb
index fe73e2641..8eb82f5c3 100644
--- a/app/models/post_version.rb
+++ b/app/models/post_version.rb
@@ -99,6 +99,20 @@ class PostVersion < ApplicationRecord
@previous.first
end
+ def subsequent
+ @subsequent ||= begin
+ PostVersion.where("post_id = ? and version > ?", post_id, version).order("version asc").limit(1).to_a
+ end
+ @subsequent.first
+ end
+
+ def current
+ @current ||= begin
+ PostVersion.where("post_id = ?", post_id).order("version desc").limit(1).to_a
+ end
+ @current.first
+ end
+
def visible?
post&.visible?
end
@@ -112,40 +126,6 @@ class PostVersion < ApplicationRecord
}
end
- def diff(version = nil)
- if post.nil?
- latest_tags = tag_array
- else
- latest_tags = post.tag_array
- latest_tags << "rating:#{post.rating}" if post.rating.present?
- latest_tags << "parent:#{post.parent_id}" if post.parent_id.present?
- latest_tags << "source:#{post.source}" if post.source.present?
- end
-
- new_tags = tag_array
- new_tags << "rating:#{rating}" if rating.present?
- new_tags << "parent:#{parent_id}" if parent_id.present?
- new_tags << "source:#{source}" if source.present?
-
- old_tags = version.present? ? version.tag_array : []
- if version.present?
- old_tags << "rating:#{version.rating}" if version.rating.present?
- old_tags << "parent:#{version.parent_id}" if version.parent_id.present?
- old_tags << "source:#{version.source}" if version.source.present?
- end
-
- added_tags = new_tags - old_tags
- removed_tags = old_tags - new_tags
-
- return {
- :added_tags => added_tags,
- :removed_tags => removed_tags,
- :obsolete_added_tags => added_tags - latest_tags,
- :obsolete_removed_tags => removed_tags & latest_tags,
- :unchanged_tags => new_tags & old_tags
- }
- end
-
def changes
delta = {
:added_tags => added_tags,
diff --git a/app/models/wiki_page_version.rb b/app/models/wiki_page_version.rb
index f80522ebe..4830b83fd 100644
--- a/app/models/wiki_page_version.rb
+++ b/app/models/wiki_page_version.rb
@@ -30,6 +30,20 @@ class WikiPageVersion < ApplicationRecord
@previous.first
end
+ def subsequent
+ @subsequent ||= begin
+ WikiPageVersion.where("wiki_page_id = ? and id > ?", wiki_page_id, id).order("id asc").limit(1).to_a
+ end
+ @subsequent.first
+ end
+
+ def current
+ @current ||= begin
+ WikiPageVersion.where("wiki_page_id = ?", wiki_page_id).order("id desc").limit(1).to_a
+ end
+ @current.first
+ end
+
def self.status_fields
{
body: "Body",
@@ -40,16 +54,27 @@ class WikiPageVersion < ApplicationRecord
}
end
- def other_names_changed
- ((other_names - previous.other_names) | (previous.other_names - other_names)).length > 0
+ def other_names_changed(type)
+ other = self.send(type)
+ ((other_names - other.other_names) | (other.other_names - other_names)).length.positive?
end
- def was_deleted
- is_deleted && !previous.is_deleted
+ def was_deleted(type)
+ other = self.send(type)
+ if type == "previous"
+ is_deleted && !other.is_deleted
+ else
+ !is_deleted && other.is_deleted
+ end
end
- def was_undeleted
- !is_deleted && previous.is_deleted
+ def was_undeleted(type)
+ other = self.send(type)
+ if type == "previous"
+ !is_deleted && other.is_deleted
+ else
+ is_deleted && !other.is_deleted
+ end
end
def self.available_includes
diff --git a/app/views/application/_diff_list.html.erb b/app/views/application/_diff_list.html.erb
index de5b7f510..d15654a03 100644
--- a/app/views/application/_diff_list.html.erb
+++ b/app/views/application/_diff_list.html.erb
@@ -2,11 +2,11 @@
<%= tag.ul class: [*ul_class] do %>
<% diff.added.each do |item| %>
- <%= tag.li item, class: ["added", ("obsolete" if item.in?(diff.obsolete_added)), *li_class] %>
+ <%= tag.li item, class: ["added", *li_class] %>
<% end %>
<% diff.removed.each do |item| %>
- <%= tag.li item, class: ["removed", ("obsolete" if item.in?(diff.obsolete_removed)), *li_class] %>
+ <%= tag.li item, class: ["removed", *li_class] %>
<% end %>
<% diff.changed.each do |old, new| %>
diff --git a/app/views/artist_commentary_versions/_listing.html.erb b/app/views/artist_commentary_versions/_listing.html.erb
index add68d998..ee29ae0d9 100644
--- a/app/views/artist_commentary_versions/_listing.html.erb
+++ b/app/views/artist_commentary_versions/_listing.html.erb
@@ -19,13 +19,13 @@
<% if !commentary_version.unchanged_empty?(:original_title) %>
Title:
- <%= diff_body_html(commentary_version, commentary_version.previous, :original_title) %>
+ <%= commentary_version_field_diff(commentary_version, params[:type], :original_title) %>
<% end %>
<% if !commentary_version.unchanged_empty?(:original_description) %>
Description:
- <%= diff_body_html(commentary_version, commentary_version.previous, :original_description) %>
+ <%= commentary_version_field_diff(commentary_version, params[:type], :original_description) %>
<% end %>
<% end %>
@@ -33,18 +33,18 @@
<% if !commentary_version.unchanged_empty?(:translated_title) %>
Title:
- <%= diff_body_html(commentary_version, commentary_version.previous, :translated_title) %>
+ <%= commentary_version_field_diff(commentary_version, params[:type], :translated_title) %>
<% end %>
<% if !commentary_version.unchanged_empty?(:translated_description) %>
Description:
- <%= diff_body_html(commentary_version, commentary_version.previous, :translated_description) %>
+ <%= commentary_version_field_diff(commentary_version, params[:type], :translated_description) %>
<% end %>
<% end %>
<% t.column "Changes", width: "3%" do |commentary_version| %>
- <%= status_diff_html(commentary_version) %>
+ <%= status_diff_html(commentary_version, params[:type]) %>
<% end %>
<% t.column "Updated", width: "10%" do |commentary_version| %>
diff --git a/app/views/artist_commentary_versions/index.html.erb b/app/views/artist_commentary_versions/index.html.erb
index 573722507..986c13532 100644
--- a/app/views/artist_commentary_versions/index.html.erb
+++ b/app/views/artist_commentary_versions/index.html.erb
@@ -1,6 +1,8 @@