mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Tasklist component refactoring - Use the same code in the processes and tasks list
This commit is contained in:
committed by
Mario Romano
parent
2f9388710e
commit
3f826bf47a
@@ -149,8 +149,8 @@ describe('ActivitiTaskList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a currentId null when the taskList is empty', () => {
|
it('should return a currentId null when the taskList is empty', () => {
|
||||||
component.selectFirstTask();
|
component.selectFirst();
|
||||||
expect(component.getCurrentTaskId()).toBeNull();
|
expect(component.getCurrentId()).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an exception when the response is wrong', (done) => {
|
it('should throw an exception when the response is wrong', (done) => {
|
||||||
@@ -192,7 +192,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
|
|
||||||
component.rowClick.subscribe(taskId => {
|
component.rowClick.subscribe(taskId => {
|
||||||
expect(taskId).toEqual(999);
|
expect(taskId).toEqual(999);
|
||||||
expect(component.getCurrentTaskId()).toEqual(999);
|
expect(component.getCurrentId()).toEqual(999);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
expect(component.isListEmpty()).toBeTruthy();
|
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';
|
const appId = '1';
|
||||||
let change = new SimpleChange(null, appId);
|
let change = new SimpleChange(null, appId);
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.ngOnChanges({'appId': change});
|
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';
|
const processDefinitionKey = 'fakeprocess';
|
||||||
let change = new SimpleChange(null, processDefinitionKey);
|
let change = new SimpleChange(null, processDefinitionKey);
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.ngOnChanges({'processDefinitionKey': change});
|
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';
|
const state = 'open';
|
||||||
let change = new SimpleChange(null, state);
|
let change = new SimpleChange(null, state);
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.ngOnChanges({'state': change});
|
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';
|
const sort = 'desc';
|
||||||
let change = new SimpleChange(null, sort);
|
let change = new SimpleChange(null, sort);
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.ngOnChanges({'name': change});
|
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';
|
const assignment = 'assignee';
|
||||||
let change = new SimpleChange(null, assignment);
|
let change = new SimpleChange(null, assignment);
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
onError: EventEmitter<any> = new EventEmitter<any>();
|
onError: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
currentTaskId: string;
|
currentInstanceId: string;
|
||||||
|
|
||||||
private defaultSchemaColumn: any[] = [
|
private defaultSchemaColumn: any[] = [
|
||||||
{type: 'text', key: 'id', title: 'Id'},
|
{type: 'text', key: 'id', title: 'Id'},
|
||||||
@@ -140,9 +140,9 @@ export class ActivitiTaskList implements OnInit, OnChanges {
|
|||||||
requestNode.size = res.total;
|
requestNode.size = res.total;
|
||||||
this.activiti.getTasks(requestNode).subscribe(
|
this.activiti.getTasks(requestNode).subscribe(
|
||||||
(response) => {
|
(response) => {
|
||||||
let taskRow = this.createDataRow(response);
|
let instancesRow = this.createDataRow(response);
|
||||||
this.renderTasks(taskRow);
|
this.renderInstances(instancesRow);
|
||||||
this.selectFirstTask();
|
this.selectFirst();
|
||||||
this.onSuccess.emit(response);
|
this.onSuccess.emit(response);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -156,55 +156,57 @@ export class ActivitiTaskList implements OnInit, OnChanges {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an array of ObjectDataRow
|
* Create an array of ObjectDataRow
|
||||||
* @param tasks
|
* @param instances
|
||||||
* @returns {ObjectDataRow[]}
|
* @returns {ObjectDataRow[]}
|
||||||
*/
|
*/
|
||||||
private createDataRow(tasks: any[]): ObjectDataRow[] {
|
private createDataRow(instances: any[]): ObjectDataRow[] {
|
||||||
let taskRows: ObjectDataRow[] = [];
|
let instancesRows: ObjectDataRow[] = [];
|
||||||
tasks.forEach((row) => {
|
instances.forEach((row) => {
|
||||||
taskRows.push(new ObjectDataRow({
|
instancesRows.push(new ObjectDataRow({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
created: row.created
|
created: row.created
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
return taskRows;
|
return instancesRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method call the adapter data table component for render the task list
|
* Render the instances list
|
||||||
* @param tasks
|
*
|
||||||
|
* @param instances
|
||||||
*/
|
*/
|
||||||
private renderTasks(tasks: any[]) {
|
private renderInstances(instances: any[]) {
|
||||||
tasks = this.optimizeTaskName(tasks);
|
instances = this.optimizeNames(instances);
|
||||||
this.data.setRows(tasks);
|
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()) {
|
if (!this.isListEmpty()) {
|
||||||
this.currentTaskId = this.data.getRows()[0].getValue('id');
|
this.currentInstanceId = this.data.getRows()[0].getValue('id');
|
||||||
} else {
|
} else {
|
||||||
this.currentTaskId = null;
|
this.currentInstanceId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current task
|
* Return the current id
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getCurrentTaskId(): string {
|
getCurrentId(): string {
|
||||||
return this.currentTaskId;
|
return this.currentInstanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the tasks list is empty
|
* Check if the list is empty
|
||||||
* @returns {ObjectDataTableAdapter|boolean}
|
* @returns {ObjectDataTableAdapter|boolean}
|
||||||
*/
|
*/
|
||||||
isListEmpty(): 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) {
|
onRowClick(event: DataRowEvent) {
|
||||||
let item = event;
|
let item = event;
|
||||||
this.currentTaskId = item.value.getValue('id');
|
this.currentInstanceId = item.value.getValue('id');
|
||||||
this.rowClick.emit(this.currentTaskId);
|
this.rowClick.emit(this.currentInstanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimize task name field
|
* Optimize name field
|
||||||
* @param tasks
|
* @param istances
|
||||||
* @returns {any[]}
|
* @returns {any[]}
|
||||||
*/
|
*/
|
||||||
private optimizeTaskName(tasks: any[]) {
|
private optimizeNames(istances: any[]) {
|
||||||
tasks = tasks.map(t => {
|
istances = istances.map(t => {
|
||||||
t.obj.name = t.obj.name || 'Nameless task';
|
t.obj.name = t.obj.name || 'Nameless task';
|
||||||
if (t.obj.name.length > 50) {
|
if (t.obj.name.length > 50) {
|
||||||
t.obj.name = t.obj.name.substring(0, 50) + '...';
|
t.obj.name = t.obj.name.substring(0, 50) + '...';
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
return tasks;
|
return istances;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createRequestNode() {
|
private createRequestNode() {
|
||||||
|
Reference in New Issue
Block a user