Commit 869c8a0047ca77c2466c5b053d85d7ab3c8d9921
1 parent
19471c06
Fixed MR Style
Showing
19 changed files
with
60 additions
and
86 deletions
Show diff stats
plugins/elasticsearch/Rakefile
@@ -2,10 +2,6 @@ | @@ -2,10 +2,6 @@ | ||
2 | 2 | ||
3 | require 'open-uri' | 3 | require 'open-uri' |
4 | 4 | ||
5 | -def elasticsearch_development | ||
6 | - return ENV["ELASTICSEARCH_DEVELOPMENT"].nil? | ||
7 | -end | ||
8 | - | ||
9 | desc "download elasticsearch" | 5 | desc "download elasticsearch" |
10 | task :download do | 6 | task :download do |
11 | unless File.exists? '/tmp/elasticsearch.deb' | 7 | unless File.exists? '/tmp/elasticsearch.deb' |
@@ -27,18 +23,14 @@ task :start do | @@ -27,18 +23,14 @@ task :start do | ||
27 | Rake::Task['install'].invoke | 23 | Rake::Task['install'].invoke |
28 | end | 24 | end |
29 | puts "Enable Elasticsearch service" | 25 | puts "Enable Elasticsearch service" |
30 | - if elasticsearch_development | ||
31 | - sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' | ||
32 | - sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' | ||
33 | - sleep 10 | ||
34 | - end | 26 | + sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' |
27 | + sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' | ||
28 | + sleep 10 | ||
35 | end | 29 | end |
36 | 30 | ||
37 | desc "stop elasticsearch" | 31 | desc "stop elasticsearch" |
38 | task :stop do | 32 | task :stop do |
39 | puts "Disable elasticsearch service" | 33 | puts "Disable elasticsearch service" |
40 | - if elasticsearch_development | ||
41 | - sh 'sudo systemctl stop elasticsearch >> /dev/null 2>&1' | ||
42 | - sh 'sudo systemctl disable elasticsearch >> /dev/null 2>&1' | ||
43 | - end | 34 | + sh 'sudo systemctl stop elasticsearch >> /dev/null 2>&1' |
35 | + sh 'sudo systemctl disable elasticsearch >> /dev/null 2>&1' | ||
44 | end | 36 | end |
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
@@ -25,7 +25,7 @@ class ElasticsearchPluginController < ApplicationController | @@ -25,7 +25,7 @@ class ElasticsearchPluginController < ApplicationController | ||
25 | def define_results | 25 | def define_results |
26 | @query = params[:query] | 26 | @query = params[:query] |
27 | @results = process_results | 27 | @results = process_results |
28 | - @hits = ( @results.try(:total) || 0 ) | 28 | + @hits = (@results.try(:total) || 0) |
29 | end | 29 | end |
30 | 30 | ||
31 | def define_searchable_types | 31 | def define_searchable_types |
plugins/elasticsearch/helpers/elasticsearch_helper.rb
@@ -2,27 +2,27 @@ module ElasticsearchHelper | @@ -2,27 +2,27 @@ module ElasticsearchHelper | ||
2 | 2 | ||
3 | def searchable_types | 3 | def searchable_types |
4 | { | 4 | { |
5 | - :all => { label: _("All Results")}, | ||
6 | - :text_article => { label: _("Articles")}, | ||
7 | - :uploaded_file => { label: _("Files")}, | ||
8 | - :community => { label: _("Communities")}, | ||
9 | - :event => { label: _("Events")}, | ||
10 | - :person => { label: _("People")} | 5 | + :all => _("All Results"), |
6 | + :text_article => _("Articles"), | ||
7 | + :uploaded_file => _("Files"), | ||
8 | + :community => _("Communities"), | ||
9 | + :event => _("Events"), | ||
10 | + :person => _("People") | ||
11 | } | 11 | } |
12 | end | 12 | end |
13 | 13 | ||
14 | def sort_types | 14 | def sort_types |
15 | sorts = { | 15 | sorts = { |
16 | - :relevance => { label: _("Relevance")}, | ||
17 | - :lexical => { label: _("Alphabetical")}, | ||
18 | - :more_recent => { label: _("More Recent")}, | 16 | + :relevance => _("Relevance"), |
17 | + :lexical => _("Alphabetical"), | ||
18 | + :more_recent => _("More Recent") | ||
19 | } | 19 | } |
20 | 20 | ||
21 | - selected_type = params[:selected_type] || nil | 21 | + selected_type = (params[:selected_type] || nil) |
22 | 22 | ||
23 | if selected_type and selected_type.to_sym != :all | 23 | if selected_type and selected_type.to_sym != :all |
24 | klass = selected_type.to_s.classify.constantize | 24 | klass = selected_type.to_s.classify.constantize |
25 | - sorts.update klass.especific_sort if klass.respond_to? :especific_sort | 25 | + sorts.update klass.specific_sort if klass.respond_to? :specific_sort |
26 | end | 26 | end |
27 | sorts | 27 | sorts |
28 | end | 28 | end |
@@ -36,7 +36,7 @@ module ElasticsearchHelper | @@ -36,7 +36,7 @@ module ElasticsearchHelper | ||
36 | 36 | ||
37 | def search_from_all_models | 37 | def search_from_all_models |
38 | begin | 38 | begin |
39 | - filter = (params[:filter] || "" ).to_sym | 39 | + filter = (params[:filter] || "").to_sym |
40 | query = get_query params[:query], sort_by: get_sort_by(filter), categories: params[:categories] | 40 | query = get_query params[:query], sort_by: get_sort_by(filter), categories: params[:categories] |
41 | Elasticsearch::Model.search(query,searchable_models, size: default_per_page(params[:per_page])).page(params[:page]).records | 41 | Elasticsearch::Model.search(query,searchable_models, size: default_per_page(params[:per_page])).page(params[:page]).records |
42 | rescue | 42 | rescue |
@@ -44,10 +44,10 @@ module ElasticsearchHelper | @@ -44,10 +44,10 @@ module ElasticsearchHelper | ||
44 | end | 44 | end |
45 | end | 45 | end |
46 | 46 | ||
47 | - def search_from_model model | 47 | + def search_from_model(model) |
48 | begin | 48 | begin |
49 | klass = model.to_s.classify.constantize | 49 | klass = model.to_s.classify.constantize |
50 | - filter = (params[:filter] || "" ).to_sym | 50 | + filter = (params[:filter] || "").to_sym |
51 | query = get_query params[:query], klass: klass, sort_by: get_sort_by(filter ,klass), categories: params[:categories] | 51 | query = get_query params[:query], klass: klass, sort_by: get_sort_by(filter ,klass), categories: params[:categories] |
52 | klass.search(query, size: default_per_page(params[:per_page])).page(params[:page]).records | 52 | klass.search(query, size: default_per_page(params[:per_page])).page(params[:page]).records |
53 | rescue | 53 | rescue |
@@ -55,26 +55,26 @@ module ElasticsearchHelper | @@ -55,26 +55,26 @@ module ElasticsearchHelper | ||
55 | end | 55 | end |
56 | end | 56 | end |
57 | 57 | ||
58 | - def default_per_page per_page=nil | ||
59 | - per_page ||= 10 | 58 | + def default_per_page(per_page=nil) |
59 | + per_page || 10 | ||
60 | end | 60 | end |
61 | 61 | ||
62 | - def get_sort_by sort_by, klass=nil | 62 | + def get_sort_by(sort_by, klass=nil) |
63 | case sort_by | 63 | case sort_by |
64 | when :lexical | 64 | when :lexical |
65 | - { "name.raw" => {"order" => "asc" }} | 65 | + {"name.raw" => {"order" => "asc"}} |
66 | when :more_recent | 66 | when :more_recent |
67 | - { "created_at" => {"order" => "desc"}} | 67 | + {"created_at" => {"order" => "desc"}} |
68 | else | 68 | else |
69 | - ( klass and klass.respond_to?(:get_sort_by) ) ? klass.get_sort_by(sort_by) : nil | 69 | + (klass and klass.respond_to?(:get_sort_by)) ? klass.get_sort_by(sort_by) : nil |
70 | end | 70 | end |
71 | end | 71 | end |
72 | 72 | ||
73 | def searchable_models | 73 | def searchable_models |
74 | - searchable_types.except(:all).keys.map { | model | model.to_s.classify.constantize } | 74 | + searchable_types.except(:all).keys.map {|model| model.to_s.classify.constantize} |
75 | end | 75 | end |
76 | 76 | ||
77 | - def query_string expression="", models=[] | 77 | + def query_string(expression="", models=[]) |
78 | return { match_all: {} } if not expression | 78 | return { match_all: {} } if not expression |
79 | { | 79 | { |
80 | query_string: { | 80 | query_string: { |
@@ -87,7 +87,7 @@ module ElasticsearchHelper | @@ -87,7 +87,7 @@ module ElasticsearchHelper | ||
87 | end | 87 | end |
88 | 88 | ||
89 | 89 | ||
90 | - def query_method expression="", models=[], categories=[] | 90 | + def query_method(expression="", models=[], categories=[]) |
91 | query = {} | 91 | query = {} |
92 | query[:query] = { | 92 | query[:query] = { |
93 | filtered: { | 93 | filtered: { |
@@ -99,7 +99,7 @@ module ElasticsearchHelper | @@ -99,7 +99,7 @@ module ElasticsearchHelper | ||
99 | } | 99 | } |
100 | 100 | ||
101 | query[:query][:filtered][:filter][:bool] = { | 101 | query[:query][:filtered][:filter][:bool] = { |
102 | - should: models.map {|model| model.filter(environment: @environment.id) } | 102 | + should: models.map {|model| model.filter(environment: @environment.id)} |
103 | } | 103 | } |
104 | 104 | ||
105 | unless categories.blank? | 105 | unless categories.blank? |
@@ -109,7 +109,7 @@ module ElasticsearchHelper | @@ -109,7 +109,7 @@ module ElasticsearchHelper | ||
109 | query | 109 | query |
110 | end | 110 | end |
111 | 111 | ||
112 | - def get_query text="", options={} | 112 | + def get_query(text="", options={}) |
113 | klass = options[:klass] | 113 | klass = options[:klass] |
114 | sort_by = options[:sort_by] | 114 | sort_by = options[:sort_by] |
115 | categories = (options[:categories] || "").split(",") | 115 | categories = (options[:categories] || "").split(",") |
@@ -123,7 +123,7 @@ module ElasticsearchHelper | @@ -123,7 +123,7 @@ module ElasticsearchHelper | ||
123 | query | 123 | query |
124 | end | 124 | end |
125 | 125 | ||
126 | - def fields_from_models klasses | 126 | + def fields_from_models(klasses) |
127 | fields = Set.new | 127 | fields = Set.new |
128 | klasses.each do |klass| | 128 | klasses.each do |klass| |
129 | klass::SEARCHABLE_FIELDS.map do |key, value| | 129 | klass::SEARCHABLE_FIELDS.map do |key, value| |
plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
1 | module ElasticsearchPluginHelper | 1 | module ElasticsearchPluginHelper |
2 | 2 | ||
3 | - def render_categories(collection, selected_collections) | ||
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, 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 | - concat ("</li>".html_safe) | ||
12 | - end | ||
13 | - else | ||
14 | - check_box_tag collection.name, collection.id, selected_collections.include?(collection.id) | ||
15 | - label_tag collection.name | ||
16 | - end | ||
17 | - end | ||
18 | - end | ||
19 | - | ||
20 | def categories_data(collection) | 3 | def categories_data(collection) |
21 | result = [] | 4 | result = [] |
22 | collection.each do | item | | 5 | collection.each do | item | |
plugins/elasticsearch/lib/elasticsearch_plugin.rb
@@ -17,7 +17,7 @@ class ElasticsearchPlugin < Noosfero::Plugin | @@ -17,7 +17,7 @@ class ElasticsearchPlugin < Noosfero::Plugin | ||
17 | end | 17 | end |
18 | 18 | ||
19 | def js_files | 19 | def js_files |
20 | - ['categories', 'jstree.min'].map{ |j| "javascripts/#{j}" } | 20 | + ['categories', 'jstree.min'].map{ |file_name| "javascripts/#{file_name}" } |
21 | end | 21 | end |
22 | 22 | ||
23 | def search_controller_filters | 23 | def search_controller_filters |
plugins/elasticsearch/lib/ext/community.rb
@@ -23,10 +23,10 @@ class Community | @@ -23,10 +23,10 @@ class Community | ||
23 | ] | 23 | ] |
24 | end | 24 | end |
25 | 25 | ||
26 | - def self.especific_sort | 26 | + def self.specific_sort |
27 | { | 27 | { |
28 | - :more_active => { label: _("More Active") }, | ||
29 | - :more_popular => { label: _("More Popular") } | 28 | + :more_active => _("More Active"), |
29 | + :more_popular => _("More Popular") | ||
30 | } | 30 | } |
31 | end | 31 | end |
32 | 32 |
plugins/elasticsearch/lib/ext/person.rb
@@ -24,10 +24,10 @@ class Person | @@ -24,10 +24,10 @@ class Person | ||
24 | ] | 24 | ] |
25 | end | 25 | end |
26 | 26 | ||
27 | - def self.especific_sort | 27 | + def self.specific_sort |
28 | { | 28 | { |
29 | - :more_active => { label: _("More Active") }, | ||
30 | - :more_popular => { label: _("More Popular") } | 29 | + :more_active => _("More Active"), |
30 | + :more_popular => _("More Popular") | ||
31 | } | 31 | } |
32 | end | 32 | end |
33 | 33 |
plugins/elasticsearch/lib/ext/text_article.rb
@@ -34,10 +34,10 @@ class TextArticle | @@ -34,10 +34,10 @@ class TextArticle | ||
34 | ] | 34 | ] |
35 | end | 35 | end |
36 | 36 | ||
37 | - def self.especific_sort | 37 | + def self.specific_sort |
38 | { | 38 | { |
39 | - :more_popular => { label: _("More Viewed") }, | ||
40 | - :more_comments => { label: _("Most Commented") } | 39 | + :more_popular => _("More Viewed"), |
40 | + :more_comments => _("Most Commented") | ||
41 | } | 41 | } |
42 | end | 42 | end |
43 | 43 |
plugins/elasticsearch/test/unit/community_test.rb
@@ -25,11 +25,11 @@ class CommunityTest < ActiveSupport::TestCase | @@ -25,11 +25,11 @@ class CommunityTest < ActiveSupport::TestCase | ||
25 | assert Community.respond_to? :should | 25 | assert Community.respond_to? :should |
26 | end | 26 | end |
27 | 27 | ||
28 | - should 'respond with especific sort' do | ||
29 | - assert Community.respond_to? :especific_sort | 28 | + should 'respond with specific sort' do |
29 | + assert Community.respond_to? :specific_sort | ||
30 | end | 30 | end |
31 | 31 | ||
32 | - should 'respond with get_sort_by to order especific sort' do | 32 | + should 'respond with get_sort_by to order specific sort' do |
33 | assert Community.respond_to? :get_sort_by | 33 | assert Community.respond_to? :get_sort_by |
34 | end | 34 | end |
35 | 35 |
plugins/elasticsearch/test/unit/person_test.rb
@@ -25,11 +25,11 @@ class PersonTest < ActionController::TestCase | @@ -25,11 +25,11 @@ class PersonTest < ActionController::TestCase | ||
25 | assert Person.respond_to? :should | 25 | assert Person.respond_to? :should |
26 | end | 26 | end |
27 | 27 | ||
28 | - should 'respond with especific sort' do | ||
29 | - assert Person.respond_to? :especific_sort | 28 | + should 'respond with specific sort' do |
29 | + assert Person.respond_to? :specific_sort | ||
30 | end | 30 | end |
31 | 31 | ||
32 | - should 'respond with get_sort_by to order especific sort' do | 32 | + should 'respond with get_sort_by to order specific sort' do |
33 | assert Person.respond_to? :get_sort_by | 33 | assert Person.respond_to? :get_sort_by |
34 | end | 34 | end |
35 | 35 |
plugins/elasticsearch/test/unit/text_article_test.rb
@@ -26,11 +26,11 @@ class TextArticleTest < ActionController::TestCase | @@ -26,11 +26,11 @@ class TextArticleTest < ActionController::TestCase | ||
26 | assert TextArticle.respond_to? :should | 26 | assert TextArticle.respond_to? :should |
27 | end | 27 | end |
28 | 28 | ||
29 | - should 'respond with especific sort' do | ||
30 | - assert TextArticle.respond_to? :especific_sort | 29 | + should 'respond with specific sort' do |
30 | + assert TextArticle.respond_to? :specific_sort | ||
31 | end | 31 | end |
32 | 32 | ||
33 | - should 'respond with get_sort_by to order especific sort' do | 33 | + should 'respond with get_sort_by to order specific sort' do |
34 | assert TextArticle.respond_to? :get_sort_by | 34 | assert TextArticle.respond_to? :get_sort_by |
35 | end | 35 | end |
36 | 36 |
plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb
1 | <div class="community-header"> | 1 | <div class="community-header"> |
2 | - <%= community.created_at.strftime("%d %B %Y at %H:%M") %> - <span class="model-label"><%= _("Community") %></span> | 2 | + <%= show_time(community.created_at) %> - <span class="model-label"><%= model_label.singularize %></span> |
3 | </div> | 3 | </div> |
4 | <div class="body"> | 4 | <div class="body"> |
5 | <h2><%= link_to community.name, community.url %></h2> | 5 | <h2><%= link_to community.name, community.url %></h2> |
plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb
1 | <div class="event-header"> | 1 | <div class="event-header"> |
2 | - <%= event.created_at.strftime("%d %B %Y at %H:%M") %> - <span class="model-label"><%= _("Event") %></span> | 2 | + <%= show_time(event.created_at) %> - <span class="model-label"><%= model_label.singularize %></span> |
3 | </div> | 3 | </div> |
4 | 4 | ||
5 | <div class="body"> | 5 | <div class="body"> |
plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | <%= profile_image person %> | 3 | <%= profile_image person %> |
4 | </div> | 4 | </div> |
5 | <div class="right-side"> | 5 | <div class="right-side"> |
6 | - <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <span class="model-label"><%= _("Person") %></span> | 6 | + <%= show_time(person.created_at) %> - <span class="model-label"><%= model_label.singularize %></span> |
7 | <div class="body"> | 7 | <div class="body"> |
8 | <h2><%= link_to person.name, person.url %></h2> | 8 | <h2><%= link_to person.name, person.url %></h2> |
9 | <p><%= person.description %></p> | 9 | <p><%= person.description %></p> |
plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb
1 | <% for result in @results.to_a %> | 1 | <% for result in @results.to_a %> |
2 | - <% for klass in @searchable_types.keys %> | ||
3 | - <% next if klass.to_s.include? "all" %> | 2 | + <% for klass, model_label in @searchable_types.except(:all) %> |
4 | <% if result.is_a? klass.to_s.classify.constantize %> | 3 | <% if result.is_a? klass.to_s.classify.constantize %> |
5 | <div class="search-item"> | 4 | <div class="search-item"> |
6 | - <%= render partial: "#{klass}_display", :locals => { klass => result} %> | 5 | + <%= render partial: "#{klass}_display", :locals => { klass => result, :model_label => model_label} %> |
7 | </div> | 6 | </div> |
8 | <% break %> | 7 | <% break %> |
9 | <% end %> | 8 | <% end %> |
plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <ul> | 2 | <ul> |
3 | <% for type, value in @sort_types %> | 3 | <% for type, value in @sort_types %> |
4 | <li class="select-search-type <%= "active" if type == @selected_sort %>"> | 4 | <li class="select-search-type <%= "active" if type == @selected_sort %>"> |
5 | - <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}&categories=#{@selected_categories.join(',')}" %> | 5 | + <%= link_to value, "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}&categories=#{@selected_categories.join(',')}" %> |
6 | </li> | 6 | </li> |
7 | <% end %> | 7 | <% end %> |
8 | </ul> | 8 | </ul> |
plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb
1 | <ul> | 1 | <ul> |
2 | <% for type,value in @searchable_types %> | 2 | <% for type,value in @searchable_types %> |
3 | <li class="select-search-type <%= "active" if type == @selected_type %>"> | 3 | <li class="select-search-type <%= "active" if type == @selected_type %>"> |
4 | - <%= link_to value[:label], "?selected_type=#{type}&query=#{@query}&categories=#{@selected_categories.join(',')}"%> | 4 | + <%= link_to value, "?selected_type=#{type}&query=#{@query}&categories=#{@selected_categories.join(',')}"%> |
5 | </li> | 5 | </li> |
6 | <% end %> | 6 | <% end %> |
7 | </ul> | 7 | </ul> |
plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb
1 | <div class="text_article-header"> | 1 | <div class="text_article-header"> |
2 | - <%= text_article.created_at.strftime("%d %B %Y at %H:%M") %> - <%= "#{text_article.author.name} -" if text_article.author %> <span class="model-label"><%= _("Article") %></span> | 2 | + <%= show_time(text_article.created_at) %> - <%= "#{text_article.author.name} -" if text_article.author %> <span class="model-label"><%= model_label.singularize %></span> |
3 | </div> | 3 | </div> |
4 | <div class="body"> | 4 | <div class="body"> |
5 | <h2><%= link_to text_article.name, text_article.url %></h2> | 5 | <h2><%= link_to text_article.name, text_article.url %></h2> |
plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb
1 | <div class="uploaded_file-header"> | 1 | <div class="uploaded_file-header"> |
2 | - <%= uploaded_file.created_at.strftime("%d %B %Y at %H:%M") %> - <%= "#{uploaded_file.author.name} -" if uploaded_file.author %><span class="model-label"><%= _("Files") %></span> | 2 | + <%= show_time(uploaded_file.created_at) %> - <%= "#{uploaded_file.author.name} -" if uploaded_file.author %><span class="model-label"><%= model_label.singularize %></span> |
3 | </div> | 3 | </div> |
4 | <div class="body"> | 4 | <div class="body"> |
5 | <h2><%= link_to uploaded_file.name, uploaded_file.url %></h2> | 5 | <h2><%= link_to uploaded_file.name, uploaded_file.url %></h2> |