Skip to content

Commit bf4978d

Browse files
authored
Org: Displays holidays in occupancy view
TYPE: Feature LINK: OGC-3255
1 parent a7dd17f commit bf4978d

6 files changed

Lines changed: 35 additions & 6 deletions

File tree

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ install_requires =
114114
pdfdocument
115115
pdfrw2
116116
pdftotext
117-
pglast
117+
# FIXME: pglast 8 fails to build on CI
118+
pglast<8
118119
phonenumbers
119120
polib
120121
psycopg[c]

src/onegov/org/assets/js/occupancycalendar.jsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ oc.defaultOptions = {
2626
*/
2727
editable: false,
2828

29+
/*
30+
True if the calendar includes holidays
31+
*/
32+
showHolidays: false,
33+
2934
/*
3035
Url which returns all available resources in the following format:
3136
{
@@ -95,7 +100,8 @@ oc.getFullcalendarOptions = function(ocExtendOptions) {
95100
// the fullcalendar default options
96101
var options = {
97102
fc: {
98-
allDaySlot: false,
103+
allDaySlot: ocOptions.showHolidays,
104+
allDayContent: '',
99105
height: 'auto',
100106
events: ocOptions.feed,
101107
slotEventOverlap: false,
@@ -174,6 +180,9 @@ oc.getFullcalendarOptions = function(ocExtendOptions) {
174180
fcOptions.selectMirror = true;
175181
fcOptions.unselectCancel = '.popup';
176182
fcOptions.selectOverlap = function(event) {
183+
if (event.extendedProps.kind === 'holiday') {
184+
return true;
185+
}
177186
if (event.display === 'background') {
178187
oc.overlappingEvents[event.id] = event;
179188
return true;
@@ -183,6 +192,9 @@ oc.getFullcalendarOptions = function(ocExtendOptions) {
183192
}
184193
};
185194
fcOptions.selectAllow = function(info) {
195+
if (info.allDay) {
196+
return false;
197+
}
186198
// we only know what to do if we overlap a single valid allocation
187199
// we only allow to add blockers in the future
188200
var keys = Object.keys(oc.overlappingEvents);
@@ -236,14 +248,19 @@ oc.getFullcalendarOptions = function(ocExtendOptions) {
236248

237249
// edit events on drag&drop, resize
238250
fcOptions.eventOverlap = function(stillEvent, movingEvent) {
239-
if (stillEvent.extendedProps.resource !== movingEvent.extendedProps.resource) {
240-
// NOTE: This doesn't take into account the hierarchy, so it is a little bit
241-
// too permissive right now. But the backend still covers us.
251+
if (stillEvent.display === 'background' || stillEvent.extendedProps.kind === 'holiday') {
242252
return true;
243253
}
244-
return stillEvent.display === 'background';
254+
// NOTE: This doesn't take into account the hierarchy, so it is a little bit
255+
// too permissive right now. But the backend still covers us.
256+
return stillEvent.extendedProps.resource !== movingEvent.extendedProps.resource;
245257
};
246258

259+
// disallow dropping events into the allDay slot
260+
fcOptions.eventAllow = function(dropInfo, draggedEvent) {
261+
return !dropInfo.allDay;
262+
}
263+
247264
fcOptions.eventDrop = fcOptions.eventResize = function(info) {
248265
var event = info.event;
249266
var url = new Url(event.extendedProps.editurl);
@@ -340,6 +357,9 @@ oc.getFullcalendarOptions = function(ocExtendOptions) {
340357
var changed = false;
341358
for (var i = 0; i < events.length; i++) {
342359
var event = events[i];
360+
if (event.extendedProps.kind === 'holiday') {
361+
continue;
362+
}
343363
// snap to the start of the hour
344364
var start = moment(event.start).startOf('hour').format('HH:mm');
345365
if (start < minTime) {

src/onegov/org/assets/js/occupancycalendar_custom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var setupOccupancyCalendar = function(calendar) {
55
minTime: calendar.data('min-time'),
66
maxTime: calendar.data('min-time'),
77
editable: calendar.data('editable'),
8+
showHolidays: calendar.data('show-holidays') || false,
89
view: calendar.data('view'),
910
date: calendar.data('date'),
1011
highlights_min: calendar.data('highlights-min'),

src/onegov/org/templates/resource_occupancy.pt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
data-resource-active="${resource.name}"
1717
data-stats-url="${stats_url|None}"
1818
data-pdf-url="${pdf_url|None}"
19+
data-show-holidays="${(request.app.org.holidays or request.app.org.has_school_holidays) and 'true' or 'false'}"
1920
></div>
2021

2122
<div class="clearfix"></div>

src/onegov/org/views/resource.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,11 @@ def view_occupancy_json(self: Resource, request: OrgRequest) -> JSON_ro:
14071407

14081408
blocking_resources = self.blocking_resources()
14091409
return *(
1410+
holiday.as_dict()
1411+
for holiday in utils.HolidayEventInfo.from_request(
1412+
request, start.date(), end.date()
1413+
)
1414+
), *(
14101415
res.as_dict()
14111416
for res in utils.ReservationEventInfo.from_reservations(
14121417
request,

src/onegov/town6/templates/resource_occupancy.pt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
data-resource-active="${resource.name}"
1717
data-stats-url="${stats_url|None}"
1818
data-pdf-url="${pdf_url|None}"
19+
data-show-holidays="${(request.app.org.holidays or request.app.org.has_school_holidays) and 'true' or 'false'}"
1920
></div>
2021

2122
</tal:b>

0 commit comments

Comments
 (0)