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'