From 9ef00e3dddfc73c4d709a2e74fe1fce7bd9d6655 Mon Sep 17 00:00:00 2001 From: Vito Date: Fri, 7 Sep 2018 11:34:26 +0100 Subject: [PATCH] [ADF-3500] added an event to react when a filter is force selected (#3753) * [ADF-3500] added an event to react when a filter is force selected * [ADF-3500] renamed method for clarification --- .../process-service.component.html | 3 ++- .../process-service.component.ts | 2 +- .../process-filters.component.md | 1 + .../process-filters.component.spec.ts | 27 +++++++++++++++---- .../components/process-filters.component.ts | 13 +++++---- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/demo-shell/src/app/components/process-service/process-service.component.html b/demo-shell/src/app/components/process-service/process-service.component.html index ed0bd1a52d..bb34ea92f5 100644 --- a/demo-shell/src/app/components/process-service/process-service.component.html +++ b/demo-shell/src/app/components/process-service/process-service.component.html @@ -133,7 +133,8 @@ #activitiprocessfilter [filterParam]="filterSelected" [appId]="appId" - (filterClick)="onProcessFilterClick($event)" + (filterClick)="onProcessFilterChange($event)" + (filterSelected)="onProcessFilterChange($event)" (success)="onSuccessProcessFilterList($event)"> diff --git a/demo-shell/src/app/components/process-service/process-service.component.ts b/demo-shell/src/app/components/process-service/process-service.component.ts index 29bea6916f..77cc65b012 100644 --- a/demo-shell/src/app/components/process-service/process-service.component.ts +++ b/demo-shell/src/app/components/process-service/process-service.component.ts @@ -297,7 +297,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit this.currentTaskId = this.taskList.getCurrentId(); } - onProcessFilterClick(event: UserProcessInstanceFilterRepresentation): void { + onProcessFilterChange(event: UserProcessInstanceFilterRepresentation): void { this.processFilter = event; this.resetProcessPaginationPage(); this.relocateLocationToProcess(); diff --git a/docs/process-services/process-filters.component.md b/docs/process-services/process-filters.component.md index 6c61341173..3fd42878bd 100644 --- a/docs/process-services/process-filters.component.md +++ b/docs/process-services/process-filters.component.md @@ -45,6 +45,7 @@ Collection of criteria used to filter process instances, which may be customized | error | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when an error occurs. | | filterClick | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the user selects a filter from the list. | | success | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the list of filters has been successfully loaded from the server. | +| filterSelected | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when a process filter is selected. | ## Details diff --git a/lib/process-services/process-list/components/process-filters.component.spec.ts b/lib/process-services/process-list/components/process-filters.component.spec.ts index 125557cae2..3eff1fe5ca 100644 --- a/lib/process-services/process-list/components/process-filters.component.spec.ts +++ b/lib/process-services/process-list/components/process-filters.component.spec.ts @@ -96,7 +96,7 @@ describe('ProcessFiltersComponent', () => { done(); }); - filterList.ngOnInit(); + fixture.detectChanges(); }); it('should select the Running process filter', (done) => { @@ -113,7 +113,24 @@ describe('ProcessFiltersComponent', () => { done(); }); - filterList.ngOnInit(); + fixture.detectChanges(); + }); + + it('should emit an event when a filter is selected', (done) => { + spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + const appId = '1'; + let change = new SimpleChange(null, appId, true); + filterList.ngOnChanges({ 'appId': change }); + + expect(filterList.currentFilter).toBeUndefined(); + + filterList.filterSelected.subscribe((filter) => { + expect(filter.name).toEqual('FakeInvolvedTasks'); + done(); + }); + + fixture.detectChanges(); + filterList.selectRunningFilter(); }); it('should return the filter task list, filtered By Name', (done) => { @@ -130,7 +147,7 @@ describe('ProcessFiltersComponent', () => { done(); }); - filterList.ngOnInit(); + fixture.detectChanges(); }); it('should emit an error with a bad response', (done) => { @@ -145,7 +162,7 @@ describe('ProcessFiltersComponent', () => { done(); }); - filterList.ngOnInit(); + fixture.detectChanges(); }); it('should emit an error with a bad response', (done) => { @@ -160,7 +177,7 @@ describe('ProcessFiltersComponent', () => { done(); }); - filterList.ngOnInit(); + fixture.detectChanges(); }); it('should emit an event when a filter is selected', (done) => { diff --git a/lib/process-services/process-list/components/process-filters.component.ts b/lib/process-services/process-list/components/process-filters.component.ts index 61e8ca6d24..1261cac351 100644 --- a/lib/process-services/process-list/components/process-filters.component.ts +++ b/lib/process-services/process-list/components/process-filters.component.ts @@ -16,7 +16,7 @@ */ import { AppsProcessService } from '@alfresco/adf-core'; -import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; +import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresentation } from 'alfresco-js-api'; import { Observable } from 'rxjs'; import { FilterProcessRepresentationModel } from '../models/filter-process.model'; @@ -27,7 +27,7 @@ import { ProcessFilterService } from './../services/process-filter.service'; templateUrl: './process-filters.component.html', styleUrls: ['process-filters.component.scss'] }) -export class ProcessFiltersComponent implements OnInit, OnChanges { +export class ProcessFiltersComponent implements OnChanges { /** The parameters to filter the task filter. If there is no match then the default one * (ie, the first filter in the list) is selected. @@ -37,7 +37,7 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { /** Emitted when the user selects a filter from the list. */ @Output() - filterClick: EventEmitter = new EventEmitter(); + filterClick: EventEmitter = new EventEmitter(); /** Emitted when the list of filters has been successfully loaded from the server. */ @Output() @@ -59,6 +59,9 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { @Input() showIcon: boolean = true; + @Output() + filterSelected: EventEmitter = new EventEmitter(); + filter$: Observable; currentFilter: ProcessInstanceFilterRepresentation; @@ -69,8 +72,6 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { private appsProcessService: AppsProcessService) { } - ngOnInit() {} - ngOnChanges(changes: SimpleChanges) { const appId = changes['appId']; const appName = changes['appName']; @@ -151,6 +152,7 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { filterParam.id === processFilter.id || filterParam.index === index) { this.currentFilter = processFilter; + this.filterSelected.emit(processFilter); } }); } @@ -172,6 +174,7 @@ export class ProcessFiltersComponent implements OnInit, OnChanges { public selectDefaultTaskFilter() { if (!this.isFilterListEmpty()) { this.currentFilter = this.filters[0]; + this.filterSelected.emit(this.filters[0]); } }