Files
doneit-web/src/app/store/despacho-store.service.ts
T
Peter Maquiran f8614029af add labels
2023-04-13 12:51:38 +01:00

158 lines
3.8 KiB
TypeScript

import { Injectable } from '@angular/core';
import { localstoreService } from './localstore.service'
import { SHA1 } from 'crypto-js'
import { customTask } from '../models/dailyworktask.model';
import { ObjectQueryService } from '../services/object-query.service';
@Injectable({
providedIn: 'root'
})
export class DespachoStoreService {
// main data
private _list: customTask[] = []
// local storage keyName
private keyName: string;
private _count = 0
ObjectQueryService = new ObjectQueryService()
newList = []
constructor() {
this.keyName = (SHA1("DespachoStoreService"+ 'home/eventSource')).toString()
window['ObjectQueryService'] = this.Query()
setTimeout(()=>{
let restore = localstoreService.get(this.keyName, {})
this._list = restore.list || []
this._count = parseInt(restore.count) || 0
}, 10)
setTimeout(()=>{
// this.Query().Update(
// (select:customTask): boolean => select.Folio == 'Formação',
// (update:customTask) => update.Folio = 'Formação 5'
// )
// this.Query().Update(
// (select:customTask): boolean => select.Folio == 'Formação',
// (update:customTask) => {
// update.Folio = 'Formação 7';
// update.DocumentURL = 'peter';
// }
// )
// this.Query().Update(
// (select:customTask): boolean => select.Folio == 'Formação',
// (update:customTask): customTask => ({
// CreateDate: '',
// DocId: 0,
// DocumentURL: '',
// DocumentsQty: '',
// FolderID: 0,
// Folio:' ',
// Remetente: '',
// Senders: '',
// SerialNumber: '',
// Status: '',
// WorkflowName: '',
// activityInstanceName: ''
// })
// )
// this.Query().Delete(
// (select: customTask): boolean => select.DocId == 3 && select.DocId >= 1
// )
}, 5000)
}
Query() {
return {
Update: (select:Function, update:Function) => {
this.ObjectQueryService.Update(select, update, this._list )
this.save({dynamicCount : true})
},
select: (select) => {
this.ObjectQueryService.select(select, this._list )
this.save({dynamicCount : true})
},
Delete : (select) => {
this.ObjectQueryService.Delete(select, this._list )
this.save({dynamicCount : true})
},
Insert: (insert: customTask | customTask[]) =>{
this.ObjectQueryService.Insert(insert, this._list)
this.save({dynamicCount : true})
}
}
}
ObjectQuery() {}
get list(): any[] {
return this._list || []
}
get count() {
return this._list.length || 0
}
set count(value: number) {
this._count = value
this.save({})
}
reset(eventsList: any) {
this._list = eventsList
this.save({dynamicCount:true})
if(window['all-process-gabinete']) {
window['all-process-gabinete']()
}
}
private save = ({dynamicCount = false})=> {
if(dynamicCount) {
this._count = this._list.length
}
setTimeout(()=>{
localstoreService.set(this.keyName,{
list: this._list,
count: this._count
})
}, 10)
this.updateNewCount()
}
updateNewCount() {
this.newList = this._list.filter((e) =>{
return this.lessthen24Hours(e.TaskStartDate)
})
}
lessthen24Hours(isoDateString:string) {
const creationDate = new Date(isoDateString)
const creationDatePlus24h = new Date(creationDate)
creationDatePlus24h.setHours((creationDate.getHours() + 24))
const currentDate = new Date()
return creationDatePlus24h.getTime() > currentDate.getTime()
}
}
export const DespachoStore = new DespachoStoreService()