From 869c8a0047ca77c2466c5b053d85d7ab3c8d9921 Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Mon, 25 Jul 2016 10:55:56 -0300 Subject: [PATCH] Fixed MR Style --- plugins/elasticsearch/Rakefile | 18 +++++------------- plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb | 2 +- plugins/elasticsearch/helpers/elasticsearch_helper.rb | 52 ++++++++++++++++++++++++++-------------------------- plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb | 17 ----------------- plugins/elasticsearch/lib/elasticsearch_plugin.rb | 2 +- plugins/elasticsearch/lib/ext/community.rb | 6 +++--- plugins/elasticsearch/lib/ext/person.rb | 6 +++--- plugins/elasticsearch/lib/ext/text_article.rb | 6 +++--- plugins/elasticsearch/test/unit/community_test.rb | 6 +++--- plugins/elasticsearch/test/unit/person_test.rb | 6 +++--- plugins/elasticsearch/test/unit/text_article_test.rb | 6 +++--- plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb | 2 +- plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb | 2 +- plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb | 2 +- plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb | 5 ++--- plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb | 2 +- plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb | 2 +- plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb | 2 +- plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb | 2 +- 19 files changed, 60 insertions(+), 86 deletions(-) diff --git a/plugins/elasticsearch/Rakefile b/plugins/elasticsearch/Rakefile index 229a657..c4a6dc9 100644 --- a/plugins/elasticsearch/Rakefile +++ b/plugins/elasticsearch/Rakefile @@ -2,10 +2,6 @@ require 'open-uri' -def elasticsearch_development - return ENV["ELASTICSEARCH_DEVELOPMENT"].nil? -end - desc "download elasticsearch" task :download do unless File.exists? '/tmp/elasticsearch.deb' @@ -27,18 +23,14 @@ task :start do Rake::Task['install'].invoke end puts "Enable Elasticsearch service" - if elasticsearch_development - sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' - sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' - sleep 10 - end + sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' + sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' + sleep 10 end desc "stop elasticsearch" task :stop do puts "Disable elasticsearch service" - if elasticsearch_development - sh 'sudo systemctl stop elasticsearch >> /dev/null 2>&1' - sh 'sudo systemctl disable elasticsearch >> /dev/null 2>&1' - end + sh 'sudo systemctl stop elasticsearch >> /dev/null 2>&1' + sh 'sudo systemctl disable elasticsearch >> /dev/null 2>&1' end diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index f0e1067..b9600c6 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -25,7 +25,7 @@ class ElasticsearchPluginController < ApplicationController def define_results @query = params[:query] @results = process_results - @hits = ( @results.try(:total) || 0 ) + @hits = (@results.try(:total) || 0) end def define_searchable_types diff --git a/plugins/elasticsearch/helpers/elasticsearch_helper.rb b/plugins/elasticsearch/helpers/elasticsearch_helper.rb index 8aa76c3..41cca79 100644 --- a/plugins/elasticsearch/helpers/elasticsearch_helper.rb +++ b/plugins/elasticsearch/helpers/elasticsearch_helper.rb @@ -2,27 +2,27 @@ module ElasticsearchHelper def searchable_types { - :all => { label: _("All Results")}, - :text_article => { label: _("Articles")}, - :uploaded_file => { label: _("Files")}, - :community => { label: _("Communities")}, - :event => { label: _("Events")}, - :person => { label: _("People")} + :all => _("All Results"), + :text_article => _("Articles"), + :uploaded_file => _("Files"), + :community => _("Communities"), + :event => _("Events"), + :person => _("People") } end def sort_types sorts = { - :relevance => { label: _("Relevance")}, - :lexical => { label: _("Alphabetical")}, - :more_recent => { label: _("More Recent")}, + :relevance => _("Relevance"), + :lexical => _("Alphabetical"), + :more_recent => _("More Recent") } - selected_type = params[:selected_type] || nil + selected_type = (params[:selected_type] || nil) if selected_type and selected_type.to_sym != :all klass = selected_type.to_s.classify.constantize - sorts.update klass.especific_sort if klass.respond_to? :especific_sort + sorts.update klass.specific_sort if klass.respond_to? :specific_sort end sorts end @@ -36,7 +36,7 @@ module ElasticsearchHelper def search_from_all_models begin - filter = (params[:filter] || "" ).to_sym + filter = (params[:filter] || "").to_sym query = get_query params[:query], sort_by: get_sort_by(filter), categories: params[:categories] Elasticsearch::Model.search(query,searchable_models, size: default_per_page(params[:per_page])).page(params[:page]).records rescue @@ -44,10 +44,10 @@ module ElasticsearchHelper end end - def search_from_model model + def search_from_model(model) begin klass = model.to_s.classify.constantize - filter = (params[:filter] || "" ).to_sym + filter = (params[:filter] || "").to_sym query = get_query params[:query], klass: klass, sort_by: get_sort_by(filter ,klass), categories: params[:categories] klass.search(query, size: default_per_page(params[:per_page])).page(params[:page]).records rescue @@ -55,26 +55,26 @@ module ElasticsearchHelper end end - def default_per_page per_page=nil - per_page ||= 10 + def default_per_page(per_page=nil) + per_page || 10 end - def get_sort_by sort_by, klass=nil + def get_sort_by(sort_by, klass=nil) case sort_by when :lexical - { "name.raw" => {"order" => "asc" }} + {"name.raw" => {"order" => "asc"}} when :more_recent - { "created_at" => {"order" => "desc"}} + {"created_at" => {"order" => "desc"}} else - ( klass and klass.respond_to?(:get_sort_by) ) ? klass.get_sort_by(sort_by) : nil + (klass and klass.respond_to?(:get_sort_by)) ? klass.get_sort_by(sort_by) : nil end end def searchable_models - searchable_types.except(:all).keys.map { | model | model.to_s.classify.constantize } + searchable_types.except(:all).keys.map {|model| model.to_s.classify.constantize} end - def query_string expression="", models=[] + def query_string(expression="", models=[]) return { match_all: {} } if not expression { query_string: { @@ -87,7 +87,7 @@ module ElasticsearchHelper end - def query_method expression="", models=[], categories=[] + def query_method(expression="", models=[], categories=[]) query = {} query[:query] = { filtered: { @@ -99,7 +99,7 @@ module ElasticsearchHelper } query[:query][:filtered][:filter][:bool] = { - should: models.map {|model| model.filter(environment: @environment.id) } + should: models.map {|model| model.filter(environment: @environment.id)} } unless categories.blank? @@ -109,7 +109,7 @@ module ElasticsearchHelper query end - def get_query text="", options={} + def get_query(text="", options={}) klass = options[:klass] sort_by = options[:sort_by] categories = (options[:categories] || "").split(",") @@ -123,7 +123,7 @@ module ElasticsearchHelper query end - def fields_from_models klasses + def fields_from_models(klasses) fields = Set.new klasses.each do |klass| klass::SEARCHABLE_FIELDS.map do |key, value| diff --git a/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb b/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb index a0c7edf..8b36407 100644 --- a/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb +++ b/plugins/elasticsearch/helpers/elasticsearch_plugin_helper.rb @@ -1,22 +1,5 @@ module ElasticsearchPluginHelper - def render_categories(collection, selected_collections) - content_tag :ul, class: "category-ident" do - if collection.respond_to? :each - collection.collect do |item| - concat ("
  • ".html_safe) - concat (check_box_tag(item.name, item.id, selected_collections.include?(item.id.to_s)) ) - concat (label_tag item.name) - concat (render_categories(item.children, selected_collections)) if item.children_count > 0 - concat ("
  • ".html_safe) - end - else - check_box_tag collection.name, collection.id, selected_collections.include?(collection.id) - label_tag collection.name - end - end - end - def categories_data(collection) result = [] collection.each do | item | diff --git a/plugins/elasticsearch/lib/elasticsearch_plugin.rb b/plugins/elasticsearch/lib/elasticsearch_plugin.rb index 7f28e65..64d6773 100644 --- a/plugins/elasticsearch/lib/elasticsearch_plugin.rb +++ b/plugins/elasticsearch/lib/elasticsearch_plugin.rb @@ -17,7 +17,7 @@ class ElasticsearchPlugin < Noosfero::Plugin end def js_files - ['categories', 'jstree.min'].map{ |j| "javascripts/#{j}" } + ['categories', 'jstree.min'].map{ |file_name| "javascripts/#{file_name}" } end def search_controller_filters diff --git a/plugins/elasticsearch/lib/ext/community.rb b/plugins/elasticsearch/lib/ext/community.rb index 3f2a8a9..cf666c3 100644 --- a/plugins/elasticsearch/lib/ext/community.rb +++ b/plugins/elasticsearch/lib/ext/community.rb @@ -23,10 +23,10 @@ class Community ] end - def self.especific_sort + def self.specific_sort { - :more_active => { label: _("More Active") }, - :more_popular => { label: _("More Popular") } + :more_active => _("More Active"), + :more_popular => _("More Popular") } end diff --git a/plugins/elasticsearch/lib/ext/person.rb b/plugins/elasticsearch/lib/ext/person.rb index eb6569a..41e26c5 100644 --- a/plugins/elasticsearch/lib/ext/person.rb +++ b/plugins/elasticsearch/lib/ext/person.rb @@ -24,10 +24,10 @@ class Person ] end - def self.especific_sort + def self.specific_sort { - :more_active => { label: _("More Active") }, - :more_popular => { label: _("More Popular") } + :more_active => _("More Active"), + :more_popular => _("More Popular") } end diff --git a/plugins/elasticsearch/lib/ext/text_article.rb b/plugins/elasticsearch/lib/ext/text_article.rb index 5021ffa..866a8dc 100644 --- a/plugins/elasticsearch/lib/ext/text_article.rb +++ b/plugins/elasticsearch/lib/ext/text_article.rb @@ -34,10 +34,10 @@ class TextArticle ] end - def self.especific_sort + def self.specific_sort { - :more_popular => { label: _("More Viewed") }, - :more_comments => { label: _("Most Commented") } + :more_popular => _("More Viewed"), + :more_comments => _("Most Commented") } end diff --git a/plugins/elasticsearch/test/unit/community_test.rb b/plugins/elasticsearch/test/unit/community_test.rb index 8729de3..41dd3ab 100644 --- a/plugins/elasticsearch/test/unit/community_test.rb +++ b/plugins/elasticsearch/test/unit/community_test.rb @@ -25,11 +25,11 @@ class CommunityTest < ActiveSupport::TestCase assert Community.respond_to? :should end - should 'respond with especific sort' do - assert Community.respond_to? :especific_sort + should 'respond with specific sort' do + assert Community.respond_to? :specific_sort end - should 'respond with get_sort_by to order especific sort' do + should 'respond with get_sort_by to order specific sort' do assert Community.respond_to? :get_sort_by end diff --git a/plugins/elasticsearch/test/unit/person_test.rb b/plugins/elasticsearch/test/unit/person_test.rb index fc9e98a..6b17bb8 100644 --- a/plugins/elasticsearch/test/unit/person_test.rb +++ b/plugins/elasticsearch/test/unit/person_test.rb @@ -25,11 +25,11 @@ class PersonTest < ActionController::TestCase assert Person.respond_to? :should end - should 'respond with especific sort' do - assert Person.respond_to? :especific_sort + should 'respond with specific sort' do + assert Person.respond_to? :specific_sort end - should 'respond with get_sort_by to order especific sort' do + should 'respond with get_sort_by to order specific sort' do assert Person.respond_to? :get_sort_by end diff --git a/plugins/elasticsearch/test/unit/text_article_test.rb b/plugins/elasticsearch/test/unit/text_article_test.rb index f110f8d..1108372 100644 --- a/plugins/elasticsearch/test/unit/text_article_test.rb +++ b/plugins/elasticsearch/test/unit/text_article_test.rb @@ -26,11 +26,11 @@ class TextArticleTest < ActionController::TestCase assert TextArticle.respond_to? :should end - should 'respond with especific sort' do - assert TextArticle.respond_to? :especific_sort + should 'respond with specific sort' do + assert TextArticle.respond_to? :specific_sort end - should 'respond with get_sort_by to order especific sort' do + should 'respond with get_sort_by to order specific sort' do assert TextArticle.respond_to? :get_sort_by end diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb index f9d1e4b..7b4c2d1 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb @@ -1,5 +1,5 @@
    - <%= community.created_at.strftime("%d %B %Y at %H:%M") %> - <%= _("Community") %> + <%= show_time(community.created_at) %> - <%= model_label.singularize %>

    <%= link_to community.name, community.url %>

    diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb index 1019640..7cc08ce 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb @@ -1,5 +1,5 @@
    - <%= event.created_at.strftime("%d %B %Y at %H:%M") %> - <%= _("Event") %> + <%= show_time(event.created_at) %> - <%= model_label.singularize %>
    diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb index fb1bf31..a42268b 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb @@ -3,7 +3,7 @@ <%= profile_image person %>
    - <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= _("Person") %> + <%= show_time(person.created_at) %> - <%= model_label.singularize %>

    <%= link_to person.name, person.url %>

    <%= person.description %>

    diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb index 7558f01..29cdc31 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_search_collection.html.erb @@ -1,9 +1,8 @@ <% for result in @results.to_a %> - <% for klass in @searchable_types.keys %> - <% next if klass.to_s.include? "all" %> + <% for klass, model_label in @searchable_types.except(:all) %> <% if result.is_a? klass.to_s.classify.constantize %>
    - <%= render partial: "#{klass}_display", :locals => { klass => result} %> + <%= render partial: "#{klass}_display", :locals => { klass => result, :model_label => model_label} %>
    <% break %> <% end %> diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb index 095a172..974975a 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_search_filter.html.erb @@ -2,7 +2,7 @@
      <% for type, value in @sort_types %>
    • "> - <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}&categories=#{@selected_categories.join(',')}" %> + <%= link_to value, "?selected_type=#{@selected_type}&query=#{@query}&filter=#{type}&categories=#{@selected_categories.join(',')}" %>
    • <% end %>
    diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb index b85cbbb..571dfcd 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_search_option.html.erb @@ -1,7 +1,7 @@
      <% for type,value in @searchable_types %>
    • "> - <%= link_to value[:label], "?selected_type=#{type}&query=#{@query}&categories=#{@selected_categories.join(',')}"%> + <%= link_to value, "?selected_type=#{type}&query=#{@query}&categories=#{@selected_categories.join(',')}"%>
    • <% end %>
    diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb index 7d345bf..696e144 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_text_article_display.html.erb @@ -1,5 +1,5 @@
    - <%= text_article.created_at.strftime("%d %B %Y at %H:%M") %> - <%= "#{text_article.author.name} -" if text_article.author %> <%= _("Article") %> + <%= show_time(text_article.created_at) %> - <%= "#{text_article.author.name} -" if text_article.author %> <%= model_label.singularize %>

    <%= link_to text_article.name, text_article.url %>

    diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb index cae24a5..78184ad 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_uploaded_file_display.html.erb @@ -1,5 +1,5 @@
    - <%= uploaded_file.created_at.strftime("%d %B %Y at %H:%M") %> - <%= "#{uploaded_file.author.name} -" if uploaded_file.author %><%= _("Files") %> + <%= show_time(uploaded_file.created_at) %> - <%= "#{uploaded_file.author.name} -" if uploaded_file.author %><%= model_label.singularize %>

    <%= link_to uploaded_file.name, uploaded_file.url %>

    -- libgit2 0.21.2