From e9a07b3d9208e4adba0947fd46c931472244ea9e Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 13:04:54 +0200 Subject: RefsĀ #3264: change shared boolean filter by select (to permit join) --- app/controllers/calendars_controller.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app/controllers/calendars_controller.rb') diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index c33aa9373..d18e165d2 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -33,8 +33,12 @@ class CalendarsController < BreadcrumbController def collection return @calendars if @calendars + scope = Calendar.where('organisation_id = ?', current_organisation.id) + + scope = shared_scope(scope) + + @q = scope.ransack(params[:q]) - @q = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).search(params[:q]) calendars = @q.result calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction @calendars = calendars.paginate(page: params[:page]) @@ -51,5 +55,16 @@ class CalendarsController < BreadcrumbController params[:q]['contains_date'] = Date.parse(date.join('-')) end end -end + def shared_scope scope + return scope unless params[:q] + + if params[:q][:shared_true] == params[:q][:shared_false] + params[:q].delete(:shared_true) + params[:q].delete(:shared_false) + end + + scope + end + +end -- cgit v1.2.3