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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user