-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the post versions more like the old format
- "Current" is now most like the old format -- It is therefore now the default for post versions - Only show the actual edits in their own column - Show the current state at that version in another column - On the "previous" view, don't double-show full list of tags for the first post versions, so leave edits blank
- Loading branch information
1 parent
cbfa8c4
commit 6aa0adb
Showing
7 changed files
with
87 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,51 @@ | ||
module PostVersionsHelper | ||
def post_version_diff(post_version, type) | ||
return "" if type == "previous" && post_version.version == 1 | ||
|
||
other = post_version.send(type) | ||
|
||
this_tags = post_version.tag_array | ||
this_tags << "rating:#{post_version.rating}" if post_version.rating.present? | ||
this_tags << "parent:#{post_version.parent_id}" if post_version.parent_id.present? | ||
this_tags << "source:#{post_version.source}" if post_version.source.present? | ||
|
||
other_tags = other.present? ? other.tag_array : [] | ||
if other.present? | ||
other_tags << "rating:#{other.rating}" if other.rating.present? | ||
other_tags << "parent:#{other.parent_id}" if other.parent_id.present? | ||
other_tags << "source:#{other.source}" if other.source.present? | ||
elsif type == "subsequent" | ||
other_tags = this_tags | ||
end | ||
added_tags = post_version.added_tags | ||
added_tags << "rating:#{post_version_value(post_version.rating)}" if post_version.rating_changed | ||
added_tags << "parent:#{post_version_value(post_version.parent_id)}" if post_version.parent_changed | ||
added_tags << "source:#{post_version_value(post_version.source)}" if post_version.source_changed | ||
|
||
removed_tags = post_version.removed_tags | ||
|
||
if type == "previous" | ||
added_tags = this_tags - other_tags | ||
removed_tags = other_tags - this_tags | ||
if type == "previous" || other.nil? | ||
obsolete_added_tags = [] | ||
obsolete_removed_tags = [] | ||
else | ||
added_tags = other_tags - this_tags | ||
removed_tags = this_tags - other_tags | ||
other_tags = other.tags.split | ||
other_tags << "rating:#{post_version_value(other.rating)}" | ||
other_tags << "parent:#{post_version_value(other.parent_id)}" | ||
other_tags << "source:#{post_version_value(other.source)}" | ||
obsolete_added_tags = added_tags - other_tags | ||
obsolete_removed_tags = removed_tags & other_tags | ||
end | ||
unchanged_tags = this_tags & other_tags | ||
|
||
html = '<span class="diff-list">' | ||
|
||
added_tags.each do |tag| | ||
html << '<ins>+' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '</ins>' | ||
html << " " | ||
obsolete_class = (obsolete_added_tags.include?(tag) ? "diff-obsolete" : ""); | ||
html << %(<ins class="#{obsolete_class}">#{link_to(wordbreakify(tag), posts_path(:tags => tag))}</ins> ) | ||
end | ||
removed_tags.each do |tag| | ||
html << '<del>-' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '</del>' | ||
html << " " | ||
end | ||
unchanged_tags.each do |tag| | ||
html << '<span>' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '</span>' | ||
html << " " | ||
obsolete_class = (obsolete_removed_tags.include?(tag) ? "diff-obsolete" : ""); | ||
html << %(<del class="#{obsolete_class}">#{link_to(wordbreakify(tag), posts_path(:tags => tag))}</del> ) | ||
end | ||
|
||
html << "</span>" | ||
html.html_safe | ||
end | ||
|
||
def post_version_field(post_version, field) | ||
value = post_version_value(post_version.send(field)) | ||
prefix = (field == :parent_id ? "parent" : field.to_s) | ||
search = prefix + ":" + value.to_s | ||
display = (field == :rating ? post_version.pretty_rating : value) | ||
%(<b>#{field.to_s.titleize}:</b> #{link_to(display, posts_path(:tags => search))}).html_safe | ||
end | ||
|
||
def post_version_value(value) | ||
return (value.present? ? value : "none") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters