diff --git a/app/controllers/manage_tags_controller.rb b/app/controllers/manage_tags_controller.rb index 4a8f601..f7a00ec 100644 --- a/app/controllers/manage_tags_controller.rb +++ b/app/controllers/manage_tags_controller.rb @@ -1,26 +1,32 @@ require 'extended_tag' + +# Manage tags stored by the acts-as_taggable_on_steroids plugin by providing an interface to create, destroy, update and list them class ManageTagsController < ApplicationController + # Index redirects to list action without modifing the url def index list render :action => 'list' end - + + # Lists the tags strting with the top tags or with the chidren of @parent if its provided def list @parent = Tag.find(params[:parent]) if params[:parent] - @tags = Tag.find_all_by_parent_id(params[:parent]).select{|t|!t.pending?} + @tags = @parent ? @parent.children.select{|t|!t.pending} : Tag.find_all.select{|t|!t.pending?} @pending_tags = Tag.find_all.select(&:pending?) end + # Prompt to data for a new tag def new - @parent_tags = Tag.find_all + @parent_tags = Tag.find_all.select{|t|!t.pending?} @tag = Tag.new end + # Collects the data and creates a new tag with it def create @tag = Tag.new @tag.name = params[:tag][:name] @tag.parent = Tag.find(params[:parent_id].to_i) if params[:parent_id] != "0" - @tag.pending = params[:tag][:pending] + @tag.pending = params[:tag][:pending] if params[:tag][:pending] if @tag.save flash[:notice] = _('Tag was successfully created.') redirect_to :action => 'list' @@ -29,11 +35,13 @@ class ManageTagsController < ApplicationController end end + # Prompt for modifications on the attributes of a tag def edit @tag = Tag.find(params[:id]) - @parent_tags = Tag.find_all - @tag.descendents - [@tag] + @parent_tags = Tag.find_all.select{|t|!t.pending?} - @tag.descendents - [@tag] end + # Do the modifications collected by edit def update @tag = Tag.find(params[:id]) @tag.name = params[:tag][:name] @@ -46,6 +54,7 @@ class ManageTagsController < ApplicationController end end + # Destroy a tag def destroy @tag = Tag.find(params[:id]) @tag.destroy -- libgit2 0.21.2