Commit c8dda603 authored by Michael Koch's avatar Michael Koch
Browse files

We can do even better.

parent d8cda71f
......@@ -150,26 +150,26 @@ function refreshReservations() {
if (r.result === "success") {
if (! _.isEqual(r.content, _reservations) || forceReload) {
if (r.content) {
let fromtime = dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from);
let totime = dayjs(_validateDate(r.preparation.to, 'YYYY-MM-DD HH:mm') ? r.preparation.to : r.event.to);
let fromtime = (resv) => dayjs(_validateDate(resv.preparation.from, 'YYYY-MM-DD HH:mm') ? resv.preparation.from : resv.event.from);
let totime = (resv) => dayjs(_validateDate(resv.preparation.to, 'YYYY-MM-DD HH:mm') ? resv.preparation.to : resv.event.to);
_reservations.all = r.content;
_reservations.open.upcoming = $.grep(_reservations.all, (r, i) => r.confirmed === 0 && r.denied === 0 && totime >= now);
_reservations.open.total = $.grep(_reservations.all, (r, i) => r.confirmed === 0 && r.denied === 0);
_reservations.confirmed.upcoming = $.grep(_reservations.all, (r, i) => r.confirmed === 1 && totime >= now);
_reservations.confirmed.total = $.grep(_reservations.all, (r, i) => r.confirmed === 1);
_reservations.denied.upcoming = $.grep(_reservations.all, (r, i) => r.denied === 1 && totime >= now);
_reservations.denied.total = $.grep(_reservations.all, (r, i) => r.denied === 1);
_reservations.archived = $.grep(_reservations.all, (r, i) => totime <= now);
_reservations.current = $.grep(_reservations.all, (r, i) => fromtime <= now && totime >= now);
_reservations.upcoming.total = $.grep(_reservations.all, (r, i) => fromtime >= now);
_reservations.upcoming.month6 = $.grep(_reservations.upcoming.total, (r, i) => fromtime >= now && fromtime <= _addDays(now, 180));
_reservations.upcoming.month3 = $.grep(_reservations.upcoming.month6, (r, i) => fromtime >= now && fromtime <= _addDays(now, 90));
_reservations.upcoming.month1 = $.grep(_reservations.upcoming.month3, (r, i) => fromtime >= now && fromtime <= _addDays(now, 30));
_reservations.upcoming.week2 = $.grep(_reservations.upcoming.month1, (r, i) => fromtime >= now && fromtime <= _addDays(now, 14));
_reservations.upcoming.week1 = $.grep(_reservations.upcoming.week2, (r, i) => fromtime >= now && fromtime <= _addDays(now, 7));
_reservations.lernsprint = $.grep(_reservations.all, (r, i) => r.room.room_type === 1);
_reservations.studyspace = $.grep(_reservations.all, (r, i) => r.room.room_type === 5);
_reservations.open.upcoming = $.grep(_reservations.all, (resv, i) => resv.confirmed === 0 && resv.denied === 0 && totime(resv) >= now);
_reservations.open.total = $.grep(_reservations.all, (resv, i) => resv.confirmed === 0 && resv.denied === 0);
_reservations.confirmed.upcoming = $.grep(_reservations.all, (resv, i) => resv.confirmed === 1 && totime(resv) >= now);
_reservations.confirmed.total = $.grep(_reservations.all, (resv, i) => resv.confirmed === 1);
_reservations.denied.upcoming = $.grep(_reservations.all, (resv, i) => resv.denied === 1 && totime(resv) >= now);
_reservations.denied.total = $.grep(_reservations.all, (resv, i) => resv.denied === 1);
_reservations.archived = $.grep(_reservations.all, (resv, i) => totime(resv) <= now);
_reservations.current = $.grep(_reservations.all, (resv, i) => fromtime(resv) <= now && totime(resv) >= now);
_reservations.upcoming.total = $.grep(_reservations.all, (resv, i) => fromtime(resv) >= now);
_reservations.upcoming.month6 = $.grep(_reservations.upcoming.total, (resv, i) => fromtime(resv) >= now && fromtime(resv) <= _addDays(now, 180));
_reservations.upcoming.month3 = $.grep(_reservations.upcoming.month6, (resv, i) => fromtime(resv) >= now && fromtime(resv) <= _addDays(now, 90));
_reservations.upcoming.month1 = $.grep(_reservations.upcoming.month3, (resv, i) => fromtime(resv) >= now && fromtime(resv) <= _addDays(now, 30));
_reservations.upcoming.week2 = $.grep(_reservations.upcoming.month1, (resv, i) => fromtime(resv) >= now && fromtime(resv) <= _addDays(now, 14));
_reservations.upcoming.week1 = $.grep(_reservations.upcoming.week2, (resv, i) => fromtime(resv) >= now && fromtime(resv) <= _addDays(now, 7));
_reservations.lernsprint = $.grep(_reservations.all, (resv, i) => resv.room.room_type === 1);
_reservations.studyspace = $.grep(_reservations.all, (resv, i) => resv.room.room_type === 5);
} else {
_reservations = {
'open': {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment