Advanced search - except author type

This commit is contained in:
Ana
2016-01-01 14:27:38 +01:00
committed by rgarcia
parent 15ce538ea2
commit 4d3e3f2e09
5 changed files with 166 additions and 4 deletions

View File

@@ -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'

View File

@@ -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