Commit f47a881be9a6223425c78945967b7c41568c4c18
1 parent
fb3fc6e4
Exists in
elasticsearch_api
Adding event to models and adding styles
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
6 changed files
with
78 additions
and
50 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
@@ -3,14 +3,14 @@ class ElasticsearchPluginController < ApplicationController | @@ -3,14 +3,14 @@ class ElasticsearchPluginController < ApplicationController | ||
3 | 3 | ||
4 | SEARCHABLE_TYPES = { :all => { label: _("All Results")}, | 4 | SEARCHABLE_TYPES = { :all => { label: _("All Results")}, |
5 | :community => { label: _("Communities")}, | 5 | :community => { label: _("Communities")}, |
6 | - :article => { label: _("Articles")}, | ||
7 | :event => { label: _("Events")}, | 6 | :event => { label: _("Events")}, |
8 | :person => { label: _("People")} | 7 | :person => { label: _("People")} |
9 | - } | ||
10 | - SEARCH_FILTERS = { :lexical => { label: _("Alphabetical Order")}, | ||
11 | - :recent => { label: _("More Recent Order")}, | ||
12 | - :access => { label: _("More accessed")} | ||
13 | - } | 8 | + } |
9 | + | ||
10 | + SEARCH_FILTERS = { :lexical => { label: _("Alphabetical Order")}, | ||
11 | + :recent => { label: _("More Recent Order")}, | ||
12 | + :access => { label: _("More accessed")} | ||
13 | + } | ||
14 | 14 | ||
15 | def index | 15 | def index |
16 | search() | 16 | search() |
@@ -18,22 +18,21 @@ class ElasticsearchPluginController < ApplicationController | @@ -18,22 +18,21 @@ class ElasticsearchPluginController < ApplicationController | ||
18 | end | 18 | end |
19 | 19 | ||
20 | def search | 20 | def search |
21 | - @searchable_types = SEARCHABLE_TYPES | ||
22 | - @selected_type = selected_type params | ||
23 | - @search_filter_types = SEARCH_FILTERS | 21 | + define_searchable_types |
22 | + define_search_fields_types | ||
24 | 23 | ||
25 | @query = params[:q] | 24 | @query = params[:q] |
26 | @results = [] | 25 | @results = [] |
27 | 26 | ||
28 | -# results 'article' | ||
29 | - results 'people' | ||
30 | - # results "community" | 27 | + if @selected_type == :all |
28 | + SEARCHABLE_TYPES.keys.each do |type| | ||
29 | + results type.to_s | ||
30 | + end | ||
31 | + else | ||
32 | + results @selected_type | ||
33 | + end | ||
31 | end | 34 | end |
32 | 35 | ||
33 | - def selected_type params | ||
34 | - return :all if params[:selected_type].nil? | ||
35 | - params[:selected_type] | ||
36 | - end | ||
37 | 36 | ||
38 | private | 37 | private |
39 | 38 | ||
@@ -76,10 +75,23 @@ class ElasticsearchPluginController < ApplicationController | @@ -76,10 +75,23 @@ class ElasticsearchPluginController < ApplicationController | ||
76 | end | 75 | end |
77 | 76 | ||
78 | def results model | 77 | def results model |
79 | - klass = model.to_s.classify.constantize | 78 | + begin |
79 | + klass = model.to_s.classify.constantize | ||
80 | + rescue | ||
81 | + return | ||
82 | + end | ||
80 | query = get_query params[:q], klass | 83 | query = get_query params[:q], klass |
81 | - query = {} | ||
82 | @results |= klass.__elasticsearch__.search(query).records.to_a | 84 | @results |= klass.__elasticsearch__.search(query).records.to_a |
83 | end | 85 | end |
84 | 86 | ||
87 | + def define_searchable_types | ||
88 | + @searchable_types = SEARCHABLE_TYPES | ||
89 | + @selected_type = params[:selected_type].nil? ? :all : params[:selected_type].to_sym | ||
90 | + end | ||
91 | + | ||
92 | + def define_search_fields_types | ||
93 | + @search_filter_types = SEARCH_FILTERS | ||
94 | + @selected_filter_field = params[:selected_filter_field].nil? ? SEARCH_FILTERS.keys.first : params[:selected_filter_field].to_sym | ||
95 | + end | ||
96 | + | ||
85 | end | 97 | end |
plugins/elasticsearch/public/style.css
1 | -.wrapper { | 1 | +.controller-elasticsearch_plugin .wrapper { |
2 | display: flex; | 2 | display: flex; |
3 | } | 3 | } |
4 | -.sidebar { | 4 | + |
5 | +.controller-elasticsearch_plugin .sidebar { | ||
5 | width: 150px; | 6 | width: 150px; |
6 | } | 7 | } |
7 | 8 | ||
8 | -.search_form { | 9 | +.controller-elasticsearch_plugin .search_form { |
9 | flex: 1; | 10 | flex: 1; |
10 | } | 11 | } |
11 | 12 | ||
13 | +.controller-elasticsearch_plugin .search_form .search_field { | ||
14 | + margin-top: 5px; | ||
15 | +} | ||
16 | +.controller-elasticsearch_plugin .search_form .search_field #q { | ||
17 | + width: 500px; | ||
18 | +} | ||
19 | + | ||
20 | +.controller-elasticsearch_plugin .results-count { | ||
21 | + margin-top: 7px; | ||
22 | + margin-right: 15px; | ||
23 | + text-align: right; | ||
24 | +} | ||
25 | + | ||
12 | .controller-elasticsearch_plugin ul { | 26 | .controller-elasticsearch_plugin ul { |
13 | list-style: none; | 27 | list-style: none; |
14 | list-style-position: inside; | 28 | list-style-position: inside; |
@@ -38,8 +52,7 @@ | @@ -38,8 +52,7 @@ | ||
38 | color: black; | 52 | color: black; |
39 | } | 53 | } |
40 | 54 | ||
41 | -.controller-elasticsearch_plugin .search-item .right-side .model-label, | ||
42 | -.controller-elasticsearch_plugin .community-header .model-label { | 55 | +.controller-elasticsearch_plugin .search-item .model-label { |
43 | background: #ddd; | 56 | background: #ddd; |
44 | color: black; | 57 | color: black; |
45 | font-weight: 900; | 58 | font-weight: 900; |
@@ -49,6 +62,9 @@ | @@ -49,6 +62,9 @@ | ||
49 | .controller-elasticsearch_plugin .search-item { | 62 | .controller-elasticsearch_plugin .search-item { |
50 | margin-bottom: 25px; | 63 | margin-bottom: 25px; |
51 | margin-top: 25px; | 64 | margin-top: 25px; |
65 | +} | ||
66 | + | ||
67 | +.controller-elasticsearch_plugin .search-item .person-item { | ||
52 | display: flex; | 68 | display: flex; |
53 | } | 69 | } |
54 | 70 |
plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb
plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb
0 → 100644
plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb
1 | -<div class="left-side"> | ||
2 | - <%= profile_image person %> | ||
3 | -</div> | ||
4 | -<div class="right-side"> | ||
5 | - <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= person.name %> <span class="model-label"><%= _("PERSON") %></span> | ||
6 | - <div class="body"> | ||
7 | - <h2><%= person.name %></h2> | ||
8 | - <p><%= person.description %></p> | 1 | +<div class="person-item"> |
2 | + <div class="left-side"> | ||
3 | + <%= profile_image person %> | ||
4 | + </div> | ||
5 | + <div class="right-side"> | ||
6 | + <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= person.name %> <span class="model-label"><%= _("PERSON") %></span> | ||
7 | + <div class="body"> | ||
8 | + <h2><%= person.name %></h2> | ||
9 | + <p><%= person.description %></p> | ||
10 | + </div> | ||
9 | </div> | 11 | </div> |
10 | </div> | 12 | </div> |
11 | - |
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
1 | <div class="wrapper"> | 1 | <div class="wrapper"> |
2 | 2 | ||
3 | <div class="sidebar"> | 3 | <div class="sidebar"> |
4 | - <%= @results.count %> | 4 | + <div class="results-count"> |
5 | + <%= @results.count %> <%= _(" results by") %> : | ||
6 | + </div> | ||
5 | <ul> | 7 | <ul> |
6 | - <li class="select-search-type active"><a href="#"> <%= @searchable_types.values[0][:label] %></a></li> | ||
7 | - <% for type in @searchable_types.values %> | ||
8 | - <li class="select-search-type"><a href="#"> <%= type[:label] %></a></li> | 8 | + <% for type,value in @searchable_types %> |
9 | + <li class="select-search-type <%= "active" if type == @selected_type %>"> | ||
10 | + <%= link_to value[:label], "?selected_type=#{type}&q=#{@query}&selected_filter_field=#{@selected_filter_field}"%> | ||
11 | + </li> | ||
9 | <% end %> | 12 | <% end %> |
10 | </ul> | 13 | </ul> |
11 | 14 | ||
@@ -23,7 +26,8 @@ | @@ -23,7 +26,8 @@ | ||
23 | <div class="search_field"> | 26 | <div class="search_field"> |
24 | <%= form_tag controller: "elasticsearch_plugin", action: "search" do %> | 27 | <%= form_tag controller: "elasticsearch_plugin", action: "search" do %> |
25 | <%= text_field_tag(:q, @query) %> | 28 | <%= text_field_tag(:q, @query) %> |
26 | - | 29 | + <%= hidden_field_tag 'selected_type', @selected_type %> |
30 | + <%= hidden_field_tag 'selected_filter_field', @selected_filter_field %> | ||
27 | <%= submit_tag _("Send") %> | 31 | <%= submit_tag _("Send") %> |
28 | <% end %> | 32 | <% end %> |
29 | </div> | 33 | </div> |
@@ -32,17 +36,14 @@ | @@ -32,17 +36,14 @@ | ||
32 | <% for result in @results %> | 36 | <% for result in @results %> |
33 | <% for klass in @searchable_types.keys %> | 37 | <% for klass in @searchable_types.keys %> |
34 | <% next if klass.to_s.include? "all" %> | 38 | <% next if klass.to_s.include? "all" %> |
35 | - | ||
36 | <% if result.is_a? klass.to_s.classify.constantize %> | 39 | <% if result.is_a? klass.to_s.classify.constantize %> |
37 | <div class="search-item"> | 40 | <div class="search-item"> |
38 | <%= render partial: "#{klass}_display", :locals => { klass => result} %> | 41 | <%= render partial: "#{klass}_display", :locals => { klass => result} %> |
39 | </div> | 42 | </div> |
40 | <% break %> | 43 | <% break %> |
41 | <% end %> | 44 | <% end %> |
42 | - | ||
43 | <% end %> | 45 | <% end %> |
44 | <% end %> | 46 | <% end %> |
45 | </div> | 47 | </div> |
46 | </div> | 48 | </div> |
47 | - | ||
48 | </div> | 49 | </div> |