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 From b54ab0a2321bbd0c5c6162a0d313800bb586a98d Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 4 May 2017 15:22:57 +0200 Subject: Fix can't edit or create calendar due to 3 parts date_select Refs #3298 --- app/controllers/calendars_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'app/controllers/calendars_controller.rb') diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index d18e165d2..5370d9cbb 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -45,14 +45,13 @@ class CalendarsController < BreadcrumbController end def ransack_contains_date - # 3 parts to date object, in order to use in ransackable_scopes + date =[] if params[:q] && !params[:q]['contains_date(1i)'].empty? - date =[] ['contains_date(1i)', 'contains_date(2i)', 'contains_date(3i)'].each do |key| - date << params[:q][key] + date << params[:q][key].to_i params[:q].delete(key) end - params[:q]['contains_date'] = Date.parse(date.join('-')) + params[:q]['contains_date'] = Date.new(*date) end end -- cgit v1.2.3