|
|
@@ -57,8 +57,14 @@ class Creneau implements ICreneau {
|
|
|
this._isMeal = value;
|
|
|
this.event.bgColor = value ? "gray" : undefined;
|
|
|
}
|
|
|
- fixedAttendee: boolean;
|
|
|
-
|
|
|
+ _fixedAttendee = false;
|
|
|
+ public get fixedAttendee(): boolean {
|
|
|
+ return this._fixedAttendee;
|
|
|
+ }
|
|
|
+ public set fixedAttendee(value: boolean) {
|
|
|
+ this._fixedAttendee = value;
|
|
|
+ this.updateEventContent();
|
|
|
+ }
|
|
|
constructor(obj: ICreneau) {
|
|
|
if (!(typeof obj.event.id == "string") || obj.event.id == "") {
|
|
|
throw new TypeError(
|
|
|
@@ -102,15 +108,30 @@ class Creneau implements ICreneau {
|
|
|
set end(value: Date) {
|
|
|
this.event.end = value;
|
|
|
}
|
|
|
+ /** Duration of the slot in millisecond */
|
|
|
get durationMs(): number {
|
|
|
return this.event.end.getTime() - this.event.start.getTime();
|
|
|
}
|
|
|
+ /** Duration of the slot in minutes */
|
|
|
get durationMin(): number {
|
|
|
return this.durationMs / 1000 / 60;
|
|
|
}
|
|
|
+ /** Duration of the slot in hours */
|
|
|
get durationH(): number {
|
|
|
return this.durationMin / 60;
|
|
|
}
|
|
|
+ /** Human readable format of the start & end, date & time */
|
|
|
+ get fromTo(): string {
|
|
|
+ return (
|
|
|
+ "le " +
|
|
|
+ dayjs(this.event.start).format("YYYY/MM/DD") +
|
|
|
+ " de " +
|
|
|
+ dayjs(this.event.start).format("HH:mm") +
|
|
|
+ " à " +
|
|
|
+ dayjs(this.event.end).format("HH:mm")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ /** Human readable format of the start & end time */
|
|
|
get horaire(): string {
|
|
|
return (
|
|
|
"De " +
|
|
|
@@ -120,32 +141,23 @@ class Creneau implements ICreneau {
|
|
|
);
|
|
|
}
|
|
|
toString(): string {
|
|
|
- return `Créneau[titre:${this.title},\tHoraire:${this.horaire}]`;
|
|
|
+ return `Créneau[titre:${this.title},\tDate:${this.fromTo}]`;
|
|
|
}
|
|
|
+
|
|
|
+ /** update the content of the event object based on the Creneau state */
|
|
|
updateEventContent(): void {
|
|
|
const missingbenevole = Math.max(this.minAttendee - this.benevoleIdList.length, 0);
|
|
|
const spanClass =
|
|
|
- this.benevoleIdList.length == 0 ? "red" : missingbenevole != 0 ? "orange" : "";
|
|
|
- this.event.content = `<div class="bubble ${spanClass}">${this.benevoleIdList.length} / ${this.minAttendee}</div>`;
|
|
|
+ (this._fixedAttendee ? " anchor" : "") +
|
|
|
+ (this.benevoleIdList.length == 0 ? " red" : missingbenevole != 0 ? " orange" : "");
|
|
|
+ this.event.content = `<div class="bubble${spanClass}">${this.benevoleIdList.length} / ${this.minAttendee}</div>`;
|
|
|
}
|
|
|
+
|
|
|
+ /** Check if the two creneaux share common time */
|
|
|
collide(other: Creneau): boolean {
|
|
|
return this.event.start < other.event.end && other.event.start < this.event.end;
|
|
|
}
|
|
|
- toJSON(): CreneauJSON {
|
|
|
- const e = this.event.toJSON();
|
|
|
- delete e.content;
|
|
|
- return {
|
|
|
- event: e,
|
|
|
- penibility: this.penibility,
|
|
|
- minAttendee: this.minAttendee,
|
|
|
- maxAttendee: this.maxAttendee,
|
|
|
- benevoleIdList: this.benevoleIdList,
|
|
|
- competencesIdList: this.competencesIdList,
|
|
|
- description: this.description,
|
|
|
- isMeal: this.isMeal,
|
|
|
- fixedAttendee: this.fixedAttendee,
|
|
|
- };
|
|
|
- }
|
|
|
+ /** Return the Mealslot to feed the optimizer*/
|
|
|
toMealSlot(): MealSlot {
|
|
|
return {
|
|
|
id: this.event.id,
|
|
|
@@ -154,6 +166,8 @@ class Creneau implements ICreneau {
|
|
|
maxAttendee: this.maxAttendee,
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ /** Return the timeslot to feed the optimizer*/
|
|
|
toTimeslotRaw(): TimeslotRaw {
|
|
|
return {
|
|
|
id: this.event.id,
|
|
|
@@ -164,6 +178,24 @@ class Creneau implements ICreneau {
|
|
|
maxAttendee: this.maxAttendee,
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ /** Get the plain javscript object that can be serialized */
|
|
|
+ toJSON(): CreneauJSON {
|
|
|
+ const e = this.event.toJSON();
|
|
|
+ delete e.content;
|
|
|
+ return {
|
|
|
+ event: e,
|
|
|
+ penibility: this.penibility,
|
|
|
+ minAttendee: this.minAttendee,
|
|
|
+ maxAttendee: this.maxAttendee,
|
|
|
+ benevoleIdList: this.benevoleIdList,
|
|
|
+ competencesIdList: this.competencesIdList,
|
|
|
+ description: this.description,
|
|
|
+ isMeal: this.isMeal,
|
|
|
+ fixedAttendee: this.fixedAttendee,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ /** Parse the plain javscript object that can be serialized */
|
|
|
static fromJSON(input: string | CreneauJSON): Creneau {
|
|
|
let obj: CreneauJSON;
|
|
|
if (typeof input == "string") {
|