Skip to content

Commit

Permalink
Merge pull request #1640 from CristinaRO/issue-3911-wrangle-to-fandoms
Browse files Browse the repository at this point in the history
Issue 3911 wrangle to fandoms
  • Loading branch information
elzj committed May 10, 2014
2 parents 181edd7 + c6c79db commit 7e163ef
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 237 deletions.
29 changes: 14 additions & 15 deletions app/controllers/tag_wranglings_controller.rb
@@ -1,6 +1,6 @@
class TagWranglingsController < ApplicationController
cache_sweeper :tag_sweeper
cache_sweeper :tag_sweeper

before_filter :check_user_status
before_filter :check_permission_to_wrangle

Expand All @@ -18,33 +18,26 @@ def index
@media_names = Media.by_name.value_of(:name)
@page_subtitle = ts("fandoms")
@tags = Fandom.unwrangled.in_use.order(sort).paginate(:page => params[:page], :per_page => ArchiveConfig.ITEMS_PER_PAGE)
elsif params[:show] == "character_relationships"
if params[:fandom_string]
@fandom = Fandom.find_by_name(params[:fandom_string])
if @fandom && @fandom.canonical?
@tags = @fandom.children.by_type("Relationship").canonical.order(sort).paginate(:page => params[:page], :per_page => ArchiveConfig.ITEMS_PER_PAGE)
else
flash[:error] = "#{params[:fandom_string]} is not a canonical fandom."
end
end
else # by fandom
klass = params[:show].classify.constantize
@tags = klass.unwrangled.in_use.order(sort).paginate(:page => params[:page], :per_page => ArchiveConfig.ITEMS_PER_PAGE)
end
end
end

def wrangle
params[:page] = '1' if params[:page].blank?
params[:sort_column] = 'name' if !valid_sort_column(params[:sort_column], 'tag')
params[:sort_direction] = 'ASC' if !valid_sort_direction(params[:sort_direction])
options = {:show => params[:show], :page => params[:page], :sort_column => params[:sort_column], :sort_direction => params[:sort_direction]}

unless params[:canonicals].blank?
canonicals = Tag.find(params[:canonicals])
canonicals.each do |tag|
tag.update_attributes(:canonical => true)
end
end

if params[:media] && !params[:selected_tags].blank?
options.merge!(:media => params[:media])
@media = Media.find_by_name(params[:media])
Expand All @@ -53,30 +46,36 @@ def wrangle
elsif params[:character_string] && !params[:selected_tags].blank?
options.merge!(:character_string => params[:character_string], :fandom_string => params[:fandom_string])
@character = Character.find_by_name(params[:character_string])

if @character && @character.canonical?
@tags = Tag.find(params[:selected_tags])
@tags.each { |tag| tag.add_association(@character) }
flash[:notice] = "#{@tags.length} relationships were wrangled to #{params[:character_string]}."

redirect_to tag_wranglings_path(options) and return
else
flash[:error] = "#{params[:character_string]} is not a canonical character."

redirect_to tag_wranglings_path(options) and return
end
elsif params[:fandom_string] && !params[:selected_tags].blank?
options.merge!(:fandom_string => params[:fandom_string])
@fandom = Fandom.find_by_name(params[:fandom_string])

if @fandom && @fandom.canonical?
@tags = Tag.find(params[:selected_tags])
@tags.each { |tag| tag.add_association(@fandom) }
else
flash[:error] = "#{params[:fandom_string]} is not a canonical fandom."
redirect_to tag_wranglings_path(options) and return

redirect_to tag_wranglings_path(options) and return
end
end

flash[:notice] = "Tags were successfully wrangled!"
redirect_to tag_wranglings_path(options)
redirect_to tag_wranglings_path(options)
end

def discuss
@comments = Comment.where(:commentable_type => 'Tag').order('updated_at DESC').paginate(:page => params[:page])
end
Expand Down
32 changes: 28 additions & 4 deletions app/controllers/tags_controller.rb
Expand Up @@ -15,7 +15,6 @@ def load_tag
end
end


# GET /tags
# GET /tags.xml
def index
Expand Down Expand Up @@ -274,7 +273,7 @@ def mass_update

saved = []
not_saved = []

# make tags canonical
unless params[:canonicals].blank?
params[:canonicals].each do |tag_id|
Expand All @@ -288,7 +287,7 @@ def mass_update
end

# remove associated tags
unless params[:remove_associated].blank?
unless params[:remove_associated].blank?
params[:remove_associated].each do |tag_id|
tag_to_remove = Tag.find(tag_id)
if tag_to_remove
Expand All @@ -298,10 +297,35 @@ def mass_update
end
end

if params[:fandom_string] && !params[:selected_tags].blank?
canonical_fandoms, noncanonical_fandom_names = [], []
fandom_names = params[:fandom_string].split(',').map(&:squish)
fandom_names.each do |fandom_name|
if (fandom = Fandom.find_by_name(fandom_name)).try(:canonical?)
canonical_fandoms << fandom
else
noncanonical_fandom_names << fandom_name
end
end

