Process dates

This commit is contained in:
Pierre HUBERT 2021-04-21 17:49:47 +02:00
parent dac00ccf3a
commit 5fec0aa24c
3 changed files with 70 additions and 15 deletions

View File

@ -101,4 +101,22 @@ const ComunicDate = {
}, },
} }
ComunicWeb.common.date = ComunicDate; ComunicWeb.common.date = ComunicDate;
/**
* Get all the days of a specified range
*
* @param {Date} start
* @param {Date} end (exclusive)
*/
function getDaysOfRange(start, end) {
let curr = start;
let list = [];
while (curr < end) {
list.push(curr);
curr = new Date(curr.getTime() + 1000*60*60*24);
}
return list;
}

View File

@ -29,4 +29,38 @@ class ForezPresenceHelper {
return new Presence(...infos) return new Presence(...infos)
}); });
} }
/**
* Add a day of presence
*
* @param {number} groupID
* @param {number} year
* @param {number} month
* @param {number} day
*/
static async AddDay(groupID, year, month, day) {
await ws("forez_presence/add_day", {
group: groupID,
year: year,
month: month,
day: day
})
}
/**
* Remove a day of presence
*
* @param {number} groupID
* @param {number} year
* @param {number} month
* @param {number} day
*/
static async DelDay(groupID, year, month, day) {
await ws("forez_presence/add_day", {
group: groupID,
year: year,
month: month,
day: day
})
}
} }

View File

@ -24,19 +24,6 @@ class GroupPresencePage {
target.appendChild(el); target.appendChild(el);
Vue.createApp({
data: () => {
return {
}
},
methods: {
}
}).mount(el);
const calEvents = presence.map((e) => { const calEvents = presence.map((e) => {
return { return {
@ -44,7 +31,7 @@ class GroupPresencePage {
start: new Date(e.year, e.month - 1, e.day), start: new Date(e.year, e.month - 1, e.day),
backgroundColor: "#0073b7", //Blue backgroundColor: "#0073b7", //Blue
borderColor: "#0073b7", //Blue borderColor: "#0073b7", //Blue
editable: false, editable: e.userID == userID(),
allDay: true, allDay: true,
description: users.get(e.userID).fullName description: users.get(e.userID).fullName
} }
@ -59,6 +46,22 @@ class GroupPresencePage {
}, },
initialView: 'dayGridMonth', initialView: 'dayGridMonth',
events: calEvents, events: calEvents,
// Update events
eventResize: function(info) {
const newDays = new Set(getDaysOfRange(info.event.start, info.event.end).map(el => el.getTime()));
const oldDays = new Set(getDaysOfRange(info.oldEvent.start, info.oldEvent.end).map(el => el.getTime()));
for (const el of newDays) {
if(oldDays.has(el)) {
newDays.delete(el)
oldDays.delete(el)
}
}
console.info("add", newDays)
console.info("del", oldDays)
}
}); });
calendar.render() calendar.render()