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