From f47a881be9a6223425c78945967b7c41568c4c18 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Wed, 8 Jun 2016 10:13:12 -0300 Subject: [PATCH] Adding event to models and adding styles --- plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb | 48 ++++++++++++++++++++++++++++++------------------ plugins/elasticsearch/public/style.css | 26 +++++++++++++++++++++----- plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb | 10 ---------- plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb | 8 ++++++++ plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb | 19 ++++++++++--------- plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb | 17 +++++++++-------- 6 files changed, 78 insertions(+), 50 deletions(-) delete mode 100644 plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb create mode 100644 plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index 904745a..bc9f3c7 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -3,14 +3,14 @@ class ElasticsearchPluginController < ApplicationController SEARCHABLE_TYPES = { :all => { label: _("All Results")}, :community => { label: _("Communities")}, - :article => { label: _("Articles")}, :event => { label: _("Events")}, :person => { label: _("People")} - } - SEARCH_FILTERS = { :lexical => { label: _("Alphabetical Order")}, - :recent => { label: _("More Recent Order")}, - :access => { label: _("More accessed")} - } + } + + SEARCH_FILTERS = { :lexical => { label: _("Alphabetical Order")}, + :recent => { label: _("More Recent Order")}, + :access => { label: _("More accessed")} + } def index search() @@ -18,22 +18,21 @@ class ElasticsearchPluginController < ApplicationController end def search - @searchable_types = SEARCHABLE_TYPES - @selected_type = selected_type params - @search_filter_types = SEARCH_FILTERS + define_searchable_types + define_search_fields_types @query = params[:q] @results = [] -# results 'article' - results 'people' - # results "community" + if @selected_type == :all + SEARCHABLE_TYPES.keys.each do |type| + results type.to_s + end + else + results @selected_type + end end - def selected_type params - return :all if params[:selected_type].nil? - params[:selected_type] - end private @@ -76,10 +75,23 @@ class ElasticsearchPluginController < ApplicationController end def results model - klass = model.to_s.classify.constantize + begin + klass = model.to_s.classify.constantize + rescue + return + end query = get_query params[:q], klass - query = {} @results |= klass.__elasticsearch__.search(query).records.to_a end + def define_searchable_types + @searchable_types = SEARCHABLE_TYPES + @selected_type = params[:selected_type].nil? ? :all : params[:selected_type].to_sym + end + + def define_search_fields_types + @search_filter_types = SEARCH_FILTERS + @selected_filter_field = params[:selected_filter_field].nil? ? SEARCH_FILTERS.keys.first : params[:selected_filter_field].to_sym + end + end diff --git a/plugins/elasticsearch/public/style.css b/plugins/elasticsearch/public/style.css index 9074da3..f312b95 100644 --- a/plugins/elasticsearch/public/style.css +++ b/plugins/elasticsearch/public/style.css @@ -1,14 +1,28 @@ -.wrapper { +.controller-elasticsearch_plugin .wrapper { display: flex; } -.sidebar { + +.controller-elasticsearch_plugin .sidebar { width: 150px; } -.search_form { +.controller-elasticsearch_plugin .search_form { flex: 1; } +.controller-elasticsearch_plugin .search_form .search_field { + margin-top: 5px; +} +.controller-elasticsearch_plugin .search_form .search_field #q { + width: 500px; +} + +.controller-elasticsearch_plugin .results-count { + margin-top: 7px; + margin-right: 15px; + text-align: right; +} + .controller-elasticsearch_plugin ul { list-style: none; list-style-position: inside; @@ -38,8 +52,7 @@ color: black; } -.controller-elasticsearch_plugin .search-item .right-side .model-label, -.controller-elasticsearch_plugin .community-header .model-label { +.controller-elasticsearch_plugin .search-item .model-label { background: #ddd; color: black; font-weight: 900; @@ -49,6 +62,9 @@ .controller-elasticsearch_plugin .search-item { margin-bottom: 25px; margin-top: 25px; +} + +.controller-elasticsearch_plugin .search-item .person-item { display: flex; } diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb deleted file mode 100644 index 68c2331..0000000 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
-

<%= article.name %>

- - -
- MY BODY CONTENT -
-
diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb new file mode 100644 index 0000000..ef54cf3 --- /dev/null +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb @@ -0,0 +1,8 @@ +
+ <%= event.created_at.strftime("%d %B %Y at %H:%M") %> - EVENT +
+ +
+

<%= event.name %>

+

<%= event.body %>

+
diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb index 1c15e05..e709282 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb @@ -1,11 +1,12 @@ -
- <%= profile_image person %> -
-
- <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= person.name %> <%= _("PERSON") %> -
-

<%= person.name %>

-

<%= person.description %>

+
+
+ <%= profile_image person %> +
+
+ <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= person.name %> <%= _("PERSON") %> +
+

<%= person.name %>

+

<%= person.description %>

+
- diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb index 6b2e3b8..aa50b66 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb @@ -1,11 +1,14 @@
-
-- libgit2 0.21.2