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:
BrokenEagle
2020-03-17 05:23:51 +00:00
parent 4b30e644bb
commit a95e57d938
15 changed files with 152 additions and 105 deletions

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

View File

@@ -112,40 +112,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,