Commit 1ddc3b4e54e29c893d40ce8a2bad4fbcdc27e8fa
Committed by
Macartur Sousa
1 parent
d99b4cc3
Exists in
elasticsearch_categories
Adds category params to controller
Signed-off-by: Macartur de Sousa <macartur.sc@gmail.com> Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Showing
6 changed files
with
43 additions
and
9 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
1 | 1 | module ElasticsearchPluginHelper |
2 | 2 | |
3 | - def render_categories collection | |
3 | + def render_categories(collection, selected_collections) | |
4 | 4 | content_tag :ul, class: "category-ident" do |
5 | 5 | if collection.respond_to? :each |
6 | 6 | collection.collect do |item| |
7 | 7 | concat ("<li>".html_safe) |
8 | - concat (check_box_tag item.name) | |
9 | - concat (item.name) | |
10 | - concat (render_categories item.children) if item.children_count | |
8 | + concat (check_box_tag(item.name, item.id, selected_collections.include?(item.id.to_s)) ) | |
9 | + concat (label_tag item.name) | |
10 | + concat (render_categories(item.children, selected_collections)) if item.children_count > 0 | |
11 | 11 | concat ("</li>".html_safe) |
12 | 12 | end |
13 | 13 | else |
14 | - check_box_tag collection.name | |
15 | - content_tag :li, collection.name | |
14 | + check_box_tag collection.name, collection.id, selected_collections.include?(collection.id) | |
15 | + label_tag collection.name | |
16 | 16 | end |
17 | 17 | end |
18 | 18 | end | ... | ... |
plugins/elasticsearch/lib/elasticsearch_plugin.rb
... | ... | @@ -0,0 +1,16 @@ |
1 | +var main = function() { | |
2 | + $('.categories ul li input').on("click", function() { | |
3 | + var categoryParam = ""; | |
4 | + if (window.location.href.search("categories") < 0) { | |
5 | + categoryParam += "&categories="; | |
6 | + } | |
7 | + if ($(".categories ul li input[checked]").length > 0){ | |
8 | + categoryParam += ("," + this.value); | |
9 | + } else { | |
10 | + categoryParam += (this.value); | |
11 | + } | |
12 | + window.location.href += categoryParam; | |
13 | + }); | |
14 | +}; | |
15 | + | |
16 | +$(document).ready(main); | ... | ... |
plugins/elasticsearch/public/style.css
... | ... | @@ -149,3 +149,16 @@ |
149 | 149 | .controller-elasticsearch_plugin #content-inner .categories .category-ident { |
150 | 150 | margin-left: 10px; |
151 | 151 | } |
152 | + | |
153 | +.controller-elasticsearch_plugin #content-inner .categories .box-title { | |
154 | + margin-bottom: 20px; | |
155 | +} | |
156 | + | |
157 | +.controller-elasticsearch_plugin #content-inner .categories ul li { | |
158 | + padding: 5px; | |
159 | + font-size: 15px; | |
160 | +} | |
161 | + | |
162 | +.controller-elasticsearch_plugin #content-inner .categories li input { | |
163 | + margin-right: 5px; | |
164 | +} | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | <ul class="search-options"> |
28 | 28 | <% for type,value in @searchable_types %> |
29 | 29 | <li class="select-search-type <%= "active" if type == @selected_type %>"> |
30 | - <%= link_to value[:label], "?selected_type=#{type}&query=#{@query}"%> | |
30 | + <%= link_to value[:label], "?selected_type=#{type}&query=#{@query}&categories=#{@selected_categories.join(',')}"%> | |
31 | 31 | </li> |
32 | 32 | <% end %> |
33 | 33 | </ul> |
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 | <ul> |
37 | 37 | <% for type, value in @sort_types %> |
38 | 38 | <li class="select-search-type <%= "active" if type == @selected_sort %>"> |
39 | - <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}" %> | |
39 | + <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}&categories=#{@selected_categories.join(',')}" %> | |
40 | 40 | </li> |
41 | 41 | <% end %> |
42 | 42 | </ul> |
... | ... | @@ -44,7 +44,7 @@ |
44 | 44 | |
45 | 45 | <div class="categories"> |
46 | 46 | <h3 class="box-title"><%= _("Categories") %></h3> |
47 | - <%= render_categories @categories %> | |
47 | + <%= render_categories(@categories, @selected_categories) %> | |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | ... | ... |