From f28c05e6c67810dc718d5f55c4f3b2b73f89825e Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 16 Jul 2007 22:30:56 +0000 Subject: [PATCH] ActionItem4: redefining find for tags to filter pending tags --- app/controllers/manage_tags_controller.rb | 35 ++++++++++++++++++++--------------- app/views/manage_tags/_a_tag.rhtml | 5 +++-- app/views/manage_tags/_form.rhtml | 2 +- app/views/manage_tags/list.rhtml | 3 ++- db/migrate/004_acts_as_taggable_migration.rb | 2 +- lib/extended_tag.rb | 21 ++++++++++++++++++--- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/app/controllers/manage_tags_controller.rb b/app/controllers/manage_tags_controller.rb index f7a00ec..cc65203 100644 --- a/app/controllers/manage_tags_controller.rb +++ b/app/controllers/manage_tags_controller.rb @@ -1,4 +1,4 @@ -require 'extended_tag' +require 'extended_tag.rb' # 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 @@ -11,22 +11,20 @@ class ManageTagsController < ApplicationController # 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 = @parent ? @parent.children.select{|t|!t.pending} : Tag.find_all.select{|t|!t.pending?} - @pending_tags = Tag.find_all.select(&:pending?) + @tags = @parent ? @parent.children : Tag.find(:all).select{|t|!t.parent} + @pending_tags = Tag.find_pendings end # Prompt to data for a new tag def new - @parent_tags = Tag.find_all.select{|t|!t.pending?} + @parent_tags = Tag.find_all @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] if params[:tag][:pending] + @tag = Tag.new(params[:tag]) + if @tag.save flash[:notice] = _('Tag was successfully created.') redirect_to :action => 'list' @@ -37,16 +35,14 @@ class ManageTagsController < ApplicationController # Prompt for modifications on the attributes of a tag def edit - @tag = Tag.find(params[:id]) - @parent_tags = Tag.find_all.select{|t|!t.pending?} - @tag.descendents - [@tag] + @tag = Tag.original_find(params[:id]) + @parent_tags = Tag.find_all - @tag.descendents - [@tag] end # Do the modifications collected by edit def update - @tag = Tag.find(params[:id]) - @tag.name = params[:tag][:name] - @tag.parent = params[:parent_id] != "0" ? Tag.find(params[:parent_id].to_i) : nil - if @tag.save + @tag = Tag.original_find(params[:id]) + if @tag.update_attributes(params[:tag]) flash[:notice] = _('Tag was successfully updated.') redirect_to :action => 'list' else @@ -56,8 +52,17 @@ class ManageTagsController < ApplicationController # Destroy a tag def destroy - @tag = Tag.find(params[:id]) + @tag = Tag.original_find(params[:id]) @tag.destroy redirect_to :action => 'list' end + + def approve + @tag = Tag.original_find(params[:id]) + @tag.pending = false + if @tag.save + flash[:notice] = _('Tag was successfuly approved') + redirect_to :action => 'list' + end + end end diff --git a/app/views/manage_tags/_a_tag.rhtml b/app/views/manage_tags/_a_tag.rhtml index 3d7d115..6c57455 100644 --- a/app/views/manage_tags/_a_tag.rhtml +++ b/app/views/manage_tags/_a_tag.rhtml @@ -3,7 +3,8 @@ <%= a_tag.name %> <%= link_to _('Edit'), {:action => 'edit', :id => a_tag } %> <%= link_to _('Destroy'), {:action => 'destroy', :id => a_tag} %> -<%= link_to _('Filter by this tag'), {:action => 'list', :parent => a_tag} %>