Commit 46b708cb6b9216f23799d268e25d1f122b4fd444
1 parent
9e9bd5c8
Exists in
master
and in
28 other branches
ActionItem4: added search tags by name
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@141 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
29 additions
and
3 deletions
Show diff stats
app/controllers/manage_tags_controller.rb
| ... | ... | @@ -67,4 +67,9 @@ class ManageTagsController < ApplicationController |
| 67 | 67 | redirect_to :action => 'list' |
| 68 | 68 | end |
| 69 | 69 | end |
| 70 | + | |
| 71 | + # Full-text search for tags that have the query terms | |
| 72 | + def search | |
| 73 | + @tags_found = Tag.find_by_contents(params[:query][:term]) | |
| 74 | + end | |
| 70 | 75 | end | ... | ... |
app/views/manage_tags/_form.rhtml
| 1 | -Name: <%= text_field 'tag', 'name' %> <br> | |
| 2 | -Parent tag: <%= select('tag', 'parent_id', @parent_tags.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) %> <br> | |
| 3 | -Pending: <%= check_box 'tag', 'pending' %> <br> | |
| 1 | +<%= _('Name') %>: <%= text_field 'tag', 'name' %> <br> | |
| 2 | +<%= _('Parent tag') %>: <%= select('tag', 'parent_id', @parent_tags.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) %> <br> | |
| 3 | +<%= _('Pending') %>: <%= check_box 'tag', 'pending' %> <br> | ... | ... |
app/views/manage_tags/list.rhtml
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +<h2> <%= _('Matching tags') %></h2> | |
| 2 | + | |
| 3 | +<% if not @tags_found.empty? %> | |
| 4 | + <%= @tags_found.size.to_s + (@tags_found.size > 1 ? ' tags' : ' tag') + _(' was found') %> | |
| 5 | + <%= render :partial => 'a_tag', :collection => @tags_found %> | |
| 6 | +<% else %> | |
| 7 | + <%= _('No tags found matching criteria') %> | |
| 8 | +<% end %> | |
| 9 | + | |
| 10 | +<%= link_to _('Back'), :action => 'list' %> | ... | ... |
lib/extended_tag.rb
| 1 | 1 | class Tag |
| 2 | + | |
| 2 | 3 | @@original_find = self.method(:find) |
| 3 | 4 | # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not |
| 4 | 5 | def self.find_with_pendings(*args) |
| 5 | 6 | @@original_find.call(*args) |
| 6 | 7 | end |
| 8 | + | |
| 7 | 9 | # Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag |
| 8 | 10 | def self.find(*args) |
| 9 | 11 | self.with_scope(:find => { :conditions => ['pending = ?', false] }) do |
| ... | ... | @@ -11,6 +13,9 @@ class Tag |
| 11 | 13 | end |
| 12 | 14 | end |
| 13 | 15 | |
| 16 | + acts_as_ferret :fields => [:name] | |
| 17 | + | |
| 18 | + | |
| 14 | 19 | # Return all the tags that were suggested but not yet approved |
| 15 | 20 | def self.find_pendings |
| 16 | 21 | self.find_with_pendings(:all, :conditions => ['pending = ?', true]) | ... | ... |