reverted post version tag change for danbooru2
This commit is contained in:
@@ -17,12 +17,8 @@ class PostVersion < ActiveRecord::Base
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def add_tag_array
|
||||
@add_tag_array ||= add_tags.scan(/\S+/)
|
||||
end
|
||||
|
||||
def del_tag_array
|
||||
@del_tag_array ||= del_tags.scan(/\S+/)
|
||||
def tag_array
|
||||
@tag_array ||= tags.scan(/\S+/)
|
||||
end
|
||||
|
||||
def presenter
|
||||
@@ -30,8 +26,45 @@ class PostVersion < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def reload
|
||||
@add_tag_array = nil
|
||||
@del_tag_array = nil
|
||||
@tag_array = nil
|
||||
super
|
||||
end
|
||||
|
||||
def sequence_for_post
|
||||
versions = PostVersion.where(:post_id => post_id).order("id desc").all
|
||||
diffs = []
|
||||
versions.each_index do |i|
|
||||
if i < versions.size - 1
|
||||
diffs << versions[i].diff(versions[i + 1])
|
||||
end
|
||||
end
|
||||
return diffs
|
||||
end
|
||||
|
||||
def diff(version)
|
||||
latest_tags = post.tag_array
|
||||
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
|
||||
|
||||
return {
|
||||
:added_tags => new_tags - old_tags,
|
||||
:removed_tags => old_tags - new_tags,
|
||||
:unchanged_tags => new_tags & old_tags,
|
||||
:obsolete_added_tags => new_tags - latest_tags,
|
||||
:obsolete_removed_tags => old_tags & latest_tags,
|
||||
}
|
||||
end
|
||||
|
||||
def previous
|
||||
PostVersion.where("post_id = ? and id < ?", post_id, id).order("id desc").first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user