Commit 102338bc0f6f766e5e7df1ea050503ceeb4ff891

Authored by MoisesMachado
1 parent 4467d7c0

ActionItem4: basic managing tags

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@36 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/manage_tags_controller.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class ManageTagsController < ApplicationController
  2 + def index
  3 + list
  4 + render :action => 'list'
  5 + end
  6 +
  7 + def list
  8 + @tags = Tag.find_all
  9 + end
  10 +
  11 + def new
  12 + @tags = Tag.find_all
  13 + @tag = Tag.new
  14 + end
  15 +
  16 + def create
  17 + @tag = Tag.new
  18 + @tag.name = params[:tag][:name]
  19 + @tag.parent = Tag.find(params[:parent_id].to_i) if params[:parent_id] != "0"
  20 + if @tag.save
  21 + flash[:notice] = _('Tag was successfully created.')
  22 + redirect_to :action => 'list'
  23 + else
  24 + render :action => 'new'
  25 + end
  26 + end
  27 +end
... ...
app/views/manage_tags/_form.rhtml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +
  2 +Name: <%= text_field 'tag', 'name' %> <br>
  3 +Parent tag: <%= select_tag 'parent_id', ['<option value="0"></option>'] + @tags.map {|n|"<option value=\"#{n.id}\">" + n.name + '</option>'} %> <br>
... ...
app/views/manage_tags/_list.rhtml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<li>
  2 +<%= a_tag.name %>
  3 +<ul>
  4 +<% a_tag.children.each do |child|%>
  5 +<%= render :partial =>'list', :locals => {:a_tag => child} %>
  6 +<% end %>
  7 +</ul>
  8 +</li>
... ...
app/views/manage_tags/list.rhtml 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<h2> <%= _("Listing tags") %> </h2>
  2 +
  3 +<ul>
  4 + <% @tags.select{|t| !t.parent }.each do |a_tag| %>
  5 + <%= render :partial => 'list', :locals => {:a_tag => a_tag} %>
  6 + <% end %>
  7 +</ul>
  8 +
  9 +<%= link_to _('New tag'), {:action => 'new'} %>
... ...
app/views/manage_tags/new.rhtml 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<h2> <%= _('New tag') %> </h2>
  2 +
  3 +<%= start_form_tag :action =>'create' %>
  4 + <%= render :partial => 'form' %>
  5 + <%= submit_tag 'Create' %>
  6 +<%= end_form_tag %>
... ...
db/migrate/007_acts_as_taggable_migration.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class ActsAsTaggableMigration < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :tags do |t|
  4 + t.column :name, :string
  5 + t.column :parent_id, :integer
  6 + end
  7 +
  8 + create_table :taggings do |t|
  9 + t.column :tag_id, :integer
  10 + t.column :taggable_id, :integer
  11 +
  12 + # You should make sure that the column created is
  13 + # long enough to store the required class names.
  14 + t.column :taggable_type, :string
  15 +
  16 + t.column :created_at, :datetime
  17 + end
  18 +
  19 + add_index :taggings, :tag_id
  20 + add_index :taggings, [:taggable_id, :taggable_type]
  21 + end
  22 +
  23 + def self.down
  24 + drop_table :taggings
  25 + drop_table :tags
  26 + end
  27 +end
... ...