aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/calendars_controller.rb
diff options
context:
space:
mode:
authorcedricnjanga2018-01-30 23:07:07 -0800
committercedricnjanga2018-01-30 23:07:07 -0800
commit4023ea52097a47458ac2fcad36d343aba0c8e68b (patch)
treee891b85392aa911bb43d1b0ef73f526226b18216 /app/controllers/calendars_controller.rb
parent7ec19d8dc153e1491cb1a693b11b3b0a351f316c (diff)
downloadchouette-core-4023ea52097a47458ac2fcad36d343aba0c8e68b.tar.bz2
Make some changes to avoid unnacessaty lines of code
Diffstat (limited to 'app/controllers/calendars_controller.rb')
-rw-r--r--app/controllers/calendars_controller.rb33
1 files changed, 19 insertions, 14 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 27c944f5f..193680342 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -1,10 +1,11 @@
class CalendarsController < ChouetteController
- include WorkgroupSupport
include PolicyChecker
defaults resource_class: Calendar
before_action :ransack_contains_date, only: [:index]
respond_to :html
respond_to :js, only: :index
+
+ belongs_to :workgroup
def index
index! do
@@ -15,7 +16,7 @@ class CalendarsController < ChouetteController
def show
show! do
@calendar = @calendar.decorate(context: {
- workgroup: current_workgroup
+ workgroup: workgroup
})
end
end
@@ -27,7 +28,7 @@ class CalendarsController < ChouetteController
calendars,
with: CalendarDecorator,
context: {
- workgroup: current_workgroup
+ workgroup: workgroup
}
)
end
@@ -47,26 +48,30 @@ class CalendarsController < ChouetteController
end
protected
+
+ alias_method :workgroup, :parent
+ helper_method :workgroup
+
def resource
- @calendar = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id).find_by_id(params[:id], true, @workgroup.id)
+ @calendar ||= workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true).find_by_id(params[:id])
end
def build_resource
super.tap do |calendar|
- calendar.workgroup = current_workgroup
+ calendar.workgroup = workgroup
calendar.organisation = current_organisation
end
end
def collection
- return @calendars if @calendars
- scope = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, @workgroup.id)
- scope = shared_scope(scope)
- @q = scope.ransack(params[:q])
-
- calendars = @q.result
- calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
- @calendars = calendars.paginate(page: params[:page])
+ @calendars ||= begin
+ scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true)
+ scope = shared_scope(scope)
+ @q = scope.ransack(params[:q])
+ calendars = @q.result
+ calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ calendars = calendars.paginate(page: params[:page])
+ end
end
def ransack_contains_date
@@ -91,4 +96,4 @@ class CalendarsController < ChouetteController
scope
end
-end
+end \ No newline at end of file