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

@@ -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() {