Skip to content

Commit

Permalink
Merge pull request #1135 from catenax-ng/chore/616-notification-refac…
Browse files Browse the repository at this point in the history
…toring

Chore/616 notification refactoring
  • Loading branch information
ds-mwesener authored Apr 2, 2024
2 parents d8deab9 + af0d30e commit 2328a34
Show file tree
Hide file tree
Showing 51 changed files with 365 additions and 1,471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ <h3 class="flex items-center">

<mat-card-content>
<app-notifications-tab
[notificationType]="NotificationType.ALERT"
[notificationsView$]="alertsCreated$"
[translationContext]="'commonAlert'"
[tableType]="TableType.RECEIVED_ALERT"
[tableType]="TableType.RECEIVED_NOTIFICATION"
[labelId]="'dashboard-alerts-created'"
[hasPagination]="false"
[optionalColumns]="['targetDate', 'severity', 'createdBy', 'type']"
Expand Down Expand Up @@ -155,13 +154,12 @@ <h3 class="flex items-center">

<mat-card-content>
<app-notifications-tab
[notificationType]="NotificationType.ALERT"
[notificationsView$]="alertsReceived$"
[translationContext]="'commonAlert'"
[labelId]="'dashboard-alerts-received'"
[hasPagination]="false"
[optionalColumns]="['targetDate', 'severity', 'createdBy', 'type']"
[tableType]="TableType.RECEIVED_ALERT"
[tableType]="TableType.RECEIVED_NOTIFICATION"
(selected)="onAlertSelected($event)"
></app-notifications-tab>
</mat-card-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@

import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NOTIFICATION_BASE_ROUTE, getRoute } from '@core/known-route';
import { getRoute, NOTIFICATION_BASE_ROUTE } from '@core/known-route';
import { DashboardStats } from '@page/dashboard/model/dashboard.model';
import { MetricData } from '@page/dashboard/presentation/dashboard.model';
import { TableType } from '@shared/components/multi-select-autocomplete/table-type.model';
import {
Notification,
Notifications,
NotificationStatusGroup,
NotificationType,
} from '@shared/model/notification.model';
import { Notification, Notifications, NotificationStatusGroup } from '@shared/model/notification.model';
import { View } from '@shared/model/view.model';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -134,6 +129,5 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.router.navigate([ `/${ link }/${ notification.id }` ]).then();
}

protected readonly NotificationType = NotificationType;
protected readonly TableType = TableType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { Injectable } from '@angular/core';
import { NotificationsFacade } from '@page/notifications/core/notifications.facade';
import { NotificationStatus } from '@shared/model/notification.model';
import { Observable } from 'rxjs';

