Commit d99b4cc3c08227f890e8314b97936634e6e167b5
Committed by
Macartur Sousa
1 parent
7aba5bb2
Exists in
elasticsearch_categories
Creates plugin helper, add categories list
Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: Macartur de Sousa <macartur.sc@gmail.com>
Showing
5 changed files
with
38 additions
and
1 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
1 | 1 | require_relative '../helpers/elasticsearch_helper' |
2 | +require_relative '../helpers/elasticsearch_plugin_helper' | |
2 | 3 | |
3 | 4 | class ElasticsearchPluginController < ApplicationController |
4 | 5 | no_design_blocks |
5 | 6 | include ElasticsearchHelper |
7 | + helper ElasticsearchPluginHelper | |
6 | 8 | |
7 | 9 | def index |
8 | 10 | search() |
... | ... | @@ -12,6 +14,7 @@ class ElasticsearchPluginController < ApplicationController |
12 | 14 | def search |
13 | 15 | define_searchable_types |
14 | 16 | define_sort_types |
17 | + define_categories | |
15 | 18 | define_results |
16 | 19 | end |
17 | 20 | |
... | ... | @@ -31,4 +34,8 @@ class ElasticsearchPluginController < ApplicationController |
31 | 34 | @selected_sort = (params[:filter] || :relevance).to_sym |
32 | 35 | end |
33 | 36 | |
37 | + def define_categories | |
38 | + @categories = Category.where(parent: nil) | |
39 | + end | |
40 | + | |
34 | 41 | end | ... | ... |
plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +module ElasticsearchPluginHelper | |
2 | + | |
3 | + def render_categories collection | |
4 | + content_tag :ul, class: "category-ident" do | |
5 | + if collection.respond_to? :each | |
6 | + collection.collect do |item| | |
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 | |
11 | + concat ("</li>".html_safe) | |
12 | + end | |
13 | + else | |
14 | + check_box_tag collection.name | |
15 | + content_tag :li, collection.name | |
16 | + end | |
17 | + end | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/elasticsearch/lib/ext/text_article.rb
... | ... | @@ -11,7 +11,7 @@ class TextArticle |
11 | 11 | def self.control_fields |
12 | 12 | { |
13 | 13 | :advertise => { type: :boolean }, |
14 | - :published => { type: 'boolean'}, | |
14 | + :published => { type: :boolean }, | |
15 | 15 | :comments_count => { type: :integer }, |
16 | 16 | :hits => { type: :integer }, |
17 | 17 | :profile => { type: :nested , hash: NestedProfile.hash } | ... | ... |
plugins/elasticsearch/public/style.css
... | ... | @@ -50,6 +50,7 @@ |
50 | 50 | font-size: 18px; |
51 | 51 | } |
52 | 52 | |
53 | +.controller-elasticsearch_plugin #content-inner .categories, | |
53 | 54 | .controller-elasticsearch_plugin #content-inner .search-filter, |
54 | 55 | .controller-elasticsearch_plugin #content-inner ul.search-options { |
55 | 56 | background: #fff; |
... | ... | @@ -145,3 +146,6 @@ |
145 | 146 | text-decoration: none; |
146 | 147 | } |
147 | 148 | |
149 | +.controller-elasticsearch_plugin #content-inner .categories .category-ident { | |
150 | + margin-left: 10px; | |
151 | +} | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
... | ... | @@ -41,6 +41,11 @@ |
41 | 41 | <% end %> |
42 | 42 | </ul> |
43 | 43 | </div> |
44 | + | |
45 | + <div class="categories"> | |
46 | + <h3 class="box-title"><%= _("Categories") %></h3> | |
47 | + <%= render_categories @categories %> | |
48 | + </div> | |
44 | 49 | </div> |
45 | 50 | |
46 | 51 | <div class="results"> |
... | ... | @@ -59,5 +64,6 @@ |
59 | 64 | <%= pagination_links @results if @results.count > 0 %> |
60 | 65 | </div> |
61 | 66 | </div> |
67 | + | |
62 | 68 | </div> |
63 | 69 | </div> | ... | ... |