Commit 4a2b904d0560a8c653593321b4960b3b7a788304

Authored by MoisesMachado
1 parent e573cab6

ActionItem4: fixed management for pending tags and added some documentation


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@76 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 1 changed file with 14 additions and 5 deletions   Show diff stats
app/controllers/manage_tags_controller.rb
1 1 require 'extended_tag'
  2 +
  3 +# Manage tags stored by the acts-as_taggable_on_steroids plugin by providing an interface to create, destroy, update and list them
2 4 class ManageTagsController < ApplicationController
  5 + # Index redirects to list action without modifing the url
3 6 def index
4 7 list
5 8 render :action => 'list'
6 9 end
7   -
  10 +
  11 + # Lists the tags strting with the top tags or with the chidren of @parent if its provided
8 12 def list
9 13 @parent = Tag.find(params[:parent]) if params[:parent]
10   - @tags = Tag.find_all_by_parent_id(params[:parent]).select{|t|!t.pending?}
  14 + @tags = @parent ? @parent.children.select{|t|!t.pending} : Tag.find_all.select{|t|!t.pending?}
11 15 @pending_tags = Tag.find_all.select(&:pending?)
12 16 end
13 17  
  18 + # Prompt to data for a new tag
14 19 def new
15   - @parent_tags = Tag.find_all
  20 + @parent_tags = Tag.find_all.select{|t|!t.pending?}
16 21 @tag = Tag.new
17 22 end
18 23  
  24 + # Collects the data and creates a new tag with it
19 25 def create
20 26 @tag = Tag.new
21 27 @tag.name = params[:tag][:name]
22 28 @tag.parent = Tag.find(params[:parent_id].to_i) if params[:parent_id] != "0"
23   - @tag.pending = params[:tag][:pending]
  29 + @tag.pending = params[:tag][:pending] if params[:tag][:pending]
24 30 if @tag.save
25 31 flash[:notice] = _('Tag was successfully created.')
26 32 redirect_to :action => 'list'
... ... @@ -29,11 +35,13 @@ class ManageTagsController &lt; ApplicationController
29 35 end
30 36 end
31 37  
  38 + # Prompt for modifications on the attributes of a tag
32 39 def edit
33 40 @tag = Tag.find(params[:id])
34   - @parent_tags = Tag.find_all - @tag.descendents - [@tag]
  41 + @parent_tags = Tag.find_all.select{|t|!t.pending?} - @tag.descendents - [@tag]
35 42 end
36 43  
  44 + # Do the modifications collected by edit
37 45 def update
38 46 @tag = Tag.find(params[:id])
39 47 @tag.name = params[:tag][:name]
... ... @@ -46,6 +54,7 @@ class ManageTagsController &lt; ApplicationController
46 54 end
47 55 end
48 56  
  57 + # Destroy a tag
49 58 def destroy
50 59 @tag = Tag.find(params[:id])
51 60 @tag.destroy
... ...