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

This was still a bit ugly (and broken). Let's fix that!

parent 0afac4ef
......@@ -150,21 +150,24 @@ 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);
_reservations.all = r.content;
_reservations.open.upcoming = $.grep(_reservations.all, (r, i) => r.confirmed === 0 && r.denied === 0 && dayjs(_validateDate(r.preparation.to, 'YYYY-MM-DD HH:mm') ? r.preparation.to : r.event.to) >= now);
_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 && dayjs(_validateDate(r.preparation.to, 'YYYY-MM-DD HH:mm') ? r.preparation.to : r.event.to) >= now);
_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 && dayjs(_validateDate(r.preparation.to, 'YYYY-MM-DD HH:mm') ? r.preparation.to : r.event.to) >= now);
_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) => dayjs(_validateDate(r.preparation.to, 'YYYY-MM-DD HH:mm') ? r.preparation.to : r.event.to) <= now);
_reservations.current = $.grep(_reservations.all, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from) <= now && dayjs(_validateDate(r.preparation.to, 'YYYY-MM-DD HH:mm') ? r.preparation.to : r.event.to) >= now);
_reservations.upcoming.total = $.grep(_reservations.all, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from)now);
_reservations.upcoming.month6 = $.grep(_reservations.upcoming.total, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from)(now, 180));
_reservations.upcoming.month3 = $.grep(_reservations.upcoming.month6, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from)Days(now, 90));
_reservations.upcoming.month1 = $.grep(_reservations.upcoming.month3, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from) <= _addDays(now, 30));
_reservations.upcoming.week2 = $.grep(_reservations.upcoming.month1, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from) <= _addDays(now, 14));
_reservations.upcoming.week1 = $.grep(_reservations.upcoming.week2, (r, i) => dayjs(_validateDate(r.preparation.from, 'YYYY-MM-DD HH:mm') ? r.preparation.from : r.event.from) <= _addDays(now, 7));
_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);
} else {
......
Supports Markdown
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