2021-07-23 05:43:52 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { localstoreService } from './localstore.service'
|
|
|
|
|
import { AES, enc, SHA1 } from 'crypto-js'
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class DespachosprStoreService {
|
|
|
|
|
|
|
|
|
|
// main data
|
|
|
|
|
private _list: [] = []
|
|
|
|
|
// local storage keyName
|
|
|
|
|
private keyName: string;
|
|
|
|
|
private _count = 0
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
|
|
|
|
this.keyName = (SHA1(this.constructor.name)).toString()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
let restore = localstoreService.get(this.keyName, {})
|
2021-07-30 16:55:13 +01:00
|
|
|
this._list = restore.list || []
|
|
|
|
|
this._count = parseInt(restore.count) || 0
|
2021-07-23 05:43:52 +01:00
|
|
|
}, 10)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get list() {
|
|
|
|
|
return this._list || []
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 08:51:52 +01:00
|
|
|
get count() { return this._count || 0 }
|
2021-07-23 10:35:53 +01:00
|
|
|
set count(value: number) {
|
2021-07-23 05:43:52 +01:00
|
|
|
this._count = value
|
2021-07-30 16:55:13 +01:00
|
|
|
this.save()
|
2021-07-23 05:43:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset(eventsList: any) {
|
|
|
|
|
this._list = eventsList
|
|
|
|
|
|
|
|
|
|
this.count = this._list.length
|
2021-07-30 16:55:13 +01:00
|
|
|
this.save()
|
2021-07-23 05:43:52 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-30 16:55:13 +01:00
|
|
|
private save() {
|
2021-07-23 05:43:52 +01:00
|
|
|
setTimeout(()=>{
|
|
|
|
|
localstoreService.set(this.keyName,{
|
2021-07-30 16:55:13 +01:00
|
|
|
list: this._list,
|
|
|
|
|
count:this._count
|
2021-07-23 05:43:52 +01:00
|
|
|
})
|
|
|
|
|
}, 10)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DespachosprStore = new DespachosprStoreService()
|