adds color coding to both urls and other names on artist versions
This commit is contained in:
Toks
2013-03-29 09:59:14 -04:00
parent 30ba85d516
commit 7e3324b5f0
4 changed files with 62 additions and 5 deletions

View File

@@ -286,7 +286,7 @@ div#c-posts {
}
}
div#c-post-versions {
div#c-post-versions, div#c-artist-versions {
div#a-index {
a {
word-wrap: break-word

View File

@@ -1,2 +1,31 @@
module ArtistVersionsHelper
def artist_version_other_names_diff(artist_version)
diff = artist_version.other_names_diff(artist_version.previous)
html = []
diff[:added_names].each do |name|
html << '<ins>' + name + '</ins>'
end
diff[:removed_names].each do |name|
html << '<del>' + name + '</del>'
end
diff[:unchanged_names].each do |name|
html << '<span>' + name + '</span>'
end
return html.join(" ").html_safe
end
def artist_version_urls_diff(artist_version)
diff = artist_version.urls_diff(artist_version.previous)
html = []
diff[:added_urls].each do |url|
html << '<li><ins>' + url + '</ins></li>'
end
diff[:removed_urls].each do |url|
html << '<li><del>' + url + '</del></li>'
end
diff[:unchanged_urls].each do |url|
html << '<li><span>' + url + '</span></li>'
end
return html.join(" ").html_safe
end
end

View File

@@ -27,6 +27,36 @@ class ArtistVersion < ActiveRecord::Base
url_string.scan(/\S+/)
end
def other_names_array
other_names.scan(/\S+/)
end
def urls_diff(version)
new_urls = url_array
old_urls = version.present? ? version.url_array : []
return {
:added_urls => new_urls - old_urls,
:removed_urls => old_urls - new_urls,
:unchanged_urls => new_urls & old_urls,
}
end
def other_names_diff(version)
new_names = other_names_array
old_names = version.present? ? version.other_names_array : []
return {
:added_names => new_names - old_names,
:removed_names => old_names - new_names,
:unchanged_names => new_names & old_names,
}
end
def previous
ArtistVersion.where("artist_id = ? and updated_at < ?", artist_id, updated_at).order("updated_at desc").first
end
def updater_name
User.id_to_name(updater_id).tr("_", " ")
end

View File

@@ -24,16 +24,14 @@
<%= link_to artist_version.name, artist_versions_path(:search => {:artist_id => artist_version.artist_id}) %>
</td>
<td><%= link_to "artist", artist_path(artist_version.artist) %></td>
<td><%= artist_version.other_names %></td>
<td><%= artist_version_other_names_diff(artist_version) %></td>
<td><%= artist_version.group_name %></td>
<td><%= compact_time artist_version.created_at %></td>
<td><%= link_to artist_version.updater_name, user_path(artist_version.updater_id) %></td>
<td><%= artist_version.is_active? %></td>
<td>
<ul>
<% artist_version.url_array.each do |url| %>
<li><%= url %></li>
<% end %>
<%= artist_version_urls_diff(artist_version) %>
</ul>
</td>
<td>