mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[ADF-2788] Filter task url involved (#3243)
* filter task url involved * task filter observer removed * tests fix * clean code
This commit is contained in:
parent
e8f1986d5d
commit
b58a24c126
@ -125,6 +125,11 @@ export const appRoutes: Routes = [
|
||||
component: ProcessServiceComponent,
|
||||
canActivate: [AuthGuardBpm]
|
||||
},
|
||||
{
|
||||
path: 'activiti/apps/:appId/tasks/:filterId',
|
||||
component: ProcessServiceComponent,
|
||||
canActivate: [AuthGuardBpm]
|
||||
},
|
||||
{
|
||||
path: 'activiti/apps/:appId/processes',
|
||||
component: ProcessServiceComponent,
|
||||
|
@ -17,7 +17,7 @@
|
||||
<adf-accordion-group [heading]="'Tasks'" [isSelected]="true" [isOpen]="true"
|
||||
[headingIcon]="'assignment'">
|
||||
<adf-filters
|
||||
[filterParam]="{name:'MY tasks'}"
|
||||
[filterParam]="filterSelected"
|
||||
[appId]="appId"
|
||||
[hasIcon]="false"
|
||||
(filterClick)="onTaskFilterClick($event)"
|
||||
|
@ -109,6 +109,9 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
|
||||
@Input()
|
||||
appId: number = null;
|
||||
|
||||
@Input()
|
||||
filterSelected: object = null;
|
||||
|
||||
@Output()
|
||||
changePageSize: EventEmitter<Pagination> = new EventEmitter();
|
||||
|
||||
@ -213,6 +216,9 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
|
||||
}
|
||||
this.sub = this.route.params.subscribe(params => {
|
||||
const applicationId = params['appId'];
|
||||
|
||||
this.filterSelected = params['filterId'] ? { id: params['filterId'] } : { index: 0 };
|
||||
|
||||
if (applicationId && applicationId !== '0') {
|
||||
this.appId = params['appId'];
|
||||
}
|
||||
@ -234,6 +240,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
|
||||
onTaskFilterClick(filter: FilterRepresentationModel): void {
|
||||
this.applyTaskFilter(filter);
|
||||
this.resetTaskPaginationPage();
|
||||
this.router.navigate(['/activiti/apps', this.appId || 0, 'tasks', filter.id]);
|
||||
}
|
||||
|
||||
resetTaskPaginationPage() {
|
||||
|
@ -52,6 +52,14 @@ describe('TaskFiltersComponent', () => {
|
||||
resolve(fakeGlobalFilter);
|
||||
});
|
||||
|
||||
let fakeGlobalEmptyFilter = {
|
||||
message: 'invalid data'
|
||||
};
|
||||
|
||||
let fakeGlobalEmptyFilterPromise = new Promise(function (resolve, reject) {
|
||||
resolve(fakeGlobalEmptyFilter);
|
||||
});
|
||||
|
||||
let mockErrorFilterList = {
|
||||
error: 'wrong request'
|
||||
};
|
||||
@ -154,6 +162,21 @@ describe('TaskFiltersComponent', () => {
|
||||
|
||||
});
|
||||
|
||||
it('should be able to fetch and select the default if the input filter is not valid', (done) => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalEmptyFilterPromise));
|
||||
spyOn(component, 'createFiltersByAppId').and.stub();
|
||||
|
||||
const appId = '1';
|
||||
let change = new SimpleChange(null, appId, true);
|
||||
component.ngOnChanges({ 'appId': change });
|
||||
|
||||
component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(component.createFiltersByAppId).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by name param', (done) => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(Observable.fromPromise(fakeGlobalFilterPromise));
|
||||
|
||||
@ -234,7 +257,7 @@ describe('TaskFiltersComponent', () => {
|
||||
});
|
||||
|
||||
it('should emit an event when a filter is selected', (done) => {
|
||||
let currentFilter = new FilterRepresentationModel({ filter: { state: 'open', assignment: 'fake-involved' } });
|
||||
let currentFilter = fakeGlobalFilter[0];
|
||||
|
||||
component.filterClick.subscribe((filter: FilterRepresentationModel) => {
|
||||
expect(filter).toBeDefined();
|
||||
@ -277,10 +300,8 @@ describe('TaskFiltersComponent', () => {
|
||||
});
|
||||
|
||||
it('should return the current filter after one is selected', () => {
|
||||
let filter = new FilterRepresentationModel({
|
||||
name: 'FakeMyTasks',
|
||||
filter: { state: 'open', assignment: 'fake-assignee' }
|
||||
});
|
||||
let filter = fakeGlobalFilter[1];
|
||||
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
component.selectFilter(filter);
|
||||
expect(component.getCurrentFilter()).toBe(filter);
|
||||
|
@ -18,7 +18,6 @@
|
||||
import { AppsProcessService } from '@alfresco/adf-core';
|
||||
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { FilterParamsModel, FilterRepresentationModel } from '../models/filter.model';
|
||||
import { TaskFilterService } from './../services/task-filter.service';
|
||||
import { TaskListService } from './../services/tasklist.service';
|
||||
@ -60,22 +59,18 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
|
||||
@Input()
|
||||
hasIcon: boolean = true;
|
||||
|
||||
private filterObserver: Observer<FilterRepresentationModel>;
|
||||
filter$: Observable<FilterRepresentationModel>;
|
||||
|
||||
currentFilter: FilterRepresentationModel;
|
||||
|
||||
filters: FilterRepresentationModel [] = [];
|
||||
|
||||
constructor(private taskFilterService: TaskFilterService, private taskListService: TaskListService, private appsProcessService: AppsProcessService) {
|
||||
this.filter$ = new Observable<FilterRepresentationModel>(observer => this.filterObserver = observer).share();
|
||||
constructor(private taskFilterService: TaskFilterService,
|
||||
private taskListService: TaskListService,
|
||||
private appsProcessService: AppsProcessService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.filter$.subscribe((filter: FilterRepresentationModel) => {
|
||||
this.filters.push(filter);
|
||||
});
|
||||
}
|
||||
ngOnInit() { }
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
let appId = changes['appId'];
|
||||
@ -98,11 +93,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
|
||||
* @param appName
|
||||
*/
|
||||
getFilters(appId?: number, appName?: string) {
|
||||
if (appName) {
|
||||
this.getFiltersByAppName(appName);
|
||||
} else {
|
||||
this.getFiltersByAppId(appId);
|
||||
}
|
||||
appName ? this.getFiltersByAppName(appName) : this.getFiltersByAppId(appId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,26 +104,10 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
|
||||
this.taskFilterService.getTaskListFilters(appId).subscribe(
|
||||
(res: FilterRepresentationModel[]) => {
|
||||
if (res.length === 0 && this.isFilterListEmpty()) {
|
||||
this.taskFilterService.createDefaultFilters(appId).subscribe(
|
||||
(resDefault: FilterRepresentationModel[]) => {
|
||||
this.resetFilter();
|
||||
resDefault.forEach((filter) => {
|
||||
this.filterObserver.next(filter);
|
||||
});
|
||||
|
||||
this.selectTaskFilter(this.filterParam, this.filters);
|
||||
this.success.emit(resDefault);
|
||||
},
|
||||
(errDefault: any) => {
|
||||
this.error.emit(errDefault);
|
||||
}
|
||||
);
|
||||
this.createFiltersByAppId(appId);
|
||||
} else {
|
||||
this.resetFilter();
|
||||
res.forEach((filter) => {
|
||||
this.filterObserver.next(filter);
|
||||
});
|
||||
|
||||
this.filters = res;
|
||||
this.selectTaskFilter(this.filterParam, this.filters);
|
||||
this.success.emit(res);
|
||||
}
|
||||
@ -151,13 +126,30 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
|
||||
this.appsProcessService.getDeployedApplicationsByName(appName).subscribe(
|
||||
application => {
|
||||
this.getFiltersByAppId(application.id);
|
||||
this.selectTaskFilter(this.filterParam, this.filters);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default filters by appId
|
||||
* @param appId
|
||||
*/
|
||||
createFiltersByAppId(appId?: number) {
|
||||
this.taskFilterService.createDefaultFilters(appId).subscribe(
|
||||
(resDefault: FilterRepresentationModel[]) => {
|
||||
this.resetFilter();
|
||||
this.filters = resDefault;
|
||||
this.selectTaskFilter(this.filterParam, this.filters);
|
||||
this.success.emit(resDefault);
|
||||
},
|
||||
(errDefault: any) => {
|
||||
this.error.emit(errDefault);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass the selected filter as next
|
||||
* @param filter
|
||||
@ -167,6 +159,10 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
|
||||
this.filterClick.emit(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select filter with task
|
||||
* @param taskId
|
||||
*/
|
||||
public selectFilterWithTask(taskId: string) {
|
||||
let filteredFilterList: FilterRepresentationModel[] = [];
|
||||
this.taskListService.getFilterForTaskById(taskId, this.filters).subscribe(
|
||||
@ -186,27 +182,26 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
|
||||
|
||||
/**
|
||||
* Select the first filter of a list if present
|
||||
* @param filterParam
|
||||
* @param filteredFilterList
|
||||
*/
|
||||
public selectTaskFilter(filterParam: FilterParamsModel, filteredFilterList: FilterRepresentationModel[]) {
|
||||
let findTaskFilter;
|
||||
if (filterParam) {
|
||||
filteredFilterList.filter((taskFilter: FilterRepresentationModel, index) => {
|
||||
if (filterParam.name && filterParam.name.toLowerCase() === taskFilter.name.toLowerCase() ||
|
||||
filterParam.id === taskFilter.id.toString()
|
||||
|| filterParam.index === index) {
|
||||
filterParam.id === taskFilter.id.toString() ||
|
||||
filterParam.index === index) {
|
||||
findTaskFilter = taskFilter;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (findTaskFilter) {
|
||||
this.currentFilter = findTaskFilter;
|
||||
} else {
|
||||
this.selectDefaultTaskFilter(filteredFilterList);
|
||||
}
|
||||
findTaskFilter ? this.currentFilter = findTaskFilter : this.selectDefaultTaskFilter(filteredFilterList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select as default task filter the first in the list
|
||||
* @param filteredFilterList
|
||||
*/
|
||||
public selectDefaultTaskFilter(filteredFilterList: FilterRepresentationModel[]) {
|
||||
if (!this.isFilterListEmpty()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user