if canonical_fandoms.present?
saved = Tag.find_by_id(params[:selected_tags])
saved = [saved] if saved.is_a?(Tag)
saved.each do |tag|
canonical_fandoms.each do |fandom|
tag.add_association(fandom)
end
end
end

if noncanonical_fandom_names.present?
flash[:error] = ts("The following names are not canonical fandoms: %{noncanonical_fandom_names}.", noncanonical_fandom_names: noncanonical_fandom_names)
end
end

flash[:notice] = ts("The following tags were successfully updated: %{tags_saved}", :tags_saved => saved.collect(&:name).join(', ')) if !saved.empty?
flash[:error] = ts("The following tags weren't saved: %{tags_not_saved}", :tags_not_saved => not_saved.collect(&:name).join(', ')) if !not_saved.empty?

redirect_to url_for(:controller => :tags, :action => :wrangle, :id => params[:id], :show => params[:show], :page => params[:page], :sort_column => params[:sort_column], :sort_direction => params[:sort_direction], :status => params[:status])
end

end
44 changes: 22 additions & 22 deletions app/views/tag_wranglings/_wrangler_dashboard.html.erb
@@ -1,7 +1,7 @@
<div id="dashboard" role="navigation region" class="tag wrangling region">
<ul class="navigation actions">
<% if current_user.is_a?(User) %>
<li><%= span_if_current('Wrangling Home', tag_wrangler_path(current_user)) %></li>
<li><%= span_if_current('Wrangling Home', tag_wrangler_path(current_user)) %></li>
<% end %>
<li><%= span_if_current('Wrangling Tools', tag_wranglings_path) %></li>
<li><%= span_if_current('Wranglers', tag_wranglers_path) %></li>
Expand All @@ -13,29 +13,29 @@
<% if @counts %>
</ul>

<ul class="navigation actions">
<% if @tag && @uses %>
<% for key in @uses %>
<% if key == 'Works' || key == 'Bookmarks' %>
<li><%= span_if_current "#{key} (#{@counts[key]})", {:controller => key.downcase.to_sym, :action => :index, :tag_id => @tag} %></li>
<% elsif key == 'External Works' %>
<li><%= span_if_current "#{key} (#{@counts[key]})", {:controller => :bookmarks, :action => :index, :tag_id => @tag} %></li>
<% else %>
<li><span><%= "#{key} (#{@counts[key]})" %></span></li>
<ul class="navigation actions">
<% if @tag && @uses %>
<% for key in @uses %>
<% if key == 'Works' || key == 'Bookmarks' %>
<li><%= span_if_current "#{key} (#{@counts[key]})", {:controller => key.downcase.to_sym, :action => :index, :tag_id => @tag} %></li>
<% elsif key == 'External Works' %>
<li><%= span_if_current "#{key} (#{@counts[key]})", {:controller => :bookmarks, :action => :index, :tag_id => @tag} %></li>
<% else %>
<li><span><%= "#{key} (#{@counts[key]})" %></span></li>
<% end %>
<% end %>
<% elsif @tag && @tag.child_types %>
<% for tag_type in @tag.child_types %>
<li>
<%= span_if_current tag_type.pluralize + " (#{@counts[tag_type.underscore.pluralize.to_sym]})", url_for(:show => tag_type.underscore.pluralize, :id => @tag) %>
</li>
<% end %>
<% else %>
<li><%= span_if_current "Fandoms by media (#{@counts[:fandoms]})", tag_wranglings_path(:show => "fandoms") %></li>
<li><%= span_if_current "Characters by fandom (#{@counts[:characters]})", tag_wranglings_path(:show => "characters") %></li>
<li><%= span_if_current "Relationships by fandom (#{@counts[:relationships]})", tag_wranglings_path(:show => "relationships") %></li>
<li><%= span_if_current "Freeforms by fandom (#{@counts[:freeforms]})", tag_wranglings_path(:show => "freeforms") %></li>
<% end %>
<% elsif @tag && @tag.child_types %>
<% for tag_type in @tag.child_types %>
<li>
<%= span_if_current tag_type.pluralize + " (#{@counts[tag_type.underscore.pluralize.to_sym]})", url_for(:show => tag_type.underscore.pluralize, :id => @tag) %>
</li>
<% end %>
<% else %>
<li><%= span_if_current "Fandoms by media (#{@counts[:fandoms]})", tag_wranglings_path(:show => "fandoms") %></li>
<li><%= span_if_current "Characters by fandom (#{@counts[:characters]})", tag_wranglings_path(:show => "characters") %></li>
<li><%= span_if_current "Relationships by fandom (#{@counts[:relationships]})", tag_wranglings_path(:show => "relationships") %></li>
<li><%= span_if_current "Freeforms by fandom (#{@counts[:freeforms]})", tag_wranglings_path(:show => "freeforms") %></li>
<% end %>
<% end %>
</ul>
</div>
Expand Down

0 comments on commit 7e163ef

Please sign in to comment.