diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
index f7ccdb1..3980021 100644
--- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
+++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
@@ -36,6 +36,7 @@ class ElasticsearchPluginController < ApplicationController
def define_categories
@categories = Category.where(parent: nil)
+ @selected_categories = (params[:categories] || "").split(",")
end
end
diff --git a/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb b/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
index d4ae4f3..16b8ffb 100644
--- a/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
+++ b/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
@@ -1,18 +1,18 @@
module ElasticsearchPluginHelper
- def render_categories collection
+ def render_categories(collection, selected_collections)
content_tag :ul, class: "category-ident" do
if collection.respond_to? :each
collection.collect do |item|
concat ("
".html_safe)
- concat (check_box_tag item.name)
- concat (item.name)
- concat (render_categories item.children) if item.children_count
+ concat (check_box_tag(item.name, item.id, selected_collections.include?(item.id.to_s)) )
+ concat (label_tag item.name)
+ concat (render_categories(item.children, selected_collections)) if item.children_count > 0
concat ("".html_safe)
end
else
- check_box_tag collection.name
- content_tag :li, collection.name
+ check_box_tag collection.name, collection.id, selected_collections.include?(collection.id)
+ label_tag collection.name
end
end
end
diff --git a/plugins/elasticsearch/lib/elasticsearch_plugin.rb b/plugins/elasticsearch/lib/elasticsearch_plugin.rb
index bceac96..e50119b 100644
--- a/plugins/elasticsearch/lib/elasticsearch_plugin.rb
+++ b/plugins/elasticsearch/lib/elasticsearch_plugin.rb
@@ -16,6 +16,10 @@ class ElasticsearchPlugin < Noosfero::Plugin
true
end
+ def js_files
+ ['categories'].map{ |j| "javascripts/#{j}" }
+ end
+
def search_controller_filters
block = proc do
diff --git a/plugins/elasticsearch/public/javascripts/categories.js b/plugins/elasticsearch/public/javascripts/categories.js
new file mode 100644
index 0000000..bad3d02
--- /dev/null
+++ b/plugins/elasticsearch/public/javascripts/categories.js
@@ -0,0 +1,16 @@
+var main = function() {
+ $('.categories ul li input').on("click", function() {
+ var categoryParam = "";
+ if (window.location.href.search("categories") < 0) {
+ categoryParam += "&categories=";
+ }
+ if ($(".categories ul li input[checked]").length > 0){
+ categoryParam += ("," + this.value);
+ } else {
+ categoryParam += (this.value);
+ }
+ window.location.href += categoryParam;
+ });
+};
+
+$(document).ready(main);
diff --git a/plugins/elasticsearch/public/style.css b/plugins/elasticsearch/public/style.css
index 15f17a9..900de26 100644
--- a/plugins/elasticsearch/public/style.css
+++ b/plugins/elasticsearch/public/style.css
@@ -149,3 +149,16 @@
.controller-elasticsearch_plugin #content-inner .categories .category-ident {
margin-left: 10px;
}
+
+.controller-elasticsearch_plugin #content-inner .categories .box-title {
+ margin-bottom: 20px;
+}
+
+.controller-elasticsearch_plugin #content-inner .categories ul li {
+ padding: 5px;
+ font-size: 15px;
+}
+
+.controller-elasticsearch_plugin #content-inner .categories li input {
+ margin-right: 5px;
+}
diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
index 4c0d2b3..7ce5272 100644
--- a/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
+++ b/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
@@ -27,7 +27,7 @@
<% for type,value in @searchable_types %>
- ">
- <%= link_to value[:label], "?selected_type=#{type}&query=#{@query}"%>
+ <%= link_to value[:label], "?selected_type=#{type}&query=#{@query}&categories=#{@selected_categories.join(',')}"%>
<% end %>
@@ -36,7 +36,7 @@
<% for type, value in @sort_types %>
- ">
- <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}" %>
+ <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}&categories=#{@selected_categories.join(',')}" %>
<% end %>
@@ -44,7 +44,7 @@
<%= _("Categories") %>
- <%= render_categories @categories %>
+ <%= render_categories(@categories, @selected_categories) %>
--
libgit2 0.21.2