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