Move more logic to the helper modules
- Diff view changes -- Only show pool description changes in diff view -- Conditionally render diff link when applicable values are changed -- Conditionally show diff view sections when values are changed - Show renames on index view -- There is plenty of space -- This wasn't shown at all for wikis -- Having to navigate to an alternate page is unwieldy for pools - Show "posts" as a status on pools -- This is so all changes among versions are quantified as a status - Standardize diff/index titles
This commit is contained in:
@@ -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
|
||||
@@ -115,6 +98,7 @@ class PoolVersion < ApplicationRecord
|
||||
|
||||
def self.status_fields
|
||||
{
|
||||
posts_changed: "Posts",
|
||||
name: "Renamed",
|
||||
description: "Description",
|
||||
was_deleted: "Deleted",
|
||||
@@ -124,6 +108,10 @@ class PoolVersion < ApplicationRecord
|
||||
}
|
||||
end
|
||||
|
||||
def posts_changed
|
||||
((post_ids - previous.post_ids) | (previous.post_ids - post_ids)).length > 0
|
||||
end
|
||||
|
||||
def was_deleted
|
||||
is_deleted && !previous.is_deleted
|
||||
end
|
||||
@@ -140,10 +128,6 @@ class PoolVersion < ApplicationRecord
|
||||
!is_active && previous.is_active
|
||||
end
|
||||
|
||||
def text_field_changed
|
||||
previous.present? && (name_changed || description_changed)
|
||||
end
|
||||
|
||||
def pretty_name
|
||||
name.tr("_", " ")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user