[ADF-1229] Task Filter - Wrong task filter is selected when a new task is created (#2147)

* Select the correct task filter after a new task is created

* Fix currentFilter
This commit is contained in:
Maurizio Vitale 2017-07-28 17:05:03 +01:00 committed by Eugenio Romano
parent 8ebd30c286
commit 0cdeb3647c

View File

@ -118,7 +118,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
this.filterObserver.next(filter); this.filterObserver.next(filter);
}); });
this.selectTaskFilter(this.filterParam); this.selectTaskFilter(this.filterParam, this.filters);
this.onSuccess.emit(resDefault); this.onSuccess.emit(resDefault);
}, },
(errDefault: any) => { (errDefault: any) => {
@ -131,7 +131,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
this.filterObserver.next(filter); this.filterObserver.next(filter);
}); });
this.selectTaskFilter(this.filterParam); this.selectTaskFilter(this.filterParam, this.filters);
this.onSuccess.emit(res); this.onSuccess.emit(res);
} }
}, },
@ -149,7 +149,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
this.activiti.getDeployedApplications(appName).subscribe( this.activiti.getDeployedApplications(appName).subscribe(
application => { application => {
this.getFiltersByAppId(application.id); this.getFiltersByAppId(application.id);
this.selectTaskFilter(this.filterParam); this.selectTaskFilter(this.filterParam, this.filters);
}, },
(err) => { (err) => {
this.onError.emit(err); this.onError.emit(err);
@ -176,7 +176,7 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
}, },
() => { () => {
if (filteredFilterList.length > 0) { if (filteredFilterList.length > 0) {
this.selectTaskFilter(new FilterParamsModel({name: 'My Tasks'})); this.selectTaskFilter(new FilterParamsModel({name: 'My Tasks'}), filteredFilterList);
this.currentFilter.landingTaskId = taskId; this.currentFilter.landingTaskId = taskId;
this.filterClick.emit(this.currentFilter); this.filterClick.emit(this.currentFilter);
} }
@ -186,24 +186,27 @@ export class TaskFiltersComponent implements OnInit, OnChanges {
/** /**
* Select the first filter of a list if present * Select the first filter of a list if present
*/ */
public selectTaskFilter(filterParam: FilterParamsModel) { public selectTaskFilter(filterParam: FilterParamsModel, filteredFilterList: FilterRepresentationModel[]) {
let findTaskFilter;
if (filterParam) { if (filterParam) {
this.filters.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 || filterParam.index === index) { filterParam.id === taskFilter.id || filterParam.index === index) {
this.currentFilter = taskFilter; findTaskFilter = taskFilter;
} }
}); });
} }
if (this.isCurrentFilterEmpty()) { if (findTaskFilter) {
this.selectDefaultTaskFilter(); 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
*/ */
public selectDefaultTaskFilter() { public selectDefaultTaskFilter(filteredFilterList: FilterRepresentationModel[]) {
if (!this.isFilterListEmpty()) { if (!this.isFilterListEmpty()) {
this.currentFilter = this.filters[0]; this.currentFilter = this.filters[0];
} }