Process list implement pagination interface (#2872)

This commit is contained in:
Maurizio Vitale
2018-02-03 18:22:05 +00:00
committed by Eugenio Romano
parent 105bc80d2c
commit 0f6ac42e4c
17 changed files with 311 additions and 141 deletions

View File

@@ -16,20 +16,22 @@
*/
import { DataColumn, DataRowEvent, DataSorting, DataTableAdapter, ObjectDataColumn, ObjectDataRow, ObjectDataTableAdapter } from '@alfresco/adf-core';
import { AppConfigService, DataColumnListComponent } from '@alfresco/adf-core';
import { AppConfigService, DataColumnListComponent, PaginatedComponent, PaginationComponent, PaginationQueryParams, UserPreferencesService } from '@alfresco/adf-core';
import { DatePipe } from '@angular/common';
import { AfterContentInit, Component, ContentChild, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model';
import { ProcessInstance } from '../models/process-instance.model';
import { processPresetsDefaultModel } from '../models/process-preset.model';
import { ProcessService } from '../services/process.service';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Pagination } from 'alfresco-js-api';
import { ProcessListModel } from '../models/process-list.model';
@Component({
selector: 'adf-process-instance-list',
styleUrls: ['./process-list.component.css'],
templateUrl: './process-list.component.html'
})
export class ProcessInstanceListComponent implements OnChanges, AfterContentInit {
export class ProcessInstanceListComponent implements OnChanges, AfterContentInit, PaginatedComponent {
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
@@ -56,6 +58,12 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
name: string;
/** The presetColumn of the custom schema to fetch. */
@Input()
page: number = 0;
@Input()
size: number = PaginationComponent.DEFAULT_PAGINATION.maxItems;
@Input()
presetColumn: string;
@@ -71,7 +79,7 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
/** Emitted when the list of process instances has been loaded successfully from the server. */
@Output()
success: EventEmitter<ProcessInstance[]> = new EventEmitter<ProcessInstance[]>();
success: EventEmitter<ProcessListModel> = new EventEmitter<ProcessListModel>();
/** Emitted when an error occurs while loading the list of process instances from the server. */
@Output()
@@ -81,8 +89,18 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
isLoading: boolean = true;
layoutPresets = {};
pagination: BehaviorSubject<Pagination>;
constructor(private processService: ProcessService,
private userPreferences: UserPreferencesService,
private appConfig: AppConfigService) {
this.size = this.userPreferences.paginationSize;
this.pagination = new BehaviorSubject<Pagination>(<Pagination> {
maxItems: this.size,
skipCount: 0,
totalItems: 0
});
}
ngAfterContentInit() {
@@ -130,6 +148,8 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
let state = changes['state'];
let sort = changes['sort'];
let name = changes['name'];
let page = changes['page'];
let size = changes['size'];
if (appId && appId.currentValue) {
changed = true;
@@ -141,6 +161,10 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
changed = true;
} else if (name && name.currentValue) {
changed = true;
} else if (page && page.currentValue !== page.previousValue) {
changed = true;
} else if (size && size.currentValue !== size.previousValue) {
changed = true;
}
return changed;
}
@@ -155,11 +179,17 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
this.processService.getProcessInstances(requestNode, this.processDefinitionKey)
.subscribe(
(response) => {
let instancesRow = this.createDataRow(response);
let instancesRow = this.createDataRow(response.data);
this.renderInstances(instancesRow);
this.selectFirst();
this.success.emit(response);
this.isLoading = false;
this.pagination.next({
count: response.data.length,
maxItems: this.size,
skipCount: this.page * this.size,
totalItems: response.total
});
},
error => {
this.error.emit(error);
@@ -297,7 +327,10 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
let requestNode = {
appDefinitionId: this.appId,
state: this.state,
sort: this.sort
sort: this.sort,
page: this.page,
size: this.size,
start: 0
};
return new ProcessFilterParamRepresentationModel(requestNode);
}
@@ -323,4 +356,12 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
private getLayoutPreset(name: string = 'default'): DataColumn[] {
return (this.layoutPresets[name] || this.layoutPresets['default']).map(col => new ObjectDataColumn(col));
}
updatePagination(params: PaginationQueryParams) {
}
get supportedPageSizes(): number[] {
return this.userPreferences.getDifferentPageSizes();
}
}

View File

@@ -0,0 +1,27 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ProcessInstance } from './process-instance.model';
export interface ProcessListModel {
size: number;
total: number;
start: number;
length: number;
data: ProcessInstance [];
}

View File

@@ -64,13 +64,13 @@ describe('ProcessService', () => {
it('should return the correct number of instances', async(() => {
service.getProcessInstances(filter).subscribe((instances) => {
expect(instances.length).toBe(1);
expect(instances.data.length).toBe(1);
});
}));
it('should return the correct instance data', async(() => {
service.getProcessInstances(filter).subscribe((instances) => {
let instance = instances[0];
let instance = instances.data[0];
expect(instance.id).toBe(exampleProcess.id);
expect(instance.name).toBe(exampleProcess.name);
expect(instance.started).toBe(exampleProcess.started);
@@ -81,8 +81,8 @@ describe('ProcessService', () => {
getProcessInstances = getProcessInstances.and.returnValue(Promise.resolve(fakeProcessInstances));
service.getProcessInstances(filter, 'fakeProcessDefinitionKey1').subscribe((instances) => {
expect(instances.length).toBe(1);
let instance = instances[0];
expect(instances.data.length).toBe(1);
let instance = instances.data[0];
expect(instance.id).toBe('340124');
expect(instance.name).toBe('James Franklin EMEA Onboarding');
expect(instance.started).toEqual(new Date('2017-10-09T12:19:44.560+0000'));

View File

@@ -23,6 +23,7 @@ import { ProcessFilterParamRepresentationModel } from '../models/filter-process.
import { ProcessDefinitionRepresentation } from '../models/process-definition.model';
import { ProcessInstanceVariable } from '../models/process-instance-variable.model';
import { ProcessInstance } from '../models/process-instance.model';
import { ProcessListModel } from '../models/process-list.model';
import 'rxjs/add/observable/throw';
declare let moment: any;
@@ -33,13 +34,15 @@ export class ProcessService {
constructor(private alfrescoApiService: AlfrescoApiService) {
}
getProcessInstances(requestNode: ProcessFilterParamRepresentationModel, processDefinitionKey?: string): Observable<ProcessInstance[]> {
getProcessInstances(requestNode: ProcessFilterParamRepresentationModel, processDefinitionKey?: string): Observable<ProcessListModel> {
return Observable.fromPromise(this.alfrescoApiService.getInstance().activiti.processApi.getProcessInstances(requestNode))
.map((res: any) => {
if (processDefinitionKey) {
return res.data.filter(process => process.processDefinitionKey === processDefinitionKey);
const filtered = res.data.filter(process => process.processDefinitionKey === processDefinitionKey);
res.data = filtered;
return res;
} else {
return res.data;
return res;
}
}).catch(err => this.handleProcessError(err));
}