Fix sorting of processlist to match that specified by filter

Refs #1307
This commit is contained in:
Will Abson
2017-01-05 12:04:03 +00:00
parent 099c32c667
commit 086c789d4d
2 changed files with 34 additions and 3 deletions

View File

@@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Rx';
import { ActivitiProcessInstanceListComponent } from './activiti-processlist.component';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { DataTableModule, ObjectDataRow, DataRowEvent, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
import { DataTableModule, ObjectDataRow, DataRowEvent, ObjectDataTableAdapter, DataSorting } from 'ng2-alfresco-datatable';
import { TranslationMock } from './../assets/translation.service.mock';
import { ProcessInstance } from '../models/process-instance.model';
@@ -275,7 +275,7 @@ describe('ActivitiProcessInstanceListComponent', () => {
});
it('should reload the list when the sort parameter changes', (done) => {
const sort = 'desc';
const sort = 'created-desc';
let change = new SimpleChange(null, sort);
component.onSuccess.subscribe((res) => {
@@ -290,6 +290,21 @@ describe('ActivitiProcessInstanceListComponent', () => {
component.ngOnChanges({'sort': change});
});
it('should sort the list when the sort parameter changes', (done) => {
const sort = 'created-asc';
let change = new SimpleChange(null, sort);
let sortSpy = spyOn(component.data, 'setSorting');
component.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(sortSpy).toHaveBeenCalledWith(new DataSorting('started', 'asc'));
done();
});
component.sort = sort;
component.ngOnChanges({'sort': change});
});
it('should reload the process list when the name parameter changes', (done) => {
const name = 'FakeTaskName';
let change = new SimpleChange(null, name);

View File

@@ -17,7 +17,7 @@
import { Component, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow } from 'ng2-alfresco-datatable';
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow, DataSorting } from 'ng2-alfresco-datatable';
import { ProcessFilterRequestRepresentation } from '../models/process-instance-filter.model';
import { ProcessInstance } from '../models/process-instance.model';
@@ -168,9 +168,25 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
*/
private renderInstances(instances: any[]) {
instances = this.optimizeNames(instances);
this.setDatatableSorting();
this.data.setRows(instances);
}
/**
* Sort the datatable rows based on current value of 'sort' property
*/
private setDatatableSorting() {
if (!this.sort) {
return;
}
let sortingParams: string[] = this.sort.split('-');
if (sortingParams.length === 2) {
let sortColumn = sortingParams[0] === 'created' ? 'started' : sortingParams[0];
let sortOrder = sortingParams[1];
this.data.setSorting(new DataSorting(sortColumn, sortOrder));
}
}
/**
* Select the first instance of a list if present
*/