Start to merge entries

This commit is contained in:
Pierre HUBERT 2021-04-21 18:27:42 +02:00
parent 79b8b8bd3c
commit bcfdb5ffee
3 changed files with 61 additions and 14 deletions

View File

@ -103,6 +103,15 @@ const ComunicDate = {
ComunicWeb.common.date = ComunicDate; ComunicWeb.common.date = ComunicDate;
/**
* Add a day to a date
*
* @param {Date} date Target date
*/
function addOneDay(date) {
return new Date(date.getTime() + 1000*60*60*24);
}
/** /**
* Get all the days of a specified range * Get all the days of a specified range
* *
@ -115,7 +124,7 @@ function getDaysOfRange(start, end) {
while (curr < end) { while (curr < end) {
list.push(curr); list.push(curr);
curr = new Date(curr.getTime() + 1000*60*60*24); curr = addOneDay(curr);
} }
return list; return list;

View File

@ -11,6 +11,10 @@ class Presence {
this.month = month; this.month = month;
this.day = day; this.day = day;
} }
get date() {
return new Date(this.year, this.month - 1, this.day);
}
} }

View File

@ -34,19 +34,53 @@ class GroupPresencePage {
// Data source // Data source
events: async function(info, success, failure) { events: async function(info, success, failure) {
try { try {
const presence = await ForezPresenceHelper.GetList(group.id); let presences = await ForezPresenceHelper.GetList(group.id);
const users = await getUsers([...new Set(presence.map(e => e.userID))]); const users = await getUsers([...new Set(presences.map(e => e.userID))]);
success(presence.map((e) => {
presences.sort((one, two) => {
if (one.userID < two.userID)
return -1;
if (one.userID > two.userID)
return 1;
return one.date - two.date;
})
presences.forEach((e) => e.end = addOneDay(e.date));
console.log(presences)
for(let i = 0; i < presences.length; i++) {
while(true) {
if (presences.length == i + 1)
break;
let curr = presences[i];
let next = presences[i + 1];
if(curr.userID != next.userID || curr.year != next.year || curr.month != next.month || curr.day != next.day - 1)
break;
curr.end = next.end;
presences.splice(i + 1, 1)
}
}
const events = presences.map((e) => {
return { return {
title: users.get(e.userID).fullName, title: users.get(e.userID).fullName,
start: new Date(e.year, e.month - 1, e.day), start: e.date,
end: e.end,
backgroundColor: "#0073b7", //Blue backgroundColor: "#0073b7", //Blue
borderColor: "#0073b7", //Blue borderColor: "#0073b7", //Blue
editable: e.userID == userID(), editable: e.userID == userID(),
allDay: true, allDay: true,
description: users.get(e.userID).fullName description: users.get(e.userID).fullName
} }
})); });
success(events);
} catch(e) { } catch(e) {
console.error(e); console.error(e);