diff --git a/assets/js/common/date.js b/assets/js/common/date.js index c71faf51..12aa9823 100644 --- a/assets/js/common/date.js +++ b/assets/js/common/date.js @@ -101,4 +101,22 @@ const ComunicDate = { }, } -ComunicWeb.common.date = ComunicDate; \ No newline at end of file +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; +} \ No newline at end of file diff --git a/assets/js/components/presence/PresenceHelper.js b/assets/js/components/presence/PresenceHelper.js index f7b9e5df..ccce0fe2 100644 --- a/assets/js/components/presence/PresenceHelper.js +++ b/assets/js/components/presence/PresenceHelper.js @@ -29,4 +29,38 @@ class ForezPresenceHelper { 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 + }) + } } \ No newline at end of file diff --git a/assets/js/pages/groups/pages/presence.js b/assets/js/pages/groups/pages/presence.js index e1463f8c..38b2ba3c 100644 --- a/assets/js/pages/groups/pages/presence.js +++ b/assets/js/pages/groups/pages/presence.js @@ -24,19 +24,6 @@ class GroupPresencePage { target.appendChild(el); - Vue.createApp({ - - data: () => { - return { - - } - }, - - methods: { - } - - }).mount(el); - const calEvents = presence.map((e) => { return { @@ -44,7 +31,7 @@ class GroupPresencePage { start: new Date(e.year, e.month - 1, e.day), backgroundColor: "#0073b7", //Blue borderColor: "#0073b7", //Blue - editable: false, + editable: e.userID == userID(), allDay: true, description: users.get(e.userID).fullName } @@ -59,6 +46,22 @@ class GroupPresencePage { }, initialView: 'dayGridMonth', 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()