[ADF-5379] Add a way to disable WS notifications (#6924)

* [ADF-5379] Add a way to disable WS notifications

* Update app-notifications.service.ts

* Update task-filters-cloud.component.spec.ts

* Move flag to upper level in config.json

* Create new notification section in app.config.json

* Update implementation

* Improve naming
This commit is contained in:
davidcanonieto
2021-05-05 14:14:44 +01:00
committed by GitHub
parent 884d646078
commit 550a223164
6 changed files with 51 additions and 7 deletions

View File

@@ -33,6 +33,7 @@
"name": "Alfresco ADF Application", "name": "Alfresco ADF Application",
"copyright": "© 2016 - 2021 Alfresco Software, Inc. All Rights Reserved." "copyright": "© 2016 - 2021 Alfresco Software, Inc. All Rights Reserved."
}, },
"notifications": true,
"search": { "search": {
"filterWithContains": true, "filterWithContains": true,
"app:fields": [ "app:fields": [

View File

@@ -54,7 +54,7 @@ export class AppNotificationsService {
private alfrescoApiService: AlfrescoApiService private alfrescoApiService: AlfrescoApiService
) { ) {
this.alfrescoApiService.alfrescoApiInitialized.subscribe(() => { this.alfrescoApiService.alfrescoApiInitialized.subscribe(() => {
if (this.isProcessServicesEnabled()) { if (this.isProcessServicesEnabled() && this.notificationsEnabled) {
this.alfrescoApiService.getInstance().oauth2Auth.once('token_issued', () => { this.alfrescoApiService.getInstance().oauth2Auth.once('token_issued', () => {
const deployedApps = this.appConfigService.get('alfresco-deployed-apps', []); const deployedApps = this.appConfigService.get('alfresco-deployed-apps', []);
@@ -76,7 +76,11 @@ export class AppNotificationsService {
}); });
} }
private isProcessServicesEnabled() { private get notificationsEnabled(): boolean {
return this.appConfigService.get('notifications', true);
}
private isProcessServicesEnabled(): boolean {
return this.authenticationService.isLoggedIn() && (this.authenticationService.isBPMProvider() || this.authenticationService.isALLProvider()); return this.authenticationService.isLoggedIn() && (this.authenticationService.isBPMProvider() || this.authenticationService.isALLProvider());
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -18,6 +18,7 @@ Shows all available filters.
- [Details](#details) - [Details](#details)
- [Filtering APS2 task filters](#filtering-aps2-task-filters) - [Filtering APS2 task filters](#filtering-aps2-task-filters)
- [Showing Filter Counters](#showing-filter-counters) - [Showing Filter Counters](#showing-filter-counters)
- [Updating Filter Counters](#updating-filter-counters)
- [See also](#see-also) - [See also](#see-also)
## Basic Usage ## Basic Usage
@@ -66,7 +67,7 @@ as the value of `filterParam` as shown in the table below:
| id | string | The id of the task filter | | id | string | The id of the task filter |
| name | string | The name of the task filter, lowercase is checked | | name | string | The name of the task filter, lowercase is checked |
| key | string | The key of the task filter | | key | string | The key of the task filter |
| index | string | The zero-based position of the filter in the array. | | index | string | The zero-based position of the filter in the array |
### Showing Filter Counters ### Showing Filter Counters
@@ -74,6 +75,20 @@ By default, filter counters are hidden. If you want to display filter counters y
![](../../docassets/images/task-filter-counter.png) ![](../../docassets/images/task-filter-counter.png)
### Updating Filter Counters
If you want to disable notification bubbles as task filters change you can change it directly from the app.config.json.
```json
{
...
"notifications": true
...
}
```
![](../../docassets/images/update-filter-bubble.png)
## See also ## See also
- [Task filter Cloud Service](../services/task-filter-cloud.service.md) - [Task filter Cloud Service](../services/task-filter-cloud.service.md)

View File

@@ -17,7 +17,7 @@
import { SimpleChange } from '@angular/core'; import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing'; import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing';
import { setupTestBed } from '@alfresco/adf-core'; import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
import { from, Observable, of } from 'rxjs'; import { from, Observable, of } from 'rxjs';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
@@ -32,6 +32,7 @@ import { TranslateModule } from '@ngx-translate/core';
describe('TaskFiltersCloudComponent', () => { describe('TaskFiltersCloudComponent', () => {
let taskFilterService: TaskFilterCloudService; let taskFilterService: TaskFilterCloudService;
let appConfigService: AppConfigService;
const fakeGlobalFilterObservable = const fakeGlobalFilterObservable =
new Observable(function (observer) { new Observable(function (observer) {
@@ -71,6 +72,8 @@ describe('TaskFiltersCloudComponent', () => {
taskFilterService = TestBed.inject(TaskFilterCloudService); taskFilterService = TestBed.inject(TaskFilterCloudService);
getTaskFilterCounterSpy = spyOn(taskFilterService, 'getTaskFilterCounter').and.returnValue(of(11)); getTaskFilterCounterSpy = spyOn(taskFilterService, 'getTaskFilterCounter').and.returnValue(of(11));
spyOn(taskFilterService, 'getTaskNotificationSubscription').and.returnValue(of(taskNotifications)); spyOn(taskFilterService, 'getTaskNotificationSubscription').and.returnValue(of(taskNotifications));
appConfigService = TestBed.inject(AppConfigService);
}); });
it('should attach specific icon for each filter if hasIcon is true', async(() => { it('should attach specific icon for each filter if hasIcon is true', async(() => {
@@ -384,6 +387,7 @@ describe('TaskFiltersCloudComponent', () => {
it('should update filter counter when notification received', fakeAsync(() => { it('should update filter counter when notification received', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(appConfigService, 'get').and.returnValue(true);
component.appName = 'my-app-1'; component.appName = 'my-app-1';
component.ngOnInit(); component.ngOnInit();
tick(5000); tick(5000);
@@ -398,8 +402,24 @@ describe('TaskFiltersCloudComponent', () => {
}); });
})); }));
it('should not update filter counter when notifications are disabled from app.config.json', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(appConfigService, 'get').and.returnValue(false);
component.appName = 'my-app-1';
component.ngOnInit();
tick(5000);
fixture.detectChanges();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(0);
});
}));
it('should reset filter counter notification when filter is selected', fakeAsync(() => { it('should reset filter counter notification when filter is selected', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(appConfigService, 'get').and.returnValue(true);
let change = new SimpleChange(undefined, 'my-app-1', true); let change = new SimpleChange(undefined, 'my-app-1', true);
component.appName = 'my-app-1'; component.appName = 'my-app-1';
component.ngOnInit(); component.ngOnInit();

View File

@@ -19,7 +19,7 @@ import { Component, EventEmitter, OnChanges, Output, SimpleChanges, OnInit } fro
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { TaskFilterCloudService } from '../services/task-filter-cloud.service'; import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
import { TaskFilterCloudModel, FilterParamsModel } from '../models/filter-cloud.model'; import { TaskFilterCloudModel, FilterParamsModel } from '../models/filter-cloud.model';
import { TranslationService } from '@alfresco/adf-core'; import { AppConfigService, TranslationService } from '@alfresco/adf-core';
import { debounceTime, takeUntil } from 'rxjs/operators'; import { debounceTime, takeUntil } from 'rxjs/operators';
import { BaseTaskFiltersCloudComponent } from './base-task-filters-cloud.component'; import { BaseTaskFiltersCloudComponent } from './base-task-filters-cloud.component';
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model'; import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
@@ -31,6 +31,7 @@ import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';
styleUrls: ['base-task-filters-cloud.component.scss'] styleUrls: ['base-task-filters-cloud.component.scss']
}) })
export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent implements OnInit, OnChanges { export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent implements OnInit, OnChanges {
/** Emitted when a filter is being selected based on the filterParam input. */ /** Emitted when a filter is being selected based on the filterParam input. */
@Output() @Output()
filterSelected = new EventEmitter<TaskFilterCloudModel>(); filterSelected = new EventEmitter<TaskFilterCloudModel>();
@@ -46,13 +47,16 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
filters$: Observable<TaskFilterCloudModel[]>; filters$: Observable<TaskFilterCloudModel[]>;
filters: TaskFilterCloudModel[] = []; filters: TaskFilterCloudModel[] = [];
currentFilter: TaskFilterCloudModel; currentFilter: TaskFilterCloudModel;
enableNotifications: boolean;
constructor(private taskFilterCloudService: TaskFilterCloudService, constructor(private taskFilterCloudService: TaskFilterCloudService,
private translationService: TranslationService) { private translationService: TranslationService,
private appConfigService: AppConfigService) {
super(); super();
} }
ngOnInit() { ngOnInit() {
this.enableNotifications = this.appConfigService.get('notifications', true);
this.initFilterCounterNotifications(); this.initFilterCounterNotifications();
this.getFilters(this.appName); this.getFilters(this.appName);
} }
@@ -98,7 +102,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
} }
initFilterCounterNotifications() { initFilterCounterNotifications() {
if (this.appName) { if (this.appName && this.enableNotifications) {
this.taskFilterCloudService.getTaskNotificationSubscription(this.appName) this.taskFilterCloudService.getTaskNotificationSubscription(this.appName)
.pipe(debounceTime(3000)) .pipe(debounceTime(3000))
.subscribe((result: TaskCloudEngineEvent[]) => { .subscribe((result: TaskCloudEngineEvent[]) => {