From 4d3e3f2e09815a12874442eb2644f7c490b51426 Mon Sep 17 00:00:00 2001 From: Ana Date: Fri, 1 Jan 2016 14:27:38 +0100 Subject: [PATCH 01/29] Advanced search - except author type --- app/assets/stylesheets/participation.scss | 9 +- .../concerns/commentable_actions.rb | 32 +++++++ app/controllers/proposals_controller.rb | 4 +- app/views/proposals/index.html.erb | 32 ++++++- app/views/shared/_advanced_search.html.erb | 93 +++++++++++++++++++ 5 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 app/views/shared/_advanced_search.html.erb diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index c7d296744..cfad21920 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1030,4 +1030,11 @@ .content { height: rem-calc(60); } -} \ No newline at end of file +} +.advanced-search-title{ + cursor:pointer; cursor: hand +} + +.blue{ + color: $brand; +} diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index df232069b..d39d1e8fe 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -4,6 +4,26 @@ module CommentableActions def index @resources = @search_terms.present? ? resource_model.search(@search_terms) : resource_model.all + if @params_author + author = User.where(username: @params_author) + @resources = author.count > 0 ? @resources.where(author_id: author.first.id) : resource_model.none + end + if @params_date + case @params_date + when '1' + min_date_time = DateTime.now -24.hour + when '2' + min_date_time = DateTime.now - 7.day + when '3' + min_date_time = DateTime.now - 30.day + when '4' + min_date_time = DateTime.now - 365.day + when '5' + @resources = @resources.where('created_at <= ?', @params_date_max) if @params_date_max + min_date_time = @params_date_min + end + @resources = @resources.where('created_at >= ?', min_date_time) if min_date_time + end @resources = @resources.tagged_with(@tag_filter) if @tag_filter @resources = @resources.page(params[:page]).for_render.send("sort_by_#{@current_order}") index_customization if index_customization.present? @@ -81,6 +101,18 @@ module CommentableActions @search_terms = params[:search] if params[:search].present? end + def parse_advanced_search_terms + search = params[:advanced_search] + if search + @params_author = search[:author] if search[:author].present? + @params_author_type = search[:author_type] if search[:author_type].present? + @params_date = search[:date] if search[:date].present? + @params_date_min = search[:date_min] if (@params_date == '5') && search[:date_min].present? + @params_date_max = search[:date_max] if (@params_date == '5') && search[:date_max].present? + @advanced_search_present = true if params[:commit] || @params_author || @params_author_type || @params_date + end + end + def set_search_order if params[:search].present? && params[:order].blank? params[:order] = 'relevance' diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 4a5e17af3..dbd4630f3 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -3,6 +3,7 @@ class ProposalsController < ApplicationController include FlagActions before_action :parse_search_terms, only: :index + before_action :parse_advanced_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] @@ -14,7 +15,7 @@ class ProposalsController < ApplicationController respond_to :html, :js def index_customization - @featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (@search_terms.blank? && @tag_filter.blank?) + @featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if (!@advanced_search_present && @search_terms.blank? && @tag_filter.blank?) if @featured_proposals.present? set_featured_proposal_votes(@featured_proposals) @resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id)) @@ -44,4 +45,5 @@ class ProposalsController < ApplicationController def set_featured_proposal_votes(proposals) @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} end + end diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index d7fdadee9..4d16876f5 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -11,10 +11,12 @@
- <% if @search_terms %> + <% if @search_terms || @advanced_search_present %>

<%= page_entries_info @proposals %> - <%= t("proposals.index.search_results", count: @proposals.size, search_term: @search_terms) %> + <% if !@advanced_search_present %> + <%= t("proposals.index.search_results", count: @proposals.size, search_term: @search_terms) %> + <% end %>

<% elsif @tag_filter %>

@@ -24,6 +26,32 @@ <% end %>

+ <% if @tag_filter || @search_terms || @advanced_search_present %> +
+
+ <%= t("proposals.index.select_order") %> +
+ <%= render 'shared/order_selector', i18n_namespace: "proposals.index" %> +
+ <% else %> +
+

+ <%= t("proposals.index.select_order_long") %> +

+ <%= render 'shared/order_selector', i18n_namespace: "proposals.index" %> +
+ <% end %> + + + +
+ <%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %> +
+ <% if @featured_proposals.present? %>