Parcourir la source

notification debug and enhancements

tigger il y a 1 an
Parent
commit
9dc7cfc618
3 fichiers modifiés avec 18 ajouts et 124 suppressions
  1. 17 14
      src/app/app.component.ts
  2. 0 109
      src/app/decorators/leave.notification.decorator.ts
  3. 1 1
      src/dependencies/fis

+ 17 - 14
src/app/app.component.ts

@@ -1,4 +1,4 @@
-import { Component, HostListener, OnInit } from '@angular/core';
+import { Component, HostListener, inject, OnInit } from '@angular/core';
 import { ActivatedRoute, Router, RouterModule, RouterOutlet, RoutesRecognized } from '@angular/router';
 import { MatModule } from '../dependencies/angularlib/mat.module';
 import { Angularlib } from 'angularlib/angularlib.module';
@@ -10,7 +10,7 @@ import { CommonModule, DatePipe } from '@angular/common';
 import { ChangeLanguage } from 'angularlib/labels/label.actions';
 import { ComponentService } from 'angularlib/component.service';
 import { NotificationModule } from 'angularlib/notification/notification.module';
-import { NOTIFICATION_STATE_TOKEN, NotificationState } from 'angularlib/notification/notification.state';
+import { NOTIFICATION_STATE_TOKEN } from 'angularlib/notification/notification.state';
 import { Notification } from 'angularlib/notification/notification.actions';
 import { generateId } from 'angularlib/base.service';
 import { Store } from '@ngxs/store';
@@ -18,9 +18,10 @@ import config from '../config/config.json';
 import { UIAuthActions } from 'angularlib/login/state/login.actions';
 import { Platform } from '@angular/cdk/platform';
 import { AppSettingsAction } from 'angularlib/ui.state/ui.state.actions';
-import { LeaveNotificationDecorator } from './decorators/leave.notification.decorator';
+import { PushNotificationDecorator as LeavePushNotif } from 'fis/leave/decorators/push.notification.decorator';
 import { FISMessaging } from 'fis/index';
 import { BusinessDataModule } from 'fis/business.data/business.data.module';
