mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Fix task list filter by processDefinitionKey
This commit is contained in:
parent
f70c52a9f7
commit
f32e20e3d9
@ -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();
|
||||
}
|
||||
|
@ -26,11 +26,13 @@ import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
|
||||
|
||||
describe('ActivitiTaskList', () => {
|
||||
|
||||
let fakeGlobalTask = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
let fakeGlobalTask = [
|
||||
{
|
||||
id: 14, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name', description: null, category: null,
|
||||
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'
|
||||
}
|
||||
@ -41,8 +43,7 @@ describe('ActivitiTaskList', () => {
|
||||
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();
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
}
|
||||
);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user