2021-07-20 19:18:16 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { Event } from '../models/event.model';
|
|
|
|
|
import { localstoreService } from './localstore.service'
|
|
|
|
|
import { AES, enc, SHA1 } from 'crypto-js'
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// shared data used in home and gabinete
|
|
|
|
|
class ExpedienteStorageServiceService {
|
|
|
|
|
|
|
|
|
|
// main data
|
2021-07-22 16:06:52 +01:00
|
|
|
private _list: Event[] = []
|
2021-07-21 22:44:24 +01:00
|
|
|
private _count = 0
|
2021-07-20 19:18:16 +01:00
|
|
|
// local storage keyName
|
|
|
|
|
private keyName: string;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
|
|
|
|
this.keyName = (SHA1(this.constructor.name+ 'ExpedienteStorage/forAll')).toString()
|
2021-07-20 19:37:02 +01:00
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
let restore = localstoreService.get(this.keyName, [])
|
2021-07-21 22:51:54 +01:00
|
|
|
this._list = restore.list || []
|
|
|
|
|
this._count = restore.count || 0
|
2021-07-20 19:37:02 +01:00
|
|
|
}, 10)
|
2021-07-20 19:18:16 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get list() {
|
|
|
|
|
return this._list
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 22:44:24 +01:00
|
|
|
get count() {
|
|
|
|
|
return this._count
|
|
|
|
|
}
|
|
|
|
|
set count(value) {
|
|
|
|
|
this._count = value
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-20 19:18:16 +01:00
|
|
|
reset(list: any) {
|
|
|
|
|
this._list = list
|
|
|
|
|
|
2021-07-21 22:44:24 +01:00
|
|
|
this.count = this._list.length
|
2021-07-20 19:18:16 +01:00
|
|
|
this.save(this._list)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private save(list: any) {
|
2021-07-20 19:37:02 +01:00
|
|
|
setTimeout(()=>{
|
2021-07-21 22:44:24 +01:00
|
|
|
localstoreService.set(this.keyName, {
|
|
|
|
|
list: list,
|
|
|
|
|
count: this.count
|
|
|
|
|
})
|
2021-07-20 19:37:02 +01:00
|
|
|
}, 10)
|
2021-07-20 19:18:16 +01:00
|
|
|
}
|
2021-07-21 19:08:31 +01:00
|
|
|
|
2021-07-20 19:18:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const ExpedienteStorage = new ExpedienteStorageServiceService()
|