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 | 2 | |
3 | 3 | require 'open-uri' |
4 | 4 | |
5 | -def elasticsearch_development | |
6 | - return ENV["ELASTICSEARCH_DEVELOPMENT"].nil? | |
7 | -end | |
8 | - | |
9 | 5 | desc "download elasticsearch" |
10 | 6 | task :download do |
11 | 7 | unless File.exists? '/tmp/elasticsearch.deb' |
... | ... | @@ -27,18 +23,14 @@ task :start do |
27 | 23 | Rake::Task['install'].invoke |
28 | 24 | end |
29 | 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 | 29 | end |
36 | 30 | |
37 | 31 | desc "stop elasticsearch" |
38 | 32 | task :stop do |
39 | 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 | 36 | end | ... | ... |
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
... | ... | @@ -25,7 +25,7 @@ class ElasticsearchPluginController < ApplicationController |
25 | 25 | def define_results |
26 | 26 | @query = params[:query] |
27 | 27 | @results = process_results |
28 | - @hits = ( @results.try(:total) || 0 ) | |
28 | + @hits = (@results.try(:total) || 0) | |
29 | 29 | end |
30 | 30 | |
31 | 31 | def define_searchable_types | ... | ... |
plugins/elasticsearch/helpers/elasticsearch_helper.rb
... | ... | @@ -2,27 +2,27 @@ module ElasticsearchHelper |
2 | 2 | |
3 | 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 | 12 | end |
13 | 13 | |
14 | 14 | def sort_types |
15 | 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 | 23 | if selected_type and selected_type.to_sym != :all |
24 | 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 | 26 | end |
27 | 27 | sorts |
28 | 28 | end |
... | ... | @@ -36,7 +36,7 @@ module ElasticsearchHelper |
36 | 36 | |
37 | 37 | def search_from_all_models |
38 | 38 | begin |
39 | - filter = (params[:filter] || "" ).to_sym | |
39 | + filter = (params[:filter] || "").to_sym | |
40 | 40 | query = get_query params[:query], sort_by: get_sort_by(filter), categories: params[:categories] |
41 | 41 | Elasticsearch::Model.search(query,searchable_models, size: default_per_page(params[:per_page])).page(params[:page]).records |
42 | 42 | rescue |
... | ... | @@ -44,10 +44,10 @@ module ElasticsearchHelper |
44 | 44 | end |
45 | 45 | end |
46 | 46 | |
47 | - def search_from_model model | |
47 | + def search_from_model(model) | |
48 | 48 | begin |
49 | 49 | klass = model.to_s.classify.constantize |
50 | - filter = (params[:filter] || "" ).to_sym | |
50 | + filter = (params[:filter] || "").to_sym | |
51 | 51 | query = get_query params[:query], klass: klass, sort_by: get_sort_by(filter ,klass), categories: params[:categories] |
52 | 52 | klass.search(query, size: default_per_page(params[:per_page])).page(params[:page]).records |
53 | 53 | rescue |
... | ... | @@ -55,26 +55,26 @@ module ElasticsearchHelper |
55 | 55 | end |
56 | 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 | 60 | end |
61 | 61 | |
62 | - def get_sort_by sort_by, klass=nil | |
62 | + def get_sort_by(sort_by, klass=nil) | |
63 | 63 | case sort_by |
64 | 64 | when :lexical |
65 | - { "name.raw" => {"order" => "asc" }} | |
65 | + {"name.raw" => {"order" => "asc"}} | |
66 | 66 | when :more_recent |
67 | - { "created_at" => {"order" => "desc"}} | |
67 | + {"created_at" => {"order" => "desc"}} | |
68 | 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 | 70 | end |
71 | 71 | end |
72 | 72 | |
73 | 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 | 75 | end |
76 | 76 | |
77 | - def query_string expression="", models=[] | |
77 | + def query_string(expression="", models=[]) | |
78 | 78 | return { match_all: {} } if not expression |
79 | 79 | { |
80 | 80 | query_string: { |
... | ... | @@ -87,7 +87,7 @@ module ElasticsearchHelper |
87 | 87 | end |
88 | 88 | |
89 | 89 | |
90 | - def query_method expression="", models=[], categories=[] | |
90 | + def query_method(expression="", models=[], categories=[]) | |
91 | 91 | query = {} |
92 | 92 | query[:query] = { |
93 | 93 | filtered: { |
... | ... | @@ -99,7 +99,7 @@ module ElasticsearchHelper |
99 | 99 | } |
100 | 100 | |
101 | 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 | 105 | unless categories.blank? |
... | ... | @@ -109,7 +109,7 @@ module ElasticsearchHelper |
109 | 109 | query |
110 | 110 | end |
111 | 111 | |
112 | - def get_query text="", options={} | |
112 | + def get_query(text="", options={}) | |
113 | 113 | klass = options[:klass] |
114 | 114 | sort_by = options[:sort_by] |
115 | 115 | categories = (options[:categories] || "").split(",") |
... | ... | @@ -123,7 +123,7 @@ module ElasticsearchHelper |
123 | 123 | query |
124 | 124 | end |
125 | 125 | |
126 | - def fields_from_models klasses | |
126 | + def fields_from_models(klasses) | |
127 | 127 | fields = Set.new |
128 | 128 | klasses.each do |klass| |
129 | 129 | klass::SEARCHABLE_FIELDS.map do |key, value| | ... | ... |
plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb
1 | 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 | 3 | def categories_data(collection) |
21 | 4 | result = [] |
22 | 5 | collection.each do | item | | ... | ... |
plugins/elasticsearch/lib/elasticsearch_plugin.rb
... | ... | @@ -17,7 +17,7 @@ class ElasticsearchPlugin < Noosfero::Plugin |
17 | 17 | end |
18 | 18 | |
19 | 19 | def js_files |
20 | - ['categories', 'jstree.min'].map{ |j| "javascripts/#{j}" } | |
20 | + ['categories', 'jstree.min'].map{ |file_name| "javascripts/#{file_name}" } | |
21 | 21 | end |
22 | 22 | |
23 | 23 | def search_controller_filters | ... | ... |
plugins/elasticsearch/lib/ext/community.rb
... | ... | @@ -23,10 +23,10 @@ class Community |
23 | 23 | ] |
24 | 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 | 31 | end |
32 | 32 | ... | ... |
plugins/elasticsearch/lib/ext/person.rb
... | ... | @@ -24,10 +24,10 @@ class Person |
24 | 24 | ] |
25 | 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 | 32 | end |
33 | 33 | ... | ... |
plugins/elasticsearch/lib/ext/text_article.rb
... | ... | @@ -34,10 +34,10 @@ class TextArticle |
34 | 34 | ] |
35 | 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 | 42 | end |
43 | 43 | ... | ... |
plugins/elasticsearch/test/unit/community_test.rb
... | ... | @@ -25,11 +25,11 @@ class CommunityTest < ActiveSupport::TestCase |
25 | 25 | assert Community.respond_to? :should |
26 | 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 | 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 | 33 | assert Community.respond_to? :get_sort_by |
34 | 34 | end |
35 | 35 | ... | ... |
plugins/elasticsearch/test/unit/person_test.rb
... | ... | @@ -25,11 +25,11 @@ class PersonTest < ActionController::TestCase |
25 | 25 | assert Person.respond_to? :should |
26 | 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 | 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 | 33 | assert Person.respond_to? :get_sort_by |
34 | 34 | end |
35 | 35 | ... | ... |
plugins/elasticsearch/test/unit/text_article_test.rb
... | ... | @@ -26,11 +26,11 @@ class TextArticleTest < ActionController::TestCase |
26 | 26 | assert TextArticle.respond_to? :should |
27 | 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 | 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 | 34 | assert TextArticle.respond_to? :get_sort_by |
35 | 35 | end |
36 | 36 | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb
1 | 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 | 3 | </div> |
4 | 4 | <div class="body"> |
5 | 5 | <h2><%= link_to community.name, community.url %></h2> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb
plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | <%= profile_image person %> |
4 | 4 | </div> |
5 | 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 | 7 | <div class="body"> |
8 | 8 | <h2><%= link_to person.name, person.url %></h2> |
9 | 9 | <p><%= person.description %></p> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb
1 | 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 | 3 | <% if result.is_a? klass.to_s.classify.constantize %> |
5 | 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 | 6 | </div> |
8 | 7 | <% break %> |
9 | 8 | <% end %> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | <ul> |
3 | 3 | <% for type, value in @sort_types %> |
4 | 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 | 6 | </li> |
7 | 7 | <% end %> |
8 | 8 | </ul> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb
1 | 1 | <ul> |
2 | 2 | <% for type,value in @searchable_types %> |
3 | 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 | 5 | </li> |
6 | 6 | <% end %> |
7 | 7 | </ul> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb
1 | 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 | 3 | </div> |
4 | 4 | <div class="body"> |
5 | 5 | <h2><%= link_to text_article.name, text_article.url %></h2> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb
1 | 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 | 3 | </div> |
4 | 4 | <div class="body"> |
5 | 5 | <h2><%= link_to uploaded_file.name, uploaded_file.url %></h2> | ... | ... |