Fix task list filter by processDefinitionKey

This commit is contained in:
mauriziovitale84 2016-11-16 16:08:14 +00:00 committed by Mario Romano
parent f70c52a9f7
commit f32e20e3d9
5 changed files with 66 additions and 39 deletions

View File

@ -177,8 +177,8 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
);
this.activitiTaskList.getTasks(requestNode).subscribe(
(response) => {
if (response.data && response.data.length > 0) {
this.taskDetails = response.data[0];
if (response && response.length > 0) {
this.taskDetails = response[0];
} else {
this.reset();
}

View File

@ -26,23 +26,24 @@ import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
describe('ActivitiTaskList', () => {
let fakeGlobalTask = {
size: 2, total: 2, start: 0,
data: [
{
id: 14, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name', description: null, category: null,
assignee: {
id: 1, firstName: null, lastName: 'Administrator', email: 'admin'
}
},
{
id: 2, name: '', description: null, category: null,
assignee: {
id: 1, firstName: null, lastName: 'Administrator', email: 'admin'
}
let fakeGlobalTask = [
{
id: 14, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name',
processDefinitionId: 'fakeprocess:5:7507',
processDefinitionKey: 'fakeprocess',
processDefinitionName: 'Fake Process Name',
description: null, category: null,
assignee: {
id: 1, firstName: null, lastName: 'Administrator', email: 'admin'
}
]
};
},
{
id: 2, name: '', description: null, category: null,
assignee: {
id: 1, firstName: null, lastName: 'Administrator', email: 'admin'
}
}
];
let fakeGlobalTotalTasks = {
size: 2, total: 2, start: 0,
@ -126,6 +127,7 @@ describe('ActivitiTaskList', () => {
spyOn(component.activiti, 'getTotalTasks').and.returnValue(Observable.fromPromise(fakeGlobalTotalTasksPromise));
spyOn(component.activiti, 'getTasks').and.returnValue(Observable.fromPromise(fakeGlobalTaskPromise));
component.state = 'open';
component.processDefinitionKey = null,
component.assignment = 'fake-assignee';
component.onSuccess.subscribe( (res) => {
expect(res).toBeDefined();
@ -136,7 +138,24 @@ describe('ActivitiTaskList', () => {
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
done();
});
component.ngOnInit();
});
it('should return the filtered task list by processDefinitionKey', (done) => {
spyOn(component.activiti, 'getTotalTasks').and.returnValue(Observable.fromPromise(fakeGlobalTotalTasksPromise));
spyOn(component.activiti, 'getTasks').and.returnValue(Observable.fromPromise(fakeGlobalTaskPromise));
component.state = 'open';
component.processDefinitionKey = 'fakeprocess';
component.assignment = 'fake-assignee';
component.onSuccess.subscribe( (res) => {
expect(res).toBeDefined();
expect(component.data).toBeDefined();
expect(component.isTaskListEmpty()).not.toBeTruthy();
expect(component.data.getRows().length).toEqual(2);
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
done();
});
component.ngOnInit();
});

View File

@ -35,7 +35,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
appId: string;
@Input()
processDefinitionId: string;
processDefinitionKey: string;
@Input()
state: string;
@ -81,23 +81,29 @@ export class ActivitiTaskList implements OnInit, OnChanges {
ngOnInit() {
if (!this.data) {
this.data = new ObjectDataTableAdapter(
[],
this.defaultSchemaColumn
);
this.data = this.initDefaultSchemaColumns();
}
this.requestNode = this.createRequestNode();
this.load(this.requestNode);
this.reload();
}
ngOnChanges(changes: SimpleChanges) {
this.reload();
}
public reload() {
this.requestNode = this.createRequestNode();
this.load(this.requestNode);
}
public reload() {
this.load(this.requestNode);
/**
* Return an initDefaultSchemaColumns instance with the default Schema Column
* @returns {ObjectDataTableAdapter}
*/
initDefaultSchemaColumns(): ObjectDataTableAdapter {
return new ObjectDataTableAdapter(
[],
this.defaultSchemaColumn
);
}
private load(requestNode: TaskQueryRequestRepresentationModel) {
@ -106,7 +112,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
requestNode.size = res.total;
this.activiti.getTasks(requestNode).subscribe(
(response) => {
let taskRow = this.createDataRow(response.data);
let taskRow = this.createDataRow(response);
this.renderTasks(taskRow);
this.selectFirstTask();
this.onSuccess.emit(response);
@ -202,7 +208,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
private createRequestNode() {
let requestNode = {
appDefinitionId: this.appId,
processDefinitionId: this.processDefinitionId,
processDefinitionKey: this.processDefinitionKey,
text: this.name,
assignment: this.assignment,
state: this.state,

View File

@ -202,13 +202,11 @@ describe('ActivitiTaskListService', () => {
service.getTasks(fakeFilter).subscribe(
res => {
expect(res).toBeDefined();
expect(res.size).toEqual(1);
expect(res.total).toEqual(1);
expect(res.data.length).toEqual(1);
expect(res.data[0].name).toEqual('FakeNameTask');
expect(res.data[0].assignee.email).toEqual('fake-email@dom.com');
expect(res.data[0].assignee.firstName).toEqual('firstName');
expect(res.data[0].assignee.lastName).toEqual('lastName');
expect(res.length).toEqual(1);
expect(res[0].name).toEqual('FakeNameTask');
expect(res[0].assignee.email).toEqual('fake-email@dom.com');
expect(res[0].assignee.firstName).toEqual('firstName');
expect(res[0].assignee.lastName).toEqual('lastName');
done();
}
);

View File

@ -69,10 +69,14 @@ export class ActivitiTaskListService {
* @param filter - TaskFilterRepresentationModel
* @returns {any}
*/
getTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<any> {
getTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<TaskDetailsModel[]> {
return Observable.fromPromise(this.callApiTasksFiltered(requestNode))
.map((res: any) => {
return res;
if (requestNode.processDefinitionKey) {
return res.data.filter(p => p.processDefinitionKey === requestNode.processDefinitionKey);
} else {
return res.data;
}
}).catch(this.handleError);
}