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

260 lines
6.5 KiB
TypeScript
Raw Normal View History

2021-08-18 12:05:27 +01:00
import { Injectable } from '@angular/core';
import { localstoreService } from './localstore.service'
import { AES, enc, SHA1 } from 'crypto-js'
2023-04-28 12:56:45 +01:00
import { momentG } from 'src/plugin/momentG';
2023-06-11 20:17:10 +01:00
import { v4 as uuidv4 } from 'uuid'
2021-08-18 12:05:27 +01:00
@Injectable({
providedIn: 'root'
})
export class DeplomasService {
private _diplomasAssinadoList = []
2021-08-24 16:32:10 +01:00
private _diplomasReviewList = []
2022-06-21 16:59:28 +01:00
private _diplomasGerarList = []
private _diplomasParaAssinar = []
2021-08-18 12:05:27 +01:00
private keyNameDiplomasAssinado: string;
2022-06-21 16:59:28 +01:00
private keyNameDiplomasParaAssinar: string;
private keyNameDiplomasGerar: string;
private keyNameDiplomasReview: string;
2021-08-18 12:05:27 +01:00
private _diplomasAssinadoListCount = 0
2021-08-24 16:32:10 +01:00
private _diplomasReviewCount = 0
2022-06-21 16:59:28 +01:00
private _diplomasGerarListCount = 0;
private _diplomasListCount = 0;
2021-08-18 12:05:27 +01:00
2023-04-13 12:51:38 +01:00
diplomasAssinadoListNewCount = []
diplomasReviewListNewCount = []
diplomasGerarListNewCount = []
diplomasParaAssinarNewCount = []
2023-04-19 12:34:28 +01:00
callbacks: {
[key: string]: {
funx: Function
id: string
}
} = {}
2022-06-21 16:59:28 +01:00
constructor() {
2023-01-12 15:27:09 +01:00
this.keyNameDiplomasAssinado = (SHA1("DeplomasService"+"diplomasAssinado")).toString()
this.keyNameDiplomasReview = (SHA1("DeplomasService"+"diplomasReview")).toString()
this.keyNameDiplomasGerar = (SHA1("DeplomasService"+"diplomasGerar")).toString()
this.keyNameDiplomasParaAssinar = (SHA1("DeplomasService"+"diplomasParaAsinar")).toString()
2021-08-18 12:05:27 +01:00
2022-06-21 16:59:28 +01:00
setTimeout(() => {
2021-08-18 12:05:27 +01:00
let restoreDiplomasAssinado = localstoreService.get(this.keyNameDiplomasAssinado, {})
2022-06-21 16:59:28 +01:00
let restoreDiplomasParaAssinar = localstoreService.get(this.keyNameDiplomasParaAssinar, {})
let restoreDiplomasReviewList = localstoreService.get(this.keyNameDiplomasReview, {})
let restoreDiplomasGerarList = localstoreService.get(this.keyNameDiplomasGerar, {})
2021-08-18 12:05:27 +01:00
this._diplomasAssinadoList = restoreDiplomasAssinado.list || []
this._diplomasAssinadoListCount = parseInt(restoreDiplomasAssinado.count) || 0
2022-06-21 16:59:28 +01:00
this._diplomasParaAssinar = restoreDiplomasParaAssinar.list || []
this._diplomasListCount = parseInt(restoreDiplomasParaAssinar.count) || 0
2021-08-24 16:32:10 +01:00
this._diplomasReviewList = restoreDiplomasReviewList.list || []
this._diplomasReviewCount = parseInt(restoreDiplomasReviewList.count) || 0
2022-06-21 16:59:28 +01:00
this._diplomasGerarList = restoreDiplomasGerarList.list || []
this._diplomasGerarListCount = parseInt(restoreDiplomasGerarList.count) || 0
2023-05-04 09:48:04 +01:00
this.runCallback()
2021-08-18 12:05:27 +01:00
}, 10)
}
2023-06-11 20:17:10 +01:00
registerCallback({funx, id = uuidv4()}) {
2023-04-19 12:34:28 +01:00
this.callbacks[id] = { funx, id}
2023-06-11 20:17:10 +01:00
return {
delete: ()=> {
delete this.callbacks[id]
}
}
2023-04-19 12:34:28 +01:00
}
runCallback() {
for (const [key, value] of Object.entries(this.callbacks)) {
value.funx()
}
}
2021-08-24 16:32:10 +01:00
get deplomasReviewCount() {
return this._diplomasReviewCount
}
set deplomasReviewCount(arg: number) {
this._diplomasReviewCount = arg
2021-08-25 15:23:30 +01:00
this.saveDiplomasReviewList()
2021-08-24 16:32:10 +01:00
}
get countDiplomasAssinadoListCount() {
2021-08-18 12:05:27 +01:00
return this._diplomasAssinadoListCount || 0
}
set countDiplomasListCount(value) {
this._diplomasAssinadoListCount = value
this.saveDiplomasAssinadoList()
}
2022-06-21 16:59:28 +01:00
get diplomasParaAssinartCount() {
2021-08-18 12:05:27 +01:00
return this._diplomasListCount || 0
}
2022-06-21 16:59:28 +01:00
set diplomasParaAssinarCount(value) {
this._diplomasParaAssinar = value
this.saveDiplomasParaAssinar()
2021-08-18 12:05:27 +01:00
}
2022-06-21 16:59:28 +01:00
// get list
get diplomasParaAssinarList() {
return this._diplomasParaAssinar
2021-08-18 12:05:27 +01:00
}
2021-08-24 16:32:10 +01:00
2022-06-21 16:59:28 +01:00
// get list
2021-08-18 12:05:27 +01:00
get diplomasAssinadoList() {
return this._diplomasAssinadoList
}
2022-06-21 16:59:28 +01:00
// get list
get diplomasReviewList() {
return this._diplomasReviewList
}
2022-06-22 15:59:21 +01:00
// get list
get DiplomaGerarList() {
return this._diplomasGerarList
}
2021-08-18 12:05:27 +01:00
resetDiplomasAssinadoList(value: any[]) {
this._diplomasAssinadoListCount = value.length
this._diplomasAssinadoList = value
this.saveDiplomasAssinadoList()
2023-02-13 17:51:36 +01:00
if(window['all-process-gabinete']) {
window['all-process-gabinete']()
}
2023-05-04 09:48:04 +01:00
this.runCallback()
2021-08-18 12:05:27 +01:00
}
2022-06-21 16:59:28 +01:00
resetDiplomasParaAssinar(value: any[]) {
2021-08-18 12:05:27 +01:00
this._diplomasListCount = value.length
2022-06-21 16:59:28 +01:00
this._diplomasParaAssinar = value
this.saveDiplomasParaAssinar()
2023-02-13 16:45:12 +01:00
2023-02-13 17:51:36 +01:00
if(window['all-process-gabinete']) {
window['all-process-gabinete']()
}
2023-05-04 09:48:04 +01:00
this.runCallback()
2021-08-18 12:05:27 +01:00
}
2021-08-24 16:32:10 +01:00
resetDiplomasReview(value: any[]) {
this._diplomasReviewList =value
this._diplomasReviewCount = value.length
this.saveDiplomasReviewList()
2023-02-13 16:45:12 +01:00
2023-02-13 17:51:36 +01:00
if(window['all-process-gabinete']) {
window['all-process-gabinete']()
}
2023-05-04 09:48:04 +01:00
this.runCallback()
2021-08-24 16:32:10 +01:00
}
2022-06-21 16:59:28 +01:00
resetDiplomaGerar(value: any[]) {
this._diplomasGerarListCount = value.length
this._diplomasGerarList = value
this.savetDiplomaGerar()
2023-02-13 17:51:36 +01:00
if(window['all-process-gabinete']) {
window['all-process-gabinete']()
}
2023-05-04 09:48:04 +01:00
this.runCallback()
2022-06-21 16:59:28 +01:00
}
2021-08-24 16:32:10 +01:00
private saveDiplomasReviewList () {
setTimeout(()=>{
2022-06-21 16:59:28 +01:00
localstoreService.set(this.keyNameDiplomasReview,{
2021-08-24 16:32:10 +01:00
list: this._diplomasReviewList,
count: this._diplomasReviewCount,
})
}, 10)
2023-04-13 12:51:38 +01:00
this.updateNewCount()
2021-08-24 16:32:10 +01:00
}
private saveDiplomasAssinadoList() {
2021-08-18 18:31:35 +01:00
2021-08-18 12:05:27 +01:00
setTimeout(()=>{
localstoreService.set(this.keyNameDiplomasAssinado,{
list: this._diplomasAssinadoList,
count: this._diplomasAssinadoListCount,
})
2023-04-13 12:51:38 +01:00
}, 10)
this.updateNewCount()
2021-08-18 12:05:27 +01:00
}
2022-06-21 16:59:28 +01:00
private saveDiplomasParaAssinar () {
2021-08-18 12:05:27 +01:00
setTimeout(()=>{
2022-06-21 16:59:28 +01:00
localstoreService.set(this.keyNameDiplomasParaAssinar,{
list: this._diplomasParaAssinar,
2021-08-18 12:05:27 +01:00
count: this._diplomasListCount,
})
}, 10)
2023-04-13 12:51:38 +01:00
this.updateNewCount()
2021-08-18 12:05:27 +01:00
}
2022-06-21 16:59:28 +01:00
private savetDiplomaGerar() {
setTimeout(()=>{
localstoreService.set(this.keyNameDiplomasGerar,{
list: this._diplomasGerarList,
count: this._diplomasGerarListCount,
})
}, 10)
2023-04-13 12:51:38 +01:00
this.updateNewCount()
2022-06-21 16:59:28 +01:00
}
2023-04-13 12:51:38 +01:00
updateNewCount() {
this.diplomasAssinadoListNewCount = this._diplomasAssinadoList.filter((e) =>{
2023-04-19 09:18:25 +01:00
return this.lessthen24Hours(e.TaskReceiveDate)
2023-04-13 12:51:38 +01:00
})
this.diplomasReviewListNewCount = this._diplomasReviewList.filter((e) =>{
2023-04-19 09:18:25 +01:00
return this.lessthen24Hours(e.TaskReceiveDate)
2023-04-13 12:51:38 +01:00
})
this.diplomasGerarListNewCount = this._diplomasGerarList.filter((e) =>{
2023-04-19 09:18:25 +01:00
return this.lessthen24Hours(e.TaskReceiveDate)
2023-04-13 12:51:38 +01:00
})
this.diplomasParaAssinarNewCount = this._diplomasParaAssinar.filter((e) =>{
2023-04-19 09:18:25 +01:00
return this.lessthen24Hours(e.TaskReceiveDate)
2023-04-13 12:51:38 +01:00
})
}
lessthen24Hours(isoDateString:string) {
2023-04-28 12:56:45 +01:00
if(!isoDateString) {
return false
}
const creationDate = new Date(isoDateString)
return momentG(new Date(), 'dd MMMM yyyy') == momentG(new Date(creationDate), 'dd MMMM yyyy')
2023-04-13 12:51:38 +01:00
}
2021-08-18 12:05:27 +01:00
}
export let DeplomasStore = new DeplomasService()