2021-07-22 16:09:47 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { localstoreService } from './localstore.service'
|
2021-08-27 13:39:52 +01:00
|
|
|
import { SHA1 } from 'crypto-js'
|
2021-08-26 13:48:29 +01:00
|
|
|
import { ExpedienteTask } from '../models/dailyworktask.model';
|
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-07-22 16:09:47 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class ExpedientegdStoreService {
|
|
|
|
|
|
2021-07-23 15:57:01 +01:00
|
|
|
// main data
|
2021-08-26 13:48:29 +01:00
|
|
|
private _list: ExpedienteTask[] = []
|
2021-07-23 15:57:01 +01:00
|
|
|
// local storage keyName
|
|
|
|
|
private keyName: string;
|
|
|
|
|
private _count = 0
|
|
|
|
|
|
2023-04-13 12:51:38 +01:00
|
|
|
newList = []
|
|
|
|
|
|
2023-04-19 12:34:28 +01:00
|
|
|
callbacks: {
|
|
|
|
|
[key: string]: {
|
|
|
|
|
funx: Function
|
|
|
|
|
id: string
|
|
|
|
|
}
|
|
|
|
|
} = {}
|
|
|
|
|
|
2021-07-23 15:57:01 +01:00
|
|
|
constructor() {
|
|
|
|
|
|
2023-01-12 15:27:09 +01:00
|
|
|
this.keyName = (SHA1("EventoaprovacaoStoreService")).toString()
|
2021-07-23 15:57:01 +01:00
|
|
|
|
2021-07-30 16:55:13 +01:00
|
|
|
setTimeout(()=> {
|
2021-07-23 15:57:01 +01:00
|
|
|
let restore = localstoreService.get(this.keyName, {})
|
2021-07-30 16:55:13 +01:00
|
|
|
this._list = restore.list || []
|
|
|
|
|
this._count = parseInt(restore.count) || 0
|
2023-05-04 09:48:04 +01:00
|
|
|
|
|
|
|
|
this.runCallback()
|
2021-07-23 15:57:01 +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-07-23 15:57:01 +01:00
|
|
|
get list() {
|
|
|
|
|
return this._list
|
|
|
|
|
}
|
|
|
|
|
get count() {
|
2023-01-30 16:27:33 +01:00
|
|
|
return this._list.length || 0
|
2021-07-23 15:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset(eventsList: any) {
|
|
|
|
|
this._list = eventsList
|
2021-07-30 16:55:13 +01:00
|
|
|
this.save()
|
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-07-23 15:57:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-30 16:55:13 +01:00
|
|
|
private save() {
|
2023-08-08 16:32:57 +01:00
|
|
|
setTimeout(() => {
|
2021-07-23 15:57:01 +01:00
|
|
|
localstoreService.set(this.keyName,{
|
2021-07-30 16:55:13 +01:00
|
|
|
list: this._list,
|
|
|
|
|
count: this._count
|
2021-07-23 15:57:01 +01:00
|
|
|
})
|
|
|
|
|
}, 10)
|
2023-04-13 12:51:38 +01:00
|
|
|
|
|
|
|
|
this.updateNewList()
|
2021-07-23 15:57:01 +01:00
|
|
|
|
|
|
|
|
}
|
2021-07-22 16:09:47 +01:00
|
|
|
|
2023-04-13 12:51:38 +01:00
|
|
|
updateNewList() {
|
|
|
|
|
this.newList = this._list.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-07-22 16:09:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ExpedienteGdStore = new ExpedientegdStoreService()
|