aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/calendars_controller.rb
diff options
context:
space:
mode:
authorjpl2017-05-02 13:04:54 +0200
committerRobert2017-05-02 16:44:25 +0200
commite9a07b3d9208e4adba0947fd46c931472244ea9e (patch)
tree580e5781e6cf89c5f0428c638fe42317df965f9d /app/controllers/calendars_controller.rb
parentfbb0d5ce53dc1aeedd3b599b59353eb65502e020 (diff)
downloadchouette-core-e9a07b3d9208e4adba0947fd46c931472244ea9e.tar.bz2
RefsĀ #3264: change shared boolean filter by select (to permit join)
Diffstat (limited to 'app/controllers/calendars_controller.rb')
-rw-r--r--app/controllers/calendars_controller.rb19
1 files changed, 17 insertions, 2 deletions
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