Add alternate comparison types to versions
- The types are: -- Previous: The default and the previously used type -- Subsequent: Compares against the next version -- Current: Compares against the current version - Allow switching between comparison types in index and diff views -- Have links vary depending upon current comparison type
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -96,6 +96,20 @@ 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",
|
||||
@@ -108,24 +122,45 @@ class PoolVersion < ApplicationRecord
|
||||
}
|
||||
end
|
||||
|
||||
def posts_changed
|
||||
((post_ids - previous.post_ids) | (previous.post_ids - post_ids)).length > 0
|
||||
def posts_changed(type)
|
||||
other = self.send(type)
|
||||
((post_ids - other.post_ids) | (other.post_ids - post_ids)).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_activated
|
||||
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 was_deactivated
|
||||
!is_active && previous.is_active
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user