Commit d99b4cc3c08227f890e8314b97936634e6e167b5

Authored by Dylan Guedes
Committed by Macartur Sousa
1 parent 7aba5bb2

Creates plugin helper, add categories list

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Macartur de Sousa <macartur.sc@gmail.com>
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
1 require_relative '../helpers/elasticsearch_helper' 1 require_relative '../helpers/elasticsearch_helper'
  2 +require_relative '../helpers/elasticsearch_plugin_helper'
2 3
3 class ElasticsearchPluginController < ApplicationController 4 class ElasticsearchPluginController < ApplicationController
4 no_design_blocks 5 no_design_blocks
5 include ElasticsearchHelper 6 include ElasticsearchHelper
  7 + helper ElasticsearchPluginHelper
6 8
7 def index 9 def index
8 search() 10 search()
@@ -12,6 +14,7 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -12,6 +14,7 @@ class ElasticsearchPluginController &lt; ApplicationController
12 def search 14 def search
13 define_searchable_types 15 define_searchable_types
14 define_sort_types 16 define_sort_types
  17 + define_categories
15 define_results 18 define_results
16 end 19 end
17 20
@@ -31,4 +34,8 @@ class ElasticsearchPluginController &lt; ApplicationController @@ -31,4 +34,8 @@ class ElasticsearchPluginController &lt; ApplicationController
31 @selected_sort = (params[:filter] || :relevance).to_sym 34 @selected_sort = (params[:filter] || :relevance).to_sym
32 end 35 end
33 36
  37 + def define_categories
  38 + @categories = Category.where(parent: nil)
  39 + end
  40 +
34 end 41 end
plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb 0 → 100644
@@ -0,0 +1,20 @@ @@ -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,7 +11,7 @@ class TextArticle
11 def self.control_fields 11 def self.control_fields
12 { 12 {
13 :advertise => { type: :boolean }, 13 :advertise => { type: :boolean },
14 - :published => { type: 'boolean'}, 14 + :published => { type: :boolean },
15 :comments_count => { type: :integer }, 15 :comments_count => { type: :integer },
16 :hits => { type: :integer }, 16 :hits => { type: :integer },
17 :profile => { type: :nested , hash: NestedProfile.hash } 17 :profile => { type: :nested , hash: NestedProfile.hash }
plugins/elasticsearch/public/style.css
@@ -50,6 +50,7 @@ @@ -50,6 +50,7 @@
50 font-size: 18px; 50 font-size: 18px;
51 } 51 }
52 52
  53 +.controller-elasticsearch_plugin #content-inner .categories,
53 .controller-elasticsearch_plugin #content-inner .search-filter, 54 .controller-elasticsearch_plugin #content-inner .search-filter,
54 .controller-elasticsearch_plugin #content-inner ul.search-options { 55 .controller-elasticsearch_plugin #content-inner ul.search-options {
55 background: #fff; 56 background: #fff;
@@ -145,3 +146,6 @@ @@ -145,3 +146,6 @@
145 text-decoration: none; 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,6 +41,11 @@
41 <% end %> 41 <% end %>
42 </ul> 42 </ul>
43 </div> 43 </div>
  44 +
  45 + <div class="categories">
  46 + <h3 class="box-title"><%= _("Categories") %></h3>
  47 + <%= render_categories @categories %>
  48 + </div>
44 </div> 49 </div>
45 50
46 <div class="results"> 51 <div class="results">
@@ -59,5 +64,6 @@ @@ -59,5 +64,6 @@
59 <%= pagination_links @results if @results.count > 0 %> 64 <%= pagination_links @results if @results.count > 0 %>
60 </div> 65 </div>
61 </div> 66 </div>
  67 +
62 </div> 68 </div>
63 </div> 69 </div>