mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
61 lines
1.2 KiB
TypeScript
61 lines
1.2 KiB
TypeScript
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
|
|
private _list: Event[] = []
|
|
private _count = 0
|
|
// local storage keyName
|
|
private keyName: string;
|
|
|
|
constructor() {
|
|
|
|
this.keyName = (SHA1(this.constructor.name+ 'ExpedienteStorage/forAll')).toString()
|
|
|
|
setTimeout(()=>{
|
|
let restore = localstoreService.get(this.keyName, [])
|
|
this._list = restore.list || []
|
|
this._count = restore.count || 0
|
|
}, 10)
|
|
|
|
}
|
|
|
|
get list() {
|
|
return this._list
|
|
}
|
|
|
|
get count() {
|
|
return this._count
|
|
}
|
|
set count(value) {
|
|
this._count = value
|
|
}
|
|
|
|
reset(list: any) {
|
|
this._list = list
|
|
|
|
this.count = this._list.length
|
|
this.save(this._list)
|
|
}
|
|
|
|
private save(list: any) {
|
|
setTimeout(()=>{
|
|
localstoreService.set(this.keyName, {
|
|
list: list,
|
|
count: this.count
|
|
})
|
|
}, 10)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
export const ExpedienteStorage = new ExpedienteStorageServiceService() |