[ADF-3082] Task Filter - Custom Task filters don't work (#3402)

* [ADF-3082] Custom Task filters don't work.

* Added an sorting input to the datatable.
* Updated documentation for the recent changes.
* Added testcases for the recent changes.

* [ADF-3082] Custom Task filters don't work

* Added a sorting input to the datatable
* Added testcases to the recent changes.
* Updated doc for the recent changes.

* * Refactored task/process list dataSort.

* * Refactored process/task list datasort method
This commit is contained in:
siva kumar
2018-05-30 13:57:08 +05:30
committed by Maurizio Vitale
parent a11766aa23
commit 9eae0fcc8f
13 changed files with 144 additions and 11 deletions

View File

@@ -207,6 +207,62 @@ describe('DataTable', () => {
expect(element.querySelector('[data-automation-id="text_FAKE"]')).not.toBeNull();
});
it('should set rows to the data when rows defined', () => {
const dataRows =
[
{ name: 'test1' },
{ name: 'test2' },
{ name: 'test3' },
{ name: 'test4' }
];
dataTable.data = new ObjectDataTableAdapter([],
[new ObjectDataColumn({ key: 'name' })]
);
dataTable.ngOnChanges({
rows: new SimpleChange(null, dataRows, false)
});
fixture.detectChanges();
const rows = dataTable.data.getRows();
expect(rows[0].getValue('name')).toEqual('test1');
expect(rows[1].getValue('name')).toEqual('test2');
});
it('should set sort order if sorting is defined', () => {
const dataSortObj = new DataSorting('created', 'desc');
const sort = [ 'created', 'desc' ];
dataTable.data = new ObjectDataTableAdapter([],
[new ObjectDataColumn({ key: 'name' })]
);
dataTable.ngOnChanges({
sorting: new SimpleChange(null, sort, false)
});
fixture.detectChanges();
const dataSort = dataTable.data.getSorting();
expect(dataSort).toEqual(dataSortObj);
});
it('should set custom sort order', () => {
const dataSortObj = new DataSorting('dummayName', 'asc');
const sort = [ 'dummayName', 'asc' ];
dataTable.data = new ObjectDataTableAdapter([],
[new ObjectDataColumn({ key: 'name' })]
);
dataTable.data.setSorting(new DataSorting('created', 'desc'));
dataTable.ngOnChanges({
sorting: new SimpleChange(null, sort, false)
});
fixture.detectChanges();
const dataSort = dataTable.data.getSorting();
expect(dataSort).toEqual(dataSortObj);
});
it('should reset selection on mode change', () => {
spyOn(dataTable, 'resetSelection').and.callThrough();

View File

@@ -67,6 +67,12 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
@Input()
rows: any[] = [];
/** Define the sort order of the datatable. Possible values are :
* [`created`, `desc`], [`created`, `asc`], [`due`, `desc`], [`due`, `asc`]
*/
@Input()
sorting: any[] = [];
/** Row selection mode. Can be none, `single` or `multiple`. For `multiple` mode,
* you can use Cmd (macOS) or Ctrl (Win) modifier key to toggle selection for multiple rows.
*/
@@ -207,6 +213,10 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
this.resetSelection();
this.emitRowSelectionEvent('row-unselect', null);
}
if (this.isPropertyChanged(changes['sorting'])) {
this.setTableSorting(changes['sorting'].currentValue);
}
}
ngDoCheck() {
@@ -224,6 +234,12 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
return rows.map(row => new ObjectDataRow(row));
}
convertToDataSorting(sorting: any[]): DataSorting {
if (sorting && sorting.length > 0) {
return new DataSorting(sorting[0], sorting[1]);
}
}
private initAndSubscribeClickStream() {
this.unsubscribeClickStream();
let singleClickStream = this.click$
@@ -300,6 +316,12 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
}
}
private setTableSorting(sorting) {
if (this.data) {
this.data.setSorting(this.convertToDataSorting(sorting));
}
}
onRowClick(row: DataRow, e: MouseEvent) {
if (e) {
e.preventDefault();