|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
|
-import { TemplateResult } from 'lit-html';
|
|
|
+import dayjs from 'dayjs';
|
|
|
import Selectable from './utils/selectable';
|
|
|
|
|
|
export interface IEvent{
|
|
|
@@ -13,6 +13,10 @@ export interface IEvent{
|
|
|
bgColor?:string,
|
|
|
content?:string
|
|
|
}
|
|
|
+export type EventJSON = Omit<IEvent,"end" |"start"> & {
|
|
|
+ start:string
|
|
|
+ end: string
|
|
|
+}
|
|
|
export class Event implements IEvent, Selectable{
|
|
|
id:string
|
|
|
start:Date
|
|
|
@@ -58,6 +62,63 @@ export class Event implements IEvent, Selectable{
|
|
|
return new Event(obj);
|
|
|
}
|
|
|
}
|
|
|
+ toJSON():EventJSON{
|
|
|
+ const output:EventJSON = {
|
|
|
+ id:this.id,
|
|
|
+ start:this.startStr,
|
|
|
+ end:this.startStr,
|
|
|
+ title:this.title,
|
|
|
+ ressourceId:this.ressourceId,
|
|
|
+ editable:this.editable,
|
|
|
+ ressourceEditable:this.ressourceEditable,
|
|
|
+ bgColor:this.bgColor,
|
|
|
+ content:this.content
|
|
|
+ }
|
|
|
+ if (this.bgColor){
|
|
|
+ output.bgColor=this.bgColor;
|
|
|
+ }
|
|
|
+ if (this.content){
|
|
|
+ output.content=this.content;
|
|
|
+ }
|
|
|
+ return output
|
|
|
+ }
|
|
|
+ static fromJSON(input:string|EventJSON):Event{
|
|
|
+ let obj:EventJSON
|
|
|
+ if (typeof input == "string"){
|
|
|
+ obj = JSON.parse(input)
|
|
|
+ }else{
|
|
|
+ obj = input as EventJSON
|
|
|
+ }
|
|
|
+
|
|
|
+ const start = dayjs(obj.start)
|
|
|
+ const end = dayjs(obj.end)
|
|
|
+ if(start.isValid()){
|
|
|
+ throw new Error(`Error during the import of the Event '${obj.id}': Invalid starting date`)
|
|
|
+ }else{
|
|
|
+ if(end.isValid()){
|
|
|
+ throw new Error(`Error during the import of the Event '${obj.id}': Invalid ending date`)
|
|
|
+ }else{
|
|
|
+
|
|
|
+ const iEvent:IEvent ={
|
|
|
+ id:obj.id,
|
|
|
+ start:start.toDate(),
|
|
|
+ end:end.toDate(),
|
|
|
+ title:obj.title,
|
|
|
+ ressourceId:obj.ressourceId,
|
|
|
+ editable:obj.editable,
|
|
|
+ ressourceEditable:obj.ressourceEditable,
|
|
|
+ bgColor:obj.bgColor,
|
|
|
+ content:obj.content
|
|
|
+ }
|
|
|
+ if (obj.bgColor){
|
|
|
+ iEvent.bgColor=obj.bgColor;
|
|
|
+ }
|
|
|
+ if (obj.content){
|
|
|
+ iEvent.content=obj.content;
|
|
|
+ }
|
|
|
+ return new Event(iEvent)
|
|
|
+ }
|
|
|
+ }}
|
|
|
}
|
|
|
|
|
|
export default Event
|