diff --git a/src/app/home/home.page.html b/src/app/home/home.page.html index f4287e966..3b16e2708 100644 --- a/src/app/home/home.page.html +++ b/src/app/home/home.page.html @@ -3,36 +3,36 @@ - + - - + + Início - + - - + + Agenda - + - - + + Gabinete - - - + + + Acções - - - + + + Chat diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 2c9d9f0d1..f16759f59 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -14,6 +14,7 @@ import { EventsService } from 'src/app/services/events.service'; import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'; import { ProcessesService } from 'src/app/services/processes.service'; import { SqliteService } from 'src/app/services/sqlite.service'; +import { ActiveTabService } from 'src/app/services/active-tab.service'; import { Device } from '@capacitor/device'; import { RouteService } from 'src/app/services/route.service'; import { NetworkServiceService, ConnectionStatus } from 'src/app/services/network-service.service'; @@ -89,10 +90,11 @@ export class HomePage implements OnInit { private RochetChatConnectorService: RochetChatConnectorService, private NetworkServiceService: NetworkServiceService, public eventService: EventsService, - ) { - if (SessionStore.exist) { - this.user = SessionStore.user; - } + public ActiveTabService: ActiveTabService + ) { + if (SessionStore.exist) { + this.user = SessionStore.user; + } this.NativeNotificationService.askForPermission(); this.NativeNotificationService.foregroundNotification(); @@ -224,10 +226,6 @@ export class HomePage implements OnInit { const info = await Device.getInfo(); } - get pathname() { - return window.location.pathname - } - updateList() { document.addEventListener('pause', function () { diff --git a/src/app/modals/create-process/create-process.page.html b/src/app/modals/create-process/create-process.page.html index a608d2197..474245384 100644 --- a/src/app/modals/create-process/create-process.page.html +++ b/src/app/modals/create-process/create-process.page.html @@ -80,7 +80,7 @@ -
+
@@ -104,7 +104,7 @@
-
+
diff --git a/src/app/modals/create-process/create-process.page.ts b/src/app/modals/create-process/create-process.page.ts index 0a82d21eb..2cd5a655b 100644 --- a/src/app/modals/create-process/create-process.page.ts +++ b/src/app/modals/create-process/create-process.page.ts @@ -97,7 +97,7 @@ export class CreateProcessPage implements OnInit { public p: PermissionService, private despachoService: DespachoService, private pedidoService: PedidoService, - public ThemeService: ThemeService + public ThemeService: ThemeService, ) { this.loggeduser = SessionStore.user; this.task = this.navParams.get('task'); @@ -199,6 +199,13 @@ export class CreateProcessPage implements OnInit { this.validateFrom = true } + defaultParticipants () { + if(this.p.userPermission([this.p.permissionList.Gabinete.pr_tasks])) { + return ['MDGPR'] + } + + return null + } injectValidation() { this.Form = new FormGroup({ @@ -212,7 +219,7 @@ export class CreateProcessPage implements OnInit { Priority: new FormControl(this.postData.Priority, [ Validators.required, ]), - participantes: new FormControl(this.taskParticipants, [ + participantes: new FormControl(this.defaultParticipants() || this.taskParticipants, [ Validators.required ]), selectedTypes: new FormControl(this.selectedTypes, [ diff --git a/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.html b/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.html index 0763b4eed..ef117e824 100644 --- a/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.html +++ b/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.html @@ -67,9 +67,11 @@
Agenda do {{calendars}}
Minha agenda
--> - -
Agenda de {{calendars}}
-
Agenda de {{loggeduser.FullName}}
+ +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
+
Minha agenda
diff --git a/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts b/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts index b8175f6fd..ed4121982 100644 --- a/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts +++ b/src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts @@ -94,6 +94,7 @@ export class DocumentSetUpMeetingPage implements OnInit { CalendarName; CalendarNameShow = true CalendarNamesOptions + testeFormDefaul = "Eudes" constructor( private modalController: ModalController, diff --git a/src/app/models/dailyworktask.model.ts b/src/app/models/dailyworktask.model.ts index 11ace9eec..4d410d9af 100644 --- a/src/app/models/dailyworktask.model.ts +++ b/src/app/models/dailyworktask.model.ts @@ -1,3 +1,5 @@ +import * as internal from "stream"; + export class DailyWorkTask{ SerialNumber: string; Folio: string; @@ -67,11 +69,29 @@ export class fullTask { workflowName: string } +export const activityInstanceNameArray = [ + 'Concluir Despacho', + 'Tarefa de Despacho','Reexecutar Despacho','Concluir Parecer', + 'Concluir Deferimento', + 'Reapreciar Deferimento', + 'Tarefa de Deferimento', + 'Assinar Diploma', + 'Diploma Assinado', + 'Retificar Diploma', + 'Gerar Diploma', + 'Editar Evento', + 'Revisar Diploma', + 'Tarefa de Parecer' +] as const; // TS3.4 syntax + + +export type activityInstanceName = typeof activityInstanceNameArray[number]; + export interface fullTaskList { serialNumber: string; taskStartDate: string; workflowDisplayName: string; - activityInstanceName: string; + activityInstanceName: activityInstanceName; totalDocuments: number; workflowInstanceDataFields: { Subject: string; @@ -142,6 +162,7 @@ export interface expedienteTask { } export interface ExpedienteTask { + Folio: string SerialNumber: string Senders : string CreateDate : any @@ -151,4 +172,23 @@ export interface ExpedienteTask { Status : string taskStartDate: string Subject: string +} + + +export interface PedidoDeDeferimento { + serialNumber: string; + taskStartDate: Date; + deadline: Date | null; + workflowDisplayName: string; + activityInstanceName: string; + totalDocuments: number; + workflowInstanceDataFields: PedidoDeDeferimentoWorkflowInstanceDataFields; +} + +export interface PedidoDeDeferimentoWorkflowInstanceDataFields { + Sender: string; + Subject: string; + FolderID: number; + Status: string; + originator: string; } \ No newline at end of file diff --git a/src/app/pages/agenda/agenda.page.html b/src/app/pages/agenda/agenda.page.html index 34e3ae41f..66d8692c9 100644 --- a/src/app/pages/agenda/agenda.page.html +++ b/src/app/pages/agenda/agenda.page.html @@ -218,8 +218,8 @@
  • Todos
  • -
  • Calendário Oficial
  • -
  • Calendário Pessoal
  • +
  • Agenda Oficial
  • +
  • Agenda Pessoal
@@ -233,10 +233,11 @@
- -
Agenda do PR
-
Agenda do MDGPR
-
Agenda do {{calendars}}
+ +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
+
diff --git a/src/app/pages/agenda/agenda.page.ts b/src/app/pages/agenda/agenda.page.ts index 68c6bb6d2..948be0e52 100644 --- a/src/app/pages/agenda/agenda.page.ts +++ b/src/app/pages/agenda/agenda.page.ts @@ -202,6 +202,7 @@ export class AgendaPage implements OnInit { this.listToPresent = [] + }) if (this.loggeduser.Profile == 'MDGPR') { @@ -233,6 +234,9 @@ export class AgendaPage implements OnInit { window['year'] = this.changeYear + console.log('SessionStore.user', SessionStore.user) + + } tigerUpdate() { diff --git a/src/app/pages/agenda/edit-event/edit-event.page.html b/src/app/pages/agenda/edit-event/edit-event.page.html index 80bd88990..9aa9dc4b6 100644 --- a/src/app/pages/agenda/edit-event/edit-event.page.html +++ b/src/app/pages/agenda/edit-event/edit-event.page.html @@ -64,10 +64,10 @@ - Calendário Oficial + Agenda Oficial - Calendário Pessoal + Agenda Pessoal diff --git a/src/app/pages/agenda/new-event/new-event.page.html b/src/app/pages/agenda/new-event/new-event.page.html index ce6d17f59..7373e3317 100644 --- a/src/app/pages/agenda/new-event/new-event.page.html +++ b/src/app/pages/agenda/new-event/new-event.page.html @@ -28,11 +28,18 @@ - - -
Agenda de {{calendars}}
-
Agenda de {{loggeduser.FullName}}
- + + + +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
+
Minha agenda
@@ -41,7 +48,6 @@
-
@@ -63,7 +69,7 @@ - Calendário {{ calendars }} + Agenda {{ calendars }} diff --git a/src/app/pages/agenda/new-event/new-event.page.ts b/src/app/pages/agenda/new-event/new-event.page.ts index fbde56775..7c59d1f29 100644 --- a/src/app/pages/agenda/new-event/new-event.page.ts +++ b/src/app/pages/agenda/new-event/new-event.page.ts @@ -117,6 +117,7 @@ export class NewEventPage implements OnInit { } if(!this.CalendarName) { + console.log('true', this.eventService.calendarNamesAry.includes('Meu calendario')) if(this.eventService.calendarNamesAry.includes('Meu calendario')) { this.CalendarName = 'Meu calendario'; console.log(this.eventService.calendarNamesAry) diff --git a/src/app/pages/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts b/src/app/pages/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts index 31ff7ae6e..bb2a17a46 100644 --- a/src/app/pages/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts +++ b/src/app/pages/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts @@ -83,9 +83,12 @@ export class DiplomasAssinarPage implements OnInit { let diplomasAssinar = diplomas.filter(data => data.activityInstanceName == "Assinar Diploma"); - - this.deplomasStore.resetDiplomasParaAssinar(diplomasAssinar) - this.diplomasList = this.sortService.sortDate(this.diplomasList, 'CreateDate') + let format = diplomasAssinar.map(element => { + return this.customTaskPipe.transform(element) + }); + + this.deplomasStore.resetDiplomasParaAssinar(format) + this.diplomasList = this.sortService.sortDate(format, 'CreateDate') } catch(error) { } diff --git a/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts b/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts index d4ac90400..0c71cfe94 100644 --- a/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts +++ b/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts @@ -9,6 +9,7 @@ import { SortService } from 'src/app/services/functions/sort.service'; import { ThemeService } from 'src/app/services/theme.service' import { PermissionService } from 'src/app/services/permission.service'; import { DeplomasStore } from 'src/app/store/deplomas.service'; +import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe'; @Component({ @@ -28,6 +29,7 @@ export class DiplomasPage implements OnInit, OnDestroy { skeletonLoader = true deplomasStore = DeplomasStore + customTaskPipe = new CustomTaskPipe() constructor( private processes: ProcessesService, @@ -124,13 +126,10 @@ export class DiplomasPage implements OnInit, OnDestroy { this.diplomasList = this.sortService.sortDate(diplomasList, 'CreateDate'); let diplomasAssinados = diplomas.filter(data => data.activityInstanceName == "Diploma Assinado"); - let diplomasAssinadoList = []; + - diplomasAssinados.forEach(async element => { - - let task = this.pipeTask(element); - diplomasAssinadoList.push(task); - // console.log('DIPLOMAS ASSINADOS', task) + let diplomasAssinadoList = diplomasAssinados.map( element => { + return this.pipeTask(element); }); this.diplomasAssinadoList = this.sortService.sortDate(diplomasAssinadoList, 'CreateDate') @@ -138,7 +137,10 @@ export class DiplomasPage implements OnInit, OnDestroy { let diplomasAssinar = diplomas.filter(data => data.activityInstanceName == "Assinar Diploma"); - this.deplomasStore.resetDiplomasParaAssinar(diplomasAssinar) + + this.deplomasStore.resetDiplomasParaAssinar(diplomasAssinar.map(element => { + return this.customTaskPipe.transform(element) + })) // console.log('DIPLOMAS ASSINADOS', this.diplomasAssinadoList) diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.html b/src/app/pages/gabinete-digital/event-list/event-list.page.html index bf3fbe9b6..235adfc26 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.html +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.html @@ -17,14 +17,12 @@ - Meu Calendário + Minha agenda - - Calendário Partilhado +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
diff --git a/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.html b/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.html index e5f8663f3..8b1c2ae12 100644 --- a/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.html +++ b/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.html @@ -33,16 +33,21 @@
- - - -
Agenda do PR
-
Agenda do MD
-
Agenda do {{calendars}}
-
Minha agenda
- + + + + +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
+
Minha agenda
- +
@@ -71,7 +76,7 @@ - {{ calendars }} + Calendário {{ calendars }} diff --git a/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html b/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html index b4bb8d044..784358d95 100644 --- a/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html +++ b/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html @@ -129,7 +129,7 @@
-
+
@@ -152,7 +152,7 @@
-
+
diff --git a/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.ts b/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.ts index a404030e8..85196ed05 100644 --- a/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.ts +++ b/src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.ts @@ -23,7 +23,7 @@ import { DespachoService } from 'src/app/Rules/despacho.service'; import { SearchDocumentPipe } from 'src/app/pipes/search-document.pipe'; import { ThemeService } from 'src/app/services/theme.service' import { SessionStore } from 'src/app/store/session.service'; - +import { PermissionService } from 'src/app/services/permission.service'; const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { parse: { @@ -109,7 +109,8 @@ export class ExpedientTaskModalPage implements OnInit { private userAuth: AuthService, private toastService: ToastService, private despachoService: DespachoService, - public ThemeService: ThemeService + public ThemeService: ThemeService, + public p: PermissionService, ) { this.loggeduser = SessionStore.user; @@ -194,6 +195,14 @@ export class ExpedientTaskModalPage implements OnInit { this.validateFrom = true; } + defaultParticipants () { + if(this.p.userPermission([this.p.permissionList.Gabinete.pr_tasks])) { + return ['MDGPR'] + } + + return null + } + injectValidation() { this.Form = new FormGroup({ @@ -210,7 +219,7 @@ export class ExpedientTaskModalPage implements OnInit { Priority: new FormControl(this.postData.Priority, [ Validators.required, ]), - participantes: new FormControl(this.taskParticipants, [ + participantes: new FormControl(this.defaultParticipants() || this.taskParticipants, [ Validators.required ]), 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 23a1d6e89..b7b169a45 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 @@ -394,8 +394,6 @@ export class ExpedienteDetailPage implements OnInit { }); }) - - }, (error) => { diff --git a/src/app/pages/gabinete-digital/gabinete-digital.page.html b/src/app/pages/gabinete-digital/gabinete-digital.page.html index 11a33dd14..12ccd0478 100644 --- a/src/app/pages/gabinete-digital/gabinete-digital.page.html +++ b/src/app/pages/gabinete-digital/gabinete-digital.page.html @@ -141,6 +141,8 @@
+ +
@@ -149,77 +151,8 @@

Todas as tarefas

{{ getAllProcessCount }} Documentos

-
-
- -
-

Eventos para Aprovação

-

{{eventoaprovacaostore.countMd + eventoaprovacaostore.countPr}} Documentos

-
- -
-
- - - - - -
-

Expediente

-

{{expedientegbstore.count}} Documentos

-
- -
-
- - - - - -
-

Pendentes

-

Meus Pendentes

-

{{pendentesstore.count}} Documentos

-
- -
-
- - - - - -
-

Despachos

-

{{despachoStore.count}} Documentos

-
- -
-
- - - - - -
-

Pedidos de Parecer

-

Pedidos de Parecer solicitados por mim

-

{{pedidosstore.countparecer}} Documentos

-
- -
-
- - - - - - -
-

Pedidos de Deferimento

-

{{pedidosstore.countdeferimento}} Documentos

-
+
@@ -235,8 +168,22 @@
- + + +
+
+ + + + + +
+

Diplomas por Assinar

+

{{ deplomasStore.diplomasParaAssinartCount }} Documentos

+
+ +
@@ -248,6 +195,8 @@

{{ deplomasStore.deplomasReviewCount }} Documentos

+ +
@@ -258,7 +207,21 @@

Diplomas

{{ deplomasStore.countDiplomasAssinadoListCount }} Documentos

- + + +
+
+ + + + + +
+

Diplomas para Assinar

+

{{ deplomasStore.diplomasParaAssinartCount }} Documentos

+
+ +
@@ -272,31 +235,89 @@

{{ deplomasStore.DiplomaGerarList.length }} Documentos

- -
+ + +
- - - - - +
-

Diplomas para Assinar

-

{{ deplomasStore.diplomasParaAssinartCount }} Documentos

+

Eventos para Aprovação

+

{{eventoaprovacaostore.countMd + eventoaprovacaostore.countPr}} Documentos

+
+ + +
+
+ + + + + +
+

Expediente

+

{{expedientegbstore.count}} Documentos

-
+ +
- - - - - + + + + +
-

Diplomas por Assinar

-

{{ deplomasStore.diplomasParaAssinartCount }} Documentos

+

Despachos

+

{{despachoStore.count}} Documentos

+ + + + +
+
+ + + + + +
+

Pedidos de Parecer

+

Pedidos de Parecer solicitados por mim

+

{{pedidosstore.countparecer}} Documentos

+
+ + +
+
+ + + + + + +
+

Pedidos de Deferimento

+

{{pedidosstore.countdeferimento}} Documentos

+
+ + +
+
+ + + + + +
+

Pendentes

+

Meus Pendentes

+

{{pendentesstore.count}} Documentos

+
+ + +
diff --git a/src/app/pages/gabinete-digital/gabinete-digital.page.ts b/src/app/pages/gabinete-digital/gabinete-digital.page.ts index 5e74dc460..51d3aafc0 100644 --- a/src/app/pages/gabinete-digital/gabinete-digital.page.ts +++ b/src/app/pages/gabinete-digital/gabinete-digital.page.ts @@ -705,12 +705,12 @@ export class GabineteDigitalPage implements OnInit { this.pendentesstore.reset(pendentes); this.updateAllProcess() - let depachoAPI: any = await this.processesbackend.GetTasksList("Despacho do Presidente da República", false).toPromise(); + let depachoAPI = await this.processesbackend.GetTasksList("Despacho do Presidente da República", false).toPromise(); if(SessionStore.user.Profile != 'PR') { - let depacho = depachoAPI.reverse().filter(data => data.activityInstanceName == "Tarefa de Despacho"); + let depacho: any = depachoAPI.reverse().filter(data => data.activityInstanceName == "Tarefa de Despacho"); depacho = depacho.filter(data => data.workflowInstanceDataFields.Status == "Active"); depacho = depacho.map((e)=> this.customTaskPipe.transform(e)) @@ -719,7 +719,7 @@ export class GabineteDigitalPage implements OnInit { this.updateAllProcess() } else if(SessionStore.user.Profile == 'PR') { - let depacho = depachoAPI.filter(data => data.activityInstanceName == "Concluir Despacho").filter(data => data.workflowInstanceDataFields.Status == "Active") + let depacho: any = depachoAPI.filter(data => data.activityInstanceName == "Concluir Despacho").filter(data => data.workflowInstanceDataFields.Status == "Active") depacho = depacho.map((e)=> this.customTaskPipe.transform(e)) this.despachoprstore.reset(depacho) this.updateAllProcess() @@ -771,12 +771,14 @@ export class GabineteDigitalPage implements OnInit { })) - let diplomasAssinar = depachoAPI.filter(data => data.activityInstanceName == "Assinar Diploma"); - + let diplomasAssinar: any = depachoAPI.filter(data => data.activityInstanceName == "Assinar Diploma"); + diplomasAssinar = diplomasAssinar.map((element) => this.expedienteTaskPipe.transform(element)) this.deplomasStore.resetDiplomasParaAssinar(diplomasAssinar) - let diplomasAssinados = depachoAPI.filter(data => data.activityInstanceName == "Diploma Assinado"); + let diplomasAssinados: any = depachoAPI.filter(data => data.activityInstanceName == "Diploma Assinado"); + diplomasAssinados = diplomasAssinados.map((element) => this.expedienteTaskPipe.transform(element)) this.deplomasStore.resetDiplomasAssinadoList(diplomasAssinados) + this.updateAllProcess() this.loadCount = true @@ -789,7 +791,10 @@ export class GabineteDigitalPage implements OnInit { if (event) { setTimeout(() => { - event?.target?.complete(); + try { + event?.target?.complete(); + } catch(error) {} + }, 2000); } else { diff --git a/src/app/pipes/expediente-task.pipe.ts b/src/app/pipes/expediente-task.pipe.ts index 39d756770..cd3a82b45 100644 --- a/src/app/pipes/expediente-task.pipe.ts +++ b/src/app/pipes/expediente-task.pipe.ts @@ -16,6 +16,7 @@ export class ExpedienteTaskPipe implements PipeTransform { "SerialNumber": fullTask.serialNumber, "taskStartDate": fullTask.taskStartDate, "Subject": fullTask.workflowInstanceDataFields.Subject, + "Folio": fullTask.workflowInstanceDataFields.Subject, "Senders": fullTask.workflowInstanceDataFields.Sender, "CreateDate": date, "DocumentsQty": fullTask.totalDocuments, diff --git a/src/app/services/active-tab.service.spec.ts b/src/app/services/active-tab.service.spec.ts new file mode 100644 index 000000000..8815e356e --- /dev/null +++ b/src/app/services/active-tab.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ActiveTabService } from './active-tab.service'; + +describe('ActiveTabService', () => { + let service: ActiveTabService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ActiveTabService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/active-tab.service.ts b/src/app/services/active-tab.service.ts new file mode 100644 index 000000000..bba6b7c8e --- /dev/null +++ b/src/app/services/active-tab.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +@Injectable({ + providedIn: 'root' +}) +export class ActiveTabService { + + pages = { + chat: false, + agenda: false, + publication: false, + home: false, + gabinete: false + } + + constructor(private router: Router) { + + this.detectActiveTab() + + this.router.events.subscribe((val) => { + this.detectActiveTab() + }); + } + + + detectActiveTab() { + this.setFalseToAllPage(); + const pathName = window.location.pathname + + if(pathName.startsWith('/home/agenda')) { + this.pages.agenda = true + } else if (pathName.startsWith('/home/events')) { + this.pages.home = true + } else if (pathName.startsWith('/home/gabinete-digital')) { + this.pages.gabinete = true + } else if (pathName.startsWith('/home/publications')) { + this.pages.publication = true + } else if (pathName.startsWith('/home/chat')) { + this.pages.chat = true + } + } + + setFalseToAllPage() { + for( const page in this.pages) { + this.pages[page] = false + } + } +} diff --git a/src/app/services/chat/chat-system.service.ts b/src/app/services/chat/chat-system.service.ts index 4e666deaf..f6bc9eab7 100644 --- a/src/app/services/chat/chat-system.service.ts +++ b/src/app/services/chat/chat-system.service.ts @@ -95,6 +95,13 @@ export class ChatSystemService { this.loadChat(); } + + document.addEventListener('resume', function () { + if(this._dm?.length == 0 && this._group?.length == 0) { + this.getAllRooms(); + } + }); + } loadChat() { diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 364e8fdab..d4f93829a 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -480,7 +480,7 @@ export class MessageService { return SessionStore.user.ChatData.data.userId == this.u._id } - private getChatObj() { + getChatObj() { return { channels: this.channels, mentions: this.mentions, diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index d603a9858..0ed0aea47 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -125,7 +125,7 @@ export class RoomService { this.hasLoadHistory = false this.subscribeAttempt = false } - }) + }); } @@ -174,11 +174,7 @@ export class RoomService { this.calDateDuration(); - (async () => { - await this.restoreMessageFromDB() - await this.loadHistory({}) - })() - + if(this.customFields?.countDownDate) { this.countDownDate(this.customFields.countDownDate); } @@ -327,7 +323,7 @@ export class RoomService { if(!found) { ChatMessage.origin = 'stream' - const message = await this.prepareCreate({message: ChatMessage, save: true}); + const message = await this.prepareCreate({message: ChatMessage, save: false}); this.registerSendMessage(message) message.from = 'stream' @@ -348,7 +344,10 @@ export class RoomService { } if(this.hasLoadHistory == true) { + this.messages.push(message) await message.addMessageDB() + } else { + this.messagesBeforeOfflineAPI.push(message) } if(this.chatOpen == false) { @@ -503,7 +502,6 @@ export class RoomService { if(previousLastMessage) { this.lastMessage = previousLastMessage; - // console.log("last message"+ previousLastMessage) this.calDateDuration(previousLastMessage._updatedAt) this.sortRoomList() } @@ -736,12 +734,11 @@ export class RoomService { setTimeout(() => { this.scrollDown() }, 50) - } } // runs onces only - + loadHistoryCount = 0 async loadHistory({limit = 1000, forceUpdate = false }) { if(forceUpdate == false) { @@ -752,33 +749,37 @@ export class RoomService { this.hasLoadHistory = true + await this.restoreMessageFromDB() const chatHistory: chatHistory = await this.RochetChatConnectorService.loadHistory(this.id, limit) if(chatHistory?.result?.messages) { - const messagesId = this.messages.map((message)=> message._id) const users = this.getUsersByStatus('online') for(let message of chatHistory.result.messages.reverse()) { - if (!messagesId.includes(message._id)) { - message.origin = 'history' - message.from = 'History' - const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message}); - if(messagesToSave != null) { - messagesToSave.received = users.map((user) => user._id) - messagesToSave.addMessageDB() - - // console.log('add history', message) - } else { - // console.log('exit') - } - } else { - // console.log('exit') + message.origin = 'history' + message.from = 'History' + const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message}); + if(messagesToSave != null) { + + messagesToSave.received = users.map((user) => user._id) + messagesToSave.addMessageDB() } + } + for( const message of this.messagesBeforeOfflineAPI) { + const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message}); + if(messagesToSave != null) { + + messagesToSave.received = users.map((user) => user._id) + messagesToSave.addMessageDB() + } + } + this.messagesBeforeOfflineAPI = [] + setTimeout(() => { this.scrollDown() }, 50) @@ -824,8 +825,10 @@ export class RoomService { wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory - this.messages.push(wewMessage) - + if(save) { + this.messages.push(wewMessage) + } + return wewMessage } @@ -842,17 +845,17 @@ export class RoomService { private findMessageBy_id (id) { for( let m of this.messages) { - if(m._id == id) { + if(m?._id == id) { return true } } - + return false } private findMessageBy_localReference (localReference) { for( let m of this.messages) { - if(m.localReference == localReference) { + if(m?.localReference == localReference) { return true } } @@ -893,7 +896,7 @@ export class RoomService { async prepareMessageCreateIfNotExist({message}) { message = this.fix_updatedAt(message) - let found = await this.findMessageBy_id(message._id) || this.findMessageBy_localReference(message.localReference) + let found = await this.findMessageBy_id(message._id) || await this.findMessageBy_localReference(message.localReference) // || await this.findMessageInDBByData({_id:message._id, localReference:message.localReference }) if (!found) { diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index ef0237780..d56956843 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -259,7 +259,7 @@ export class EventsService { console.log('ROLE',e.Role, e.FullName) - if(!this.calendarNamesAry.includes(e.FullName)) { + if(!this.calendarNamesAry.find(x => x.Role == e.Role)) { /* if(e.Role == "Presidente da República") { this.calendarNamesAry.push(e.Role) console.log('PR ROLE',this.calendarNamesAry) @@ -271,13 +271,21 @@ export class EventsService { console.log('NORMAL ROLE',this.calendarNamesAry) } */ //this.calendarRole.push(e.Role) + let objectShared = { + "Fullname": e.FullName, + "Role": e.Role + } + this.calendarNamesAry.push(objectShared) + + + console.log('objectShared',this.calendarNamesAry) this.calendarNamesType[e.FullName] = {} } this.calendarNamesType[e.FullName][sharedCalendar.CalendarName] = true this.calendarNamesType[e.FullName][sharedCalendar.CalendarName+'Id'] = sharedCalendar.CalendarId - + this.calendarNamesType[e.FullName]['RoleId'] = sharedCalendar.CalendarRoleId }) } @@ -290,11 +298,13 @@ export class EventsService { if(!this.calendarNamesAry.includes('Meu calendario')) { this.calendarNamesAry.push('Meu calendario') + console.log(this.calendarNamesAry) this.calendarNamesType['Meu calendario'] = {} } this.calendarNamesType['Meu calendario'][sharedCalendar.CalendarName] = true this.calendarNamesType['Meu calendario'][sharedCalendar.CalendarName+'Id'] = sharedCalendar.CalendarId + this.calendarNamesType['Meu calendario']['RoleId'] = sharedCalendar.CalendarRoleId } diff --git a/src/app/services/processes.service.ts b/src/app/services/processes.service.ts index 8f1604a2d..d952907d7 100644 --- a/src/app/services/processes.service.ts +++ b/src/app/services/processes.service.ts @@ -87,7 +87,7 @@ export class ProcessesService { return this.http.get(`${geturl}`, options); } - GetTask(serialnumber:string): Observable{ + GetTask(serialnumber:string): Observable { const geturl = environment.apiURL + 'Tasks/FindTask'; let params = new HttpParams(); diff --git a/src/app/shared/agenda/event-list/event-list.page.html b/src/app/shared/agenda/event-list/event-list.page.html index 9b9e0ed27..69004c032 100644 --- a/src/app/shared/agenda/event-list/event-list.page.html +++ b/src/app/shared/agenda/event-list/event-list.page.html @@ -11,10 +11,12 @@ - Meu Calendário + Minha agenda - - Calendário Partilhado + +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
diff --git a/src/app/shared/agenda/event-list/event-list.page.ts b/src/app/shared/agenda/event-list/event-list.page.ts index 1463ebabe..c47bb9815 100644 --- a/src/app/shared/agenda/event-list/event-list.page.ts +++ b/src/app/shared/agenda/event-list/event-list.page.ts @@ -6,6 +6,7 @@ import { NavigationEnd, Router } from '@angular/router'; import { LoginUserRespose } from 'src/app/models/user.model'; import { SortService } from 'src/app/services/functions/sort.service'; import { SessionStore } from 'src/app/store/session.service'; +import { EventsService } from 'src/app/services/events.service'; @Component({ selector: 'app-event-list', @@ -36,6 +37,7 @@ export class EventListPage implements OnInit { private processes:ProcessesService, private router: Router, private sortService: SortService, + public eventService: EventsService, ) { this.loggeduser = SessionStore.user; } diff --git a/src/app/shared/agenda/new-event/new-event.page.html b/src/app/shared/agenda/new-event/new-event.page.html index a0fe8d331..5fc142ee0 100644 --- a/src/app/shared/agenda/new-event/new-event.page.html +++ b/src/app/shared/agenda/new-event/new-event.page.html @@ -40,11 +40,17 @@ - -
Agenda do PR
-
Agenda do MD
-
Agenda do {{calendars}}
-
Minha agenda
+ + +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
+
Minha agenda
diff --git a/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.html b/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.html index 6a9dd1fd2..5cfbdaa15 100644 --- a/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.html +++ b/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.html @@ -2,11 +2,11 @@
Diplomas para assinar
- +
@@ -38,7 +38,7 @@
- {{ task.Folio }} + {{ task.Folio || task.workflowInstanceDataFields.Subject }}
diff --git a/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts b/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts index 6e3998ae3..8fc1cce52 100644 --- a/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts +++ b/src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts @@ -71,9 +71,8 @@ export class DiplomasAssinarPage implements OnInit { let diplomasAssinar = diplomas.reverse().filter(data => data.activityInstanceName == "Assinar Diploma"); - diplomasAssinar.forEach(element => { - let task: customTask = this.customTaskPipe.transform(element) - this.diplomasList.push(task); + this.diplomasList = diplomasAssinar.map(element => { + return this.customTaskPipe.transform(element) }); this.diplomasList = this.sortService.sortDate(this.diplomasList, 'CreateDate') diff --git a/src/app/shared/gabinete-digital/diplomas/diplomas.page.ts b/src/app/shared/gabinete-digital/diplomas/diplomas.page.ts index be14d6caa..50f4cf8d5 100644 --- a/src/app/shared/gabinete-digital/diplomas/diplomas.page.ts +++ b/src/app/shared/gabinete-digital/diplomas/diplomas.page.ts @@ -66,29 +66,23 @@ export class DiplomasPage implements OnInit { let diplomas = await this.processes.GetTasksList("Despacho do Presidente da República", false).toPromise(); this.diplomasList = []; - let diplomasList = []; // let diplomasReview = diplomas.reverse().filter(data => data.activityInstanceName == "Diploma Assinado"); - diplomas.forEach(element => { - - let task = this.pipeTask(element) - diplomasList.push(task); + let diplomasList = diplomas.map(element => { + return this.pipeTask(element) }); - diplomasList = diplomasList.filter(data => data.activityInstanceName != "Tarefa de Despacho"); + diplomasList = diplomasList.filter(data => data.activityInstanceName == "Revisar Diploma"); this.diplomasList = this.sortService.sortDate(diplomasList, 'CreateDate') this.deplomasStore.resetDiplomasReview(this.diplomasList) - let diplomasAssinadoList = [] let diplomasAssinados = diplomas.reverse().filter(data => data.activityInstanceName == "Diploma Assinado"); - diplomasAssinados.forEach(async element => { - - let task = this.pipeTask(element) - diplomasAssinadoList.push(task); + let diplomasAssinadoList = diplomasAssinados.map(element => { + return this.pipeTask(element) }); this.diplomasAssinadoList = this.sortService.sortDate(diplomasAssinadoList, 'CreateDate') diff --git a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html index 314adb043..e6004146f 100644 --- a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html +++ b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html @@ -10,10 +10,12 @@ - Meu Calendário + Minha agenda - - Calendário Partilhado + +
Agenda do PR
+
Agenda do MD
+
Agenda do {{calendars.FullName}}
diff --git a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts index b21e9b2f7..4ef2dcb5e 100644 --- a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts +++ b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts @@ -10,6 +10,8 @@ import { EventoAprovacaoStore } from 'src/app/store/eventoaprovacao-store.servic import { SortService } from 'src/app/services/functions/sort.service'; import { Storage } from '@ionic/storage'; import { SessionStore } from 'src/app/store/session.service'; +import { EventsService } from 'src/app/services/events.service'; + @Component({ selector: 'app-events-to-approve', @@ -35,7 +37,8 @@ export class EventsToApprovePage implements OnInit { private router: Router, private userAuth: AuthService, private sortService: SortService, - private storage: Storage + private storage: Storage, + public eventService: EventsService, ) { this.loggeduser = SessionStore.user; diff --git a/src/app/shared/header/header.page.html b/src/app/shared/header/header.page.html index 40f801f40..1be4eaaea 100644 --- a/src/app/shared/header/header.page.html +++ b/src/app/shared/header/header.page.html @@ -74,7 +74,7 @@
+ [class.active]="ActiveTabService.pages.home"> @@ -83,7 +83,7 @@
+ [class.active]="ActiveTabService.pages.agenda"> @@ -91,7 +91,7 @@
+ [class.active]="ActiveTabService.pages.gabinete"> @@ -99,14 +99,14 @@
+ [class.active]="ActiveTabService.pages.publication"> Acções
+ [class.active]="ActiveTabService.pages.chat"> Chat diff --git a/src/app/shared/header/header.page.ts b/src/app/shared/header/header.page.ts index 3ad89fdfe..64b5a90ee 100644 --- a/src/app/shared/header/header.page.ts +++ b/src/app/shared/header/header.page.ts @@ -12,7 +12,7 @@ import { RouteService } from 'src/app/services/route.service'; import { PermissionList } from 'src/app/models/permission/permissionList'; import { PermissionService } from 'src/app/services/permission.service'; import { EventTrigger } from 'src/app/services/eventTrigger.service' -/* import { Events } from 'ionic-angular' */ +import { ActiveTabService } from 'src/app/services/active-tab.service'; @Component({ selector: 'app-header', @@ -48,6 +48,7 @@ export class HeaderPage implements OnInit { public RouteService: RouteService, public p: PermissionService, private eventTriger: EventTrigger, + public ActiveTabService: ActiveTabService ) { this.loggeduser = SessionStore.user; router.events.subscribe((val) => { @@ -98,27 +99,6 @@ export class HeaderPage implements OnInit { } } - locationPathname(): string { - let path = window.location.pathname; - if(path.includes('/home/events')){ - return '/home/events'; - } - else if(path.includes('/home/agenda')){ - return '/home/agenda'; - } - else if(path.includes('/home/gabinete-digital')){ - return '/home/gabinete-digital'; - } - else if(path.includes('/home/publications')){ - return '/home/publications'; - } - else if(path.includes('/home/chat')){ - return '/home/chat'; - } - else{ - return path; - } - } async openSearch() { diff --git a/src/plugin/src/connection/indexedDb/connector.d.ts b/src/plugin/src/connection/indexedDb/connector.d.ts index b2659d0db..1fb933e57 100644 --- a/src/plugin/src/connection/indexedDb/connector.d.ts +++ b/src/plugin/src/connection/indexedDb/connector.d.ts @@ -1,7 +1,7 @@ import { DatabaseSchema } from '../../models/register-modal.interface.js'; export declare class IndexedDBConnection { constructor(); - connect(config: DatabaseSchema): Promise; - migrate(config: DatabaseSchema): Promise; + static connect(config: DatabaseSchema): Promise; + static migrate(config: DatabaseSchema): Promise; private runMigrations; } diff --git a/src/plugin/src/connection/indexedDb/connector.js b/src/plugin/src/connection/indexedDb/connector.js index 9db8b0b0d..abc57da00 100644 --- a/src/plugin/src/connection/indexedDb/connector.js +++ b/src/plugin/src/connection/indexedDb/connector.js @@ -13,8 +13,13 @@ export class IndexedDBConnection { reject(e.target.error.name); }; request.onupgradeneeded = async (e) => { - throw ('need to migrate first'); + console.log('need to migrate first'); + await this.migrate(config); + return await this.connect(config); }; + // request.onblocked = async (e: any) => { + // reject(e.target.error.name); + // } } else { reject("IDBDatabase not supported inside webworker"); diff --git a/src/plugin/src/connection/indexedDb/indexedb.d.ts b/src/plugin/src/connection/indexedDb/indexedb.d.ts index 3e9bd7a25..f8e32357a 100644 --- a/src/plugin/src/connection/indexedDb/indexedb.d.ts +++ b/src/plugin/src/connection/indexedDb/indexedb.d.ts @@ -11,7 +11,7 @@ declare class _indexedDB { getOneByIndex: (keyPath: string, value: string | number) => Promise; getManyByIndex: (keyPath: string, value: string | number) => Promise; getAll: () => Promise; - add: (value: Object, key?: any) => Promise; + add: (value: Object, key?: any) => Promise; update: (value: any, key?: any) => Promise; deleteByID: (id: any) => Promise; deleteAll: () => Promise; diff --git a/src/plugin/src/connection/indexedDb/indexedb.js b/src/plugin/src/connection/indexedDb/indexedb.js index db3270c46..010e45a94 100644 --- a/src/plugin/src/connection/indexedDb/indexedb.js +++ b/src/plugin/src/connection/indexedDb/indexedb.js @@ -77,6 +77,13 @@ class _indexedDB { var _a, _b; (_b = (_a = tx) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a); resolve(e.target.result); + db.transaction; + }; + request.onerror = (e) => { + let data = { + error: e.target['error'] + }; + resolve(data); }; }) .catch(reject); @@ -94,11 +101,6 @@ class _indexedDB { (_b = (_a = tx) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a); resolve(e.target.result); }; - - request.onerror = (e) => { - console.log(value, key) - console.log(e) - } }) .catch(reject); }); @@ -152,6 +154,7 @@ class _indexedDB { request.onsuccess = e => { cursorCallback(e); resolve(); + // db.close(); }; }) .catch(reject); @@ -278,7 +281,6 @@ class _indexedDB { delete: async (methods) => { if (methods[methods.length - 1].methodName == 'delete' && methods[methods.length - 1].arguments == null) { - const customMethods = Object.create(methods); customMethods[methods.length - 1].methodName = 'execute'; const result = await this.requestHandler(TableSchema, config, queryId).select(customMethods); @@ -293,15 +295,11 @@ class _indexedDB { } else if (methods[methods.length - 1].methodName == 'delete' && typeof methods[methods.length - 1].arguments == 'object') { - const IdInObject = methods[methods.length - 1].arguments; const idValue = IdInObject[TableSchema.id.keyPath]; - - const result = await this.getActions(TableSchema.name, config).deleteByID(idValue) - console.log('delete7', IdInObject,idValue, result.type == 'success', result.type) return { queryId: queryId, - value: result.type == 'success' + value: await this.getActions(TableSchema.name, config).deleteByID(idValue) }; } else if (methods[methods.length - 1].methodName == 'delete' && @@ -310,8 +308,6 @@ class _indexedDB { queryId: queryId, value: await this.getActions(TableSchema.name, config).deleteAll() }; - } else { - console.log('delete else') } }, insert: async (methods) => { @@ -319,19 +315,19 @@ class _indexedDB { const rows = methods[0].arguments; for (let insert of rows) { const id = await this.getActions(TableSchema.name, config).add(insert); - createdObjKeys.push(id); + insert[TableSchema.id.keyPath] = id; } // return first element if (rows.length == 1) { return { queryId: queryId, - value: await this.getActions(TableSchema.name, config).getByID(createdObjKeys[0]) + value: rows[0] }; } else { return { queryId: queryId, - value: createdObjKeys + value: rows }; } } diff --git a/src/plugin/src/connection/intreface.d.ts b/src/plugin/src/connection/intreface.d.ts index b836048a4..5d31fbfcc 100644 --- a/src/plugin/src/connection/intreface.d.ts +++ b/src/plugin/src/connection/intreface.d.ts @@ -1,2 +1,2 @@ export declare type actionParam = 'insert' | 'update' | 'delete' | 'select'; -export declare type dbType = 'indexedDB'; +export declare type dbType = 'indexedDB' | 'localStorage'; diff --git a/src/plugin/src/connection/worker.js b/src/plugin/src/connection/worker.js index 83bea5d75..174c12cc3 100644 --- a/src/plugin/src/connection/worker.js +++ b/src/plugin/src/connection/worker.js @@ -1,17 +1,26 @@ import { indexedDB } from './indexedDb/indexedb.js'; onmessage = async (oEvent) => { const { TableSchema, DBconfig, queryId, action, arg } = oEvent.data; - const result = await indexedDB.requestHandler(TableSchema, DBconfig, queryId)[action](arg); + indexedDB.requestHandler(TableSchema, DBconfig, queryId)[action](arg).then((result) => { + try { + postMessage(result); + } + catch (error) { + postMessage({ + queryId: result.queryId, + value: undefined + }); + } + }).catch((result)=> { + try { + postMessage(result); + } + catch (error) { + postMessage({ + queryId: result.queryId, + value: undefined + }); + } + }) - console.log('return response', result) - try { - - postMessage(result); - } - catch (error) { - postMessage({ - queryId: result.queryId, - value: undefined - }); - } }; diff --git a/src/plugin/src/index.d.ts b/src/plugin/src/index.d.ts index f378d0fe3..da23bc5ac 100644 --- a/src/plugin/src/index.d.ts +++ b/src/plugin/src/index.d.ts @@ -1,6 +1,7 @@ import { Model } from './models/model.js'; +import { LocalStorage } from './models/model.js'; import { ModelReader } from './models/model.reader.js'; -import { registerModel } from './models/register-model.js'; +import { registerModel, migrate } from './models/register-model.js'; export declare const models: { Value(arg: any): {}; CharField(data?: import("./models/field/interface.js").CharFieldParams): import("./models/field/allFields.js").CharField; @@ -21,7 +22,8 @@ export declare const models: { }; }; Model: typeof Model; + LocalStorage: typeof LocalStorage; read: typeof ModelReader.read; + migrate: typeof migrate; register: typeof registerModel.register; - migrate: typeof registerModel.register; }; diff --git a/src/plugin/src/index.js b/src/plugin/src/index.js index 04ce4b13e..0db38b57f 100644 --- a/src/plugin/src/index.js +++ b/src/plugin/src/index.js @@ -1,8 +1,10 @@ import { Model } from './models/model.js'; +import { LocalStorage } from './models/model.js'; import * as Fields from './models/field/fields.js'; import { ModelReader } from './models/model.reader.js'; -import { registerModel } from './models/register-model.js'; -export const models = Object.assign(Object.assign({ Model, read: ModelReader.read, register: registerModel.register, migrate: registerModel.register }, Fields), { Value(arg) { +import { registerModel, migrate } from './models/register-model.js'; +export const models = Object.assign(Object.assign({ Model, + LocalStorage, read: ModelReader.read, migrate: migrate, register: registerModel.register }, Fields), { Value(arg) { if (arg == 'null') { return {}; } diff --git a/src/plugin/src/models/model.d.ts b/src/plugin/src/models/model.d.ts index 73f32f0b7..1574ec608 100644 --- a/src/plugin/src/models/model.d.ts +++ b/src/plugin/src/models/model.d.ts @@ -1,5 +1,5 @@ import { getParams } from './model.interface.js'; -import { DatabaseSchema, TableSchema } from './register-modal.interface.js'; +import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema } from './register-modal.interface.js'; import { ModelManager } from './model-manager.js'; export declare class Model extends ModelManager { constructor(obg?: any); @@ -47,3 +47,18 @@ export declare class Model extends ModelManager { all: () => Promise; }; } +export declare class LocalStorage { + constructor(); + static save(data?: Object): void; + static get(): any; + static getModelName(): string; + static getDBSchema(): DatabaseSchemaLocalStorage; + static getTableSchema(): TableSchema; + private static getIgnoreAttributes; + static ignoreAttributes(attributesStartWidth?: string[]): void; + private static getFields; + private static formValidation; + static clear(): void; + static clearComponent(): void; + static clearStorage(): void; +} diff --git a/src/plugin/src/models/model.js b/src/plugin/src/models/model.js index 941b7f573..9ed0a8a30 100644 --- a/src/plugin/src/models/model.js +++ b/src/plugin/src/models/model.js @@ -1,7 +1,7 @@ var _a, _b; import { hashCode, uniqueGenerator } from '../utils.js'; import { ModelManager } from './model-manager.js'; -import { models, modelsConfig } from './register-model.js'; +import { models, modelsConfig, modelsConfigLocalStorage } from './register-model.js'; import { FieldType } from '../sql/query/interface.js'; import * as Fields from './field/allFields.js'; let methods = {} = {}; @@ -134,6 +134,10 @@ export class Model extends (_b = ModelManager) { delete newInstance[fieldName]; } } + Object.defineProperty(newInstance, TableSchema.id.keyPath, { + configurable: false, + writable: false + }); delete newInstance.obj; return newInstance; } @@ -211,11 +215,16 @@ export class Model extends (_b = ModelManager) { const queryId = uniqueGenerator(); const createObject = await super.obj(DBconfig, TableSchema).create(_methods, queryId); if (createObject) { - const ModelName = this.getModelName(); - let newInstance = new models[ModelName](); - Object.assign(newInstance, createObject); - delete newInstance.obj; - return newInstance; + if (typeof createObject[TableSchema.id.keyPath] == 'object') { + throw (createObject[TableSchema.id.keyPath].error); + } + else { + const ModelName = this.getModelName(); + let newInstance = new models[ModelName](); + Object.assign(newInstance, createObject); + delete newInstance.obj; + return newInstance; + } } else { } @@ -303,3 +312,82 @@ Model.object = ({ queryId = uniqueGenerator(), DBconfig, TableSchema, some = nul } }; }; +export class LocalStorage { + constructor() { } + static save(data = {}) { + const dataToSave = this.getFields(Object.assign(this, Object.assign({}, data))); + const key = this.getTableSchema().id; + localStorage.setItem(key.keyPath, JSON.stringify(dataToSave)); + } + static get() { + const key = this.getTableSchema().id; + const restedData = JSON.parse(localStorage.getItem(key.keyPath)); + Object.assign(this, Object.assign({}, restedData)); + return restedData; + } + static getModelName() { + return this.toString().split('(' || /s+/)[0].split(' ' || /s+/)[1]; + } + static getDBSchema() { + const modalName = this.getModelName(); + return modelsConfigLocalStorage[modalName].DatabaseSchema; + } + static getTableSchema() { + const modalName = this.getModelName(); + return modelsConfigLocalStorage[modalName].TableSchema; + } + static getIgnoreAttributes() { + return false; + } + static ignoreAttributes(attributesStartWidth = []) { + if (!this.getIgnoreAttributes()) { + this.getIgnoreAttributes = () => { + return attributesStartWidth; + }; + } + } + static getFields(arg) { + const TableSchema = this.getTableSchema(); + const filteredArgs = {}; + const fieldsName = TableSchema.fields.map((field) => field.name); + const Attributes = this.getIgnoreAttributes(); + const fieldNameFilter = fieldsName.filter((fieldName) => { + if (Attributes) { + for (let Attribute of Attributes) { + if (fieldName.startsWith(Attribute)) { + return false; + } + } + } + return true; + }); + for (let fieldName of fieldNameFilter) { + if (arg.hasOwnProperty(fieldName)) { + filteredArgs[fieldName] = arg[fieldName]; + } + } + return filteredArgs; + } + static formValidation(data) { + const TableSchema = this.getTableSchema(); + for (let field of TableSchema.fields) { + const Field = new Fields[field.className](field.fieldAttributes); + const FieldValue = data[field.name]; + if (!Field.valid(FieldValue)) { + throw ('invalid insert into ' + TableSchema.name + ', invalid value for field ' + field.name + ' = ' + JSON.stringify(FieldValue)); + } + } + return true; + } + static clear() { + this.clearComponent(); + this.clearStorage(); + } + static clearComponent() { + const key = this.getTableSchema().id; + } + static clearStorage() { + const key = this.getTableSchema().id; + localStorage.removeItem(key.keyPath); + } +} diff --git a/src/plugin/src/models/model.reader.d.ts b/src/plugin/src/models/model.reader.d.ts index bc4188236..8d6d3ce87 100644 --- a/src/plugin/src/models/model.reader.d.ts +++ b/src/plugin/src/models/model.reader.d.ts @@ -9,3 +9,13 @@ export declare class ModelReader { attributes: AttributesMap<"maxLength" | "minLength" | "choices" | "primaryKey" | "unique" | "autoIncrement" | "type" | "model" | "blank" | "default" | "onDelete" | "foreignKey", string[]>; }; } +export declare class LocalStorageModelReader { + static read(modelClassRepresentation: any): { + modelName: string; + fields: { + [key: string]: any; + }; + attributes: AttributesMap<"maxLength" | "minLength" | "choices" | "primaryKey" | "unique" | "autoIncrement" | "type" | "model" | "blank" | "default" | "onDelete" | "foreignKey", string[]>; + fieldTypes: FieldsMap<"CharField" | "JsonField" | "AutoField" | "BigIntegerField" | "DateField" | "IntegerField" | "TextField" | "BooleanField" | "OneToOneField" | "ForeignKey" | "ManyToManyField" | "indexedDBJsonField" | "indexedDBArrayField" | "DateTimeField", string[]>; + }; +} diff --git a/src/plugin/src/models/model.reader.js b/src/plugin/src/models/model.reader.js index 37e537b3e..397660b36 100644 --- a/src/plugin/src/models/model.reader.js +++ b/src/plugin/src/models/model.reader.js @@ -32,3 +32,22 @@ export class ModelReader { }; } } +export class LocalStorageModelReader { + static read(modelClassRepresentation) { + const classInstance = modelClassRepresentation; + const fieldTypes = {}; + const attributes = {}; + const modelName = classInstance.getModelName(); + const fields = {}; + for (const [fieldName, Field] of Object.entries(classInstance)) { + // const type = Field?.fieldName + fields[fieldName] = Field || null; + } + return { + modelName, + fields, + attributes, + fieldTypes + }; + } +} diff --git a/src/plugin/src/models/register-model.d.ts b/src/plugin/src/models/register-model.d.ts index c87bd5309..a3d81b004 100644 --- a/src/plugin/src/models/register-model.d.ts +++ b/src/plugin/src/models/register-model.d.ts @@ -1,11 +1,11 @@ -import { Model } from './model.js'; -import { DatabaseSchema, TableSchema } from './register-modal.interface.js'; +import { Model, LocalStorage } from './model.js'; +import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema, TableSchemaLocalStorage } from './register-modal.interface.js'; import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js'; interface register { databaseName: string; version: number; - type: 'indexedDB'; - models: typeof Model[]; + type: 'indexedDB' | 'localStorage'; + models: typeof Model[] | typeof LocalStorage[]; } export declare const models: {}; export declare const modelsConfig: { @@ -17,10 +17,21 @@ export declare const modelsConfig: { }; }; }; +export declare const modelsLocalStorage: {}; +export declare const modelsConfigLocalStorage: { + [key: string]: { + DatabaseSchema: DatabaseSchemaLocalStorage; + TableSchema: TableSchemaLocalStorage; + }; +}; +export declare function migrate(register: register): void; export declare class registerModel { static register(entries: register): Promise; static manyToManyRelationShip(foreignKeyField: ManyToManyField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): Model; } +export declare class registerLocalStorage { + static register(entries: register): Promise; +} export declare class ModelEditor { static addMethodOneToOneField(foreignKeyField: OneToOneField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void; static addMethodForeignKey(foreignKeyField: ForeignKey, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void; diff --git a/src/plugin/src/models/register-model.js b/src/plugin/src/models/register-model.js index 794ff592b..4281870bb 100644 --- a/src/plugin/src/models/register-model.js +++ b/src/plugin/src/models/register-model.js @@ -1,5 +1,5 @@ import { Model } from './model.js'; -import { ModelReader } from './model.reader.js'; +import { LocalStorageModelReader, ModelReader } from './model.reader.js'; import { indexedDB } from './../connection/indexedDb/indexedb.js'; import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js'; import { uncapitalize } from '../utils.js'; @@ -7,6 +7,16 @@ import { FieldType } from '../sql/query/interface.js'; import { ModelMigrations } from './mode-migrations.js'; export const models = {}; export const modelsConfig = {}; +export const modelsLocalStorage = {}; +export const modelsConfigLocalStorage = {}; +export function migrate(register) { + if (register.type == 'indexedDB') { + registerModel.register(register); + } + else if (register.type == 'localStorage') { + registerLocalStorage.register(register); + } +} export class registerModel { static async register(entries) { var _a, _b, _c; @@ -122,6 +132,65 @@ export class registerModel { }); } } +export class registerLocalStorage { + static async register(entries) { + const databaseSchema = { + databaseName: entries.databaseName, + version: entries.version, + type: 'localStorage', + stores: [] + }; + for (const modelClassRepresentations of entries.models) { + const ModelName = modelClassRepresentations.getModelName(); + modelsLocalStorage[ModelName] = modelClassRepresentations; + } + let index = 0; + for (const modelClassRepresentations of entries.models) { + const { fields, modelName, attributes, fieldTypes } = LocalStorageModelReader.read(modelClassRepresentations); + // const idFieldName = attributes?.primaryKey?.shift() + databaseSchema.stores.push({ + name: modelName, + id: { + keyPath: modelName, + type: FieldType.VARCHAR, + autoIncrement: false + }, + attributes: attributes, + fields: [], + fieldTypes + }); + for (const [fieldName, Field] of Object.entries(fields)) { + databaseSchema.stores[index].fields.push({ + name: fieldName, + keyPath: fieldName, + options: { + unique: false, + type: null + }, + className: Field === null || Field === void 0 ? void 0 : Field.fieldName, + fieldAttributes: Object.assign({}, Field) + }); + } + index++; + } + for (const modelClassRepresentations of entries.models) { + const ModelName = modelClassRepresentations.getModelName(); + const tableSchema = databaseSchema.stores.find((e) => e.name == ModelName); + modelClassRepresentations.getDBSchema = () => { + return databaseSchema; + }; + modelClassRepresentations.getTableSchema = () => { + return tableSchema; + }; + modelsConfigLocalStorage[ModelName] = { + DatabaseSchema: databaseSchema, + TableSchema: tableSchema + }; + modelsLocalStorage[ModelName] = modelClassRepresentations; + } + ModelMigrations.migrationsState(true); + } +} export class ModelEditor { static addMethodOneToOneField(foreignKeyField, FieldName, modelName, databaseSchema) { const foreignKeyFieldModel = foreignKeyField.model; diff --git a/version/git-version.ts b/version/git-version.ts index 00a8aeade..b0be56738 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "13c50fe49", - "SHA": "13c50fe491fdfd6bc7e0d44c3417b2e89ebbfbd8", + "shortSHA": "ec475c76b", + "SHA": "ec475c76beabb561946c54be10244bdc854900bd", "branch": "no_bug_movemente", "lastCommitAuthor": "'Eudes Inácio'", - "lastCommitTime": "'Mon Feb 6 19:12:25 2023 +0100'", - "lastCommitMessage": "Peter bug solved 15 min", - "lastCommitNumber": "4750", + "lastCommitTime": "'Thu Feb 9 11:25:57 2023 +0100'", + "lastCommitMessage": "Required fields description added to forms", + "lastCommitNumber": "4751", "change": "", - "changeStatus": "On branch no_bug_movemente\nYour branch is up to date with 'origin/no_bug_movemente'.\n\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: capacitor.config.ts\n\tmodified: src/app/home/home.page.ts\n\tmodified: src/app/modals/create-process/create-process.page.html\n\tmodified: src/app/modals/document-set-up-meeting/document-set-up-meeting.page.html\n\tmodified: src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts\n\tmodified: src/app/pages/agenda/agenda.page.html\n\tmodified: src/app/pages/agenda/agenda.page.ts\n\tmodified: src/app/pages/agenda/new-event/new-event.page.html\n\tmodified: src/app/pages/agenda/new-event/new-event.page.scss\n\tmodified: src/app/pages/agenda/new-event/new-event.page.ts\n\tmodified: src/app/pages/gabinete-digital/event-list/event-list.page.html\n\tmodified: src/app/pages/gabinete-digital/event-list/event-list.page.ts\n\tmodified: src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.html\n\tmodified: src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html\n\tmodified: src/app/pages/publications/edit-action/edit-action.page.html\n\tmodified: src/app/pages/publications/new-action/new-action.page.html\n\tmodified: src/app/pages/publications/new-action/new-action.page.scss\n\tmodified: src/app/pages/publications/new-publication/new-publication.page.html\n\tmodified: src/app/pages/publications/new-publication/new-publication.page.scss\n\tmodified: src/app/services/events.service.ts\n\tmodified: src/app/services/native-notification.service.ts\n\tmodified: src/app/shared/agenda/edit-event-to-approve/edit-event-to-approve.page.html\n\tmodified: src/app/shared/agenda/edit-event/edit-event.page.html\n\tmodified: src/app/shared/agenda/new-event/new-event.page.html\n\tmodified: src/app/shared/agenda/new-event/new-event.page.scss\n\tmodified: src/app/shared/gabinete-digital/edit-event-to-approve/edit-event.page.html\n\tmodified: src/app/shared/gabinete-digital/edit-event-to-approve/edit-event.page.scss\n\tmodified: src/app/shared/publication/edit-action/edit-action.page.html\n\tmodified: src/app/shared/publication/new-action/new-action.page.html\n\tmodified: src/app/shared/publication/new-action/new-action.page.scss\n\tmodified: src/app/shared/publication/new-publication/new-publication.page.html\n\tmodified: src/app/shared/publication/new-publication/new-publication.page.scss\n\tnew file: src/assets/images/exclamation-mark.png\n\tnew file: src/assets/images/exclamation_mark.svg\n\tmodified: src/environments/environment.prod.ts\n\tmodified: src/environments/environment.ts", + "changeStatus": "On branch no_bug_movemente\nYour branch and 'origin/no_bug_movemente' have diverged,\nand have 1 and 10 different commits each, respectively.\n (use \"git pull\" to merge the remote branch into yours)\n\nAll conflicts fixed but you are still merging.\n (use \"git commit\" to conclude merge)\n\nChanges to be committed:\n\tmodified: src/app/home/home.page.html\n\tmodified: src/app/home/home.page.ts\n\tmodified: src/app/modals/create-process/create-process.page.html\n\tmodified: src/app/modals/create-process/create-process.page.ts\n\tmodified: src/app/modals/document-set-up-meeting/document-set-up-meeting.page.html\n\tmodified: src/app/modals/document-set-up-meeting/document-set-up-meeting.page.ts\n\tmodified: src/app/models/dailyworktask.model.ts\n\tmodified: src/app/pages/agenda/agenda.page.html\n\tmodified: src/app/pages/agenda/agenda.page.ts\n\tmodified: src/app/pages/agenda/edit-event/edit-event.page.html\n\tmodified: src/app/pages/agenda/new-event/new-event.page.html\n\tmodified: src/app/pages/agenda/new-event/new-event.page.ts\n\tmodified: src/app/pages/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts\n\tmodified: src/app/pages/gabinete-digital/diplomas/diplomas.page.ts\n\tmodified: src/app/pages/gabinete-digital/event-list/event-list.page.html\n\tmodified: src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.html\n\tmodified: src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html\n\tmodified: src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.ts\n\tmodified: src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.html\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.ts\n\tmodified: src/app/pipes/expediente-task.pipe.ts\n\tnew file: src/app/services/active-tab.service.spec.ts\n\tnew file: src/app/services/active-tab.service.ts\n\tmodified: src/app/services/chat/chat-system.service.ts\n\tmodified: src/app/services/chat/message.service.ts\n\tmodified: src/app/services/chat/room.service.ts\n\tmodified: src/app/services/events.service.ts\n\tmodified: src/app/services/processes.service.ts\n\tmodified: src/app/shared/agenda/event-list/event-list.page.html\n\tmodified: src/app/shared/agenda/event-list/event-list.page.ts\n\tmodified: src/app/shared/agenda/new-event/new-event.page.html\n\tmodified: src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.html\n\tmodified: src/app/shared/gabinete-digital/diplomas-assinar/diplomas-assinar.page.ts\n\tmodified: src/app/shared/gabinete-digital/diplomas/diplomas.page.ts\n\tmodified: src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html\n\tmodified: src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts\n\tmodified: src/app/shared/header/header.page.html\n\tmodified: src/app/shared/header/header.page.ts\n\tmodified: src/plugin/src/connection/indexedDb/connector.d.ts\n\tmodified: src/plugin/src/connection/indexedDb/connector.js\n\tmodified: src/plugin/src/connection/indexedDb/indexedb.d.ts\n\tmodified: src/plugin/src/connection/indexedDb/indexedb.js\n\tmodified: src/plugin/src/connection/intreface.d.ts\n\tmodified: src/plugin/src/connection/worker.js\n\tmodified: src/plugin/src/index.d.ts\n\tmodified: src/plugin/src/index.js\n\tmodified: src/plugin/src/models/model.d.ts\n\tmodified: src/plugin/src/models/model.js\n\tmodified: src/plugin/src/models/model.reader.d.ts\n\tmodified: src/plugin/src/models/model.reader.js\n\tmodified: src/plugin/src/models/register-model.d.ts\n\tmodified: src/plugin/src/models/register-model.js", "changeAuthor": "eudes.inacio" } \ No newline at end of file