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

83 lines
2.0 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
import { localstoreService } from './localstore.service'
import { AES, enc, SHA1 } from 'crypto-js'
@Injectable({
providedIn: 'root'
})
export class PedidosStoreService {
private _listparecer: Event[]
private _listdeferimento: Event[]
// local storage keyName
private keyNameparecer: string;
private keyNamedeferiemnto: string;
private _count = 0
constructor() {
this.keyNameparecer = (SHA1(this.constructor.name+"parecer")).toString()
this.keyNamedeferiemnto = (SHA1(this.constructor.name+"deferimneto")).toString()
setTimeout(()=>{
let restoreparecer = localstoreService.get(this.keyNameparecer, {})
let restoredeferimento = localstoreService.get(this.keyNamedeferiemnto, {})
this._listparecer = restoredeferimento.eventsListdeferimento || []
this._listdeferimento = restoreparecer.eventsListparecer || []
this._count = restoredeferimento.count + restoreparecer.count || 0
}, 10)
}
get listparecer() {
return this._listparecer
}
get listdeferimento() {
return this._listdeferimento
}
get count() {
return this._count
}
set count(value) {
this._count = value
}
resetparecer(eventsList: any) {
this._listparecer = eventsList
this.count = this._listparecer.length
this.savedeferimento(this._listparecer)
}
resetdeferimento(eventsList: any) {
this._listdeferimento = eventsList
this.count = this._listdeferimento.length
this.saveparecer(this._listdeferimento)
}
private saveparecer(eventsListparecer: any) {
setTimeout(()=>{
localstoreService.set(this.keyNameparecer,{
eventsListparecer,
count: this._listdeferimento,
})
}, 10)
}
private savedeferimento(eventsListdeferimento: any) {
setTimeout(()=>{
localstoreService.set(this.keyNamedeferiemnto,{
eventsListdeferimento,
count: this._listparecer,
})
}, 10)
}
}
export const PedidosStore = new PedidosStoreService()