mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-4299] Add e2e tests for task counters and notifications (#6726)
* [ACA-4299] Add ete tests for task counters and notifications * Fix unit test * Fix update for indirect counter changes
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ChartsModule } from 'ng2-charts';
|
||||
@@ -112,6 +112,8 @@ import localePl from '@angular/common/locales/pl';
|
||||
import localeFi from '@angular/common/locales/fi';
|
||||
import localeDa from '@angular/common/locales/da';
|
||||
import localeSv from '@angular/common/locales/sv';
|
||||
import { setupAppNotifications } from './services/app-notifications-factory';
|
||||
import { AppNotificationsService } from './services/app-notifications.service';
|
||||
|
||||
registerLocaleData(localeFr);
|
||||
registerLocaleData(localeDe);
|
||||
@@ -225,6 +227,13 @@ registerLocaleData(localeSv);
|
||||
name: 'lazy-loading',
|
||||
source: 'resources/lazy-loading'
|
||||
}
|
||||
},
|
||||
AppNotificationsService,
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: setupAppNotifications,
|
||||
deps: [AppNotificationsService],
|
||||
multi: true
|
||||
}
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
|
@@ -17,23 +17,6 @@
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { CloudLayoutService } from './services/cloud-layout.service';
|
||||
import { NotificationModel, NotificationService } from '@alfresco/adf-core';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { NotificationCloudService } from '@alfresco/adf-process-services-cloud';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
const SUBSCRIPTION_QUERY = `
|
||||
subscription {
|
||||
engineEvents(eventType: [
|
||||
PROCESS_STARTED
|
||||
TASK_ASSIGNED
|
||||
TASK_UPDATED
|
||||
]) {
|
||||
eventType
|
||||
entity
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@Component({
|
||||
selector: 'app-cloud-layout',
|
||||
@@ -48,26 +31,13 @@ export class CloudLayoutComponent implements OnInit {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private cloudLayoutService: CloudLayoutService,
|
||||
private notificationCloudService: NotificationCloudService,
|
||||
private notificationService: NotificationService,
|
||||
private translateService: TranslateService
|
||||
private cloudLayoutService: CloudLayoutService
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
let root: string = '';
|
||||
this.route.params.subscribe((params) => {
|
||||
this.appName = params.appName;
|
||||
this.notificationCloudService.makeGQLQuery(
|
||||
this.appName, SUBSCRIPTION_QUERY
|
||||
)
|
||||
.pipe(map((events: any) => events.data.engineEvents))
|
||||
.subscribe((result) => {
|
||||
result.map((engineEvent) => {
|
||||
this.notifyEvent(engineEvent);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (this.route.snapshot && this.route.snapshot.firstChild) {
|
||||
@@ -92,37 +62,4 @@ export class CloudLayoutComponent implements OnInit {
|
||||
onStartProcess() {
|
||||
this.router.navigate([`/cloud/${this.appName}/start-process/`]);
|
||||
}
|
||||
|
||||
notifyEvent(engineEvent) {
|
||||
let message;
|
||||
switch (engineEvent.eventType) {
|
||||
case 'TASK_ASSIGNED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_ASSIGNED',
|
||||
{ taskName: engineEvent.entity.name || '', assignee: engineEvent.entity.assignee });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'PROCESS_STARTED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.PROCESS_STARTED',
|
||||
{ processName: engineEvent.entity.name });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_UPDATED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_UPDATED',
|
||||
{ taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
pushNotification(engineEvent: any, message: string) {
|
||||
const notification = {
|
||||
messages: [message],
|
||||
icon: 'info',
|
||||
datetime: new Date(),
|
||||
initiator: { displayName: engineEvent.entity.initiator || 'System' }
|
||||
} as NotificationModel;
|
||||
|
||||
this.notificationService.pushToNotificationHistory(notification);
|
||||
}
|
||||
}
|
||||
|
22
demo-shell/src/app/services/app-notifications-factory.ts
Normal file
22
demo-shell/src/app/services/app-notifications-factory.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AppNotificationsService } from './app-notifications.service';
|
||||
|
||||
export function setupAppNotifications(appNotificationsService: AppNotificationsService) {
|
||||
return () => appNotificationsService;
|
||||
}
|
110
demo-shell/src/app/services/app-notifications.service.ts
Normal file
110
demo-shell/src/app/services/app-notifications.service.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AppConfigService, NotificationService, NotificationModel, AlfrescoApiService, IdentityUserService } from '@alfresco/adf-core';
|
||||
import { NotificationCloudService } from '@alfresco/adf-process-services-cloud';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
const SUBSCRIPTION_QUERY = `
|
||||
subscription {
|
||||
engineEvents(eventType: [
|
||||
PROCESS_STARTED
|
||||
TASK_ASSIGNED
|
||||
TASK_UPDATED,
|
||||
TASK_CREATED
|
||||
]) {
|
||||
eventType
|
||||
entity
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@Injectable()
|
||||
export class AppNotificationsService {
|
||||
|
||||
constructor(
|
||||
private appConfigService: AppConfigService,
|
||||
private notificationCloudService: NotificationCloudService,
|
||||
private notificationService: NotificationService,
|
||||
private translateService: TranslateService,
|
||||
private identityUserService: IdentityUserService,
|
||||
private alfrescoApiService: AlfrescoApiService
|
||||
) {
|
||||
this.alfrescoApiService.alfrescoApiInitialized.subscribe(() => {
|
||||
const deployedApps = this.appConfigService.get('alfresco-deployed-apps', []);
|
||||
if (deployedApps?.length) {
|
||||
deployedApps.forEach((app) => {
|
||||
this.notificationCloudService
|
||||
.makeGQLQuery(app.name, SUBSCRIPTION_QUERY)
|
||||
.pipe(map((events: any) => events.data.engineEvents))
|
||||
.subscribe((result) => {
|
||||
result.map((engineEvent) => this.notifyEvent(engineEvent));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
notifyEvent(engineEvent) {
|
||||
let message;
|
||||
switch (engineEvent.eventType) {
|
||||
case 'TASK_ASSIGNED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_ASSIGNED', { taskName: engineEvent.entity.name || '', assignee: engineEvent.entity.assignee });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_UPDATED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_UPDATED', { taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_COMPLETED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_COMPLETED', { taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_ACTIVATED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_ACTIVATED', { taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_CANCELLED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_CANCELLED', { taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_SUSPENDED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_SUSPENDED', { taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
case 'TASK_CREATED':
|
||||
message = this.translateService.instant('NOTIFICATIONS.TASK_CREATED', { taskName: engineEvent.entity.name || '' });
|
||||
this.pushNotification(engineEvent, message);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
pushNotification(engineEvent: any, message: string) {
|
||||
if (engineEvent.entity.assignee === this.identityUserService.getCurrentUserInfo().username) {
|
||||
const notification = {
|
||||
messages: [message],
|
||||
icon: 'info',
|
||||
datetime: new Date(),
|
||||
initiator: { displayName: engineEvent.entity.initiator || 'System' }
|
||||
} as NotificationModel;
|
||||
|
||||
this.notificationService.pushToNotificationHistory(notification);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user