blob: afa4c129c464d14a1ce8ce1d90cbeff4ed582d43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
class CalendarsController < BreadcrumbController
defaults resource_class: Calendar
before_action :check_policy, only: [:edit, :update, :destroy]
private
def calendar_params
params.require(:calendar).permit(:id, :name, :short_name, :shared, periods_attributes: [:id, :begin, :end, :_destroy], dates: [])
end
def sort_column
Calendar.column_names.include?(params[:sort]) ? params[:sort] : 'short_name'
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
end
protected
def resource
@calendar = current_organisation.calendars.find_by_id(params[:id])
end
def build_resource
super.tap do |calendar|
calendar.organisation = current_organisation
end
end
def collection
return @calendars if @calendars
if params[:q]
params[:q].delete(:shared_eq) if params[:q][:shared_eq] == ''
params[:q].delete(:short_name_cont) if params[:q][:short_name_cont] == ''
end
@q = current_organisation.calendars.search(params[:q])
calendars = @q.result(distinct: true)
ap "FILTERED COLLECTION LENGTH : #{@q.result.length}"
calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
@calendars = calendars.paginate(page: params[:page])
end
def check_policy
authorize resource
end
end
|