Files
doneit-web/src/app/store/calendar.service.ts
T

105 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-07-19 13:01:06 +01:00
import { Injectable } from '@angular/core';
import { eventSource } from '../models/agenda/eventSource';
import { SHA1, SHA256, AES, enc } from 'crypto-js'
2021-09-27 16:23:41 +01:00
import { localstoreService } from './localstore.service'
2021-08-31 09:00:33 +01:00
import { EventList, EventListStore } from '../models/agenda/AgendaEventList';
2021-07-19 13:01:06 +01:00
@Injectable({
providedIn: 'root'
})
export class CalendarService {
2021-08-31 09:00:33 +01:00
private _eventSource : EventListStore[] = []
2021-07-20 08:51:29 +01:00
private keyName: string;
2021-09-27 16:23:41 +01:00
localstoreService = localstoreService
2021-07-19 13:01:06 +01:00
2021-09-27 16:23:41 +01:00
constructor() {
2021-07-19 13:01:06 +01:00
2023-01-12 15:27:09 +01:00
this.keyName = (SHA1("CalendarService"+ 'eventSource')).toString()
2021-07-19 13:01:06 +01:00
2021-09-27 16:23:41 +01:00
let restore = this.localstoreService.get(this.keyName, [])
2021-07-19 13:01:06 +01:00
2022-04-02 14:13:37 +01:00
restore.forEach((element:EventListStore, eventIndex) => {
this._eventSource.push({
startTime: new Date(element.startTime),
endTime: new Date(element.endTime),
allDay: element.allDay,
event: element.event,
calendarName: element.calendarName,
CalendarId: element.CalendarId,
profile: element.profile,
id: element.id,
2021-07-19 13:01:06 +01:00
});
2022-04-02 14:13:37 +01:00
});
2021-07-19 13:01:06 +01:00
}
2021-08-31 09:00:33 +01:00
ResetList(eventSource: EventListStore[]) {
2021-07-20 19:18:16 +01:00
this._eventSource = eventSource
setTimeout(() => {
this.localstoreService.set(this.keyName, this._eventSource)
}, 10)
2021-07-19 13:01:06 +01:00
}
get eventSource() {
2021-09-27 16:23:41 +01:00
return this._eventSource || []
2021-07-19 13:01:06 +01:00
}
2021-07-20 19:18:16 +01:00
2021-07-19 13:01:06 +01:00
removeRange(rangeStartDate, rangeEndDate, profile) {
this._eventSource = this._eventSource.filter((e)=> {
if(new Date(rangeStartDate).getTime() <= new Date(e.startTime).getTime() &&
new Date(rangeEndDate).getTime() >= new Date(e.endTime).getTime() && e.profile == profile) {
return false
}
return true
})
}
2021-08-31 09:00:33 +01:00
pushEvent(eventsList: EventList[], profile: 'pr' | 'md') {
2021-07-19 13:01:06 +01:00
let news = []
eventsList.forEach((element, eventIndex) => {
news.push({
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: profile,
id: element.EventId,
2022-04-02 14:13:37 +01:00
CalendarId: element.CalendarId
2021-07-19 13:01:06 +01:00
});
});
let instance = this._eventSource.concat(news)
const ids = instance.map(o => o.id)
const filtered = instance.filter(({id}, index) => !ids.includes(id, index + 1))
this._eventSource = (filtered)
2021-07-20 08:51:29 +01:00
setTimeout(() => {
this.localstoreService.set(this.keyName, this._eventSource)
}, 10)
2021-07-19 13:01:06 +01:00
}
2021-09-27 16:23:41 +01:00
delete() {
this._eventSource = []
}
}
export const CalendarStore = new CalendarService()