Merge pull request #4339 from BrokenEagle/version-reports

Add alternate version comparisons
This commit is contained in:
evazion
2020-03-20 16:32:28 -05:00
committed by GitHub
45 changed files with 559 additions and 304 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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