+import { NotificationService } from 'angularlib/notification/notification.service';
 
 @Component({
   selector: 'app-root',
@@ -68,8 +69,10 @@ export class AppComponent extends BaseComponent implements OnInit {
   /**number of notifications */
   protected notificationCount: number = 0;
 
-  private leaveNotification: LeaveNotificationDecorator<any>;
-  private leaveNotificationSubscription: Subscription;
+  private leavePushNotif$: Subscription;
+
+  private messaging = inject(FISMessaging);
+  private notification = inject(NotificationService);
 
   constructor(
     private router: Router,
@@ -82,7 +85,6 @@ export class AppComponent extends BaseComponent implements OnInit {
     private platform: Platform
   ) {
     super(store,cs);
-    this.leaveNotification = new LeaveNotificationDecorator(this,{serviceId:'09 - Leave Application'});
   }
 
   @HostListener('window:mousedown')
@@ -109,16 +111,17 @@ export class AppComponent extends BaseComponent implements OnInit {
     this.loginService.user$.pipe(untilDestroy(this)).subscribe((user:any) => {
       if (user?.fisInfo) {
         this.timeout.pipe(untilDestroy(this),takeUntil(this.loginService.loggedOut)).subscribe();
-        if (!this.leaveNotificationSubscription) {
-          this.leaveNotificationSubscription = this.leaveNotification.subscribe({
-            next: async notif => {
-              
-            }
-          });
+        if (this.leavePushNotif$ === undefined) {
+          this.leavePushNotif$ = new LeavePushNotif(
+            this,
+            this.loginService,
+            this.messaging,
+            this.notification
+          ).subscribe();
         }
       } else {
-        if (this.leaveNotificationSubscription) this.leaveNotificationSubscription.unsubscribe();
-        this.leaveNotificationSubscription = undefined;
+        if (this.leavePushNotif$) this.leavePushNotif$.unsubscribe();
+        this.leavePushNotif$ = undefined;
       }
     });
 

+ 0 - 109
src/app/decorators/leave.notification.decorator.ts

@@ -1,109 +0,0 @@
-import { formatDate } from "@angular/common";
-import { inject } from "@angular/core";
-import { untilDestroy } from "angularlib/base.component";
-import { NotificationService } from "angularlib/notification/notification.service";
-import { DecoratorSubject } from "fis-commons/decorator";
-import { debounceNotification } from "fis-commons/notification/operators";
-import { skipUndefined } from "fis-commons/observable/operators";
-import { adjustISOTimezoneOffset } from "fis/fis.date";
-import { FISMessaging } from "fis/index";
-import { NotificationRequest } from "fis/tm/tm.i";
-import { firstValueFrom } from "rxjs";
-
-export class LeaveNotificationDecorator<T> extends DecoratorSubject<T> {
-    messaging = inject(FISMessaging);
-    notification = inject(NotificationService);
-    subscriptionId;
-    empRoleId;
-
-    constructor(
-        private component: any,
-        request?: NotificationRequest
-    ) {
-        super();
-        this.empRoleId = component.loginService.user?.fisInfo?.defaultEmpRoleId;
-        this.messaging.Notification(request).pipe(untilDestroy(component),debounceNotification(200)).subscribe({
-            next: (notif:any) => {
-                if (!this.subscriptionId) this.subscriptionId = notif?.data?.SubscriptionData?.subscriptionId;
-                this.onReceiveNotification(notif)
-                this.next(notif);
-            },
-            error: error => this.error(error),
-            complete: () => this.complete()
-        });
-    }
-
-    private async onReceiveNotification(notif) {
-        const OPERATION = notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationData?.Operation
-            || notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationModuleData?.extendedProperties?.operation;
-        const DOC_CODE = notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationData?.Code
-            || notif.data?.data?.NotificationMicroserviceData?.uiMessage?.NotificationModuleData?.extendedProperties?.docRefNo;
-        let leave;
-        let applicant;
-        await firstValueFrom(this.messaging.GetData({
-            serviceId: 'Leave Application Data',
-            parameter: `__clearSearchValue__=true,caching=false`
-        },{liveResponsesOnly:true}).pipe(skipUndefined(),debounceNotification(100))).then(res => {
-            leave = res.GenericFisData?.data?.DataService?.rows?.row?.find(x => x.column.ps_doc_header_ps_doc_ref_no === DOC_CODE)?.column;
-        }).catch(error => console.error(error));
-        if (leave) {
-            await firstValueFrom(this.messaging.GetData({
-                serviceId: 'Employee Role Data',
-                parameter: `roleId=${leave?.ps_doc_leave_emp_role_id},__clearSearchValue__=true,caching=false`
-            }).pipe(skipUndefined())).then(res => {
-                applicant = res.GenericFisData?.data?.DataService?.rows?.row[0]?.column || res.data?.GenericFisData?.data?.DataService?.rows?.row[0]?.column;
-            }).catch(error => console.error(error));
-            switch (OPERATION?.toLowerCase()) {
-                case 'new': {
-                    this.notification.notify({
-                        message:{
-                        title:{key:'new_leave_applied',default:'New Leave Applied'},
-                        desc: `${applicant?.pers_name}`,
-                        timestamp: new Date(),
-                        },
-                        action: () => {this.component.cs.navigate('/leave/approval')}
-                    });
-                    break;
-                }
-                case 'modify': {
-                    this.notification.notify({
-                        message:{
-                        title: {key:'leave_modified',default:'Leave Modified'},
-                        desc: `${applicant?.pers_name}`,
-                        timestamp: new Date(),
-                        },
-                        action: () => {this.component.cs.navigate('/leave/approval')}
-                    });
-                    break;
-                }
-                case 'post': {
-                    if (leave?.ps_doc_leave_emp_role_id !== this.empRoleId) break;
-                    const DATE_FROM = formatDate(adjustISOTimezoneOffset(leave.ps_doc_leave_ps_dt_from),'yyyy-MM-dd EEE',this.component.cs.appSettings.locale);
-                    this.notification.notify({
-                        message:{
-                        title: {key:'leave_approved',default:'Leave Approved'},
-                        desc: {key:`#{leave_date_from}: ${DATE_FROM}`,default:''},
-                        timestamp: new Date(),
-                        },
-                        action: () => {this.component.cs.navigate('/leave',{type:'view',detailsTabIndex:1})}
-                    });
-                    break;
-                }
-                case 'cancel': {
-                    if (leave?.ps_doc_leave_emp_role_id !== this.empRoleId) break;
-                    const DATE_FROM = formatDate(adjustISOTimezoneOffset(leave.ps_doc_leave_ps_dt_from),'yyyy-MM-dd EEE',this.component.cs.appSettings.locale);
-                    this.notification.notify({
-                        message:{
-                        title: {key:'leave_cancelled',default:'Leave Cancelled'},
-                        desc: {key:`#{leave_date_from}: ${DATE_FROM}`,default:''},
-                        timestamp: new Date(),
-                        },
-                        action: () => {this.component.cs.navigate('/leave',{type:'view',detailsTabIndex:2})}
-                    });
-                    break;
-                }
-                default: break;
-            }
-        }
-    }
-}

+ 1 - 1
src/dependencies/fis

@@ -1 +1 @@
-Subproject commit c7f0d75ab5ec915e779c15cd74b8ea81edc18c37
+Subproject commit 2d43afbae85955c959f7b8dc89e552ec7cabf9b1