[ADF-3141] ProcessList Enanchement (#3454)

* * Process list enhancements

* * Updated doc for the recent changes

* * After rebase

* * Require changes done
* after rebase
This commit is contained in:
siva kumar
2018-08-01 18:32:05 +05:30
committed by Eugenio Romano
parent 50e5e7a36a
commit 052a5ab049
6 changed files with 99 additions and 295 deletions

View File

@@ -16,19 +16,13 @@
*/
import {
DataColumn,
DataTableSchema,
DataRowEvent,
DataSorting,
DataTableComponent,
DataTableAdapter,
ObjectDataColumn,
ObjectDataRow,
ObjectDataTableAdapter,
EmptyCustomContentDirective
} from '@alfresco/adf-core';
import {
AppConfigService,
DataColumnListComponent,
PaginatedComponent,
PaginationComponent,
PaginationModel,
@@ -43,8 +37,7 @@ import {
Input,
OnChanges,
Output,
SimpleChanges,
ViewChild
SimpleChanges
} from '@angular/core';
import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model';
import { processPresetsDefaultModel } from '../models/process-preset.model';
@@ -57,14 +50,12 @@ import { ProcessListModel } from '../models/process-list.model';
styleUrls: ['./process-list.component.css'],
templateUrl: './process-list.component.html'
})
export class ProcessInstanceListComponent implements OnChanges, AfterContentInit, PaginatedComponent {
export class ProcessInstanceListComponent extends DataTableSchema implements OnChanges, AfterContentInit, PaginatedComponent {
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
static PRESET_KEY = 'adf-process-list.presets';
@ContentChild(EmptyCustomContentDirective) emptyCustomContent: EmptyCustomContentDirective;
@ViewChild('dataTable') dataTable: DataTableComponent;
/** The id of the app. */
@Input()
appId: number;
@@ -101,10 +92,6 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
@Input()
size: number = PaginationComponent.DEFAULT_PAGINATION.maxItems;
/** Name of a custom schema to fetch from `app.config.json`. */
@Input()
presetColumn: string;
/** Data source to define the datatable. */
@Input()
data: DataTableAdapter;
@@ -139,14 +126,15 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
requestNode: ProcessFilterParamRepresentationModel;
currentInstanceId: string;
isLoading: boolean = true;
layoutPresets = {};
rows: any[] = [];
sorting: any[] = ['created', 'desc'];
pagination: BehaviorSubject<PaginationModel>;
constructor(private processService: ProcessService,
private userPreferences: UserPreferencesService,
private appConfig: AppConfigService) {
appConfig: AppConfigService) {
super(appConfig, ProcessInstanceListComponent.PRESET_KEY, processPresetsDefaultModel);
this.size = this.userPreferences.paginationSize;
this.pagination = new BehaviorSubject<PaginationModel>(<PaginationModel> {
@@ -157,27 +145,16 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
}
ngAfterContentInit() {
this.loadLayoutPresets();
this.setupSchema();
this.createDatatableSchema();
if (this.data && this.data.getColumns().length === 0) {
this.data.setColumns(this.columns);
}
if (this.appId != null) {
this.reload();
}
}
/**
* Setup html-based (html definitions) or code behind (data adapter) schema.
* If component is assigned with an empty data adater the default schema settings applied.
*/
setupSchema() {
let schema = this.getSchema();
if (!this.data) {
this.data = new ObjectDataTableAdapter([], schema);
} else if (this.data.getColumns().length === 0) {
this.data.setColumns(schema);
}
}
ngOnChanges(changes: SimpleChanges) {
if (this.isPropertyChanged(changes)) {
if (this.isSortChanged(changes)) {
@@ -234,8 +211,7 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
this.processService.getProcessInstances(requestNode, this.processDefinitionKey)
.subscribe(
(response) => {
let instancesRow = this.createDataRow(response.data);
this.renderInstances(instancesRow);
this.rows = this.optimizeNames(response.data);
this.selectFirst();
this.success.emit(response);
this.isLoading = false;
@@ -252,59 +228,16 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
});
}
/**
* Create an array of ObjectDataRow
* @param instances
*/
private createDataRow(instances: any[]): ObjectDataRow[] {
let instancesRows: ObjectDataRow[] = [];
instances.forEach((row) => {
instancesRows.push(new ObjectDataRow(row));
});
return instancesRows;
}
/**
* Render the instances list
*
* @param instances
*/
private renderInstances(instances: any[]) {
instances = this.optimizeNames(instances);
this.dataTable.resetSelection();
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
*/
selectFirst() {
if (this.selectFirstRow) {
if (!this.isListEmpty()) {
let row = this.data.getRows()[0];
row.isSelected = true;
this.data.selectedRow = row;
this.currentInstanceId = row.getValue('id');
let dataRow = this.rows[0];
dataRow.isSelected = true;
this.currentInstanceId = dataRow['id'];
} else {
if (this.data) {
this.data.selectedRow = null;
}
this.currentInstanceId = null;
}
}
@@ -321,8 +254,7 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
* Check if the list is empty
*/
isListEmpty(): boolean {
return this.data === undefined ||
(this.data && this.data.getRows() && this.data.getRows().length === 0);
return !this.rows || this.rows.length === 0;
}
/**
@@ -352,9 +284,9 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
* @param instances
*/
private optimizeNames(instances: any[]): any[] {
instances = instances.map(t => {
t.obj.name = this.getProcessNameOrDescription(t.obj, 'medium');
return t;
instances = instances.map(instance => {
instance.name = this.getProcessNameOrDescription(instance, 'medium');
return instance;
});
return instances;
}
@@ -391,41 +323,6 @@ export class ProcessInstanceListComponent implements OnChanges, AfterContentInit
return new ProcessFilterParamRepresentationModel(requestNode);
}
private loadLayoutPresets(): void {
const externalSettings = this.appConfig.get('adf-process-list.presets', null);
if (externalSettings) {
this.layoutPresets = Object.assign({}, processPresetsDefaultModel, externalSettings);
} else {
this.layoutPresets = processPresetsDefaultModel;
}
}
getSchema(): any {
let customSchemaColumns = [];
customSchemaColumns = this.getSchemaFromConfig(this.presetColumn).concat(this.getSchemaFromHtml());
if (customSchemaColumns.length === 0) {
customSchemaColumns = this.getDefaultLayoutPreset();
}
return customSchemaColumns;
}
getSchemaFromHtml(): any {
let schema = [];
if (this.columnList && this.columnList.columns && this.columnList.columns.length > 0) {
schema = this.columnList.columns.map(c => <DataColumn> c);
}
return schema;
}
private getSchemaFromConfig(name: string): DataColumn[] {
return name ? (this.layoutPresets[name]).map(col => new ObjectDataColumn(col)) : [];
}
private getDefaultLayoutPreset(): DataColumn[] {
return (this.layoutPresets['default']).map(col => new ObjectDataColumn(col));
}
updatePagination(params: PaginationModel) {
const needsReload = params.maxItems || params.skipCount;
this.size = params.maxItems;