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

97 lines
2.2 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 EventoaprovacaoStoreService {
// main data
2021-07-30 16:55:13 +01:00
private _listPr: any[] = []
private _listMd: any[] = []
// local storage keyName
private keyNamemd: string;
private keyNamepr: string;
private _count = 0
2021-08-25 16:20:25 +01:00
private _countPr = 0
private _countMd = 0
2021-07-23 15:57:01 +01:00
constructor() {
2021-07-23 15:57:01 +01:00
this.keyNamemd = (SHA1(this.constructor.name+"md")).toString()
this.keyNamepr = (SHA1(this.constructor.name+"pr")).toString()
setTimeout(()=>{
2021-07-30 16:55:13 +01:00
let restoreMd = localstoreService.get(this.keyNamemd, {})
let restorePr = localstoreService.get(this.keyNamepr, {})
2021-08-25 16:32:02 +01:00
this._listPr = restorePr.listPr || []
this._listMd = restoreMd.lisMd || []
2021-07-30 16:55:13 +01:00
this._countMd = parseInt(restoreMd.countListMd) || 0
2021-08-25 16:32:02 +01:00
this._countPr = parseInt(restorePr.countListPr) || 0
2021-07-30 16:55:13 +01:00
this._count = (this._countMd + this._countPr) || 0
2021-07-23 15:57:01 +01:00
}, 10)
2021-07-23 15:57:01 +01:00
}
2021-07-30 16:55:13 +01:00
get listpr() { return this._listPr }
get listmd() { return this._listMd }
2021-08-25 08:51:52 +01:00
get count() { return this._count || 0 }
2021-07-30 16:55:13 +01:00
set count(value: number) {
this._count = value
2021-07-23 15:57:01 +01:00
}
2021-08-25 08:51:52 +01:00
get countPr() { return this._countPr || 0 }
set countPr (value: number) {
2021-07-30 16:55:13 +01:00
this._countPr = value
2021-07-23 15:57:01 +01:00
}
2021-08-25 08:51:52 +01:00
get countMd() { return this._countMd || 0 }
2021-07-30 16:55:13 +01:00
set countMd (value) {
this._countMd = value
2021-07-23 15:57:01 +01:00
}
resetpr(eventsList: any) {
2021-07-30 16:55:13 +01:00
this._listPr = eventsList
2021-07-23 15:57:01 +01:00
2021-07-30 16:55:13 +01:00
this.countPr = this._listPr.length
this.count = this.countPr + this.countMd
this.savePr()
2021-07-23 15:57:01 +01:00
}
resetmd(eventsList: any) {
2021-07-30 16:55:13 +01:00
this._listMd = eventsList
2021-07-23 15:57:01 +01:00
2021-07-30 16:55:13 +01:00
this.countMd = this._listMd.length
this.count = this.countPr + this.countMd
this.saveMd()
2021-07-23 15:57:01 +01:00
}
2021-07-30 16:55:13 +01:00
private saveMd() {
2021-08-25 08:51:52 +01:00
setTimeout(()=>{
2021-07-23 15:57:01 +01:00
localstoreService.set(this.keyNamemd,{
2021-07-30 16:55:13 +01:00
lisMd: this._listMd,
countListMd: this._countMd
2021-07-23 15:57:01 +01:00
})
}, 10)
}
2021-08-25 08:51:52 +01:00
2021-07-30 16:55:13 +01:00
private savePr() {
2021-07-23 15:57:01 +01:00
setTimeout(()=>{
localstoreService.set(this.keyNamepr,{
2021-07-30 16:55:13 +01:00
listPr: this._listPr,
countListPr: this._countPr
2021-07-23 15:57:01 +01:00
})
}, 10)
}
}
export const EventoAprovacaoStore = new EventoaprovacaoStoreService()