1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

display external calendars list in public calendar + pull availabilities

This commit is contained in:
Sylvain 2019-12-02 16:49:20 +01:00
parent cca6b14f58
commit 22be9f6a08
6 changed files with 47 additions and 16 deletions

View File

@ -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 });
}
}
};

View File

@ -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; }]
}
})

View File

@ -36,3 +36,14 @@
<h3 class="col-md-11 col-sm-11 col-xs-11 text-black" translate>{{ 'calendar.show_unavailables' }}</h3>
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.dispo" ng-change="filterAvailabilities(filter)">
</div>
<div class="m-t">
<div class="row">
<h3 class="col-md-11 col-sm-11 col-xs-11 text-black" translate>{{ 'calendar.externals' }}</h3>
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.externals" ng-change="toggleFilter('externals', filter)">
</div>
<div class="row" ng-repeat="e in externals">
<span class="col-md-11 col-sm-11 col-xs-11">{{::e.name}}</span>
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="e.checked" ng-change="filterAvailabilities(filter)">
</div>
</div>

View File

@ -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

View File

@ -4,7 +4,7 @@
class ICalendar < ActiveRecord::Base
has_many :i_calendar_events
after_create sync_events
after_create :sync_events
private

View File

@ -306,6 +306,7 @@ fr:
machines: "Machines"
spaces: "Espaces"
events: "Évènements"
externals: "Autres calendriers"
spaces_list:
# liste des espaces