mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
add/remove ical imports in public agenda
also: a little of refacftoring in CalendarController
This commit is contained in:
parent
32e7fc3900
commit
538b5cef78
@ -39,7 +39,7 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
$scope.spaces = spacesPromise.filter(t => !t.disabled);
|
$scope.spaces = spacesPromise.filter(t => !t.disabled);
|
||||||
|
|
||||||
// List of external iCalendar sources
|
// List of external iCalendar sources
|
||||||
$scope.externals = iCalendarPromise;
|
$scope.externals = iCalendarPromise.map(e => Object.assign(e, { checked: true }));
|
||||||
|
|
||||||
// add availabilities source to event sources
|
// add availabilities source to event sources
|
||||||
$scope.eventSources = [];
|
$scope.eventSources = [];
|
||||||
@ -56,14 +56,25 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
dispo: filter.dispo
|
dispo: filter.dispo
|
||||||
});
|
});
|
||||||
$scope.calendarConfig.events = availabilitySourceUrl();
|
$scope.calendarConfig.events = availabilitySourceUrl();
|
||||||
$scope.externals.filter(e => e.checked).forEach(e => {
|
// external iCalendar events sources
|
||||||
|
$scope.externals.forEach(e => {
|
||||||
|
if (e.checked) {
|
||||||
|
if (!$scope.eventSources.some(evt => evt.id === e.id)) {
|
||||||
$scope.eventSources.push({
|
$scope.eventSources.push({
|
||||||
|
id: e.id,
|
||||||
url: `/api/i_calendar/${e.id}/events`,
|
url: `/api/i_calendar/${e.id}/events`,
|
||||||
textColor: e.text_color,
|
textColor: e.text_color || '#000',
|
||||||
color: e.color
|
color: e.color
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($scope.eventSources.some(evt => evt.id === e.id)) {
|
||||||
|
const idx = $scope.eventSources.findIndex(evt => evt.id === e.id);
|
||||||
|
$scope.eventSources.splice(idx, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return uiCalendarConfig.calendars.calendar.fullCalendar('refetchEvents');
|
uiCalendarConfig.calendars.calendar.fullCalendar('refetchEventSources');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +84,7 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
$scope.calendarStyle = function (calendar) {
|
$scope.calendarStyle = function (calendar) {
|
||||||
return {
|
return {
|
||||||
'border-color': calendar.color,
|
'border-color': calendar.color,
|
||||||
'color': calendar.text_color,
|
'color': calendar.text_color
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -142,6 +153,47 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
|
|
||||||
/* PRIVATE SCOPE */
|
/* PRIVATE SCOPE */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kind of constructor: these actions will be realized first when the controller is loaded
|
||||||
|
*/
|
||||||
|
const initialize = () => {
|
||||||
|
// fullCalendar (v2) configuration
|
||||||
|
$scope.calendarConfig = CalendarConfig({
|
||||||
|
events: availabilitySourceUrl(),
|
||||||
|
slotEventOverlap: true,
|
||||||
|
header: {
|
||||||
|
left: 'month agendaWeek agendaDay',
|
||||||
|
center: 'title',
|
||||||
|
right: 'today prev,next'
|
||||||
|
},
|
||||||
|
minTime: moment.duration(moment(bookingWindowStart.setting.value).format('HH:mm:ss')),
|
||||||
|
maxTime: moment.duration(moment(bookingWindowEnd.setting.value).format('HH:mm:ss')),
|
||||||
|
defaultView: window.innerWidth <= 480 ? 'agendaDay' : 'agendaWeek',
|
||||||
|
eventClick (event, jsEvent, view) {
|
||||||
|
return calendarEventClickCb(event, jsEvent, view);
|
||||||
|
},
|
||||||
|
viewRender (view, element) {
|
||||||
|
return viewRenderCb(view, element);
|
||||||
|
},
|
||||||
|
eventRender (event, element, view) {
|
||||||
|
return eventRenderCb(event, element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$scope.externals.forEach(e => {
|
||||||
|
if (e.checked) {
|
||||||
|
$scope.eventSources.push({
|
||||||
|
id: e.id,
|
||||||
|
url: `/api/i_calendar/${e.id}/events`,
|
||||||
|
textColor: e.text_color || '#000',
|
||||||
|
color: e.color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback triggered when an event object is clicked in the fullCalendar view
|
||||||
|
*/
|
||||||
const calendarEventClickCb = function (event, jsEvent, view) {
|
const calendarEventClickCb = function (event, jsEvent, view) {
|
||||||
// current calendar object
|
// current calendar object
|
||||||
const { calendar } = uiCalendarConfig.calendars;
|
const { calendar } = uiCalendarConfig.calendars;
|
||||||
@ -184,7 +236,10 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// function is called when calendar view is rendered or changed
|
/**
|
||||||
|
* This function is called when calendar view is rendered or changed
|
||||||
|
* @see https://fullcalendar.io/docs/v3/viewRender#v2
|
||||||
|
*/
|
||||||
const viewRenderCb = function (view, element) {
|
const viewRenderCb = function (view, element) {
|
||||||
toggleSlotEventOverlap(view);
|
toggleSlotEventOverlap(view);
|
||||||
if (view.type === 'agendaDay') {
|
if (view.type === 'agendaDay') {
|
||||||
@ -193,6 +248,10 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback triggered by fullCalendar when it is about to render an event.
|
||||||
|
* @see https://fullcalendar.io/docs/v3/eventRender#v2
|
||||||
|
*/
|
||||||
const eventRenderCb = function (event, element) {
|
const eventRenderCb = function (event, element) {
|
||||||
if (event.tags && event.tags.length > 0) {
|
if (event.tags && event.tags.length > 0) {
|
||||||
let html = '';
|
let html = '';
|
||||||
@ -212,30 +271,6 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
|||||||
|
|
||||||
var availabilitySourceUrl = () => `/api/availabilities/public?${$.param(getFilter())}`;
|
var availabilitySourceUrl = () => `/api/availabilities/public?${$.param(getFilter())}`;
|
||||||
|
|
||||||
const initialize = () =>
|
|
||||||
// fullCalendar (v2) configuration
|
|
||||||
$scope.calendarConfig = CalendarConfig({
|
|
||||||
events: availabilitySourceUrl(),
|
|
||||||
slotEventOverlap: true,
|
|
||||||
header: {
|
|
||||||
left: 'month agendaWeek agendaDay',
|
|
||||||
center: 'title',
|
|
||||||
right: 'today prev,next'
|
|
||||||
},
|
|
||||||
minTime: moment.duration(moment(bookingWindowStart.setting.value).format('HH:mm:ss')),
|
|
||||||
maxTime: moment.duration(moment(bookingWindowEnd.setting.value).format('HH:mm:ss')),
|
|
||||||
defaultView: window.innerWidth <= 480 ? 'agendaDay' : 'agendaWeek',
|
|
||||||
eventClick (event, jsEvent, view) {
|
|
||||||
return calendarEventClickCb(event, jsEvent, view);
|
|
||||||
},
|
|
||||||
viewRender (view, element) {
|
|
||||||
return viewRenderCb(view, element);
|
|
||||||
},
|
|
||||||
eventRender (event, element, view) {
|
|
||||||
return eventRenderCb(event, element);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// !!! MUST BE CALLED AT THE END of the controller
|
// !!! MUST BE CALLED AT THE END of the controller
|
||||||
return initialize();
|
return initialize();
|
||||||
}
|
}
|
||||||
|
@ -306,6 +306,7 @@ en:
|
|||||||
machines: "Machines"
|
machines: "Machines"
|
||||||
spaces: "Spaces"
|
spaces: "Spaces"
|
||||||
events: "Events"
|
events: "Events"
|
||||||
|
externals: "Other calendars"
|
||||||
|
|
||||||
spaces_list:
|
spaces_list:
|
||||||
# list of spaces
|
# list of spaces
|
||||||
|
@ -306,6 +306,7 @@ es:
|
|||||||
machines: "Máquinas"
|
machines: "Máquinas"
|
||||||
spaces: "Espacios"
|
spaces: "Espacios"
|
||||||
events: "Eventos"
|
events: "Eventos"
|
||||||
|
externals: "Otros calendarios"
|
||||||
|
|
||||||
spaces_list:
|
spaces_list:
|
||||||
# list of spaces
|
# list of spaces
|
||||||
|
@ -306,6 +306,7 @@ pt:
|
|||||||
machines: "Máquinas"
|
machines: "Máquinas"
|
||||||
spaces: "Espaços"
|
spaces: "Espaços"
|
||||||
events: "Eventos"
|
events: "Eventos"
|
||||||
|
externals: "Outras agendas"
|
||||||
|
|
||||||
spaces_list:
|
spaces_list:
|
||||||
# list of spaces
|
# list of spaces
|
||||||
|
Loading…
x
Reference in New Issue
Block a user