From 40ea3fcc58e20aab276671f231af9adabe95e54b Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 23 Nov 2015 11:12:35 +0100 Subject: [PATCH] displays relevance order in searches --- app/controllers/concerns/commentable_actions.rb | 6 ++++++ app/controllers/debates_controller.rb | 3 ++- app/controllers/proposals_controller.rb | 3 ++- app/helpers/orders_helper.rb | 7 +++++++ app/views/shared/_order_selector.html.erb | 14 ++++++-------- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 7 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 app/helpers/orders_helper.rb diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 9eb27226b..df232069b 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -81,6 +81,12 @@ module CommentableActions @search_terms = params[:search] if params[:search].present? end + def set_search_order + if params[:search].present? && params[:order].blank? + params[:order] = 'relevance' + end + end + def set_resource_votes(instance) send("set_#{resource_name}_votes", instance) end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 8a5def88b..e28f053c7 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -4,9 +4,10 @@ class DebatesController < ApplicationController before_action :parse_search_terms, only: :index before_action :parse_tag_filter, only: :index + before_action :set_search_order, only: :index before_action :authenticate_user!, except: [:index, :show] - has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index + has_orders %w{hot_score confidence_score created_at most_commented random relevance}, only: :index has_orders %w{most_voted newest oldest}, only: :show load_and_authorize_resource diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 1be046b7a..cc8a286ec 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -4,9 +4,10 @@ class ProposalsController < ApplicationController before_action :parse_search_terms, only: :index before_action :parse_tag_filter, only: :index + before_action :set_search_order, only: :index before_action :authenticate_user!, except: [:index, :show] - has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index + has_orders %w{hot_score confidence_score created_at most_commented random relevance}, only: :index has_orders %w{most_voted newest oldest}, only: :show load_and_authorize_resource diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 000000000..08d5588ca --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,7 @@ +module OrdersHelper + + def valid_orders + @valid_orders.reject { |order| order =='relevance' && params[:search].blank? } + end + +end \ No newline at end of file diff --git a/app/views/shared/_order_selector.html.erb b/app/views/shared/_order_selector.html.erb index 883205493..e120e98e5 100644 --- a/app/views/shared/_order_selector.html.erb +++ b/app/views/shared/_order_selector.html.erb @@ -1,14 +1,12 @@ -<% # Params: - # - # i18n_namespace: for example "moderation.debates.index" -%> -
- + <% valid_orders.each do |order| %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 6d7fc70db..a91d6c235 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -90,6 +90,7 @@ en: created_at: "newest" most_commented: "most commented" random: "random" + relevance: "relevance" filter_topic: one: " with topic '%{topic}'" other: " with topic '%{topic}'" @@ -166,6 +167,7 @@ en: created_at: "newest" most_commented: "most commented" random: "random" + relevance: "relevance" filter_topic: one: " with topic '%{topic}'" other: " with topic '%{topic}'" diff --git a/config/locales/es.yml b/config/locales/es.yml index 9cbed4c38..431a1daf8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -90,6 +90,7 @@ es: created_at: "más nuevos" most_commented: "más comentados" random: "aleatorio" + relevance: "relevancia" filter_topic: one: " con el tema '%{topic}'" other: " con el tema '%{topic}'" @@ -166,6 +167,7 @@ es: created_at: "más nuevas" most_commented: "más comentadas" random: "aleatorias" + relevance: "relevancia" filter_topic: one: " con el tema '%{topic}'" other: " con el tema '%{topic}'"