@Injectable({
Expand Down Expand Up @@ -52,4 +53,24 @@ export class NotificationHelperService {
return this.notificationsFacade.declineNotification(id, reason);
}

modalCallback(status: NotificationStatus, id: string, reason?: string): Observable<void> {
switch (status) {
case NotificationStatus.ACKNOWLEDGED:
return this.notificationsFacade.acknowledgeNotification(id);
case NotificationStatus.APPROVED:
return this.notificationsFacade.approveNotification(id);
case NotificationStatus.CANCELED:
return this.notificationsFacade.cancelNotification(id);
case NotificationStatus.CLOSED:
return this.notificationsFacade.closeNotification(id, reason);
case NotificationStatus.ACCEPTED:
return this.notificationsFacade.acceptNotification(id, reason);
case NotificationStatus.DECLINED:
return this.notificationsFacade.declineNotification(id, reason);
default:
return null;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
>
<app-button
*ngIf="actionHelperService.showApproveButton(selectedNotification)"
(click)="notificationCommonModalComponent?.show('approve')"
(click)="notificationCommonModalComponent?.show(NotificationStatus.APPROVED)"
[color]="'primary'"
[isDisabled]="!actionHelperService.isAuthorizedForButton(NotificationAction.APPROVE)"
>
Expand All @@ -60,7 +60,7 @@
>
<app-button
*ngIf="actionHelperService.showCancelButton(selectedNotification)"
(click)="notificationCommonModalComponent?.show('cancel')"
(click)="notificationCommonModalComponent?.show(NotificationStatus.CANCELED)"
[color]="'primary'"
[isDisabled]="!actionHelperService.isAuthorizedForButton(NotificationAction.CANCEL)"
>
Expand All @@ -80,7 +80,7 @@
>
<app-button
*ngIf="actionHelperService.showCloseButton(selectedNotification)"
(click)="notificationCommonModalComponent?.show('close')"
(click)="notificationCommonModalComponent?.show(NotificationStatus.CLOSED)"
[color]="'primary'"
[isDisabled]="!actionHelperService.isAuthorizedForButton(NotificationAction.CLOSE)"
>
Expand All @@ -100,7 +100,7 @@
>
<app-button
*ngIf="actionHelperService.showAcceptButton(selectedNotification)"
(click)="notificationCommonModalComponent?.show('accept')"
(click)="notificationCommonModalComponent?.show(NotificationStatus.ACCEPTED)"
[color]="'primary'"
[isDisabled]="!actionHelperService.isAuthorizedForButton(NotificationAction.ACCEPT)"
>
Expand All @@ -120,7 +120,7 @@
>
<app-button
*ngIf="actionHelperService.showAcknowledgeButton(selectedNotification)"
(click)="notificationCommonModalComponent?.show('acknowledge')"
(click)="notificationCommonModalComponent?.show(NotificationStatus.ACKNOWLEDGED)"
[color]="'primary'"
[isDisabled]="!actionHelperService.isAuthorizedForButton(NotificationAction.ACKNOWLEDGE)"
>
Expand All @@ -140,7 +140,7 @@
>
<app-button
*ngIf="actionHelperService.showDeclineButton(selectedNotification)"
(click)="notificationCommonModalComponent?.show('decline')"
(click)="notificationCommonModalComponent?.show(NotificationStatus.DECLINED)"
[color]="'primary'"
[isDisabled]="!actionHelperService.isAuthorizedForButton(NotificationAction.DECLINE)"
>
Expand All @@ -157,7 +157,6 @@
(confirmActionCompleted)="handleConfirmActionCompletedEvent()"
[helperService]="helperService"
[selectedNotification]="selectedNotification"
[translationContext]="TranslationContext.COMMONALERT"
></app-notification-common-modal>

<div class="detail--wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { NotificationActionHelperService } from '@shared/assembler/notification-
import { NotificationCommonModalComponent } from '@shared/components/notification-common-modal/notification-common-modal.component';
import { CreateHeaderFromColumns, TableConfig, TableEventConfig } from '@shared/components/table/table.model';
import { ToastService } from '@shared/components/toasts/toast.service';
import { Notification, NotificationType } from '@shared/model/notification.model';
import { Notification, NotificationStatus, NotificationType } from '@shared/model/notification.model';
import { TranslationContext } from '@shared/model/translation-context.model';
import { View } from '@shared/model/view.model';
import { NotificationAction } from '@shared/modules/notification/notification-action.enum';
Expand Down Expand Up @@ -206,8 +206,8 @@ export class NotificationDetailComponent implements AfterViewInit, OnDestroy {
.subscribe();
}

protected readonly TranslationContext = TranslationContext;
protected readonly NotificationType = NotificationType;
protected readonly NotificationAction = NotificationAction;

protected readonly NotificationStatus = NotificationStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
<app-notification-common-modal
(confirmActionCompleted)="handleConfirmActionCompletedEvent()"
[helperService]="helperService"
[translationContext]="TranslationContext.COMMONALERT"
></app-notification-common-modal>

<app-notification
[notificationType]="NotificationType.ALERT"
[queuedAndRequestedNotifications$]="notificationsQueuedAndRequested$"
[receivedNotifications$]="notificationsReceived$"
[isInvestigation]="isInvestigation"
[translationContext]="TranslationContext.COMMONALERT"
[receivedOptionalColumns]="['severity', 'createdBy', 'createdByName', 'type']"
[receivedMultiSortList]="notificationReceivedSortList"
Expand All @@ -37,7 +34,7 @@
[queuedAndRequestedMultiSortList]="notificationQueuedAndRequestedSortList"
(onReceivedTableConfigChanged)="onReceivedTableConfigChange($event)"
(onQueuedAndRequestedTableConfigChanged)="onQueuedAndRequestedTableConfigChange($event)"
(alertFilterChanged)="filterNotifications($event)"
(notificationsFilterChanged)="filterNotifications($event)"
(selected)="openDetailPage($event)"
[menuActionsConfig]="menuActionsConfig"
></app-notification>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { NotificationMenuActionsAssembler } from '@shared/assembler/notification
import { NotificationCommonModalComponent } from '@shared/components/notification-common-modal/notification-common-modal.component';
import { Notification, NotificationStatus } from '@shared/model/notification.model';
import { Severity } from '@shared/model/severity.model';
import { CloseNotificationModalComponent } from '@shared/modules/notification/modal/close/close-notification-modal.component';
import { KeycloakService } from 'keycloak-angular';

describe('NotificationMenuActionsAssembler', () => {
Expand All @@ -52,7 +51,6 @@ describe('NotificationMenuActionsAssembler', () => {
NotificationActionHelperService,
NotificationCommonModalComponent,
NotificationMenuActionsAssembler,
CloseNotificationModalComponent,
],
});
notificationCommonModalComponent = TestBed.inject(NotificationCommonModalComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { NotificationActionHelperService } from '@shared/assembler/notification-action-helper.service';
import { NotificationCommonModalComponent } from '@shared/components/notification-common-modal/notification-common-modal.component';
import { MenuActionConfig } from '@shared/components/table/table.model';
import { Notification } from '@shared/model/notification.model';
import { Notification, NotificationStatus } from '@shared/model/notification.model';
import { NotificationAction } from '@shared/modules/notification/notification-action.enum';

export class NotificationMenuActionsAssembler {
Expand All @@ -28,42 +28,42 @@ export class NotificationMenuActionsAssembler {
{
label: 'actions.close',
icon: 'close',
action: data => modal.show('close', data),
action: data => modal.show(NotificationStatus.CLOSED, data),
condition: data => helperService.showCloseButton(data),
isAuthorized: helperService.isAuthorizedForButton(NotificationAction.CLOSE),
},
{
label: 'actions.approve',
icon: 'share',
action: data => modal.show('approve', data),
action: data => modal.show(NotificationStatus.APPROVED, data),
condition: data => helperService.showApproveButton(data),
isAuthorized: helperService.isAuthorizedForButton(NotificationAction.APPROVE),
},
{
label: 'actions.cancel',
icon: 'cancel',
action: data => modal.show('cancel', data),
action: data => modal.show(NotificationStatus.CANCELED, data),
condition: data => helperService.showCancelButton(data),
isAuthorized: helperService.isAuthorizedForButton(NotificationAction.CANCEL),
},
{
label: 'actions.acknowledge',
icon: 'work',
action: data => modal.show('acknowledge', data),
action: data => modal.show(NotificationStatus.ACKNOWLEDGED, data),
condition: data => helperService.showAcknowledgeButton(data),
isAuthorized: helperService.isAuthorizedForButton(NotificationAction.ACKNOWLEDGE),
},
{
label: 'actions.accept',
icon: 'assignment_turned_in',
action: data => modal.show('accept', data),
action: data => modal.show(NotificationStatus.ACCEPTED, data),
condition: data => helperService.showAcceptButton(data),
isAuthorized: helperService.isAuthorizedForButton(NotificationAction.ACCEPT),
},
{
label: 'actions.decline',
icon: 'assignment_late',
action: data => modal.show('decline', data),
action: data => modal.show(NotificationStatus.DECLINED, data),
condition: data => helperService.showDeclineButton(data),
isAuthorized: helperService.isAuthorizedForButton(NotificationAction.DECLINE),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
import {Owner} from '@page/parts/model/owner.enum';
import { Owner } from '@page/parts/model/owner.enum';
import {
channelOfNotification,
getOwnerOfTable,
isAsBuilt,
} from '@shared/components/multi-select-autocomplete/autocomplete-strategy';
import {NotificationChannel, TableType} from '@shared/components/multi-select-autocomplete/table-type.model';
import { NotificationChannel, TableType } from '@shared/components/multi-select-autocomplete/table-type.model';

describe('Autocomplete Strategies', () => {

Expand All @@ -46,9 +46,7 @@ describe('Autocomplete Strategies', () => {
});

it('should determine channel of notification', async () => {
expect(channelOfNotification(TableType.CREATED_INVESTIGATION)).toBe(NotificationChannel.SENDER);
expect(channelOfNotification(TableType.CREATED_ALERT)).toBe(NotificationChannel.SENDER);
expect(channelOfNotification(TableType.RECEIVED_INVESTIGATION)).toBe(NotificationChannel.RECEIVER);
expect(channelOfNotification(TableType.RECEIVED_INVESTIGATION)).toBe(NotificationChannel.RECEIVER);
expect(channelOfNotification(TableType.SENT_NOTIFICATION)).toBe(NotificationChannel.SENDER);
expect(channelOfNotification(TableType.RECEIVED_NOTIFICATION)).toBe(NotificationChannel.RECEIVER);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,7 @@ export class PartsStrategy extends AutocompleteStrategy {
@Injectable({
providedIn: 'any',
})
export class InvestigationStrategy extends AutocompleteStrategy {
notificationService: NotificationService;

constructor(notificationService: NotificationService) {
super();
this.notificationService = notificationService;
}

retrieveSuggestionValues(tableType: TableType, filterColumns: string, searchElement: string): any {
const notificationChannel = channelOfNotification(tableType);
return this.notificationService.getDistinctFilterValues(
notificationChannel,
filterColumns,
searchElement,
true,
);
}
}

@Injectable({
providedIn: 'any',
})
export class AlertStrategy extends AutocompleteStrategy {
export class NotificationStrategy extends AutocompleteStrategy {
notificationService: NotificationService;

constructor(notificationService: NotificationService) {
Expand Down Expand Up @@ -120,11 +98,9 @@ export const AutocompleteStrategyMap = new Map<TableType, any>([
[ TableType.AS_PLANNED_OWN, PartsStrategy ],
[ TableType.AS_PLANNED_CUSTOMER, PartsStrategy ],
[ TableType.AS_PLANNED_SUPPLIER, PartsStrategy ],
[ TableType.RECEIVED_INVESTIGATION, InvestigationStrategy ],
[ TableType.CREATED_INVESTIGATION, InvestigationStrategy ],
[ TableType.RECEIVED_ALERT, AlertStrategy ],
[ TableType.CREATED_ALERT, AlertStrategy ],
[ TableType.CONTRACTS, ContractsStrategy]
[ TableType.RECEIVED_NOTIFICATION, NotificationStrategy ],
[ TableType.SENT_NOTIFICATION, NotificationStrategy ],
[ TableType.CONTRACTS, ContractsStrategy ],
]);

export function getOwnerOfTable(tableType: TableType): Owner {
Expand All @@ -145,14 +121,10 @@ export function isAsBuilt(tableType: TableType): boolean {
}

export function channelOfNotification(tableType: TableType): NotificationChannel {
if (tableType === TableType.CREATED_ALERT || tableType === TableType.CREATED_INVESTIGATION) {
if (tableType === TableType.SENT_NOTIFICATION) {
return NotificationChannel.SENDER;
} else {
return NotificationChannel.RECEIVER;
}

}

export function isInvestigation(tableType: TableType): boolean {
return [ TableType.RECEIVED_INVESTIGATION, TableType.CREATED_INVESTIGATION ].includes(tableType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export enum TableType {
AS_BUILT_CUSTOMER = 'AS_BUILT_CUSTOMER',
AS_PLANNED_SUPPLIER = 'AS_PLANNED_SUPPLIER',
AS_PLANNED_CUSTOMER = 'AS_PLANNED_CUSTOMER',
RECEIVED_INVESTIGATION = 'RECEIVED_INVESTIGATION',
CREATED_INVESTIGATION = 'CREATED_INVESTIGATION',
RECEIVED_ALERT = 'RECEIVED_ALERT',
CREATED_ALERT = 'CREATED_ALERT',
RECEIVED_NOTIFICATION = 'RECEIVED_NOTIFICATION',
SENT_NOTIFICATION = 'SENT_NOTIFICATION',
CONTRACTS='CONTRACTS'
}

Expand Down
Loading

0 comments on commit 2328a34

Please sign in to comment.