diff --git a/app/assets/javascripts/controllers/calendar.js b/app/assets/javascripts/controllers/calendar.js index 33d811f55..ce0e1298d 100644 --- a/app/assets/javascripts/controllers/calendar.js +++ b/app/assets/javascripts/controllers/calendar.js @@ -16,8 +16,8 @@ * Controller used in the public calendar global */ -Application.Controllers.controller('CalendarController', ['$scope', '$state', '$aside', 'moment', 'Availability', 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig', 'trainingsPromise', 'machinesPromise', 'spacesPromise', - function ($scope, $state, $aside, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig, trainingsPromise, machinesPromise, spacesPromise) { +Application.Controllers.controller('CalendarController', ['$scope', '$state', '$aside', 'moment', 'Availability', 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig', 'trainingsPromise', 'machinesPromise', 'spacesPromise', 'iCalendarPromise', + function ($scope, $state, $aside, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig, trainingsPromise, machinesPromise, spacesPromise, iCalendarPromise) { /* PRIVATE STATIC CONSTANTS */ let currentMachineEvent = null; machinesPromise.forEach(m => m.checked = true); @@ -38,12 +38,11 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ // List of spaces $scope.spaces = spacesPromise.filter(t => !t.disabled); + // List of external iCalendar sources + $scope.externals = iCalendarPromise; + // add availabilities source to event sources $scope.eventSources = []; - $scope.eventSources.push({ - url: '/api/i_calendar/events', - textColor: 'black' - }); // filter availabilities if have change $scope.filterAvailabilities = function (filter, scope) { @@ -52,10 +51,19 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ trainings: isSelectAll('trainings', scope), machines: isSelectAll('machines', scope), spaces: isSelectAll('spaces', scope), + externals: isSelectAll('externals', scope), evt: filter.evt, dispo: filter.dispo }); - return $scope.calendarConfig.events = availabilitySourceUrl(); + $scope.calendarConfig.events = availabilitySourceUrl(); + $scope.externals.filter(e => e.checked).forEach(e => { + $scope.eventSources.push({ + url: `/api/i_calendar/${e.id}/events`, + textColor: e.textColor, + color: e.color + }); + }); + return uiCalendarConfig.calendars.calendar.fullCalendar('refetchEvents'); }; // a variable for formation/machine/event/dispo checkbox is or not checked @@ -63,6 +71,7 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ trainings: isSelectAll('trainings', $scope), machines: isSelectAll('machines', $scope), spaces: isSelectAll('spaces', $scope), + externals: isSelectAll('externals', $scope), evt: true, dispo: true }; @@ -89,6 +98,9 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ spaces () { return $scope.spaces; }, + externals () { + return $scope.externals; + }, filter () { return $scope.filter; }, @@ -99,10 +111,11 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ return $scope.filterAvailabilities; } }, - controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'spaces', 'filter', 'toggleFilter', 'filterAvailabilities', function ($scope, $uibModalInstance, trainings, machines, spaces, filter, toggleFilter, filterAvailabilities) { + controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'spaces', 'externals', 'filter', 'toggleFilter', 'filterAvailabilities', function ($scope, $uibModalInstance, trainings, machines, spaces, externals, filter, toggleFilter, filterAvailabilities) { $scope.trainings = trainings; $scope.machines = machines; $scope.spaces = spaces; + $scope.externals = externals; $scope.filter = filter; $scope.toggleFilter = (type, filter) => toggleFilter(type, filter); @@ -124,19 +137,19 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$ if (event.available_type === 'machines') { currentMachineEvent = event; calendar.fullCalendar('changeView', 'agendaDay'); - return calendar.fullCalendar('gotoDate', event.start); + calendar.fullCalendar('gotoDate', event.start); } else if (event.available_type === 'space') { calendar.fullCalendar('changeView', 'agendaDay'); - return calendar.fullCalendar('gotoDate', event.start); + calendar.fullCalendar('gotoDate', event.start); } else if (event.available_type === 'event') { - return $state.go('app.public.events_show', { id: event.event_id }); + $state.go('app.public.events_show', { id: event.event_id }); } else if (event.available_type === 'training') { - return $state.go('app.public.training_show', { id: event.training_id }); + $state.go('app.public.training_show', { id: event.training_id }); } else { if (event.machine_id) { - return $state.go('app.public.machines_show', { id: event.machine_id }); + $state.go('app.public.machines_show', { id: event.machine_id }); } else if (event.space_id) { - return $state.go('app.public.space_show', { id: event.space_id }); + $state.go('app.public.space_show', { id: event.space_id }); } } }; diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb index 62503a9cf..7ebc08af3 100644 --- a/app/assets/javascripts/router.js.erb +++ b/app/assets/javascripts/router.js.erb @@ -638,6 +638,7 @@ angular.module('application.router', ['ui.router']) trainingsPromise: ['Training', function (Training) { return Training.query().$promise; }], machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }], spacesPromise: ['Space', function (Space) { return Space.query().$promise; }], + iCalendarPromise: ['ICalendar', function (ICalendar) { return ICalendar.query().$promise; }], translations: ['Translations', function (Translations) { return Translations.query(['app.public.calendar']).$promise; }] } }) diff --git a/app/assets/templates/calendar/filter.html.erb b/app/assets/templates/calendar/filter.html.erb index c275fbeb9..76172a3a5 100644 --- a/app/assets/templates/calendar/filter.html.erb +++ b/app/assets/templates/calendar/filter.html.erb @@ -36,3 +36,14 @@

{{ 'calendar.show_unavailables' }}

+
+
+

{{ 'calendar.externals' }}

+ +
+ +
+ {{::e.name}} + +
+
diff --git a/app/controllers/api/i_calendar_controller.rb b/app/controllers/api/i_calendar_controller.rb index 5e17224f6..b828b709d 100644 --- a/app/controllers/api/i_calendar_controller.rb +++ b/app/controllers/api/i_calendar_controller.rb @@ -27,7 +27,12 @@ class API::ICalendarController < API::ApiController end def events - @events = ICalendarEvent.where(i_calendar_id: params[:id]).joins(:i_calendar) + start_date = ActiveSupport::TimeZone[params[:timezone]]&.parse(params[:start]) + end_date = ActiveSupport::TimeZone[params[:timezone]]&.parse(params[:end])&.end_of_day + + @events = ICalendarEvent.where(i_calendar_id: params[:id]) + .where('dtstart >= ? AND dtend <= ?', start_date, end_date) + .joins(:i_calendar) end def sync diff --git a/app/models/i_calendar.rb b/app/models/i_calendar.rb index d670e4986..1f63f6129 100644 --- a/app/models/i_calendar.rb +++ b/app/models/i_calendar.rb @@ -4,7 +4,7 @@ class ICalendar < ActiveRecord::Base has_many :i_calendar_events - after_create sync_events + after_create :sync_events private diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index 522562d10..c5493ad5f 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -306,6 +306,7 @@ fr: machines: "Machines" spaces: "Espaces" events: "Évènements" + externals: "Autres calendriers" spaces_list: # liste des espaces