|
|
@@ -13,7 +13,7 @@ import { lastValueFrom } from 'rxjs';
|
|
|
import { UsersProfilesService } from './../../services/users-profiles.service';
|
|
|
import { SocketService } from './../../services/socket.service';
|
|
|
import { EncService } from './../../services/enc/enc.service';
|
|
|
-import { Component, Inject, OnInit } from '@angular/core';
|
|
|
+import { Component, Inject, OnInit, ViewChild } from '@angular/core';
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { LoginDataService } from 'src/app/services/login/login-data.service';
|
|
|
@@ -43,6 +43,7 @@ import { DOCUMENT } from '@angular/common';
|
|
|
import { NotificationsService } from 'src/app/services/notifications.service';
|
|
|
import { FunctionsService } from 'src/app/services/functions.service';
|
|
|
import { NotificationDialogComponent } from './notification-dialog/notification-dialog.component';
|
|
|
+import { MatSidenav } from '@angular/material/sidenav';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-template',
|
|
|
@@ -75,6 +76,8 @@ export class TemplateComponent implements OnInit {
|
|
|
unreadNotifications: number;
|
|
|
totalNotifications: NotificationsListItem[];
|
|
|
|
|
|
+ @ViewChild('rightDrawer') sidenav?: MatSidenav;
|
|
|
+
|
|
|
constructor(
|
|
|
@Inject(DOCUMENT) private _document: Document,
|
|
|
public resourcesService: ResourcesService,
|
|
|
@@ -457,13 +460,22 @@ export class TemplateComponent implements OnInit {
|
|
|
this.resourcesService.openSnackBar(notification.msg);
|
|
|
}else{
|
|
|
notification.response.FECHA = this._functionsService.getDateTimeHour(notification.response.FECREG);
|
|
|
+ notification.response.FECREG_DISP = this._functionsService.notificationDate(notification.response.FECREG);
|
|
|
+
|
|
|
let audienceArr = JSON.parse(notification.response.AUDIENCIA);
|
|
|
let idUserDec = await this._encService.decrypt(idUser);
|
|
|
|
|
|
for(const user of audienceArr as string[]){
|
|
|
let userDec = await this._encService.decrypt(user);
|
|
|
if(userDec == idUserDec){
|
|
|
+ let notificationsAux = this.totalNotifications;
|
|
|
+ notificationsAux.reverse();
|
|
|
+ notificationsAux.push(notification.response);
|
|
|
+ notificationsAux.reverse();
|
|
|
+
|
|
|
+ this.totalNotifications = notificationsAux;
|
|
|
this.notificationsForPanel.push(notification.response);
|
|
|
+ this.unreadNotifications++;
|
|
|
|
|
|
setTimeout(() => {
|
|
|
let divNotification = this._document.getElementById(`notification-${notification.response.ID_NOTIFICACION}`);
|
|
|
@@ -507,6 +519,16 @@ export class TemplateComponent implements OnInit {
|
|
|
|
|
|
this.isLoading = false;
|
|
|
this.checkCatalogues();
|
|
|
+
|
|
|
+ setInterval(() => {
|
|
|
+ let notificationsAux: NotificationsListItem[] = [];
|
|
|
+ for(const notification of this.totalNotifications){
|
|
|
+ notification.FECREG_DISP = this._functionsService.notificationDate(notification.FECREG);
|
|
|
+ notificationsAux.push(notification);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.totalNotifications = notificationsAux;
|
|
|
+ }, 30000);
|
|
|
}catch(error: any){
|
|
|
let msg = '';
|
|
|
if(error.error == undefined){
|
|
|
@@ -545,7 +567,7 @@ export class TemplateComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- notification.FECREG = this._functionsService.notificationDate(notification.FECREG)!;
|
|
|
+ notification.FECREG_DISP = this._functionsService.notificationDate(notification.FECREG)!;
|
|
|
notificationsArr.push(notification);
|
|
|
}
|
|
|
|
|
|
@@ -777,7 +799,25 @@ export class TemplateComponent implements OnInit {
|
|
|
|
|
|
}
|
|
|
|
|
|
- openNotification(idNotification: string){
|
|
|
+ openNotification(idNotification: string, isFromSidenav: boolean){
|
|
|
+ let notificationFilt = this.totalNotifications.filter(item => item.ID_NOTIFICACION == idNotification);
|
|
|
+ if(notificationFilt.length > 0){
|
|
|
+ let notification = notificationFilt[0];
|
|
|
+ notification.READED = true;
|
|
|
+
|
|
|
+ let notificationsAux: NotificationsListItem[] = [];
|
|
|
+ for(const notificationObj of this.totalNotifications){
|
|
|
+ if(notificationObj.ID_NOTIFICACION == notification.ID_NOTIFICACION){
|
|
|
+ notificationsAux.push(notification);
|
|
|
+ }else{
|
|
|
+ notificationsAux.push(notificationObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.totalNotifications = notificationsAux;
|
|
|
+ this.unreadNotifications--;
|
|
|
+ }
|
|
|
+
|
|
|
this.closeNotification(idNotification);
|
|
|
let dialogRef = this._dialg.open(NotificationDialogComponent, {
|
|
|
width: '520px',
|
|
|
@@ -787,8 +827,44 @@ export class TemplateComponent implements OnInit {
|
|
|
});
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(res => {
|
|
|
- let resArr = res.split('|');
|
|
|
- console.log(resArr);
|
|
|
+ if(res != null && res != undefined && res != ''){
|
|
|
+ let resArr = res.split('|');
|
|
|
+ if(resArr.length < 2){
|
|
|
+ this.resourcesService.openSnackBar('La acción seleccionada es inválida.');
|
|
|
+ }else if(resArr[0] == 'start'){
|
|
|
+ this.startWorkOrder(resArr[1], resArr[2]);
|
|
|
+ }else{
|
|
|
+ console.log(resArr);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isFromSidenav){
|
|
|
+ this.sidenav?.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ private async startWorkOrder(idOrder: string, orderType: string){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let idOrderEnc = await this._encService.encrypt(idOrder);
|
|
|
+ let formData = new FormData();
|
|
|
+
|
|
|
+ formData.append('id_user', idUser);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('id_order', idOrderEnc);
|
|
|
+
|
|
|
+ if(orderType == 'Correctivo'){
|
|
|
+ console.log(formData);
|
|
|
+ }
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.resourcesService.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this.resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|