diff --git a/config.xml b/config.xml index 97d2fb38d..7b18d7926 100644 --- a/config.xml +++ b/config.xml @@ -3,7 +3,7 @@ gabinete digital An awesome Ionic/Cordova app. Ionic Framework Team - + diff --git a/src/app/pages/events/events.page.html b/src/app/pages/events/events.page.html index 3fc7279de..71e1d70ad 100644 --- a/src/app/pages/events/events.page.html +++ b/src/app/pages/events/events.page.html @@ -94,7 +94,7 @@
-
diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index 45f20d623..5f3e52a9a 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -67,7 +67,8 @@ export class EventsPage implements OnInit { toDayEventStorage = ToDayEventStorage expedienteGdStore = ExpedienteGdStore - listToPresent + listToPresent = []; + listToPresentexpediente =[] expedienteTaskPipe = new ExpedienteTaskPipe() @@ -118,18 +119,6 @@ export class EventsPage implements OnInit { this.segment = "Combinada"; this.profile = "mdgpr"; - this.showGreeting(); - - this.router.events.forEach((event) => { - if (event instanceof NavigationEnd && event.url == '/home/events') { - this.RefreshEvents(); - setTimeout(()=>{ - this.LoadList(); - }, 1500) - } - }); - this.hideSearch(); - this.getEventsFromLocalDb(); //this.checkScreenOrientation(); @@ -196,17 +185,16 @@ export class EventsPage implements OnInit { const list = mdOficialEvents.concat(mdPessoalEvents); console.log("getAllMdOficialPessoalEvents", list) this.SqliteAddEvent(list); - this.listToPresent = this.toDayEventStorage.eventsList - this.toDayEventStorage.reset(list) + this.listToPresent = list - if (this.toDayEventStorage.eventsList.length > 0) { - this.currentEvent = this.toDayEventStorage.eventsList[0].Subject; - this.currentHoursMinutes = this.toDayEventStorage.eventsList[0].StartDate; + if (list.length > 0) { + this.currentEvent = list[0].Subject; + this.currentHoursMinutes = list[0].StartDate; } - this.totalEvent = this.toDayEventStorage.eventsList.length; + this.totalEvent = list.length; this.showLoader = false; } @@ -218,15 +206,14 @@ export class EventsPage implements OnInit { const list = prOficialEvents.concat(prPessoalEvents); console.log("getAllPrOficialPessoalEvents", list) this.SqliteAddEvent(list); - this.toDayEventStorage.reset(list) - if (this.toDayEventStorage.eventsList.length > 0) { - this.currentEvent = this.toDayEventStorage.eventsList[0].Subject; - this.currentHoursMinutes = this.toDayEventStorage.eventsList[0].StartDate; + if (list.length > 0) { + this.currentEvent = list[0].Subject; + this.currentHoursMinutes = list[0].StartDate; } - this.listToPresent = this.toDayEventStorage.eventsList; - this.totalEvent = this.toDayEventStorage.eventsList.length; + this.listToPresent = list; + this.totalEvent = list.length; this.showLoader = false; } @@ -326,7 +313,7 @@ export class EventsPage implements OnInit { Body: "" } - if(!event.Organizer){ + if (!event.Organizer) { this.sqliteservice.addEvent(data); console.log("Events page add event sqllite") } @@ -336,31 +323,49 @@ export class EventsPage implements OnInit { getEventsFromLocalDb() { - synchro.registerCallback('Online', () => { + if (synchro.connected === true) { + this.showGreeting(); + this.router.events.forEach((event) => { if (event instanceof NavigationEnd && event.url == '/home/events') { this.RefreshEvents(); - this.LoadList(); + setTimeout(() => { + this.LoadList(); + }, 1500) } }); - console.log('Onlineee') - - }) - - - synchro.registerCallback('Offline', () => { - this.platform.ready().then(() => { - this.sqliteservice.getAllEvents().then((event) => { - this.listToPresent = event - this.totalEvent = this.listToPresent.length - this.currentEvent = this.listToPresent[0].Subject - this.currentHoursMinutes = this.listToPresent[0].StartDate - console.log("All events from local,", event) - }) - console.log('Offlineee') + this.hideSearch(); + } else { + this.sqliteservice.getAllEvents().then((event:any[]) => { + this.listToPresent = event + this.totalEvent = this.listToPresent.length + this.currentEvent = this.listToPresent[0].Subject + this.currentHoursMinutes = this.listToPresent[0].StartDate + console.log("All events from local,", event) }) - }) + this.sqliteservice.getprocessByworkflow("Expediente").then((process: any[]) => { + var expedientlist = []; + process.forEach((element) => { + let task = { + CreateDate: element.taskStartDate, + DocumentsQty: element.totalDocuments, + Senders: JSON.parse(element.workflowInstanceDataFields).Sender, + SerialNumber: element.serialNumber, + Status: JSON.parse(element.workflowInstanceDataFields).Status, + Subject: JSON.parse(element.workflowInstanceDataFields).Subject, + WorkflowName: element.workflowDisplayName, + activityInstanceName: element.activityInstanceName, + taskStartDate: element.taskStartDate, + } + expedientlist.push(task); + }) + const ExpedienteTask = expedientlist.map(e => this.expedienteTaskPipe.transform(e)) + this.listToPresentexpediente = ExpedienteTask; + + + }) + } } @@ -418,10 +423,13 @@ export class EventsPage implements OnInit { LoadList() { this.processes.GetTaskListExpediente(false).subscribe(result => { console.log("Expediente", result); + this.sqliteservice.addProcess(result) const ExpedienteTask = result.map(e => this.expedienteTaskPipe.transform(e)) - this.expedienteGdStore.reset(ExpedienteTask) + console.log("Expediente 2", ExpedienteTask); + + this.listToPresentexpediente = ExpedienteTask; }); } @@ -444,9 +452,9 @@ export class EventsPage implements OnInit { } } - viewExpedientListPage(){ - if(this.loggeduser.Profile == 'MDGPR'){ - if( window.innerWidth < 701){ + viewExpedientListPage() { + if (this.loggeduser.Profile == 'MDGPR') { + if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/expediente']); } else { @@ -454,8 +462,8 @@ export class EventsPage implements OnInit { this.router.navigate(['/home/gabinete-digital'], navigationExtras); } } - else if(this.loggeduser.Profile == 'PR'){ - if( window.innerWidth < 701){ + else if (this.loggeduser.Profile == 'PR') { + if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/expedientes-pr']); } else { diff --git a/src/app/pages/gabinete-digital/despachos-pr/despacho-pr/despacho-pr.page.ts b/src/app/pages/gabinete-digital/despachos-pr/despacho-pr/despacho-pr.page.ts index d321ef1db..07a8fc5bb 100644 --- a/src/app/pages/gabinete-digital/despachos-pr/despacho-pr/despacho-pr.page.ts +++ b/src/app/pages/gabinete-digital/despachos-pr/despacho-pr/despacho-pr.page.ts @@ -8,7 +8,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { Event } from '../../../../models/event.model'; import { MenuController, ModalController, PopoverController } from '@ionic/angular'; -import { momentG } from 'src/plugin/momentG' +import { momentG } from 'src/plugin/momentG' import { DiscartExpedientModalPage } from '../../discart-expedient-modal/discart-expedient-modal.page'; import { BookMeetingModalPage } from '../../expediente/book-meeting-modal/book-meeting-modal.page'; import { CreateProcessPage } from 'src/app/modals/create-process/create-process.page'; @@ -19,6 +19,9 @@ import { ToastService } from 'src/app/services/toast.service'; import { Location } from '@angular/common' import { DespachoService } from 'src/app/Rules/despacho.service'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; + @Component({ selector: 'app-despacho-pr', templateUrl: './despacho-pr.page.html', @@ -28,7 +31,7 @@ export class DespachoPrPage implements OnInit { months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"]; - customDate:any; + customDate: any; task: any; fulltask: any; @@ -51,34 +54,25 @@ export class DespachoPrPage implements OnInit { private activatedRoute: ActivatedRoute, private toastService: ToastService, private location: Location, - private despachoService: DespachoService - ) { - this.activatedRoute.paramMap.subscribe(params => { - if(params["params"].SerialNumber) { - this.serialNumber = params["params"].SerialNumber; - } - if(params["params"].caller) { - this.caller = params["params"].caller; - } - }); + private despachoService: DespachoService, + private sqliteservice: SqliteService + ) { + this.activatedRoute.paramMap.subscribe(params => { + if (params["params"].SerialNumber) { + this.serialNumber = params["params"].SerialNumber; + } + if (params["params"].caller) { + this.caller = params["params"].caller; + } + }); - console.log('DespachoPrPage SerialNumber', this.serialNumber) - } + console.log('DespachoPrPage SerialNumber', this.serialNumber) + } ngOnInit() { this.profile = "mdgpr"; console.log(this.serialNumber); - - this.activateRoute.paramMap.subscribe(paramMap => { - if (!paramMap.has('SerialNumber')) { - return; - } - /* this.serialNumber = paramMap.get('SerialNumber'); */ - this.LoadTaskDetail(this.serialNumber); - // this.LoadRelatedEvents(this.serialNumber); - }); - this.LoadTaskDetail(this.serialNumber); - // this.LoadRelatedEvents(this.serialNumber); + this.getFromDB(); } close() { @@ -91,12 +85,12 @@ export class DespachoPrPage implements OnInit { async LoadTaskDetail(serial: string) { - this.processes.GetTask(serial).subscribe((res:fullTask) => { + this.processes.GetTask(serial).subscribe((res: fullTask) => { this.task = { "SerialNumber": res.serialNumber, "Folio": res.workflowInstanceDataFields.Subject, "Senders": res.originator.email, - "CreateDate": momentG(new Date(res.taskStartDate),'yyyy-MM-dd HH:mm:ss'), + "CreateDate": momentG(new Date(res.taskStartDate), 'yyyy-MM-dd HH:mm:ss'), "DocumentURL": res.workflowInstanceDataFields.ViewerRequest, "Remetente": res.workflowInstanceDataFields.Sender, "Note": res.workflowInstanceDataFields.TaskMessage || res.workflowInstanceDataFields.Note, @@ -111,32 +105,36 @@ export class DespachoPrPage implements OnInit { console.log(this.task); console.log('GetTask', res); + this.sqliteservice.updateProcess(res) let thedate = new Date(this.task.CreateDate); - this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); - this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users=>{ - this.intervenientes = users.filter(user=>{ + this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users => { + this.sqliteservice.updateProcessInterveners(JSON.stringify(this.serialNumber), JSON.stringify(users)).then(() => { + console.log('internen despacho pr ') + }) + this.intervenientes = users.filter(user => { return user.Type == 'I'; }); - this.cc = users.filter(user=>{ + this.cc = users.filter(user => { return user.Type == 'CC'; }) || [] - - if(!this.cc) { + + if (!this.cc) { this.cc = [] } }); - }, (error)=>{ + }, (error) => { try { this.goBack() } catch (e) { window.history.back(); } finally { - if(error.status == 0) { + if (error.status == 0) { this.toastService.badRequest('Não é possível visualizar este processo no modo offline') } else { this.toastService.badRequest('Processo não encontrado') @@ -145,11 +143,76 @@ export class DespachoPrPage implements OnInit { }); } - viewDocument(docId:string){ - this.processes.GetDocumentUrl(docId, '361').subscribe(res=>{ + getFromDB() { + if (synchro.connected === true) { + this.activateRoute.paramMap.subscribe(paramMap => { + if (!paramMap.has('SerialNumber')) { + return; + } + /* this.serialNumber = paramMap.get('SerialNumber'); */ + this.LoadTaskDetail(this.serialNumber); + // this.LoadRelatedEvents(this.serialNumber); + }); + this.LoadTaskDetail(this.serialNumber); + // this.LoadRelatedEvents(this.serialNumber); + + } else { + this.sqliteservice.getProcessById(this.serialNumber).then((process: any[]) => { + console.log('OFFLINE', process) + this.task = { + "SerialNumber": process[0].serialNumber, + "Folio": JSON.parse(process[0].workflowInstanceDataFields).Subject, + "Senders": JSON.parse(process[0].originator).email, + "CreateDate": momentG(new Date(process[0].taskStartDate), 'yyyy-MM-dd HH:mm:ss'), + "DocumentURL": JSON.parse(process[0].workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(process[0].workflowInstanceDataFields).Sender, + "Note": JSON.parse(process[0].workflowInstanceDataFields).TaskMessage || JSON.parse(process[0].workflowInstanceDataFields).Note, + "FolderId": JSON.parse(process[0].workflowInstanceDataFields).FolderID, + "FsId": '361', + "DocId": JSON.parse(process[0].workflowInstanceDataFields).DispatchDocId, + "WorkflowName": process[0].workflowDisplayName, + "DeadlineType": JSON.parse(process[0].workflowInstanceDataFields).DeadlineType, + "activityInstanceName": process[0].activityInstanceName, + } + console.log("OFFLINE TASK", this.task) + let fulltak = { + Documents: JSON.parse(process[0].Documents), + actions: JSON.parse(process[0].actions), + activityInstanceName: process[0].activityInstanceName, + formURL: process[0].formURL, + originator: JSON.parse(process[0].originator), + serialNumber: process[0].serialNumber, + taskStartDate: process[0].taskStartDate, + totalDocuments: process[0].totalDocuments, + workflowDisplayName: process[0].workflowDisplayName, + workflowID: process[0].workflowID, + workflowInstanceDataFields: JSON.parse(process[0].workflowInstanceDataFields), + workflowInstanceFolio: process[0].workflowInstanceFolio, + workflowInstanceID: process[0].workflowInstanceID, + workflowName: process[0].workflowName + } + this.fulltask = fulltak; + console.log(this.task); + + let thedate = new Date(this.task.CreateDate); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); + + this.intervenientes = JSON.parse(process[0].interveners).filter(user => { + return user.Type == 'I'; + }); + this.cc = JSON.parse(process[0].interveners).filter(user => { + return user.Type == 'CC'; + }); + + }) + } + } + + viewDocument(docId: string) { + this.processes.GetDocumentUrl(docId, '361').subscribe(res => { console.log(res); - const url: string = res.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1"); - const browser = this.iab.create(url,"_blank"); + const url: string = res.replace("webTRIX.Viewer", "webTRIX.Viewer.Branch1"); + const browser = this.iab.create(url, "_blank"); browser.show(); }); } @@ -159,7 +222,7 @@ export class DespachoPrPage implements OnInit { this.modalController.dismiss(); } - async executado(note:string, documents:any) { + async executado(note: string, documents: any) { let body = { "serialNumber": this.serialNumber, "action": "Conhecimento", @@ -167,7 +230,7 @@ export class DespachoPrPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -176,7 +239,7 @@ export class DespachoPrPage implements OnInit { await this.processes.CompleteTask(body).toPromise() this.close(); this.toastService.successMessage() - } catch(error) { + } catch (error) { this.toastService.badRequest() } finally { @@ -185,7 +248,7 @@ export class DespachoPrPage implements OnInit { } - async arquivar(note:string, documents:any){ + async arquivar(note: string, documents: any) { let body = { "serialNumber": this.serialNumber, "action": "Arquivo", @@ -193,7 +256,7 @@ export class DespachoPrPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -212,7 +275,7 @@ export class DespachoPrPage implements OnInit { } - async generateDiploma(note:string, documents:any){ + async generateDiploma(note: string, documents: any) { const loader = this.toastService.loading() @@ -234,7 +297,7 @@ export class DespachoPrPage implements OnInit { } - async concluir(note:string, documents:any){ + async concluir(note: string, documents: any) { let body = { "serialNumber": this.serialNumber, "action": "Executado", @@ -242,7 +305,7 @@ export class DespachoPrPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -261,7 +324,7 @@ export class DespachoPrPage implements OnInit { } - async reexecutar(note:string, documents:any) { + async reexecutar(note: string, documents: any) { let body = { "serialNumber": this.serialNumber, "action": "Reexecutar", @@ -269,7 +332,7 @@ export class DespachoPrPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -291,27 +354,27 @@ export class DespachoPrPage implements OnInit { return new Date(e).toDateString() } - sendExpedienteToPending(){ - this.processes.SetTaskToPending(this.serialNumber).subscribe(res=>{ + sendExpedienteToPending() { + this.processes.SetTaskToPending(this.serialNumber).subscribe(res => { this.popoverController.dismiss('close') this.toastService.successMessage('Processo enviado para pendentes') this.goBack() - },()=>{ + }, () => { this.toastService.badRequest('Processo não encontrado') }); } - async openAddNoteModal(actionName:string) { + async openAddNoteModal(actionName: string) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'add-note-modal-no-height' } const modal = await this.modalController.create({ component: AddNotePage, - componentProps:{ + componentProps: { showAttachmentBtn: true, }, cssClass: classs, @@ -320,9 +383,9 @@ export class DespachoPrPage implements OnInit { await modal.present(); - modal.onDidDismiss().then( async (res) => { + modal.onDidDismiss().then(async (res) => { console.log(res); - if(res.data) { + if (res.data) { const DocumentToSave = res.data.documents.map((e) => { return { @@ -336,19 +399,19 @@ export class DespachoPrPage implements OnInit { Attachments: DocumentToSave, } - if(actionName == 'Executado'){ + if (actionName == 'Executado') { await this.executado(res.data.note, docs); } - else if(actionName == 'Arquivar'){ + else if (actionName == 'Arquivar') { await this.arquivar(res.data.note, docs); } - else if(actionName == 'Gerar Diploma'){ + else if (actionName == 'Gerar Diploma') { await this.generateDiploma(res.data.note, docs); } - else if(actionName == 'Concluido'){ + else if (actionName == 'Concluido') { await this.concluir(res.data.note, docs); } - else if(actionName == 'Reexecução'){ + else if (actionName == 'Reexecução') { await this.reexecutar(res.data.note, docs); } this.goBack(); @@ -359,9 +422,9 @@ export class DespachoPrPage implements OnInit { async openExpedientActionsModal(taskAction: any, task: any) { //this.modalController.dismiss(); let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -375,9 +438,9 @@ export class DespachoPrPage implements OnInit { cssClass: classs, }); await modal.present(); - modal.onDidDismiss().then(res=>{ + modal.onDidDismiss().then(res => { console.log(res['data']); - if(res['data']=='openDiscart'){ + if (res['data'] == 'openDiscart') { console.log('open discart'); this.distartExpedientModal(); } @@ -387,10 +450,10 @@ export class DespachoPrPage implements OnInit { }); } - async distartExpedientModal2(task: any){ + async distartExpedientModal2(task: any) { const modal = await this.modalController.create({ component: DiscartExpedientModalPage, - componentProps: { + componentProps: { serialNumber: task.serialNumber, folderId: task.workflowInstanceDataFields.FolderID, action: 'discart', @@ -405,9 +468,9 @@ export class DespachoPrPage implements OnInit { async openBookMeetingModal(task: any) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -424,9 +487,9 @@ export class DespachoPrPage implements OnInit { async openDelegarModal(task: any) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -441,11 +504,11 @@ export class DespachoPrPage implements OnInit { modal.onDidDismiss(); } - async distartExpedientModal(){ + async distartExpedientModal() { console.log(this.fulltask); const modal = await this.modalController.create({ component: DiscartExpedientModalPage, - componentProps: { + componentProps: { serialNumber: this.fulltask.serialNumber, folderId: this.fulltask.workflowInstanceDataFields.FolderID, action: 'complete', @@ -455,8 +518,8 @@ export class DespachoPrPage implements OnInit { }); await modal.present(); - modal.onDidDismiss().then(res=>{ - if(res['data']=='close'){ + modal.onDidDismiss().then(res => { + if (res['data'] == 'close') { this.close(); /* console.log('2Expedient Discard closed2'); this.close(); @@ -472,7 +535,7 @@ export class DespachoPrPage implements OnInit { componentProps: { task: this.task, fulltask: this.fulltask, - taskAction:taskAction, + taskAction: taskAction, showEnviarPendentes: false }, translucent: true @@ -480,11 +543,11 @@ export class DespachoPrPage implements OnInit { await popover.present(); - popover.onDidDismiss().then(( res =>{ + popover.onDidDismiss().then((res => { + + if (res['data'] == 'close') { + this.goBack() - if( res['data'] == 'close') { - this.goBack() - } })) diff --git a/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.html b/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.html index 92787fa63..5a4a59a3c 100644 --- a/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.html +++ b/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.html @@ -33,7 +33,7 @@
@@ -67,13 +67,13 @@
Lista vazia
-
+
diff --git a/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.ts b/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.ts index 407083190..3cc3e9896 100644 --- a/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.ts +++ b/src/app/pages/gabinete-digital/despachos-pr/despachos-pr.page.ts @@ -17,6 +17,9 @@ import { NavigationEnd, NavigationExtras, NavigationStart, Router } from '@angul import { __awaiter } from 'tslib'; import { DespachosprStore } from 'src/app/store/despachospr-store.service'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; + @Component({ selector: 'app-despachos-pr', templateUrl: './despachos-pr.page.html', @@ -26,61 +29,48 @@ export class DespachosPrPage implements OnInit { @ViewChild(CalendarComponent) myCal: CalendarComponent; - taskslist:DailyWorkTask[] = []; - despachoList:any[] = []; - deferimentoList:DailyWorkTask[] = []; + taskslist: DailyWorkTask[] = []; + despachoList: any[] = []; + deferimentoList: DailyWorkTask[] = []; taskList: customTask[] = []; taskType: string; - serialNumber:string; - totalDocs:any; + serialNumber: string; + totalDocs: any; - profile:string; - segment:string; + profile: string; + segment: string; // @Output() openExpedientDetail:EventEmitter = new EventEmitter(); - loadedAttachments:any; + loadedAttachments: any; dicIndex = 0; inicial = false loggeduser: LoginUserRespose; skeletonLoader = true despachoprstore = DespachosprStore + listToPresent = []; - constructor ( - private processes:ProcessesService, + constructor( + private processes: ProcessesService, private modalController: ModalController, private alertService: AlertService, private authService: AuthService, private router: Router, - ) { + private sqliteservice: SqliteService + ) { - this.loggeduser = authService.ValidatedUser; - this.profile = 'mdgpr'; + this.loggeduser = authService.ValidatedUser; + this.profile = 'mdgpr'; - } + } ngOnInit() { //Inicializar segment this.segment = "despachos"; - - const location = window.location - const pathname = location.pathname + location.search - - this.LoadList() - - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith(pathname)) { - if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.doRefresh() - } else { - this.LoadList() - } - } - }); - + this.getFromDB(); } segmentChanged(ev: any) { @@ -88,15 +78,15 @@ export class DespachosPrPage implements OnInit { this.LoadList(); } - goToDespachoPr(serialNumber:any){ - this.router.navigate(['/home/gabinete-digital/despachos-pr',serialNumber,'gabinete-digital']); + goToDespachoPr(serialNumber: any) { + this.router.navigate(['/home/gabinete-digital/despachos-pr', serialNumber, 'gabinete-digital']); } - notImplemented(){ + notImplemented() { this.alertService.presentAlert('Funcionalidade em desenvolvimento'); } - openExpedientDetailPage(data){ + openExpedientDetailPage(data) { console.log(data); } @@ -124,59 +114,123 @@ export class DespachosPrPage implements OnInit { console.log(despachosPr); despachosPr = despachosPr.filter(data => data.workflowInstanceDataFields.Status == "Active"); - despachosPr.forEach( (element, index) => { + despachosPr.forEach((element, index) => { let date = new Date(element.taskStartDate); - date.setMonth(date.getMonth() + 1); - let taskDate = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); - let task = { - "SerialNumber": element.serialNumber, - "Folio": element.workflowInstanceDataFields.Subject, - "Senders": element.workflowInstanceDataFields.Sender, - "CreateDate": taskDate, - "DocumentURL": element.workflowInstanceDataFields.ViewerRequest, - "Remetente": element.workflowInstanceDataFields.Remetente, - "DocumentsQty": element.totalDocuments, - "DocId": element.workflowInstanceDataFields.DocIdDiferimento, - "WorkflowName": element.workflowDisplayName, - "activityInstanceName": element.activityInstanceName, - } + let task = { + "SerialNumber": element.serialNumber, + "Folio": element.workflowInstanceDataFields.Subject, + "Senders": element.workflowInstanceDataFields.Sender, + "CreateDate": taskDate, + "DocumentURL": element.workflowInstanceDataFields.ViewerRequest, + "Remetente": element.workflowInstanceDataFields.Remetente, + "DocumentsQty": element.totalDocuments, + "DocId": element.workflowInstanceDataFields.DocIdDiferimento, + "WorkflowName": element.workflowDisplayName, + "activityInstanceName": element.activityInstanceName, + } this.despachoList.push(task); console.log(this.despachoList); }); - this.despachoprstore.reset(this.despachoList); + this.listToPresent = this.despachoList - } + } - sortArrayISODate(myArray: any) { - return myArray.sort(function(a, b) { - return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0); + getFromDB() { + if (synchro.connected === true) { + const location = window.location + const pathname = location.pathname + location.search + + this.LoadList() + + this.router.events.forEach((event) => { + if (event instanceof NavigationStart && event.url.startsWith(pathname)) { + if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.doRefresh() + } else { + this.LoadList() + } + } }); + } else { + this.sqliteservice.getAllProcess().then((all) => { + console.log('DESPACHO PR ALL', all) + }) + this.sqliteservice.getprocessByworkflow('Despacho do Presidente da República').then(async (process: any[]) => { + console.log('DESPACHO PR', process) + + let despachosPr; + switch (this.loggeduser.Profile) { + case 'MDGPR': + despachosPr = await process.reverse().filter(data => data.activityInstanceName == "Tarefa de Despacho"); + break; + case 'PR': + console.log(process); + + despachosPr = await process.reverse().filter(data => data.activityInstanceName == "Concluir Despacho"); + break; + } + + despachosPr = despachosPr.filter(data => JSON.parse(data.workflowInstanceDataFields).Status == "Active"); + despachosPr.forEach((element, index) => { + + let date = new Date(element.taskStartDate); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); + + let task = { + "SerialNumber": element.serialNumber, + "Folio": JSON.parse(element.workflowInstanceDataFields).Subject, + "Senders": JSON.parse(element.workflowInstanceDataFields).Sender, + "CreateDate": taskDate, + "DocumentURL": JSON.parse(element.workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(element.workflowInstanceDataFields).Remetente, + "DocumentsQty": element.totalDocuments, + "DocId": JSON.parse(element.workflowInstanceDataFields).DocIdDiferimento, + "WorkflowName": element.workflowDisplayName, + "activityInstanceName": element.activityInstanceName, + } + + this.despachoList.push(task); + console.log(this.despachoList); + }); + this.listToPresent = this.despachoList; + + }) } + } + + sortArrayISODate(myArray: any) { + return myArray.sort(function (a, b) { + return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0); + }); + } doRefresh() { - setTimeout(()=>{ + setTimeout(() => { this.LoadList(); }, 1000) } - async viewExpedientDetail(serialNumber:any) { + async viewExpedientDetail(serialNumber: any) { console.log(this.profile); let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop' } const modal = await this.modalController.create({ component: DespachoPage, - componentProps:{ + componentProps: { enterAnimation: "", serialNumber: serialNumber, profile: this.profile, @@ -184,7 +238,7 @@ export class DespachosPrPage implements OnInit { cssClass: classs, }); await modal.present(); - modal.onDidDismiss().then((res)=>{ + modal.onDidDismiss().then((res) => { console.log('refresh list'); this.LoadList(); }); @@ -193,7 +247,7 @@ export class DespachosPrPage implements OnInit { async openBookMeetingModal(task: customFullTask) { - const doc = this.loadedAttachments[ this.dicIndex]; + const doc = this.loadedAttachments[this.dicIndex]; task = { serialNumber: doc.SourceId, @@ -208,9 +262,9 @@ export class DespachosPrPage implements OnInit { } let classs; - if( window.innerWidth <= 800) { + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ diff --git a/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.html b/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.html index 8d26f9959..ca763aa67 100644 --- a/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.html +++ b/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.html @@ -33,8 +33,8 @@
Intervenientes
-
-

{{interveniente.Name}}

+
+

{{task.Name}}

diff --git a/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.ts b/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.ts index 262b21dc0..bb54edda6 100644 --- a/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.ts +++ b/src/app/pages/gabinete-digital/despachos/despacho/despacho.page.ts @@ -4,7 +4,7 @@ import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'; import { ActivatedRoute } from '@angular/router'; import { Event } from '../../../../models/event.model'; import { MenuController, ModalController, PopoverController } from '@ionic/angular'; -import { momentG } from 'src/plugin/momentG' +import { momentG } from 'src/plugin/momentG' import { DiscartExpedientModalPage } from '../../discart-expedient-modal/discart-expedient-modal.page'; import { BookMeetingModalPage } from '../../expediente/book-meeting-modal/book-meeting-modal.page'; import { CreateProcessPage } from 'src/app/modals/create-process/create-process.page'; @@ -18,6 +18,10 @@ import { fullTask } from 'src/app/models/dailyworktask.model'; import { Attachment, AttachmentList } from 'src/app/models/Excludetask'; import { PermissionService } from 'src/app/OtherService/permission.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { Platform } from '@ionic/angular'; + @Component({ selector: 'app-despacho', templateUrl: './despacho.page.html', @@ -27,20 +31,22 @@ export class DespachoPage implements OnInit { months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"]; - customDate:any; + customDate: any; // task: customTask; task; - attachments:any; + attachments: any; fulltask: any; eventsList: Event[] = []; serialnumber: string; - caller:string; + caller: string; profile: string; intervenientes: any; cc: any = []; + synch = synchro; + constructor(private activateRoute: ActivatedRoute, private processes: ProcessesService, private iab: InAppBrowser, @@ -52,14 +58,16 @@ export class DespachoPage implements OnInit { private despachoService: DespachoService, private location: Location, public p: PermissionService, + private sqliteservice: SqliteService, + private platform: Platform - ) { + ) { this.activatedRoute.paramMap.subscribe(params => { - if(params["params"].SerialNumber) { + if (params["params"].SerialNumber) { this.serialnumber = params["params"].SerialNumber; } - if(params["params"].caller) { + if (params["params"].caller) { this.caller = params["params"].caller; } }); @@ -72,8 +80,8 @@ export class DespachoPage implements OnInit { return; } }); + this.getFromDb() - this.LoadTaskDetail(this.serialnumber) } close() { @@ -113,12 +121,13 @@ export class DespachoPage implements OnInit { } async LoadTaskDetail(serial: string) { - this.processes.GetTask(serial).subscribe( (res: fullTask) => { + this.processes.GetTask(serial).subscribe((res: fullTask) => { + console.log('despacho detail', res) this.task = { "SerialNumber": res.serialNumber, "Folio": res.workflowInstanceDataFields.Subject, "Senders": res.originator.email, - "CreateDate": momentG(new Date(res.taskStartDate),'yyyy-MM-dd HH:mm:ss'), + "CreateDate": momentG(new Date(res.taskStartDate), 'yyyy-MM-dd HH:mm:ss'), "DocumentURL": res.workflowInstanceDataFields.ViewerRequest, "Remetente": res.workflowInstanceDataFields.Sender, "Note": res.workflowInstanceDataFields.TaskMessage || res.workflowInstanceDataFields.Note, @@ -131,27 +140,33 @@ export class DespachoPage implements OnInit { "activityInstanceName": res.activityInstanceName, "Status": res.workflowInstanceDataFields.Status, } + + this.sqliteservice.updateProcess(res); this.fulltask = res; let thedate = new Date(this.task.CreateDate); - this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); - this.processes.GetTaskParticipants(this.task.FolderID).subscribe(users=>{ + this.processes.GetTaskParticipants(this.task.FolderID).subscribe(users => { + this.sqliteservice.updateProcessInterveners(JSON.stringify(this.serialnumber), JSON.stringify(users)) + console.log('interveniers online', users) - this.intervenientes = users.filter(user=>{ + this.intervenientes = users.filter(user => { + console.log('interveniers online 2', users) return user.Type == 'I'; }); - this.cc = users.filter(user=>{ + this.cc = users.filter(user => { + console.log('interveniers online 3', users) return user.Type == 'CC'; }); }); - }, (error)=>{ + }, (error) => { try { this.goBack() } catch (e) { this.location.back(); } finally { - if(error.status == 0) { + if (error.status == 0) { this.toastService.badRequest('Não é possível visualizar este processo no modo offline') } else { this.toastService.badRequest('Processo não encontrado') @@ -160,10 +175,84 @@ export class DespachoPage implements OnInit { }); } - viewDocument(docId:string){ - this.processes.GetDocumentUrl(docId, '361').subscribe(res=>{ - const url: string = res.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1"); - const browser = this.iab.create(url,"_blank"); + getFromDb() { + if (synchro.connected === true) { + this.LoadTaskDetail(this.serialnumber) + } + + if (synchro.connected === false) { + this.platform.ready().then(() => { + this.sqliteservice.getProcessById(this.serialnumber).then((process) => { + + var workflow = JSON.parse(process[0].workflowInstanceDataFields); + var intervine = JSON.parse(process[0].interveners) + var origina + if (process[0].originator === "undefined") { + origina = "" + } else { + origina = JSON.parse(process[0].originator) + } + + console.log('sqlite', process) + + this.task = { + "SerialNumber": process[0].serialNumber, + "Folio": workflow.Subject, + "Senders": origina.email || process[0].originator, + "CreateDate": momentG(new Date(process[0].taskStartDate), 'yyyy-MM-dd HH:mm:ss'), + "DocumentURL": workflow.ViewerRequest, + "Remetente": workflow.Sender, + "Note": workflow.TaskMessage || workflow.Note, + "FolderId": workflow.FolderID, + "FsId": workflow.FsId, + "DocId": workflow.DocID, + "DocumentsQty": process[0].DocumentsQty, + "WorkflowName": process[0].workflowDisplayName, + "DeadlineType": workflow.DeadlineType, + "activityInstanceName": process[0].activityInstanceName, + "Status": workflow.Status, + } + + let thedate = new Date(this.task.CreateDate); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); + + let fulltak = { + Documents: JSON.parse(process[0].Documents), + actions: JSON.parse(process[0].actions), + activityInstanceName: process[0].activityInstanceName, + formURL: process[0].formURL, + originator: JSON.parse(process[0].originator), + serialNumber: process[0].serialNumber, + taskStartDate: process[0].taskStartDate, + totalDocuments: process[0].totalDocuments, + workflowDisplayName: process[0].workflowDisplayName, + workflowID: process[0].workflowID, + workflowInstanceDataFields: JSON.parse(process[0].workflowInstanceDataFields), + workflowInstanceFolio: process[0].workflowInstanceFolio, + workflowInstanceID: process[0].workflowInstanceID, + workflowName: process[0].workflowName + } + this.fulltask = fulltak; + + console.log('interveniers offline', intervine) + this.intervenientes = intervine.filter(user => { + console.log('interveniers offline 2', user) + return user.Type == 'I'; + }); + this.cc = intervine.filter(user => { + console.log('interveniers offline 3', user) + return user.Type == 'CC'; + }); + + }) + }) + } + } + + viewDocument(docId: string) { + this.processes.GetDocumentUrl(docId, '361').subscribe(res => { + const url: string = res.replace("webTRIX.Viewer", "webTRIX.Viewer.Branch1"); + const browser = this.iab.create(url, "_blank"); browser.show(); }); } @@ -173,7 +262,7 @@ export class DespachoPage implements OnInit { this.modalController.dismiss(); } - async executado(note:string, documents:any) { + async executado(note: string, documents: any) { const loader = this.toastService.loading() @@ -181,7 +270,7 @@ export class DespachoPage implements OnInit { await this.despachoService.executado(note, documents, this.serialnumber).toPromise(); this.toastService.successMessage('Processo criado') this.close(); - } catch(error) { + } catch (error) { this.toastService.badRequest("Processo não criado") } finally { @@ -189,12 +278,12 @@ export class DespachoPage implements OnInit { } } - async arquivar(note:string, documents: AttachmentList) { + async arquivar(note: string, documents: AttachmentList) { const loader = this.toastService.loading() try { - await this.despachoService.arquivar(note, documents,this.serialnumber).toPromise() + await this.despachoService.arquivar(note, documents, this.serialnumber).toPromise() this.toastService.successMessage('Processo descartado') this.close(); } catch (error) { @@ -206,7 +295,7 @@ export class DespachoPage implements OnInit { } - async reexecute(note:string, documents:any) { + async reexecute(note: string, documents: any) { let body = { "serialNumber": this.serialnumber, "action": "Reexecução", @@ -214,7 +303,7 @@ export class DespachoPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -239,26 +328,26 @@ export class DespachoPage implements OnInit { async sendExpedienteToPending() { - this.despachoService.sendExpedienteToPending(this.serialnumber).subscribe(res=>{ + this.despachoService.sendExpedienteToPending(this.serialnumber).subscribe(res => { this.goBack(); this.toastService.successMessage() }, - error => { - this.toastService.badRequest("Processo não enviado para despacho") - }); + error => { + this.toastService.badRequest("Processo não enviado para despacho") + }); } - async openAddNoteModal(actionName:string) { + async openAddNoteModal(actionName: string) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'add-note-modal-no-height' } const modal = await this.modalController.create({ component: AddNotePage, - componentProps:{ + componentProps: { showAttachmentBtn: true, }, cssClass: classs, @@ -267,8 +356,8 @@ export class DespachoPage implements OnInit { await modal.present(); - modal.onDidDismiss().then( async (res) => { - if(res.data){ + modal.onDidDismiss().then(async (res) => { + if (res.data) { const DocumentToSave = res.data.documents.map((e) => { return { @@ -282,16 +371,16 @@ export class DespachoPage implements OnInit { Attachments: DocumentToSave, } - if(actionName == 'Executado'){ + if (actionName == 'Executado') { await this.executado(res.data.note, docs); this.goBack(); } - else if(actionName == 'Arquivar'){ + else if (actionName == 'Arquivar') { await this.arquivar(res.data.note, docs); this.goBack(); } - else if(actionName == 'Reexecução'){ + else if (actionName == 'Reexecução') { await this.reexecute(res.data.note, docs); this.goBack(); } @@ -302,9 +391,9 @@ export class DespachoPage implements OnInit { async openExpedientActionsModal(taskAction: any, task: any) { let classs; - if( window.innerWidth <= 800) { + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -318,10 +407,10 @@ export class DespachoPage implements OnInit { cssClass: classs, }); await modal.present(); - modal.onDidDismiss().then( async (res)=>{ + modal.onDidDismiss().then(async (res) => { console.log(res['data']); - if(res['data']=='openDiscart'){ + if (res['data'] == 'openDiscart') { await this.distartExpedientModal(); } @@ -331,9 +420,9 @@ export class DespachoPage implements OnInit { async openBookMeetingModal(task: any) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -350,9 +439,9 @@ export class DespachoPage implements OnInit { async openDelegarModal(task: any) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -364,7 +453,7 @@ export class DespachoPage implements OnInit { backdropDismiss: false }); await modal.present(); - modal.onDidDismiss().then(res=>{ + modal.onDidDismiss().then(res => { this.goBack(); }); } @@ -373,7 +462,7 @@ export class DespachoPage implements OnInit { console.log(this.fulltask); const modal = await this.modalController.create({ component: DiscartExpedientModalPage, - componentProps: { + componentProps: { serialNumber: this.fulltask.serialNumber, folderId: this.fulltask.workflowInstanceDataFields.FolderID, action: 'complete', @@ -383,8 +472,8 @@ export class DespachoPage implements OnInit { }); await modal.present(); - modal.onDidDismiss().then(res=>{ - if(res['data']=='close'){ + modal.onDidDismiss().then(res => { + if (res['data'] == 'close') { this.close(); /* console.log('2Expedient Discard closed2'); this.close(); diff --git a/src/app/pages/gabinete-digital/despachos/despachos.page.html b/src/app/pages/gabinete-digital/despachos/despachos.page.html index a6f23f08b..59b84271b 100644 --- a/src/app/pages/gabinete-digital/despachos/despachos.page.html +++ b/src/app/pages/gabinete-digital/despachos/despachos.page.html @@ -33,7 +33,7 @@
@@ -68,13 +68,13 @@
Lista vazia
-
+
diff --git a/src/app/pages/gabinete-digital/despachos/despachos.page.ts b/src/app/pages/gabinete-digital/despachos/despachos.page.ts index a2996b91e..f8e1e4b60 100644 --- a/src/app/pages/gabinete-digital/despachos/despachos.page.ts +++ b/src/app/pages/gabinete-digital/despachos/despachos.page.ts @@ -3,6 +3,11 @@ import { NavigationStart, Router } from '@angular/router'; import { DespachoService } from 'src/app/Rules/despacho.service'; import { DespachoStore } from 'src/app/store/despacho-store.service'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; +import { Platform } from '@ionic/angular'; +import { isThisHour } from 'date-fns'; + @Component({ selector: 'app-despachos', templateUrl: './despachos.page.html', @@ -12,31 +17,21 @@ import { DespachoStore } from 'src/app/store/despacho-store.service'; export class DespachosPage implements OnInit { despachoStore = DespachoStore; + synch = synchro; + listToPresent = []; - constructor ( + constructor( private router: Router, - private despachoRule: DespachoService + private despachoRule: DespachoService, + private sqliteservice: SqliteService, + private platform: Platform ) { - - } + + } ngOnInit() { - const location = window.location - const pathname = location.pathname + location.search - - this.LoadList() - - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith(pathname)) { - if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing() - } else { - this.LoadList() - } - } - }); - + this.getFromDb() } async refreshing() { @@ -51,7 +46,60 @@ export class DespachosPage implements OnInit { async LoadList() { - await this.despachoRule.getList({updateStore: true}) + await this.despachoRule.getList({ updateStore: true }).then((pre) => { + this.listToPresent = pre; + console.log('despachooo', pre) + }) + + } + + getFromDb() { + if (synchro.connected === true) { + const location = window.location + const pathname = location.pathname + location.search + + this.LoadList() + + this.router.events.forEach((event) => { + if (event instanceof NavigationStart && event.url.startsWith(pathname)) { + if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing() + } else { + this.LoadList() + } + } + }); + } + + if (synchro.connected === false) { + this.platform.ready().then(() => { + this.sqliteservice.getDespachosProcess('Tarefa de Despacho').then((process: any[]) => { + var listtopresent = []; + process.forEach(element => { + var workflow = JSON.parse(element.workflowInstanceDataFields); + let task = { + "CreateDate": element.taskStartDate, + "DocId": workflow.DispatchDocID, + "DocumentURL": undefined, + "DocumentsQty": element.totalDocuments, + "FolderID": workflow.FolderID, + "Folio": workflow.Subject, + "Remetente": undefined, + "Senders": workflow.Sender, + "SerialNumber": element.serialNumber, + "Status": workflow.Status, + "WorkflowName": element.workflowDisplayName + } + + listtopresent.push(task); + + }); + + this.listToPresent = listtopresent; + + }) + }) + } } get skeletonLoader(): boolean { @@ -66,9 +114,8 @@ export class DespachosPage implements OnInit { }, 2000); } - async GoToDespacho(serialNumber:any) { - console.log('Despachos serial',serialNumber) - this.router.navigate(['/home/gabinete-digital/despachos',serialNumber,'gabinete-digital']); + async GoToDespacho(serialNumber: any) { + this.router.navigate(['/home/gabinete-digital/despachos', serialNumber, 'gabinete-digital']); } diff --git a/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts b/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts index 1f8dd62fa..66a905ff1 100644 --- a/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts +++ b/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts @@ -12,6 +12,9 @@ import { DeplomaOptionsPage } from 'src/app/shared/popover/deploma-options/deplo import { ToastService } from 'src/app/services/toast.service'; import { Location } from '@angular/common'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; + @Component({ selector: 'app-diploma', templateUrl: './diploma.page.html', @@ -42,6 +45,7 @@ export class DiplomaPage implements OnInit { private animationController: AnimationController, private toastService: ToastService, private location: Location, + private sqliteservice: SqliteService ) { this.activatedRoute.paramMap.subscribe(params => { // console.log(params["params"]); @@ -59,7 +63,7 @@ export class DiplomaPage implements OnInit { ngOnInit() { this.profile = "mdgpr"; - this.LoadTaskDetail(this.serialNumber); + this.getFromDb(); } goBack() { @@ -125,11 +129,15 @@ export class DiplomaPage implements OnInit { "activityInstanceName": res.activityInstanceName, } this.fulltask = res; + this.sqliteservice.updateProcess(res) let thedate = new Date(this.task.CreateDate); this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]); this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users=>{ + this.sqliteservice.updateProcessInterveners(JSON.stringify(this.serialNumber), JSON.stringify(users)).then(() => { + console.log('internen diploma ') + }) this.intervenientes = users.filter(user=>{ return user.Type == 'I'; }); @@ -155,6 +163,62 @@ export class DiplomaPage implements OnInit { } + getFromDb() { + if(synchro.connected === true) { + this.LoadTaskDetail(this.serialNumber); + } else { + this.sqliteservice.getProcessById(this.serialNumber).then((process) => { + + this.task = { + "SerialNumber": process[0].serialNumber, + "Folio": JSON.parse(process[0].workflowInstanceDataFields).Subject, + "Senders": JSON.parse(process[0].originator).email, + "CreateDate": momentG(new Date(process[0].taskStartDate),'yyyy-MM-dd HH:mm:ss'), + "DocumentURL": JSON.parse(process[0].workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(process[0].workflowInstanceDataFields).Sender, + "Note": JSON.parse(process[0].workflowInstanceDataFields).TaskMessage || JSON.parse(process[0].workflowInstanceDataFields).Note, + "FolderId": JSON.parse(process[0].workflowInstanceDataFields).FolderID, + "FsId": '361', + "DocId": JSON.parse(process[0].workflowInstanceDataFields).DispatchDocId, + "WorkflowName": process[0].workflowDisplayName, + "DeadlineType": JSON.parse(process[0].workflowInstanceDataFields).DeadlineType, + "activityInstanceName": process[0].activityInstanceName, + } + + let fulltak = { + Documents: JSON.parse(process[0].Documents), + actions: JSON.parse(process[0].actions), + activityInstanceName: process[0].activityInstanceName, + formURL: process[0].formURL, + originator: JSON.parse(process[0].originator), + serialNumber: process[0].serialNumber, + taskStartDate: process[0].taskStartDate, + totalDocuments: process[0].totalDocuments, + workflowDisplayName: process[0].workflowDisplayName, + workflowID: process[0].workflowID, + workflowInstanceDataFields: JSON.parse(process[0].workflowInstanceDataFields), + workflowInstanceFolio: process[0].workflowInstanceFolio, + workflowInstanceID: process[0].workflowInstanceID, + workflowName: process[0].workflowName + } + this.fulltask = fulltak + + let thedate = new Date(this.task.CreateDate); + this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]); + + this.intervenientes = JSON.parse(process[0].interveners).filter(user=>{ + return user.Type == 'I'; + }); + this.cc = JSON.parse(process[0].interveners).filter(user=>{ + return user.Type == 'CC'; + }); + + this.attachments = JSON.parse(process[0].Documents) + + }) + } + } + viewDocument(docId:string){ this.processes.GetDocumentUrl(docId, '361').subscribe(res=>{ const url: string = res.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1"); diff --git a/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts b/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts index 4a9c8e21f..4b712b6e0 100644 --- a/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts +++ b/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts @@ -3,34 +3,38 @@ import { ActivatedRoute, NavigationEnd, NavigationError, NavigationExtras, Navig import { DailyWorkTask } from '../../../models/dailyworktask.model'; import { ProcessesService } from 'src/app/services/processes.service'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; + @Component({ selector: 'app-diplomas', templateUrl: './diplomas.page.html', styleUrls: ['./diplomas.page.scss'], }) export class DiplomasPage implements OnInit, OnDestroy { - list:DailyWorkTask[] = []; - diplomasList:DailyWorkTask[] = []; - diplomasAssinadoList:DailyWorkTask[] = []; + list: DailyWorkTask[] = []; + diplomasList: DailyWorkTask[] = []; + diplomasAssinadoList: DailyWorkTask[] = []; showLoader: boolean; - totalDocs:any; - serialNumber:string; + totalDocs: any; + serialNumber: string; - segment:string; + segment: string; skeletonLoader = true constructor( - private processes:ProcessesService, + private processes: ProcessesService, private router: Router, private activatedRoute: ActivatedRoute, + private sqliteservice: SqliteService ) { this.diplomasList = []; //Inicializar segment this.segment = 'validar'; this.activatedRoute.queryParams.subscribe(params => { - if(params['validar'] == 'true') { + if (params['validar'] == 'true') { this.segment = 'validar'; } else if (params['assinados'] == 'true') { this.segment = 'assinados'; @@ -43,27 +47,14 @@ export class DiplomasPage implements OnInit, OnDestroy { //this.segment = 'validar'; this.activatedRoute.queryParams.subscribe(params => { - if(params['segment'] == 'validar') { + if (params['segment'] == 'validar') { this.segment = 'validar'; } else if (params['segment'] == 'assinados') { this.segment = 'assinados'; } }); - const location = window.location - const pathname = location.pathname + location.search - - this.LoadList() - - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith(pathname)) { - if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing() - } else { - this.LoadList() - } - } - }); + this.getFromDb() } @@ -141,7 +132,7 @@ export class DiplomasPage implements OnInit, OnDestroy { }); } */ - async getTotalDocs(DocId:any) { + async getTotalDocs(DocId: any) { let res = await this.processes.GetDocumentDetails(DocId, '361').toPromise(); console.log(res.DocumentsTotal); return res.DocumentsTotal; @@ -155,7 +146,7 @@ export class DiplomasPage implements OnInit, OnDestroy { this.LoadList(); } - goToDiploma(serialNumber:any) { + goToDiploma(serialNumber: any) { this.router.navigate(['/home/gabinete-digital/diplomas', serialNumber, 'gabinete-digital']); } @@ -192,11 +183,54 @@ export class DiplomasPage implements OnInit, OnDestroy { } + getFromDb() { + if (synchro.connected === true) { + const location = window.location + const pathname = location.pathname + location.search + + this.LoadList() + + this.router.events.forEach((event) => { + if (event instanceof NavigationStart && event.url.startsWith(pathname)) { + if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing() + } else { + this.LoadList() + } + } + }); + } else { + this.sqliteservice.getprocessByworkflow("Despacho do Presidente da República").then((process: any[]) => { + + let diplomasValidar = process.filter(data => data.activityInstanceName == "Revisar Diploma"); + let diplomasList = []; + diplomasValidar.forEach(async element => { + + let task = this.pipeTaskOffline(element) + diplomasList.push(task); + + }); + this.diplomasList = this.sortArrayISODate(diplomasList.reverse()); + + let diplomasAssinados = process.reverse().filter(data => data.activityInstanceName == "Diploma Assinado"); + let diplomasAssinadoList = [] + diplomasAssinados.forEach(async element => { + + let task = this.pipeTaskOffline(element) + diplomasAssinadoList.push(task); + }); + console.log('diplomasAssinados', diplomasAssinados) + this.diplomasAssinadoList = this.sortArrayISODate(diplomasAssinadoList).reverse(); + + }) + } + } + pipeTask(element) { let date = new Date(element.taskStartDate); date.setMonth(date.getMonth() + 1); - let taskDate = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); return { "SerialNumber": element.serialNumber, "Folio": element.workflowInstanceDataFields.Subject, @@ -212,8 +246,28 @@ export class DiplomasPage implements OnInit, OnDestroy { } } + pipeTaskOffline(element) { + let date = new Date(element.taskStartDate); + date.setMonth(date.getMonth() + 1); + + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); + return { + "SerialNumber": element.serialNumber, + "Folio": JSON.parse(element.workflowInstanceDataFields).Subject, + "Senders": JSON.parse(element.workflowInstanceDataFields).Sender, + "CreateDate": taskDate, + "DocumentURL": JSON.parse(element.workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(element.workflowInstanceDataFields).Remetente, + "DocumentsQty": element.totalDocuments, + "DocId": JSON.parse(element.workflowInstanceDataFields).DocIdDiferimento, + "WorkflowName": element.workflowDisplayName, + "activityInstanceName": element.activityInstanceName, + "Status": JSON.parse(element.workflowInstanceDataFields).Status, + } + } + sortArrayISODate(myArray: any) { - return myArray.sort(function(a, b) { + return myArray.sort(function (a, b) { return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0); }); } diff --git a/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts b/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts index 467f5c94b..e3ed260c1 100644 --- a/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts +++ b/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts @@ -79,7 +79,7 @@ export class ApproveEventPage implements OnInit { console.log(this.serialNumber); console.log(this.caller); this.getProcessFromDB(); - this.getTask(); + } goBack() { @@ -105,6 +105,10 @@ export class ApproveEventPage implements OnInit { getProcessFromDB() { + if (synchro.connected === true) { + this.getTask(); + } + synchro.registerCallback('Offline', () => { this.platform.ready().then(() => { diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.ts b/src/app/pages/gabinete-digital/event-list/event-list.page.ts index 0cddeb18c..a8e18ac30 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.ts +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.ts @@ -46,27 +46,10 @@ export class EventListPage implements OnInit { ) { } ngOnInit() { + this.segment = 'MDGPR'; - - const location = window.location - const pathname = location.pathname + location.search - this.getEventToAproveFromDB(); - - this.LoadToApproveEvents() - - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith(pathname)) { - if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing() - } else { - this.LoadToApproveEvents() - } - } - }); - - window.onresize = (event) => { // if not mobile remove all component if( window.innerWidth <= 800){ @@ -78,6 +61,23 @@ export class EventListPage implements OnInit { getEventToAproveFromDB() { + if( synchro.connected === true) { + const location = window.location + const pathname = location.pathname + location.search + + this.LoadToApproveEvents() + + this.router.events.forEach((event) => { + if (event instanceof NavigationStart && event.url.startsWith(pathname)) { + if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing() + } else { + this.LoadToApproveEvents() + } + } + }); + } + synchro.registerCallback('Offline', () => { this.platform.ready().then(() => { diff --git a/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts b/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts index c562d7666..438e00020 100644 --- a/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts +++ b/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts @@ -9,7 +9,7 @@ import { ModalController, PopoverController } from '@ionic/angular'; import { ExpedientTaskModalPage } from '../expedient-task-modal/expedient-task-modal.page'; import { BookMeetingModalPage } from '../book-meeting-modal/book-meeting-modal.page'; import { ViewEventPage } from 'src/app/pages/agenda/view-event/view-event.page'; -import { momentG } from 'src/plugin/momentG' +import { momentG } from 'src/plugin/momentG' import { DiscartExpedientModalPage } from '../../discart-expedient-modal/discart-expedient-modal.page'; import { OptsExpedientePage } from 'src/app/shared/popover/opts-expediente/opts-expediente.page'; import { ToastService } from 'src/app/services/toast.service'; @@ -37,18 +37,18 @@ export class ExpedienteDetailPage implements OnInit { months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"]; - customDate:any; + customDate: any; task: expedienteTask; fulltask: any; eventsList: Event[]; serialNumber: string; - caller:string; + caller: string; profile: string; intervenientes: any; cc: any = []; - documents:SearchList[] = []; - attachments:any; + documents: SearchList[] = []; + attachments: any; hideSendToPendentes = true searchDocumentPipe = new SearchDocumentPipe() @@ -75,10 +75,10 @@ export class ExpedienteDetailPage implements OnInit { private sqliteservice: SqliteService, ) { this.activatedRoute.paramMap.subscribe(params => { - if(params["params"].SerialNumber) { + if (params["params"].SerialNumber) { this.serialNumber = params["params"].SerialNumber; } - if(params["params"].caller) { + if (params["params"].caller) { this.caller = params["params"].caller; } }); @@ -86,9 +86,6 @@ export class ExpedienteDetailPage implements OnInit { ngOnInit() { this.getFromDB(); - if(this.onlinecheck) { - this.LoadTaskDetail(this.serialNumber); - } } @@ -102,53 +99,58 @@ export class ExpedienteDetailPage implements OnInit { getFromDB() { - synchro.registerCallback('Online', () => { - this.onlinecheck = true; - }) + if(synchro.connected === true) { + this.LoadTaskDetail(this.serialNumber); + } - synchro.registerCallback('Offline', () => { - this.platform.ready().then(() => { - this.onlinecheck = false; - this.sqliteservice.getProcessById(this.serialNumber).then((process) => { - console.log("expedient ditail", process) + synchro.registerCallback('Offline', () => { + this.platform.ready().then(() => { + this.onlinecheck = false; + this.sqliteservice.getProcessById(this.serialNumber).then((process) => { + console.log("expedient ditail", process) - var workflow = JSON.parse(process[0].workflowInstanceDataFields); - var origina = JSON.parse(process[0].originator) + var workflow = JSON.parse(process[0].workflowInstanceDataFields); + var origina + if (process[0].originator === "undefined") { + origina = "" + } else { + origina = JSON.parse(process[0].originator) + } - this.task = { - "SerialNumber": process[0].serialNumber, - "Folio": workflow.Subject, - "Senders": origina.email, - "CreateDate": momentG(new Date(process[0].taskStartDate),'yyyy-MM-dd HH:mm:ss'), - "DocumentURL": workflow.ViewerRequest, - "Remetente": workflow.Sender, - "Note": workflow.TaskMessage || workflow.Note, - "FolderId": workflow.FolderID, - "FsId": workflow.FsId, - "DocId": workflow.DocID, - "WorkflowName": process[0].workflowDisplayName, - "Status": workflow.Status, - "DispatchNumber": workflow.DispatchNumber, - "AttachmentsProcessLastInstanceID": workflow.AttachmentsProcessLastInstanceID, - "InstanceID": workflow.InstanceID - } + this.task = { + "SerialNumber": process[0].serialNumber, + "Folio": workflow.Subject, + "Senders": origina.email || process[0].originator, + "CreateDate": momentG(new Date(process[0].taskStartDate), 'yyyy-MM-dd HH:mm:ss'), + "DocumentURL": workflow.ViewerRequest, + "Remetente": workflow.Sender, + "Note": workflow.TaskMessage || workflow.Note, + "FolderId": workflow.FolderID, + "FsId": workflow.FsId, + "DocId": workflow.DocID, + "WorkflowName": process[0].workflowDisplayName, + "Status": workflow.Status, + "DispatchNumber": workflow.DispatchNumber, + "AttachmentsProcessLastInstanceID": workflow.AttachmentsProcessLastInstanceID, + "InstanceID": workflow.InstanceID + } + }) }) }) - }) } - async approve(note:string, documents:any) { + async approve(note: string, documents: any) { let body = { "serialNumber": this.serialNumber, "action": "Aprovar", - "ActionTypeId": 100000004 , + "ActionTypeId": 100000004, "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } console.log(body); @@ -159,15 +161,15 @@ export class ExpedienteDetailPage implements OnInit { await this.processes.CompleteTask(body).toPromise(); this.close(); this.toastService.successMessage('Processo aprovado') - } catch(error) { + } catch (error) { this.toastService.badRequest('Processo não aprovado') - } finally { + } finally { loader.remove() } } - async sendToReview(note:string, documents:any) { + async sendToReview(note: string, documents: any) { let body = { "serialNumber": this.serialNumber, "action": "Retificar", @@ -175,7 +177,7 @@ export class ExpedienteDetailPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -184,7 +186,7 @@ export class ExpedienteDetailPage implements OnInit { await this.processes.CompleteTask(body).toPromise() this.close(); this.toastService.successMessage() - } catch(error) { + } catch (error) { this.toastService.badRequest() } finally { loader.remove() @@ -192,16 +194,16 @@ export class ExpedienteDetailPage implements OnInit { } - async openAddNoteModal(actionName:string) { + async openAddNoteModal(actionName: string) { let classs; - if( window.innerWidth < 701) { + if (window.innerWidth < 701) { classs = 'modal modal-desktop' - } else { + } else { classs = 'add-note-modal' } const modal = await this.modalController.create({ component: AddNotePage, - componentProps:{ + componentProps: { showAttachmentBtn: false, }, cssClass: classs, @@ -212,7 +214,7 @@ export class ExpedienteDetailPage implements OnInit { modal.onDidDismiss().then(res => { console.log(res); - if(res.data){ + if (res.data) { const DocumentToSave = res.data.documents.map((e) => { return { ApplicationId: e.ApplicationType, @@ -225,10 +227,10 @@ export class ExpedienteDetailPage implements OnInit { Attachments: DocumentToSave, } - if(actionName == 'Aprovar'){ + if (actionName == 'Aprovar') { this.approve(res.data.note, docs); } - else if(actionName == 'Revisão'){ + else if (actionName == 'Revisão') { this.sendToReview(res.data.note, docs); } this.goBack(); @@ -278,14 +280,14 @@ export class ExpedienteDetailPage implements OnInit { } sendExpedienteToPending() { - this.processes.SetTaskToPending(this.serialNumber).subscribe(res=>{ + this.processes.SetTaskToPending(this.serialNumber).subscribe(res => { console.log(res); this.toastService.successMessage('Processo enviado para pendentes') this.goBack(); }, - (error)=>{ - this.toastService.badRequest('Processo não enviado para pendentes') - }); + (error) => { + this.toastService.badRequest('Processo não enviado para pendentes') + }); } async LoadTaskDetail(serial: string) { @@ -297,7 +299,7 @@ export class ExpedienteDetailPage implements OnInit { "SerialNumber": res.serialNumber, "Folio": res.workflowInstanceDataFields.Subject, "Senders": res.originator.email, - "CreateDate": momentG(new Date(res.taskStartDate),'yyyy-MM-dd HH:mm:ss'), + "CreateDate": momentG(new Date(res.taskStartDate), 'yyyy-MM-dd HH:mm:ss'), "DocumentURL": res.workflowInstanceDataFields.ViewerRequest, "Remetente": res.workflowInstanceDataFields.Sender, "Note": res.workflowInstanceDataFields.TaskMessage || res.workflowInstanceDataFields.Note, @@ -315,14 +317,14 @@ export class ExpedienteDetailPage implements OnInit { this.sqliteservice.updateProcess(res) let thedate = new Date(this.task.CreateDate); - this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); - this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users=>{ - this.intervenientes = users.filter(user=>{ + this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users => { + this.intervenientes = users.filter(user => { return user.Type == 'I'; }); - this.cc = users.filter(user=>{ + this.cc = users.filter(user => { return user.Type == 'CC'; }); }) @@ -330,14 +332,14 @@ export class ExpedienteDetailPage implements OnInit { console.log('this.task', this.task.InstanceID) console.log('this.task.DocumentURL', this.task.DocumentURL) - }, (error)=>{ + }, (error) => { try { this.toastService.badRequest('Processo não encontrado') this.goBack() } catch (e) { window.history.back(); } finally { - if(error.status == 0) { + if (error.status == 0) { this.toastService.badRequest('Não é possível visualizar este processo no modo offline') } else { this.toastService.badRequest('Processo não encontrado') @@ -353,15 +355,15 @@ export class ExpedienteDetailPage implements OnInit { } - viewDocument(DocId:string) { + viewDocument(DocId: string) { - this.expedienteService.viewDocument({ApplicationId:'361', DocId}) + this.expedienteService.viewDocument({ ApplicationId: '361', DocId }) } getAttachments(serialNumber) { console.log(serialNumber); - this.attachmentsService.getAttachmentsBySerial(serialNumber).subscribe(res=>{ + this.attachmentsService.getAttachmentsBySerial(serialNumber).subscribe(res => { this.attachments = res; console.log('res', res); }); @@ -382,45 +384,45 @@ export class ExpedienteDetailPage implements OnInit { } }); await modal.present(); - modal.onDidDismiss().then( async (res)=> { - if(res){ - const data = res.data; - this.documents.push(data.selected); - this.documents.forEach((element: any) => { + modal.onDidDismiss().then(async (res) => { + if (res) { + const data = res.data; + this.documents.push(data.selected); + this.documents.forEach((element: any) => { - let body = { - "InstanceID": this.task.InstanceID, - "WorkflowDisplayName": this.task.WorkflowName, - "FolderID": this.task.FolderId, - "DispatchNumber": this.task.DispatchNumber, - "AttachmentsProcessLastInstanceID": this.task.AttachmentsProcessLastInstanceID, - "Attachments": [] - } + let body = { + "InstanceID": this.task.InstanceID, + "WorkflowDisplayName": this.task.WorkflowName, + "FolderID": this.task.FolderId, + "DispatchNumber": this.task.DispatchNumber, + "AttachmentsProcessLastInstanceID": this.task.AttachmentsProcessLastInstanceID, + "Attachments": [] + } - const Attachments = this.searchDocumentPipe.transformToAttachment(element) - body.Attachments = Attachments; + const Attachments = this.searchDocumentPipe.transformToAttachment(element) + body.Attachments = Attachments; - const loader = this.toastService.loading() + const loader = this.toastService.loading() - this.attachmentsService.AddAttachment(body).subscribe((res)=> { - this.toastService.successMessage() - }, ()=> { - this.toastService.badRequest() - }, ()=> { - loader.remove() - }); + this.attachmentsService.AddAttachment(body).subscribe((res) => { + this.toastService.successMessage() + }, () => { + this.toastService.badRequest() + }, () => { + loader.remove() + }); }); - } + } }); } async openExpedientActionsModal(taskAction: any, task: any) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -433,9 +435,9 @@ export class ExpedienteDetailPage implements OnInit { cssClass: classs, }); await modal.present(); - modal.onDidDismiss().then( async(res)=>{ + modal.onDidDismiss().then(async (res) => { let body = res['data']; - if(res['data']) { + if (res['data']) { const loader = this.toastService.loading() try { await this.processes.CompleteTask(body).toPromise(); @@ -446,47 +448,47 @@ export class ExpedienteDetailPage implements OnInit { loader.remove() } } - else{ + else { this.close(); } }); } - async distartExpedientModal(body:any) { + async distartExpedientModal(body: any) { const modal = await this.modalController.create({ component: DiscartExpedientModalPage, - componentProps: { + componentProps: { }, cssClass: 'discart-expedient-modal', backdropDismiss: false }); await modal.present(); - modal.onDidDismiss().then( async (res)=>{ + modal.onDidDismiss().then(async (res) => { console.log(res['data']); - if(body == 'descartar') { - if(res['data']== 'Yes') { + if (body == 'descartar') { + if (res['data'] == 'Yes') { const loader = this.toastService.loading() try { - await this.expedienteService.discard({SerialNumber: this.task.SerialNumber}).toPromise() + await this.expedienteService.discard({ SerialNumber: this.task.SerialNumber }).toPromise() this.toastService.successMessage('Processo descartado'); this.goBack(); } catch (error) { this.toastService.badRequest('Processo não descartado') - } finally { + } finally { loader.remove() } } - else if(res['data'] == 'No'){ + else if (res['data'] == 'No') { //Do nothing } } - else{ - if(res['data']== 'Yes') { + else { + if (res['data'] == 'Yes') { const loader = this.toastService.loading() try { @@ -500,7 +502,7 @@ export class ExpedienteDetailPage implements OnInit { } } - else if(res['data'] == 'No') { + else if (res['data'] == 'No') { console.log('Update'); const loader = this.toastService.loading() try { @@ -509,7 +511,7 @@ export class ExpedienteDetailPage implements OnInit { this.goBack(); } catch (error) { this.toastService.badRequest() - } finally { + } finally { loader.remove() } } @@ -521,9 +523,9 @@ export class ExpedienteDetailPage implements OnInit { console.log(task); let classs; - if( window.innerWidth < 701){ + if (window.innerWidth < 701) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -535,12 +537,12 @@ export class ExpedienteDetailPage implements OnInit { backdropDismiss: false }); await modal.present(); - modal.onDidDismiss().then(res=>{ + modal.onDidDismiss().then(res => { this.goBack(); }); } - goToEvent(eventId:any) { + goToEvent(eventId: any) { this.router.navigate(['/home/events', eventId, 'expediente']); } @@ -570,7 +572,7 @@ export class ExpedienteDetailPage implements OnInit { componentProps: { task: this.task, fulltask: this.fulltask, - taskAction:taskAction, + taskAction: taskAction, }, translucent: true }); diff --git a/src/app/pages/gabinete-digital/expediente/expediente.page.ts b/src/app/pages/gabinete-digital/expediente/expediente.page.ts index 0f2833669..94cd5821a 100644 --- a/src/app/pages/gabinete-digital/expediente/expediente.page.ts +++ b/src/app/pages/gabinete-digital/expediente/expediente.page.ts @@ -39,25 +39,8 @@ export class ExpedientePage implements OnInit { ngOnInit() { - const location = window.location - const pathname = location.pathname + location.search - this.getEventsFromLocalDb(); - if (this.onlinecheck) { - this.LoadList() - - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith(pathname)) { - if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing() - } else { - this.LoadList() - } - } - }); - } - } async LoadList() { @@ -74,6 +57,7 @@ export class ExpedientePage implements OnInit { let task = this.expedienteTaskPipe.transform(element) this.taskslist.push(task); + this.sqliteservice.addProcess(task); }); this.listToPresent = this.taskslist @@ -136,17 +120,25 @@ export class ExpedientePage implements OnInit { getEventsFromLocalDb() { - synchro.registerCallback('Online', () => { - this.onlinecheck = true; - }) + if (synchro.connected === true) { + const location = window.location + const pathname = location.pathname + location.search + this.LoadList() - - synchro.registerCallback('Offline', () => { - this.platform.ready().then(() => { - this.onlinecheck = false; - this.taskslist = new Array(); + this.router.events.forEach((event) => { + if (event instanceof NavigationStart && event.url.startsWith(pathname)) { + if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing() + } else { + this.LoadList() + } + } + }); + } else { + this.taskslist = new Array(); this.sqliteservice.getprocessByworkflow("Expediente").then((expediente: any[]) => { + console.log("All expedientes from local,", expediente) expediente.forEach((element) => { @@ -168,12 +160,9 @@ export class ExpedientePage implements OnInit { }); this.listToPresent = this.taskslist - console.log("All expedientes from local,", expediente) + }) - console.log('Offlineee') - }) - - }) + } } } diff --git a/src/app/pages/gabinete-digital/gabinete-digital.page.ts b/src/app/pages/gabinete-digital/gabinete-digital.page.ts index 360af0377..7bd66c8da 100644 --- a/src/app/pages/gabinete-digital/gabinete-digital.page.ts +++ b/src/app/pages/gabinete-digital/gabinete-digital.page.ts @@ -174,33 +174,9 @@ export class GabineteDigitalPage implements OnInit, DoCheck { this.segmentVista = "boxview" } - const pathname = window.location.pathname - this.getAllProcessFromDB() - this.router.events.forEach((event) => { - if (event instanceof NavigationEnd && event.url == pathname) { - - this.waitForDomService.selector({ - selector: 'app-gabinete-digital ion-content .aside-wrapper', - callback: () => { - this.checkRoutes(); - this.LoadCounts(); - } - }) - } - }); - - this.hideRefreshButton(); - - this.waitForDomService.selector({ - selector: 'app-gabinete-digital ion-content .aside-wrapper', - callback: () => { - this.loadAllProcesses(); - } - }) - } async loadAllProcesses() { @@ -245,7 +221,7 @@ export class GabineteDigitalPage implements OnInit, DoCheck { this.allProcessesList = removeDuplicate(this.allProcessesList) this.allProcessesList = this.sortArrayISODate(this.allProcessesList).reverse(); - this.totalDocumentStore.resetCount(this.allProcessesList.length) + }); @@ -281,14 +257,31 @@ export class GabineteDigitalPage implements OnInit, DoCheck { getAllProcessFromDB() { - synchro.registerCallback('Online', () => { - this.platform.ready().then(() => { - this.loadAllProcesses(); + if (synchro.connected === true ) { + const pathname = window.location.pathname + this.router.events.forEach((event) => { + if (event instanceof NavigationEnd && event.url == pathname) { + + this.waitForDomService.selector({ + selector: 'app-gabinete-digital ion-content .aside-wrapper', + callback: () => { + this.checkRoutes(); + this.LoadCounts(); + } + }) + } + }); + + this.hideRefreshButton(); + + this.waitForDomService.selector({ + selector: 'app-gabinete-digital ion-content .aside-wrapper', + callback: () => { + this.loadAllProcesses(); + } }) - }) - - synchro.registerCallback('Offline', () => { - this.platform.ready().then(() => { + } else { + this.hideRefreshButton(); this.sqliteservice.getAllProcess().then((allprocess: any[]) => { allprocess.forEach(element => { @@ -297,7 +290,6 @@ export class GabineteDigitalPage implements OnInit, DoCheck { let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); var workflowInstanceDataFields = JSON.parse(element.workflowInstanceDataFields); - console.log("WORKFLOW all process", workflowInstanceDataFields) let task = { "SerialNumber": element.serialNumber, @@ -320,14 +312,10 @@ export class GabineteDigitalPage implements OnInit, DoCheck { this.allProcessesList = removeDuplicate(this.allProcessesList) this.allProcessesList = this.sortArrayISODate(this.allProcessesList).reverse(); - this.totalDocumentStore.resetCount(this.allProcessesList.length) - }); console.log("All process from db ", allprocess) }) - }) - console.log('Offlineee') - }) + } } sortArrayISODate(myArray: any) { @@ -545,7 +533,7 @@ export class GabineteDigitalPage implements OnInit, DoCheck { let allPreocesses_ = await this.processesbackend.GetTasksList("", false).toPromise(); let count_all_processes = Object.keys(allPreocesses_).length; - this.totalDocumentStore.resetCount(count_all_processes) + let expedientes = await this.processesbackend.GetTaskListExpediente(false).toPromise(); expedientes = expedientes.filter(data => data.workflowInstanceDataFields.Status == "Active") diff --git a/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts b/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts index 53d32bbb2..447443c1e 100644 --- a/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts +++ b/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts @@ -20,6 +20,9 @@ import { PermissionService } from 'src/app/OtherService/permission.service'; import { Location } from '@angular/common'; import { PedidoService } from 'src/app/Rules/pedido.service'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; + @Component({ selector: 'app-pedido', @@ -30,10 +33,10 @@ export class PedidoPage implements OnInit { months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"]; - customDate:any; + customDate: any; task: any; - attachments:any; + attachments: any; fulltask: any; eventsList: Event[]; serialnumber: string; @@ -55,31 +58,32 @@ export class PedidoPage implements OnInit { private toastService: ToastService, public p: PermissionService, private location: Location, - private pedidoService: PedidoService - ) { - this.loggeduser = authService.ValidatedUser; + private pedidoService: PedidoService, + private sqliteservice: SqliteService, + ) { + this.loggeduser = authService.ValidatedUser; - this.activatedRoute.paramMap.subscribe(params => { - // console.log(params["params"]); + this.activatedRoute.paramMap.subscribe(params => { + // console.log(params["params"]); - if(params["params"].SerialNumber) { - this.serialnumber = params["params"].SerialNumber; - } - if(params["params"].caller) { - this.caller = params["params"].caller; - } + if (params["params"].SerialNumber) { + this.serialnumber = params["params"].SerialNumber; + } + if (params["params"].caller) { + this.caller = params["params"].caller; + } - }); - } + }); + } ngOnInit() { - this.LoadTaskDetail(this.serialnumber); + this.getfromDb() } close() { this.modalController.dismiss(); } - notImplemented(){ + notImplemented() { this.alertService.presentAlert('Funcionalidade em desenvolvimento'); } @@ -91,12 +95,13 @@ export class PedidoPage implements OnInit { this.processes.GetTask(this.serialnumber).subscribe(res => { this.fulltask = res + console.log('FULLTAK ONLINe', this.fulltask); - if(res.workflowDisplayName == 'Pedido de Parecer' || res.workflowDisplayName == 'Pedido de Parecer do Presidente'){ + if (res.workflowDisplayName == 'Pedido de Parecer' || res.workflowDisplayName == 'Pedido de Parecer do Presidente') { let date = new Date(res.taskStartDate); date.setMonth(date.getMonth() + 1); - let taskDate = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); this.task = { "SerialNumber": res.serialNumber, @@ -116,12 +121,13 @@ export class PedidoPage implements OnInit { "Status": res.workflowInstanceDataFields.Status, } console.log(this.task); + this.sqliteservice.updateProcess(res); } - else if(res.workflowDisplayName == 'Pedido de Deferimento'){ + else if (res.workflowDisplayName == 'Pedido de Deferimento') { let date = new Date(res.taskStartDate); date.setMonth(date.getMonth() + 1); - let taskDate = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); this.task = { "SerialNumber": res.serialNumber, @@ -140,28 +146,32 @@ export class PedidoPage implements OnInit { "activityInstanceName": res.activityInstanceName, "Status": res.workflowInstanceDataFields.Status, } + this.sqliteservice.updateProcess(res); } let thedate = new Date(res.taskStartDate); - this.customDate = this.days[thedate.getDay()]+ ", " + thedate.getDate() +" de " + ( this.months[thedate.getMonth()]); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); - this.processes.GetTaskParticipants(res.workflowInstanceDataFields.FolderID).subscribe(users=>{ - this.intervenientes = users.filter(user=>{ + this.processes.GetTaskParticipants(res.workflowInstanceDataFields.FolderID).subscribe(users => { + this.sqliteservice.updateProcessInterveners(JSON.stringify(this.serialnumber), JSON.stringify(users)).then(() =>{ + console.log('Pedido ') + }) + this.intervenientes = users.filter(user => { return user.Type == 'I'; }); - this.cc = users.filter(user=>{ + this.cc = users.filter(user => { return user.Type == 'CC'; }); }); this.getDocumentDetails(res.workflowInstanceDataFields.FolderID, '361'); - }, (error)=>{ + }, (error) => { try { this.goBack() this.close() } catch (e) { window.history.back(); - } finally { - if(error.status == 0) { + } finally { + if (error.status == 0) { this.toastService.badRequest('Não é possível visualizar este processo no modo offline') } else { this.toastService.badRequest('Processo não encontrado') @@ -171,17 +181,111 @@ export class PedidoPage implements OnInit { }); } - getDocumentDetails(forlderId:string, applicationId:string){ - this.processes.GetDocumentDetails(forlderId,applicationId).subscribe(res=>{ + getfromDb() { + if (synchro.connected === true) { + this.LoadTaskDetail(this.serialnumber); + } + + if (synchro.connected === false) { + this.sqliteservice.getProcessById(this.serialnumber).then((process) => { + + console.log('PROCESS BY ID', process,this.serialnumber ) + + let fulltak = { + Documents: JSON.parse(process[0].Documents), + actions: JSON.parse(process[0].actions), + activityInstanceName: process[0].activityInstanceName, + formURL: process[0].formURL, + originator: JSON.parse(process[0].originator), + serialNumber: process[0].serialNumber, + taskStartDate: process[0].taskStartDate, + totalDocuments: process[0].totalDocuments, + workflowDisplayName: process[0].workflowDisplayName, + workflowID: process[0].workflowID, + workflowInstanceDataFields: JSON.parse(process[0].workflowInstanceDataFields), + workflowInstanceFolio: process[0].workflowInstanceFolio, + workflowInstanceID: process[0].workflowInstanceID, + workflowName: process[0].workflowName + } + + this.fulltask = fulltak; + console.log('FULLTAK OFFLINE', this.fulltask); + + if (process[0].workflowDisplayName == 'Pedido de Parecer' || process[0].workflowDisplayName == 'Pedido de Parecer do Presidente') { + let date = new Date(process[0].taskStartDate); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); + + this.task = { + "SerialNumber": process[0].serialNumber, + "Folio": JSON.parse(process[0].workflowInstanceDataFields).Subject, + "Senders": JSON.parse(process[0].workflowInstanceDataFields).Sender, + "CreateDate": taskDate, + "DocumentURL": JSON.parse(process[0].workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(process[0].workflowInstanceDataFields).Sender, + "Note": JSON.parse(process[0].workflowInstanceDataFields).TaskMessage, + "FolderId": JSON.parse(process[0].workflowInstanceDataFields).FolderID, + "FsId": '361', + "DocId": JSON.parse(process[0].workflowInstanceDataFields).DocIdDeferimento, + "WorkflowName": process[0].workflowDisplayName, + "DeadlineType": JSON.parse(process[0].workflowInstanceDataFields).DeadlineType, + "ProcessInstanceID": JSON.parse(process[0].workflowInstanceDataFields).InstanceID, + "activityInstanceName": process[0].activityInstanceName, + "Status": JSON.parse(process[0].workflowInstanceDataFields).Status, + } + + this.attachments = JSON.parse(process[0].Documents); + } else if (process[0].workflowDisplayName == 'Pedido de Deferimento') { + + let date = new Date(process[0].taskStartDate); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); + this.task = { + "SerialNumber": process[0].serialNumber, + "Folio": JSON.parse(process[0].workflowInstanceDataFields).Subject, + "Senders": JSON.parse(process[0].workflowInstanceDataFields).Sender, + "CreateDate": taskDate, + "DocumentURL": JSON.parse(process[0].workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(process[0].workflowInstanceDataFields).Sender, + "Note": JSON.parse(process[0].workflowInstanceDataFields).TaskMessage, + "FolderId": JSON.parse(process[0].workflowInstanceDataFields).FolderID, + "FsId": '361', + "DocId": JSON.parse(process[0].workflowInstanceDataFields).DocIdDeferimento, + "WorkflowName": process[0].workflowDisplayName, + "DeadlineType": JSON.parse(process[0].workflowInstanceDataFields).DeadlineType, + "ProcessInstanceID": JSON.parse(process[0].workflowInstanceDataFields).InstanceID, + "activityInstanceName": process[0].activityInstanceName, + "Status": JSON.parse(process[0].workflowInstanceDataFields).Status, + } + this.attachments = JSON.parse(process[0].Documents); + } + + let thedate = new Date(process[0].taskStartDate); + this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]); + + this.intervenientes = JSON.parse(process[0].interveners).filter(user => { + return user.Type == 'I'; + }); + this.cc = JSON.parse(process[0].interveners).filter(user => { + return user.Type == 'CC'; + }); + this.getDocumentDetails(JSON.parse(process[0].workflowInstanceDataFields).FolderID, '361'); + + }) + } + } + + getDocumentDetails(forlderId: string, applicationId: string) { + this.processes.GetDocumentDetails(forlderId, applicationId).subscribe(res => { this.attachments = res.Documents; - // console.log(res['Documents']); + console.log('Attachment',this.attachments); }) } - viewDocument(docId:string) { - this.processes.GetDocumentUrl(docId, '361').subscribe(res=>{ - const url: string = res.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1"); - const browser = this.iab.create(url,"_blank"); + viewDocument(docId: string) { + this.processes.GetDocumentUrl(docId, '361').subscribe(res => { + const url: string = res.replace("webTRIX.Viewer", "webTRIX.Viewer.Branch1"); + const browser = this.iab.create(url, "_blank"); browser.show(); }); } @@ -199,17 +303,17 @@ export class PedidoPage implements OnInit { task: this.task, serialNumber: this.task.SerialNumber, fulltask: this.fulltask, - taskAction:taskAction, + taskAction: taskAction, showEnviarPendentes: false }, translucent: true }); await popover.present(); - popover.onDidDismiss().then(( res =>{ + popover.onDidDismiss().then((res => { - if( res['data'] == 'close') { - this.goBack() + if (res['data'] == 'close') { + this.goBack() } // alert(JSON.stringify(res)+' nada') @@ -217,7 +321,7 @@ export class PedidoPage implements OnInit { })) } - async repreciar(note:string, documents:any) { + async repreciar(note: string, documents: any) { let body = { "serialNumber": this.serialnumber, "action": "Reapreciação", @@ -225,7 +329,7 @@ export class PedidoPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -237,17 +341,18 @@ export class PedidoPage implements OnInit { this.close(); } catch (error) { this.toastService.badRequest() - } finally { + } finally { loader.remove() } } - async arquivar(note:string, documents:any) { + async arquivar(note: string, documents: any) { const loader = this.toastService.loading() try { - await this.pedidoService.arquivar({serialNumber: this.serialnumber, + await this.pedidoService.arquivar({ + serialNumber: this.serialnumber, documents, note }).toPromise() @@ -262,7 +367,7 @@ export class PedidoPage implements OnInit { } - async assignar(note:string, documents:any) { + async assignar(note: string, documents: any) { let body = { "serialNumber": this.serialnumber, "action": "Reencaminhar", @@ -270,7 +375,7 @@ export class PedidoPage implements OnInit { "dataFields": { "ReviewUserComment": note, }, - "AttachmentList" :documents, + "AttachmentList": documents, } const loader = this.toastService.loading() @@ -281,16 +386,16 @@ export class PedidoPage implements OnInit { this.close(); } catch (error) { this.toastService.badRequest() - } finally { + } finally { loader.remove() } } sendExpedienteToPending() { - this.processes.SetTaskToPending(this.serialnumber).subscribe(res=>{ + this.processes.SetTaskToPending(this.serialnumber).subscribe(res => { this.goBack(); - },()=>{ + }, () => { this.toastService.badRequest('Processo não encontrado') }); @@ -299,9 +404,9 @@ export class PedidoPage implements OnInit { async openExpedientActionsModal(taskAction: any, task: any) { let classs; - if( window.innerWidth <= 800) { + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -314,7 +419,7 @@ export class PedidoPage implements OnInit { cssClass: classs, }); await modal.present(); - modal.onDidDismiss().then(res=>{ + modal.onDidDismiss().then(res => { console.log('Modal closed'); this.goBack(); }); @@ -322,9 +427,9 @@ export class PedidoPage implements OnInit { async openBookMeetingModal(task: any) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -355,12 +460,12 @@ export class PedidoPage implements OnInit { // } // }); // } - - async distartExpedientModal(){ + + async distartExpedientModal() { console.log(this.fulltask); const modal = await this.modalController.create({ component: DiscartExpedientModalPage, - componentProps: { + componentProps: { serialNumber: this.fulltask.SerialNumber, folderId: this.fulltask.workflowInstanceDataFields.FolderID, action: 'complete', @@ -370,8 +475,8 @@ export class PedidoPage implements OnInit { }); await modal.present(); - modal.onDidDismiss().then(res=>{ - if(res['data']=='close'){ + modal.onDidDismiss().then(res => { + if (res['data'] == 'close') { this.close(); /* console.log('2Expedient Discard closed2'); this.close(); @@ -385,9 +490,9 @@ export class PedidoPage implements OnInit { console.log(task); let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -405,9 +510,9 @@ export class PedidoPage implements OnInit { async openForwardModal(task: any) { let classs; - if( window.innerWidth <= 800) { + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'modal modal-desktop showAsideOptions' } const modal = await this.modalController.create({ @@ -426,9 +531,9 @@ export class PedidoPage implements OnInit { console.log(task); let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'book-meeting-modal modal modal-desktop' - } else { + } else { classs = 'add-note-modal-no-height showAsideOptions' } const modal = await this.modalController.create({ @@ -441,21 +546,21 @@ export class PedidoPage implements OnInit { backdropDismiss: false }); await modal.present(); - modal.onDidDismiss().then(res=>{ + modal.onDidDismiss().then(res => { this.goBack(); }); } - async openAddNoteModal(actionName:string) { + async openAddNoteModal(actionName: string) { let classs; - if( window.innerWidth <= 800){ + if (window.innerWidth <= 800) { classs = 'modal modal-desktop' - } else { + } else { classs = 'add-note-modal-no-height' } const modal = await this.modalController.create({ component: AddNotePage, - componentProps:{ + componentProps: { showAttachmentBtn: true, }, cssClass: classs, @@ -465,8 +570,8 @@ export class PedidoPage implements OnInit { await modal.present(); - modal.onDidDismiss().then( async (res) => { - const DocumentToSave = await res.data.documents.map( async (e) => { + modal.onDidDismiss().then(async (res) => { + const DocumentToSave = await res.data.documents.map(async (e) => { return { ApplicationId: e.ApplicationType, SourceId: e.Id, @@ -477,16 +582,16 @@ export class PedidoPage implements OnInit { Attachments: DocumentToSave, } - if(res.data){ - if(actionName == 'Solicitar Reapreciação') { + if (res.data) { + if (actionName == 'Solicitar Reapreciação') { await this.repreciar(res.data.note, docs); this.goBack(); } - else if(actionName == 'Arquivar') { + else if (actionName == 'Arquivar') { await this.arquivar(res.data.note, docs); this.goBack(); } - else if(actionName == 'Assignar') { + else if (actionName == 'Assignar') { await this.assignar(res.data.note, docs); } } diff --git a/src/app/pages/gabinete-digital/pedidos/pedidos.page.html b/src/app/pages/gabinete-digital/pedidos/pedidos.page.html index ce73fd988..122800aed 100644 --- a/src/app/pages/gabinete-digital/pedidos/pedidos.page.html +++ b/src/app/pages/gabinete-digital/pedidos/pedidos.page.html @@ -38,13 +38,13 @@
-
+
@@ -77,11 +77,11 @@
-
+
diff --git a/src/app/pages/gabinete-digital/pedidos/pedidos.page.ts b/src/app/pages/gabinete-digital/pedidos/pedidos.page.ts index ccc747f4a..94e381f86 100644 --- a/src/app/pages/gabinete-digital/pedidos/pedidos.page.ts +++ b/src/app/pages/gabinete-digital/pedidos/pedidos.page.ts @@ -7,6 +7,10 @@ import { ModalController, NavParams } from '@ionic/angular'; import { AlertService } from 'src/app/services/alert.service'; import { PedidosStore } from 'src/app/store/pedidos-store.service'; import { ModalService } from 'src/app/services/modal.service'; + +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; + @Component({ selector: 'app-pedidos', templateUrl: './pedidos.page.html', @@ -18,6 +22,8 @@ export class PedidosPage implements OnInit { taskslist:DailyWorkTask[] = []; parecerList:any[] = []; + listToPresentparecerList: any[] = []; + listToPresentdeferimentoList: any[] = []; fulltask:any; parecerListResult:customTask[] = []; @@ -38,7 +44,8 @@ export class PedidosPage implements OnInit { private modalController: ModalController, private alertService: AlertService, private activatedRoute: ActivatedRoute, - private modalService: ModalService + private modalService: ModalService, + private sqliteservice: SqliteService ) { //Inicializar segment this.segment = 'parecer'; @@ -57,21 +64,7 @@ export class PedidosPage implements OnInit { } ngOnInit() { - - this.LoadList() - - this.router.events.forEach((event) => { - if(event instanceof NavigationStart && '/home/gabinete-digital/pedidos?parecer=true'.startsWith(event.url) || - event instanceof NavigationStart && '/home/gabinete-digital/pedidos?deferimento=true'.startsWith(event.url) - ) { - - if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing() - } else { - this.LoadList() - } - } - }); + this.getFromDb(); } goBack() { @@ -141,7 +134,8 @@ export class PedidosPage implements OnInit { } this.parecerList.push(task); }); - this.pedidosstorage.resetparecer(this.parecerList); + this.sqliteservice.addProcess(this.parecerList); + this.listToPresentparecerList = this.parecerList } else if(this.segment == 'deferimento') { @@ -181,7 +175,8 @@ export class PedidosPage implements OnInit { }); - this.pedidosstorage.resetdeferimento(this.deferimentoList); + this.sqliteservice.addProcess(this.deferimentoList); + this.listToPresentdeferimentoList = this.deferimentoList }); @@ -189,6 +184,83 @@ export class PedidosPage implements OnInit { } + getFromDb() { + if(synchro.connected === true) { + this.LoadList() + + this.router.events.forEach((event) => { + if(event instanceof NavigationStart && '/home/gabinete-digital/pedidos?parecer=true'.startsWith(event.url) || + event instanceof NavigationStart && '/home/gabinete-digital/pedidos?deferimento=true'.startsWith(event.url) + ) { + + if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing() + } else { + this.LoadList() + } + } + }); + } + + if(synchro.connected === false) { + let parecerlist = []; + let deferimentolist = [] + this.sqliteservice.getprocessByworkflowpedido("Pedido de Parecer", "Pedido de Parecer do Presidente").then((process: any[]) => { + + process.forEach((element) => { + if(JSON.parse(element.workflowInstanceDataFields).Status == "Active") { + let date = new Date(element.taskStartDate); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); + + let task = { + "SerialNumber": element.serialNumber, + "Folio": JSON.parse(element.workflowInstanceDataFields).Subject, + "Senders": JSON.parse(element.workflowInstanceDataFields).Sender, + "CreateDate": taskDate, + "DocumentURL": JSON.parse(element.workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(element.workflowInstanceDataFields).Remetente, + "DocumentsQty": element.totalDocuments, + "DocId": JSON.parse(element.workflowInstanceDataFields).DocIdDiferimento, + "WorkflowName": element.workflowDisplayName, + "activityInstanceName": element.activityInstanceName, + } + parecerlist.push(task) + } + }) + this.listToPresentparecerList = parecerlist; + console.log('parecer',process) + }) + + this.sqliteservice.getprocessByworkflow("Pedido de Deferimento").then((process: any[]) => { + process.forEach((element) => { + if(JSON.parse(element.workflowInstanceDataFields).Status == "Active") { + let date = new Date(element.taskStartDate); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); + + let task = { + "SerialNumber": element.serialNumber, + "Folio": JSON.parse(element.workflowInstanceDataFields).Subject, + "Senders": JSON.parse(element.workflowInstanceDataFields).Sender, + "CreateDate": taskDate, + "DocumentURL": JSON.parse(element.workflowInstanceDataFields).ViewerRequest, + "Remetente": JSON.parse(element.workflowInstanceDataFields).Remetente, + "DocumentsQty": element.totalDocuments, + "DocId": JSON.parse(element.workflowInstanceDataFields).DocIdDiferimento, + "WorkflowName": element.workflowDisplayName, + "activityInstanceName": element.activityInstanceName, + } + deferimentolist.push(task) + } + }) + this.listToPresentdeferimentoList = deferimentolist; + console.log('deferimento',process) + }) + + } + } + segmentChanged(ev: any) { this.LoadList(); } diff --git a/src/app/pages/gabinete-digital/pendentes/pendentes.page.html b/src/app/pages/gabinete-digital/pendentes/pendentes.page.html index dc2d3daa4..43af02c1b 100644 --- a/src/app/pages/gabinete-digital/pendentes/pendentes.page.html +++ b/src/app/pages/gabinete-digital/pendentes/pendentes.page.html @@ -27,7 +27,7 @@ diff --git a/src/app/pages/gabinete-digital/pendentes/pendentes.page.ts b/src/app/pages/gabinete-digital/pendentes/pendentes.page.ts index fc629d6c9..fcd1f61df 100644 --- a/src/app/pages/gabinete-digital/pendentes/pendentes.page.ts +++ b/src/app/pages/gabinete-digital/pendentes/pendentes.page.ts @@ -10,6 +10,10 @@ import { LoginUserRespose } from 'src/app/models/user.model'; import { AuthService } from 'src/app/services/auth.service'; import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe'; +import { SqliteService } from 'src/app/services/sqlite.service'; +import { synchro } from 'src/app/services/socket/synchro.service'; +import { Platform } from '@ionic/angular'; + @Component({ selector: 'app-pendentes', @@ -20,46 +24,37 @@ export class PendentesPage implements OnInit { @ViewChild(CalendarComponent) myCal: CalendarComponent; taskType: string; - serialNumber:string; - totalDocs:any; + serialNumber: string; + totalDocs: any; showLoader: boolean; loggeduser: LoginUserRespose; - @Input() profile:string; - segment:string; + @Input() profile: string; + segment: string; skeletonLoader = true pendentesstore = PendentesStore; customTaskPipe = new CustomTaskPipe() + listToPresent = []; + + synch = synchro constructor( - private processes:ProcessesService, + private processes: ProcessesService, private alertService: AlertService, private router: Router, private authService: AuthService, private activatedRoute: ActivatedRoute, - ) { - this.loggeduser = authService.ValidatedUser; - this.profile = 'mdgpr'; - } + private sqliteservice: SqliteService, + private platform: Platform + ) { + this.loggeduser = authService.ValidatedUser; + this.profile = 'mdgpr'; + } ngOnInit() { //Inicializar segment this.segment = "despachos"; - - const location = window.location - const pathname = location.pathname + location.search - - this.LoadList() - - this.router.events.forEach((event) => { - if (event instanceof NavigationEnd && event.url.startsWith(pathname)) { - if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing() - } else { - this.LoadList() - } - } - }); + this.getFromDb(); } @@ -87,20 +82,69 @@ export class PendentesPage implements OnInit { pendentesList.push(task); }); - pendentesList = removeDuplicate( pendentesList) + pendentesList = removeDuplicate(pendentesList) pendentesList = this.sortArrayISODate(pendentesList); - - this.pendentesstore.reset(pendentesList); + this.listToPresent = pendentesList; this.skeletonLoader = false; } sortArrayISODate(myArray: any) { - return myArray.sort(function(a, b) { + return myArray.sort(function (a, b) { return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0); }); } + getFromDb() { + + if (synchro.connected === true) { + const location = window.location + const pathname = location.pathname + location.search + + this.LoadList() + + this.router.events.forEach((event) => { + if (event instanceof NavigationEnd && event.url.startsWith(pathname)) { + if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing() + } else { + this.LoadList() + } + } + }); + } + + synchro.registerCallback('Offline', () => { + this.platform.ready().then(() => { + this.sqliteservice.getAllProcess().then((process: any[]) => { + var pendingList = [] + process.forEach(element => { + var workflow = JSON.parse(element.workflowInstanceDataFields); + if (workflow.Status === "Pending") { + let task = { + "CreateDate": element.taskStartDate, + "DocumentsQty": element.totalDocuments, + "FolderID": workflow.FolderID, + "Folio": workflow.Subject, + "Senders": workflow.Sender, + "SerialNumber": element.serialNumber, + "Status": workflow.Status, + "WorkflowName": element.workflowDisplayName + + } + pendingList.push(task) + } + }); + + pendingList = this.sortArrayISODate(pendingList); + this.listToPresent = pendingList; + console.log('pendentes', pendingList) + + }) + }) + }) + } + async refreshing() { setTimeout(() => { this.LoadList(); @@ -115,24 +159,24 @@ export class PendentesPage implements OnInit { }, 2000); } - async viewTaskDetails({ SerialNumber, WorkflowName, activityInstanceName }:customTask) { - if(WorkflowName == 'Despacho') { - this.router.navigate(['/home/gabinete-digital/despachos',SerialNumber,'gabinete-digital']); + async viewTaskDetails({ SerialNumber, WorkflowName, activityInstanceName }: customTask) { + if (WorkflowName == 'Despacho') { + this.router.navigate(['/home/gabinete-digital/despachos', SerialNumber, 'gabinete-digital']); } - else if(WorkflowName == 'Pedido de Parecer' || WorkflowName == 'Pedido de Deferimento' || WorkflowName == 'Pedido de Parecer do Presidente') { - this.router.navigate(['/home/gabinete-digital/pedidos',SerialNumber,'gabinete-digital']); + else if (WorkflowName == 'Pedido de Parecer' || WorkflowName == 'Pedido de Deferimento' || WorkflowName == 'Pedido de Parecer do Presidente') { + this.router.navigate(['/home/gabinete-digital/pedidos', SerialNumber, 'gabinete-digital']); } - else if(WorkflowName == 'Expediente') { - this.router.navigate(['/home/gabinete-digital/expediente',SerialNumber,'gabinete-digital']); + else if (WorkflowName == 'Expediente') { + this.router.navigate(['/home/gabinete-digital/expediente', SerialNumber, 'gabinete-digital']); } - else if(WorkflowName == 'Expediente' && this.loggeduser.Profile == 'PR') { - this.router.navigate(['/home/gabinete-digital/expedientes-pr',SerialNumber,'gabinete-digital']); + else if (WorkflowName == 'Expediente' && this.loggeduser.Profile == 'PR') { + this.router.navigate(['/home/gabinete-digital/expedientes-pr', SerialNumber, 'gabinete-digital']); } else if (activityInstanceName == "Tarefa de Parecer") { - this.router.navigate(['/home/gabinete-digital/pedidos',SerialNumber,'gabinete-digital']); + this.router.navigate(['/home/gabinete-digital/pedidos', SerialNumber, 'gabinete-digital']); } - else if(activityInstanceName == "Tarefa de Despacho") { - this.router.navigate(['/home/gabinete-digital/despachos',SerialNumber,'gabinete-digital']); + else if (activityInstanceName == "Tarefa de Despacho") { + this.router.navigate(['/home/gabinete-digital/despachos', SerialNumber, 'gabinete-digital']); } else { console.log('cant find page for this task', WorkflowName, activityInstanceName) @@ -144,4 +188,4 @@ export class PendentesPage implements OnInit { return new Date(e).toDateString() } - } +} diff --git a/src/app/services/socket/synchro.service.ts b/src/app/services/socket/synchro.service.ts index 649e34dfd..ba388fcfc 100644 --- a/src/app/services/socket/synchro.service.ts +++ b/src/app/services/socket/synchro.service.ts @@ -83,21 +83,17 @@ class SynchroService { - //if(!this._connected) { - + if(!this._connected === true) { this.BackgroundService.online() + console.log('Online',this._connected) this.callBacks.forEach((e)=>{ if(e.type == 'Online') { e.funx() } }) - - //} + } console.log('open ======================= welcome to socket server') - this.eventtrigger.publishSomeData({ - internet: "online" - }) this._connected = true @@ -180,17 +176,18 @@ class SynchroService { // event.code is usually 1006 in this case console.log('[close] Connection died'); console.log('Reconnect') - + - // if(this._connected){ + if(this._connected === false){ this.BackgroundService.offline(); + console.log('Offline',this._connected) this.callBacks.forEach((e)=>{ if(e.type == 'Offline') { e.funx() } }) - //} + } // status diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts index a21f97653..c745e4826 100644 --- a/src/app/services/sqlite.service.ts +++ b/src/app/services/sqlite.service.ts @@ -94,7 +94,8 @@ export class SqliteService { workflowID INTERGER, workflowInstanceDataFields Text, workflowInstanceID INTERGER, - workflowName varchar(255) + workflowName varchar(255), + interveners Text )`, []) .then((res) => { console.log("Sucess AllProcess Table created: ", res) @@ -168,6 +169,13 @@ export class SqliteService { console.log("process attachment updated") }) } + //updateAttachment + updateProcessInterveners(id, interveners,) { + let data = [document]; + return this.dbInstance.executeSql(`UPDATE ${this.allprocess} SET interveners = ? WHERE serialNumber = ${id}`, [interveners]).then(() => { + console.log("process interveners updated") + }) + } //getAllEvents getAllEvents() { var hashattachment = false; @@ -264,6 +272,21 @@ export class SqliteService { }); } + //getDespachosProcess + getDespachosProcess(process) { + return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE activityInstanceName = ?`, [process]).then((res) => { + this.ALLPROCESS = []; + if (res.rows.length > 0) { + for (var i = 0; i < res.rows.length; i++) { + this.ALLPROCESS.push(res.rows.item(i)); + } + return this.ALLPROCESS; + } + }, (e) => { + console.log(" Get all process error", JSON.stringify(e)); + }); + } + //getprocessByworkflow getprocessByworkflow(process) { return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? `, [process]).then((res) => { @@ -279,6 +302,21 @@ export class SqliteService { }); } + //getprocessByworkflowpedido + getprocessByworkflowpedido(process, process2) { + return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE workflowDisplayName = ? OR workflowDisplayName = ? `, [process, process2]).then((res) => { + this.ALLPROCESS = []; + if (res.rows.length > 0) { + for (var i = 0; i < res.rows.length; i++) { + this.ALLPROCESS.push(res.rows.item(i)); + } + return this.ALLPROCESS; + } + }, (e) => { + console.log(" Get all process error", JSON.stringify(e)); + }); + } + getProcessById(serial) { return this.dbInstance.executeSql(`SELECT * FROM ${this.allprocess} WHERE serialNumber = ? `, [serial]).then((res) => { this.PROCESS = []; diff --git a/src/app/shared/gabinete-digital/all-processes/all-processes.page.ts b/src/app/shared/gabinete-digital/all-processes/all-processes.page.ts index 93ca56583..82143c00e 100644 --- a/src/app/shared/gabinete-digital/all-processes/all-processes.page.ts +++ b/src/app/shared/gabinete-digital/all-processes/all-processes.page.ts @@ -33,38 +33,7 @@ export class AllProcessesPage implements OnInit { ngOnInit() { - this.sqliteservice.getAllProcess().then((allprocess: any[]) => { - this.allProcessesList = allprocess; - console.log("All process from db ", allprocess) - }) - - - /* synchro.registerCallback('Online', () => { - this.platform.ready().then(() => { - this.loadAllProcesses(); - - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith('/home/gabinete-digital')) { - if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing(); - } else { - this.loadAllProcesses(); - } - } - }); - }) - }) - - synchro.registerCallback('Offline', () => { - this.platform.ready().then(() => { - - this.sqliteservice.getAllProcess().then((allprocess: any[]) => { - this.allProcessesList = allprocess; - console.log("All process from db ", allprocess) - }) - }) - console.log('Offlineee') - }) */ + this.getAllProcessFromDB() } doRefresh() { @@ -150,65 +119,56 @@ export class AllProcessesPage implements OnInit { getAllProcessFromDB() { - synchro.registerCallback('Online', () => { - this.platform.ready().then(() => { - this.loadAllProcesses(); + if(synchro.connected === true) { + this.loadAllProcesses(); - this.router.events.forEach((event) => { - if (event instanceof NavigationStart && event.url.startsWith('/home/gabinete-digital')) { - if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { - this.refreshing(); - } else { - this.loadAllProcesses(); - } + this.router.events.forEach((event) => { + if (event instanceof NavigationStart && event.url.startsWith('/home/gabinete-digital')) { + if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) { + this.refreshing(); + } else { + this.loadAllProcesses(); } + } + }); + } else { + this.sqliteservice.getAllProcess().then((allprocess: any[]) => { + allprocess.forEach(element => { + let date = new Date(element.taskStartDate); + date.setMonth(date.getMonth() + 1); + let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); + + var workflowInstanceDataFields = JSON.parse(element.workflowInstanceDataFields); + + let task = { + "SerialNumber": element.serialNumber, + "Folio": workflowInstanceDataFields.Subject, + "Senders": workflowInstanceDataFields.Sender, + "CreateDate": taskDate, + "DocumentURL": workflowInstanceDataFields.ViewerRequest, + "Remetente": workflowInstanceDataFields.Remetente, + "DocumentsQty": element.totalDocuments, + "DocId": workflowInstanceDataFields.DispatchDocId, + "FolderID": workflowInstanceDataFields.FolderID, + "WorkflowName": element.workflowDisplayName, + "activityInstanceName": element.activityInstanceName, + "Status": workflowInstanceDataFields.Status, + "Agenda": workflowInstanceDataFields.Agenda, + "customDate": this.setFormatDate(new Date(workflowInstanceDataFields.StartDate), new Date(workflowInstanceDataFields.EndDate), workflowInstanceDataFields.IsAllDayEvent), + } + + this.allProcessesList.push(task); + this.allProcessesList = removeDuplicate(this.allProcessesList) + this.allProcessesList = this.sortArrayISODate(this.allProcessesList).reverse(); + }); + + + + this.allProcessesList = allprocess; + console.log("All process from db ", allprocess) }) - }) - - synchro.registerCallback('Offline', () => { - this.platform.ready().then(() => { - - this.sqliteservice.getAllProcess().then((allprocess: any[]) => { - allprocess.forEach(element => { - let date = new Date(element.taskStartDate); - date.setMonth(date.getMonth() + 1); - let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); - - var workflowInstanceDataFields = JSON.parse(element.workflowInstanceDataFields); - console.log("WORKFLOW all process", workflowInstanceDataFields) - - let task = { - "SerialNumber": element.serialNumber, - "Folio": workflowInstanceDataFields.Subject, - "Senders": workflowInstanceDataFields.Sender, - "CreateDate": taskDate, - "DocumentURL": workflowInstanceDataFields.ViewerRequest, - "Remetente": workflowInstanceDataFields.Remetente, - "DocumentsQty": element.totalDocuments, - "DocId": workflowInstanceDataFields.DispatchDocId, - "FolderID": workflowInstanceDataFields.FolderID, - "WorkflowName": element.workflowDisplayName, - "activityInstanceName": element.activityInstanceName, - "Status": workflowInstanceDataFields.Status, - "Agenda": workflowInstanceDataFields.Agenda, - "customDate": this.setFormatDate(new Date(workflowInstanceDataFields.StartDate), new Date(workflowInstanceDataFields.EndDate), workflowInstanceDataFields.IsAllDayEvent), - } - - this.allProcessesList.push(task); - this.allProcessesList = removeDuplicate(this.allProcessesList) - this.allProcessesList = this.sortArrayISODate(this.allProcessesList).reverse(); - - }); - - - - this.allProcessesList = allprocess; - console.log("All process from db ", allprocess) - }) - }) - console.log('Offlineee') - }) + } } sortArrayISODate(myArray: any) {