Fix agenda event list

This commit is contained in:
Peter Maquiran
2021-07-18 19:03:01 +01:00
parent 9fed35f8df
commit b6b95d929f
4 changed files with 301 additions and 173 deletions
-90
View File
@@ -1,90 +0,0 @@
import { Injectable } from '@angular/core';
import { eventSource } from '../models/agenda/eventSource';
import { SHA1, SHA256, AES, enc } from 'crypto-js'
import { LocalstoreService } from './localstore.service'
@Injectable({
providedIn: 'root'
})
export class CalendarService {
private _eventSource : eventSource[] = []
constructor(localstoreService: LocalstoreService) {
const keyName = (SHA1(this.constructor.name+ 'eventSource')).toString()
let restore = localstoreService.get(keyName, [])
setTimeout(()=>{
restore.forEach((element, eventIndex) => {
this._eventSource.push({
title: element.title,
startTime: new Date(element.startTime),
endTime: new Date(element.endTime),
allDay: element.allDay,
event: element.event,
calendarName: element.calendarName,
profile: element.profile,
id: element.id,
});
});
},1)
setTimeout(() => {
setInterval(()=> {
localstoreService.set(keyName, this._eventSource)
}, 5000)
}, 10000)
}
ResetList(eventSource: eventSource[]) {
this._eventSource = eventSource
}
get eventSource() {
return this._eventSource
}
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
})
}
pushEvent(eventsList, profile: 'pr' | 'md') {
let news = []
eventsList.forEach((element, eventIndex) => {
news.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: profile,
id: element.EventId,
});
});
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)
}
}