[ADF-1309] Task List Pagination (#2255)

* Basic version

* Fix pagination errors

* Fix error on complete task

* Add error

* Fix unit test

* Remove the external paginator component

* Rollback unit test about error event
This commit is contained in:
Maurizio Vitale
2017-08-29 14:28:27 +01:00
committed by Mario Romano
parent 8e3d84504a
commit 5d22e78bb7
28 changed files with 646 additions and 367 deletions

View File

@@ -15,20 +15,21 @@
* limitations under the License.
*/
import { AfterContentInit, Component, ContentChild, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { AfterContentInit, Component, ContentChild, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { DataColumnListComponent } from 'ng2-alfresco-core';
import { DataColumn, DataRowEvent, DataTableAdapter, ObjectDataRow, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
import { Observable } from 'rxjs/Rx';
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { TaskListModel } from '../models/task-list.model';
import { TaskListService } from './../services/tasklist.service';
const DEFAULT_SIZE = 5;
@Component({
selector: 'adf-tasklist, activiti-tasklist',
templateUrl: './tasklist.component.html',
styleUrls: ['./tasklist.component.css']
})
export class TaskListComponent implements OnChanges, AfterContentInit {
export class TaskListComponent implements OnChanges, OnInit, AfterContentInit {
requestNode: TaskQueryRequestRepresentationModel;
@@ -72,6 +73,12 @@ export class TaskListComponent implements OnChanges, AfterContentInit {
currentInstanceId: string;
@Input()
page: number = 0;
@Input()
size: number = DEFAULT_SIZE;
isLoading: boolean = true;
/**
@@ -92,6 +99,23 @@ export class TaskListComponent implements OnChanges, AfterContentInit {
constructor(private taskListService: TaskListService) {
}
ngOnInit() {
if (this.data === undefined) {
this.data = new ObjectDataTableAdapter();
}
this.taskListService.tasksList$.subscribe(
(tasks) => {
let instancesRow = this.createDataRow(tasks.data);
this.renderInstances(instancesRow);
this.selectTask(this.landingTaskId);
this.onSuccess.emit(tasks);
this.isLoading = false;
}, (error) => {
this.onError.emit(error);
this.isLoading = false;
});
}
ngAfterContentInit() {
this.setupSchema();
}
@@ -132,32 +156,11 @@ export class TaskListComponent implements OnChanges, AfterContentInit {
}
private isPropertyChanged(changes: SimpleChanges): boolean {
let changed: boolean = false;
let changed: boolean = true;
let appId = changes['appId'];
let processInstanceId = changes['processInstanceId'];
let processDefinitionKey = changes['processDefinitionKey'];
let state = changes['state'];
let sort = changes['sort'];
let name = changes['name'];
let assignment = changes['assignment'];
let landingTaskId = changes['landingTaskId'];
if (appId && appId.currentValue) {
changed = true;
} else if (processInstanceId && processInstanceId.currentValue) {
changed = true;
} else if (processDefinitionKey && processDefinitionKey.currentValue) {
changed = true;
} else if (state && state.currentValue) {
changed = true;
} else if (sort && sort.currentValue) {
changed = true;
} else if (name && name.currentValue) {
changed = true;
} else if (assignment && assignment.currentValue) {
changed = true;
} else if (landingTaskId && landingTaskId.currentValue && !this.isEqualToCurrentId(landingTaskId.currentValue)) {
changed = true;
if (landingTaskId && landingTaskId.currentValue && this.isEqualToCurrentId(landingTaskId.currentValue)) {
changed = false;
}
return changed;
}
@@ -171,24 +174,15 @@ export class TaskListComponent implements OnChanges, AfterContentInit {
private load(requestNode: TaskQueryRequestRepresentationModel) {
this.isLoading = true;
this.loadTasksByState().subscribe(
(response) => {
let instancesRow = this.createDataRow(response);
this.renderInstances(instancesRow);
this.selectTask(requestNode.landingTaskId);
this.onSuccess.emit(response);
this.isLoading = false;
}, (error) => {
this.onError.emit(error);
this.isLoading = false;
});
this.loadTasksByState().subscribe();
}
private loadTasksByState(): Observable<TaskDetailsModel[]> {
private loadTasksByState(): Observable<TaskListModel> {
return this.requestNode.state === 'all'
? this.taskListService.findAllTasksWhitoutState(this.requestNode)
: this.taskListService.findAllTaskByState(this.requestNode);
: this.taskListService.findTasksByState(this.requestNode);
}
/**
* Create an array of ObjectDataRow
* @param instances
@@ -281,6 +275,7 @@ export class TaskListComponent implements OnChanges, AfterContentInit {
}
private createRequestNode() {
let requestNode = {
appDefinitionId: this.appId,
processInstanceId: this.processInstanceId,
@@ -289,7 +284,10 @@ export class TaskListComponent implements OnChanges, AfterContentInit {
assignment: this.assignment,
state: this.state,
sort: this.sort,
landingTaskId: this.landingTaskId
landingTaskId: this.landingTaskId,
page: this.page,
size: this.size,
start: 0
};
return new TaskQueryRequestRepresentationModel(requestNode);
}