Commit dc3d7f7a2e7379a2354c617bcbdd3b63ee9a1a01

Authored by Evandro Junior
2 parents ad2ef918 3a2b55ee

Merge branch 'staging' into captcha_serpro_plugin

* staging:
  Update proposals_discussion plugin
  New hotspot to add custom buttons on content manager page
  pg_search: refactor search query
app/views/cms/_view_items.html.erb
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 <%= time_ago_in_words article.updated_at %> 13 <%= time_ago_in_words article.updated_at %>
14 </td> 14 </td>
15 <td class="article-controls"> 15 <td class="article-controls">
  16 + <%= @plugins.dispatch(:extra_content_actions, article).collect { |content| instance_exec(&content) }.join("") %>
16 <%= expirable_button article, :edit, _('Edit'), {:action => 'edit', :id => article.id} if !remove_content_button(:edit, article) %> 17 <%= expirable_button article, :edit, _('Edit'), {:action => 'edit', :id => article.id} if !remove_content_button(:edit, article) %>
17 <%= button_without_text :eyes, _('Public view'), article.view_url %> 18 <%= button_without_text :eyes, _('Public view'), article.view_url %>
18 <%= display_spread_button(article) unless remove_content_button(:spread, article) %> 19 <%= display_spread_button(article) unless remove_content_button(:spread, article) %>
lib/noosfero/plugin.rb
@@ -260,6 +260,13 @@ class Noosfero::Plugin @@ -260,6 +260,13 @@ class Noosfero::Plugin
260 end.select {|const| const.is_a?(Class) && const < Noosfero::Plugin::Macro} 260 end.select {|const| const.is_a?(Class) && const < Noosfero::Plugin::Macro}
261 end 261 end
262 262
  263 + # New buttons actions with icons in each article on content manager page
  264 + # returns = proc block that creates html code to custom buttons
  265 + #
  266 + def extra_content_actions(article)
  267 + nil
  268 + end
  269 +
263 # Here the developer may specify the events to which the plugins can 270 # Here the developer may specify the events to which the plugins can
264 # register and must return true or false. The default value must be false. 271 # register and must return true or false. The default value must be false.
265 # Must also explicitly define its returning variables. 272 # Must also explicitly define its returning variables.
plugins/pg_search/lib/ext/active_record.rb
@@ -4,9 +4,8 @@ class ActiveRecord::Base @@ -4,9 +4,8 @@ class ActiveRecord::Base
4 def self.pg_search_plugin_search(query) 4 def self.pg_search_plugin_search(query)
5 filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') 5 filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
6 if defined?(self::SEARCHABLE_FIELDS) 6 if defined?(self::SEARCHABLE_FIELDS)
7 - select("*,ts_rank(to_tsvector('simple', #{pg_search_plugin_fields}), to_tsquery('#{filtered_query}')) as rank").  
8 - where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')").  
9 - order("rank DESC") 7 + where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')").
  8 + order("ts_rank(to_tsvector('simple', #{pg_search_plugin_fields}), to_tsquery('#{filtered_query}')) DESC")
10 else 9 else
11 raise "No searchable fields defined for #{self.name}" 10 raise "No searchable fields defined for #{self.name}"
12 end 11 end
plugins/proposals_discussion
1 -Subproject commit 5aa7a5fa14d9ba12b0588696449a5a89c60c1092 1 +Subproject commit a8df9e37aa5eaee1d1b5195d1de945c298a7e43e
test/unit/plugin_test.rb
@@ -567,4 +567,16 @@ class PluginTest &lt; ActiveSupport::TestCase @@ -567,4 +567,16 @@ class PluginTest &lt; ActiveSupport::TestCase
567 assert_equal [], p.article_extra_toolbar_buttons(nil) 567 assert_equal [], p.article_extra_toolbar_buttons(nil)
568 end 568 end
569 569
  570 + should 'get extra buttons actions on content manager grid' do
  571 + class Plugin1 < Noosfero::Plugin
  572 + def extra_content_actions
  573 + proc do
  574 + '<a href="#" class="icon">Btn</a>'
  575 + end
  576 + end
  577 + end
  578 + p = Plugin1.new
  579 + assert_tag_in_string p.extra_content_actions.call(), :tag => 'a', :content => 'Btn'
  580 + end
  581 +
570 end 582 end