|
|
@@ -38,7 +38,7 @@ import { TypeFormSubcontract } from 'src/app/interfaces/personal-managment/subco
|
|
|
import { EquipmentManagementService } from 'src/app/services/equipment-management.service';
|
|
|
import { EquipmentDetails, EquipmentDetailsResponse } from 'src/app/interfaces/equipment-management.interface';
|
|
|
import { EquipmentAlertComponent } from './equipment-alert/equipment-alert.component';
|
|
|
-import { NotificationDetailsResponse, NotificationsListItem } from 'src/app/interfaces/notification.interface';
|
|
|
+import { NotificationDetailsResponse, NotificationsListItem, NotificationsListResponse } from 'src/app/interfaces/notification.interface';
|
|
|
import { DOCUMENT } from '@angular/common';
|
|
|
import { NotificationsService } from 'src/app/services/notifications.service';
|
|
|
import { FunctionsService } from 'src/app/services/functions.service';
|
|
|
@@ -72,6 +72,8 @@ export class TemplateComponent implements OnInit {
|
|
|
|
|
|
modulesActivated = false;
|
|
|
notificationsForPanel: NotificationsListItem[];
|
|
|
+ unreadNotifications: number;
|
|
|
+ totalNotifications: NotificationsListItem[];
|
|
|
|
|
|
constructor(
|
|
|
@Inject(DOCUMENT) private _document: Document,
|
|
|
@@ -95,6 +97,8 @@ export class TemplateComponent implements OnInit {
|
|
|
this.menuItems = [];
|
|
|
this.nestedMenu = [];
|
|
|
this.notificationsForPanel = [];
|
|
|
+ this.unreadNotifications = 0;
|
|
|
+ this.totalNotifications = [];
|
|
|
}
|
|
|
|
|
|
async ngOnInit() {
|
|
|
@@ -495,6 +499,8 @@ export class TemplateComponent implements OnInit {
|
|
|
|
|
|
let userName = localStorage.getItem('nombre_usuario');
|
|
|
let name = await this._encService.decrypt(userName!);
|
|
|
+
|
|
|
+ await this.getNotifications();
|
|
|
|
|
|
this.userName = name;
|
|
|
this.nestedMenu = menu.response;
|
|
|
@@ -516,6 +522,46 @@ export class TemplateComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async getNotifications(){
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let notifications: NotificationsListResponse = await lastValueFrom(this._notificationsService.getNotificationsByUser(idUser, 1));
|
|
|
+
|
|
|
+ if(notifications.error){
|
|
|
+ this.openDialog(notifications.msg);
|
|
|
+ }else{
|
|
|
+ let notificationsArr: NotificationsListItem[] = [];
|
|
|
+ let idUserDec = await this._encService.decrypt(idUser);
|
|
|
+
|
|
|
+ for(const notification of notifications.response){
|
|
|
+ let scopeArr = JSON.parse(notification.ALCANCE);
|
|
|
+ for(const item of scopeArr){
|
|
|
+ let userDec = await this._encService.decrypt(item.USUARIO);
|
|
|
+ if(userDec == idUserDec && item.ESTADO == 'No leído'){
|
|
|
+ this.unreadNotifications++;
|
|
|
+ notification.READED = false;
|
|
|
+ }else if(userDec == idUserDec && item.ESTADO == 'Leído'){
|
|
|
+ notification.READED = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ notification.FECREG = this._functionsService.orderDate(notification.FECREG)!;
|
|
|
+ notificationsArr.push(notification);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.totalNotifications = notificationsArr;
|
|
|
+ }
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.openDialog('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.openDialog('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this.openDialog(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
closeNotification(id: string){
|
|
|
let notification = this._document.getElementById(`notification-${id}`);
|
|
|
//Eliminar la clase de entrada
|
|
|
@@ -741,7 +787,8 @@ export class TemplateComponent implements OnInit {
|
|
|
});
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(res => {
|
|
|
- console.log(res);
|
|
|
+ let resArr = res.split('|');
|
|
|
+ console.log(resArr);
|
|
|
});
|
|
|
}
|
|
|
}
|