Commit 4a2b904d0560a8c653593321b4960b3b7a788304
1 parent
e573cab6
Exists in
master
and in
28 other branches
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 | require 'extended_tag' | 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 | class ManageTagsController < ApplicationController | 4 | class ManageTagsController < ApplicationController |
5 | + # Index redirects to list action without modifing the url | ||
3 | def index | 6 | def index |
4 | list | 7 | list |
5 | render :action => 'list' | 8 | render :action => 'list' |
6 | end | 9 | end |
7 | - | 10 | + |
11 | + # Lists the tags strting with the top tags or with the chidren of @parent if its provided | ||
8 | def list | 12 | def list |
9 | @parent = Tag.find(params[:parent]) if params[:parent] | 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 | @pending_tags = Tag.find_all.select(&:pending?) | 15 | @pending_tags = Tag.find_all.select(&:pending?) |
12 | end | 16 | end |
13 | 17 | ||
18 | + # Prompt to data for a new tag | ||
14 | def new | 19 | def new |
15 | - @parent_tags = Tag.find_all | 20 | + @parent_tags = Tag.find_all.select{|t|!t.pending?} |
16 | @tag = Tag.new | 21 | @tag = Tag.new |
17 | end | 22 | end |
18 | 23 | ||
24 | + # Collects the data and creates a new tag with it | ||
19 | def create | 25 | def create |
20 | @tag = Tag.new | 26 | @tag = Tag.new |
21 | @tag.name = params[:tag][:name] | 27 | @tag.name = params[:tag][:name] |
22 | @tag.parent = Tag.find(params[:parent_id].to_i) if params[:parent_id] != "0" | 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 | if @tag.save | 30 | if @tag.save |
25 | flash[:notice] = _('Tag was successfully created.') | 31 | flash[:notice] = _('Tag was successfully created.') |
26 | redirect_to :action => 'list' | 32 | redirect_to :action => 'list' |
@@ -29,11 +35,13 @@ class ManageTagsController < ApplicationController | @@ -29,11 +35,13 @@ class ManageTagsController < ApplicationController | ||
29 | end | 35 | end |
30 | end | 36 | end |
31 | 37 | ||
38 | + # Prompt for modifications on the attributes of a tag | ||
32 | def edit | 39 | def edit |
33 | @tag = Tag.find(params[:id]) | 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 | end | 42 | end |
36 | 43 | ||
44 | + # Do the modifications collected by edit | ||
37 | def update | 45 | def update |
38 | @tag = Tag.find(params[:id]) | 46 | @tag = Tag.find(params[:id]) |
39 | @tag.name = params[:tag][:name] | 47 | @tag.name = params[:tag][:name] |
@@ -46,6 +54,7 @@ class ManageTagsController < ApplicationController | @@ -46,6 +54,7 @@ class ManageTagsController < ApplicationController | ||
46 | end | 54 | end |
47 | end | 55 | end |
48 | 56 | ||
57 | + # Destroy a tag | ||
49 | def destroy | 58 | def destroy |
50 | @tag = Tag.find(params[:id]) | 59 | @tag = Tag.find(params[:id]) |
51 | @tag.destroy | 60 | @tag.destroy |