Tasklist component refactoring - Use the same code in the processes and tasks list

This commit is contained in:
mauriziovitale84
2016-11-18 11:24:16 +00:00
committed by Mario Romano
parent 2f9388710e
commit 3f826bf47a
2 changed files with 41 additions and 39 deletions

View File

@@ -149,8 +149,8 @@ describe('ActivitiTaskList', () => {
});
it('should return a currentId null when the taskList is empty', () => {
component.selectFirstTask();
expect(component.getCurrentTaskId()).toBeNull();
component.selectFirst();
expect(component.getCurrentId()).toBeNull();
});
it('should throw an exception when the response is wrong', (done) => {
@@ -192,7 +192,7 @@ describe('ActivitiTaskList', () => {
component.rowClick.subscribe(taskId => {
expect(taskId).toEqual(999);
expect(component.getCurrentTaskId()).toEqual(999);
expect(component.getCurrentId()).toEqual(999);
done();
});
@@ -219,7 +219,7 @@ describe('ActivitiTaskList', () => {
expect(component.isListEmpty()).toBeTruthy();
});
it('should reload the process list when the appId parameter changes', (done) => {
it('should reload the list when the appId parameter changes', (done) => {
const appId = '1';
let change = new SimpleChange(null, appId);
@@ -236,7 +236,7 @@ describe('ActivitiTaskList', () => {
component.ngOnChanges({'appId': change});
});
it('should reload the process list when the processDefinitionKey parameter changes', (done) => {
it('should reload the list when the processDefinitionKey parameter changes', (done) => {
const processDefinitionKey = 'fakeprocess';
let change = new SimpleChange(null, processDefinitionKey);
@@ -253,7 +253,7 @@ describe('ActivitiTaskList', () => {
component.ngOnChanges({'processDefinitionKey': change});
});
it('should reload the process list when the state parameter changes', (done) => {
it('should reload the list when the state parameter changes', (done) => {
const state = 'open';
let change = new SimpleChange(null, state);
@@ -270,7 +270,7 @@ describe('ActivitiTaskList', () => {
component.ngOnChanges({'state': change});
});
it('should reload the process list when the sort parameter changes', (done) => {
it('should reload the list when the sort parameter changes', (done) => {
const sort = 'desc';
let change = new SimpleChange(null, sort);
@@ -304,7 +304,7 @@ describe('ActivitiTaskList', () => {
component.ngOnChanges({'name': change});
});
it('should reload the process list when the assignment parameter changes', (done) => {
it('should reload the list when the assignment parameter changes', (done) => {
const assignment = 'assignee';
let change = new SimpleChange(null, assignment);

View File

@@ -63,7 +63,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
@Output()
onError: EventEmitter<any> = new EventEmitter<any>();
currentTaskId: string;
currentInstanceId: string;
private defaultSchemaColumn: any[] = [
{type: 'text', key: 'id', title: 'Id'},
@@ -140,9 +140,9 @@ export class ActivitiTaskList implements OnInit, OnChanges {
requestNode.size = res.total;
this.activiti.getTasks(requestNode).subscribe(
(response) => {
let taskRow = this.createDataRow(response);
this.renderTasks(taskRow);
this.selectFirstTask();
let instancesRow = this.createDataRow(response);
this.renderInstances(instancesRow);
this.selectFirst();
this.onSuccess.emit(response);
}, (error) => {
console.error(error);
@@ -156,55 +156,57 @@ export class ActivitiTaskList implements OnInit, OnChanges {
/**
* Create an array of ObjectDataRow
* @param tasks
* @param instances
* @returns {ObjectDataRow[]}
*/
private createDataRow(tasks: any[]): ObjectDataRow[] {
let taskRows: ObjectDataRow[] = [];
tasks.forEach((row) => {
taskRows.push(new ObjectDataRow({
private createDataRow(instances: any[]): ObjectDataRow[] {
let instancesRows: ObjectDataRow[] = [];
instances.forEach((row) => {
instancesRows.push(new ObjectDataRow({
id: row.id,
name: row.name,
created: row.created
}));
});
return taskRows;
return instancesRows;
}
/**
* The method call the adapter data table component for render the task list
* @param tasks
* Render the instances list
*
* @param instances
*/
private renderTasks(tasks: any[]) {
tasks = this.optimizeTaskName(tasks);
this.data.setRows(tasks);
private renderInstances(instances: any[]) {
instances = this.optimizeNames(instances);
this.data.setRows(instances);
}
/**
* Select the first task of a tasklist if present
* Select the first instance of a list if present
*/
selectFirstTask() {
selectFirst() {
if (!this.isListEmpty()) {
this.currentTaskId = this.data.getRows()[0].getValue('id');
this.currentInstanceId = this.data.getRows()[0].getValue('id');
} else {
this.currentTaskId = null;
this.currentInstanceId = null;
}
}
/**
* Return the current task
* Return the current id
* @returns {string}
*/
getCurrentTaskId(): string {
return this.currentTaskId;
getCurrentId(): string {
return this.currentInstanceId;
}
/**
* Check if the tasks list is empty
* Check if the list is empty
* @returns {ObjectDataTableAdapter|boolean}
*/
isListEmpty(): boolean {
return this.data === undefined || (this.data && this.data.getRows() && this.data.getRows().length === 0);
return this.data === undefined ||
(this.data && this.data.getRows() && this.data.getRows().length === 0);
}
/**
@@ -213,24 +215,24 @@ export class ActivitiTaskList implements OnInit, OnChanges {
*/
onRowClick(event: DataRowEvent) {
let item = event;
this.currentTaskId = item.value.getValue('id');
this.rowClick.emit(this.currentTaskId);
this.currentInstanceId = item.value.getValue('id');
this.rowClick.emit(this.currentInstanceId);
}
/**
* Optimize task name field
* @param tasks
* Optimize name field
* @param istances
* @returns {any[]}
*/
private optimizeTaskName(tasks: any[]) {
tasks = tasks.map(t => {
private optimizeNames(istances: any[]) {
istances = istances.map(t => {
t.obj.name = t.obj.name || 'Nameless task';
if (t.obj.name.length > 50) {
t.obj.name = t.obj.name.substring(0, 50) + '...';
}
return t;
});
return tasks;
return istances;
}
private createRequestNode() {