[ADF-2505] ADF Processlist multi selection issues. (#3115)

* [ADF-2505] Added new input to check if first row has to be selected

* [ADF-2505] Reset selection when data changes

* [ADF-2505] Added documentation
This commit is contained in:
Deepak Paul
2018-03-23 13:46:06 +05:30
committed by Eugenio Romano
parent 845bdebfc9
commit 12f29d5524
4 changed files with 46 additions and 14 deletions

View File

@@ -34,6 +34,7 @@ Renders a list containing all the process instances matched by the parameters sp
| data | DataTableAdapter | | Data source to define the datatable. | | data | DataTableAdapter | | Data source to define the datatable. |
| multiselect | boolean | false | Toggles multiple row selection, renders checkboxes at the beginning of each row. | | multiselect | boolean | false | Toggles multiple row selection, renders checkboxes at the beginning of each row. |
| selectionMode | string | 'single' | 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. | | selectionMode | string | 'single' | 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. |
| selectFirstRow | boolean | true | Toggles default selection of the first row. |
### Events ### Events

View File

@@ -1,6 +1,5 @@
<div *ngIf="!requestNode">{{ 'ADF_PROCESS_LIST.FILTERS.MESSAGES.NONE' | translate }}</div> <div>
<div *ngIf="requestNode"> <adf-datatable #dataTable
<adf-datatable
[data]="data" [data]="data"
[loading]="isLoading" [loading]="isLoading"
[selectionMode]="selectionMode" [selectionMode]="selectionMode"
@@ -21,7 +20,7 @@
<!--Add your custom empty template here--> <!--Add your custom empty template here-->
<ng-template> <ng-template>
<div class="no-content-message"> <div class="no-content-message">
{{ 'ADF_PROCESS_LIST.LIST.NONE' | translate }} {{ (requestNode ? 'ADF_PROCESS_LIST.LIST.NONE' : 'ADF_PROCESS_LIST.FILTERS.MESSAGES.NONE') | translate }}
</div> </div>
</ng-template> </ng-template>
</no-content-template> </no-content-template>

View File

@@ -279,6 +279,27 @@ describe('ProcessInstanceListComponent', () => {
expect(dataRow[1].isSelected).toEqual(false); expect(dataRow[1].isSelected).toEqual(false);
}); });
it('should not select first row when selectFirstRow is false', () => {
component.data = new ObjectDataTableAdapter(
[
{ id: '999', name: 'Fake-name' },
{ id: '888', name: 'Fake-name-888' }
],
[
{ type: 'text', key: 'id', title: 'Id' },
{ type: 'text', key: 'name', title: 'Name' }
]
);
component.selectFirstRow = false;
component.selectFirst();
const dataRow = component.data.getRows();
expect(dataRow).toBeDefined();
expect(dataRow[0].getValue('id')).toEqual('999');
expect(dataRow[0].isSelected).toEqual(false);
expect(dataRow[1].getValue('id')).toEqual('888');
expect(dataRow[1].isSelected).toEqual(false);
});
it('should throw an exception when the response is wrong', fakeAsync(() => { it('should throw an exception when the response is wrong', fakeAsync(() => {
let emitSpy: jasmine.Spy = spyOn(component.error, 'emit'); let emitSpy: jasmine.Spy = spyOn(component.error, 'emit');
let mockError = 'Fake server error'; let mockError = 'Fake server error';

View File

@@ -19,6 +19,7 @@ import {
DataColumn, DataColumn,
DataRowEvent, DataRowEvent,
DataSorting, DataSorting,
DataTableComponent,
DataTableAdapter, DataTableAdapter,
ObjectDataColumn, ObjectDataColumn,
ObjectDataRow, ObjectDataRow,
@@ -41,7 +42,8 @@ import {
Input, Input,
OnChanges, OnChanges,
Output, Output,
SimpleChanges SimpleChanges,
ViewChild
} from '@angular/core'; } from '@angular/core';
import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model'; import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model';
import { processPresetsDefaultModel } from '../models/process-preset.model'; import { processPresetsDefaultModel } from '../models/process-preset.model';
@@ -59,6 +61,8 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent; @ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
@ViewChild('dataTable') dataTable: DataTableComponent;
/** The id of the app. */ /** The id of the app. */
@Input() @Input()
appId: number; appId: number;
@@ -108,6 +112,10 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
@Input() @Input()
selectionMode: string = 'single'; // none|single|multiple selectionMode: string = 'single'; // none|single|multiple
/* Toggles default selection of the first row */
@Input()
selectFirstRow: boolean = true;
/** Emitted when a row in the process list is clicked. */ /** Emitted when a row in the process list is clicked. */
@Output() @Output()
rowClick: EventEmitter<string> = new EventEmitter<string>(); rowClick: EventEmitter<string> = new EventEmitter<string>();
@@ -243,6 +251,7 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
*/ */
private renderInstances(instances: any[]) { private renderInstances(instances: any[]) {
instances = this.optimizeNames(instances); instances = this.optimizeNames(instances);
this.dataTable.resetSelection();
this.setDatatableSorting(); this.setDatatableSorting();
this.data.setRows(instances); this.data.setRows(instances);
} }
@@ -266,16 +275,18 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
* Select the first instance of a list if present * Select the first instance of a list if present
*/ */
selectFirst() { selectFirst() {
if (!this.isListEmpty()) { if (this.selectFirstRow) {
let row = this.data.getRows()[0]; if (!this.isListEmpty()) {
row.isSelected = true; let row = this.data.getRows()[0];
this.data.selectedRow = row; row.isSelected = true;
this.currentInstanceId = row.getValue('id'); this.data.selectedRow = row;
} else { this.currentInstanceId = row.getValue('id');
if (this.data) { } else {
this.data.selectedRow = null; if (this.data) {
this.data.selectedRow = null;
}
this.currentInstanceId = null;
} }
this.currentInstanceId = null;
} }
} }