[ADF-3039] Task List - Enanchement (#3404)

* * Created DataColumnSchemaAssembler component to get column schema from html and app.config.json
* Removed column related  method  from tasklist.

* * Removed data property from the tasklist component
* Using rows input property instead of data input property of the datatable

* *  Renamed  DataColumnSchemaAssembler to DataTableSchema
* Refactored DataTableSchema component

* * Changed schem property into an  input schemaColumns property  in dataTable component

* * Added selectFirstRow input property to select a first row of datatable
* Removed unnecessary method from tasklist component

* * Added test case for the recent changes
* Added mock object for the tasklist spec

* * Added testcases for recent changes in the datatable component

* * Updated datatable and tasklist document for the recent changes

* * Refactored process-service and task list component
* Updated datatable document.

* [ADF-3039] Task List - Enanchement
* Changed schemaColumn name to columns
* Updated datatable documentation.
*  data input Annotated  with @deprecated in the tasklist component

* * Added an sorting input to the datatable.
* Updated datatable and tasklist documentation
* Added method to get current sorting order.

* * After rebasing

* * Revert  sorting changes

* * After rebase

* * fixed conflicts

* * Fixed failing testcase after rebased.
This commit is contained in:
siva kumar
2018-06-01 14:09:09 +05:30
committed by Maurizio Vitale
parent 2f12f518ef
commit d4f57b8786
12 changed files with 546 additions and 420 deletions

View File

@@ -15,10 +15,9 @@
* limitations under the License.
*/
import { DataColumn, DataRowEvent, DataTableAdapter, ObjectDataColumn,
ObjectDataRow, ObjectDataTableAdapter, EmptyCustomContentDirective } from '@alfresco/adf-core';
import { DataRowEvent, DataTableAdapter, DataTableSchema, EmptyCustomContentDirective } from '@alfresco/adf-core';
import {
AppConfigService, DataColumnListComponent, PaginationComponent, PaginatedComponent,
AppConfigService, PaginationComponent, PaginatedComponent,
UserPreferencesService, UserPreferenceValues, PaginationModel } from '@alfresco/adf-core';
import {
AfterContentInit, Component, ContentChild, EventEmitter,
@@ -36,13 +35,14 @@ import { TaskListService } from './../services/tasklist.service';
templateUrl: './task-list.component.html',
styleUrls: ['./task-list.component.css']
})
export class TaskListComponent implements OnChanges, AfterContentInit, PaginatedComponent {
export class TaskListComponent extends DataTableSchema implements OnChanges, AfterContentInit, PaginatedComponent {
static PRESET_KEY = 'adf-task-list.presets';
@ContentChild(EmptyCustomContentDirective) emptyCustomContent: EmptyCustomContentDirective;
requestNode: TaskQueryRequestRepresentationModel;
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
@ContentChild(EmptyCustomContentDirective) emptyCustomContent: EmptyCustomContentDirective;
/** The id of the app. */
@Input()
appId: number;
@@ -69,7 +69,7 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
@Input()
assignment: string;
/** Define the sort order of the processes. Possible values are : `created-desc`,
/** Define the sort order of the tasks. Possible values are : `created-desc`,
* `created-asc`, `due-desc`, `due-asc`
*/
@Input()
@@ -88,6 +88,7 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
/** Data source object that represents the number and the type of the columns that
* you want to show.
*/
/** @deprecated 2.4.0 */
@Input()
data: DataTableAdapter;
@@ -98,14 +99,14 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
@Input()
selectionMode: string = 'single'; // none|single|multiple
/** Custom preset column schema in JSON format. */
@Input()
presetColumn: string;
/** Toggles multiple row selection, renders checkboxes at the beginning of each row */
@Input()
multiselect: boolean = false;
/* Toggles default selection of the first row */
@Input()
selectFirstRow: boolean = true;
/** Emitted when a task in the list is clicked */
@Output()
rowClick: EventEmitter<string> = new EventEmitter<string>();
@@ -124,7 +125,6 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
currentInstanceId: string;
selectedInstances: any[];
layoutPresets = {};
pagination: BehaviorSubject<PaginationModel>;
/** The page number of the tasks to fetch. */
@@ -135,6 +135,7 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
@Input()
size: number = PaginationComponent.DEFAULT_PAGINATION.maxItems;
rows: any[] = [];
isLoading: boolean = true;
sorting: any[] = ['created', 'desc'];
@@ -148,9 +149,9 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
hasCustomDataSource: boolean = false;
constructor(private taskListService: TaskListService,
private appConfig: AppConfigService,
appConfigService: AppConfigService,
private userPreferences: UserPreferencesService) {
super(appConfigService, TaskListComponent.PRESET_KEY, taskPresetsDefaultModel);
this.userPreferences.select(UserPreferenceValues.PaginationSize).subscribe((pageSize) => {
this.size = pageSize;
});
@@ -163,23 +164,20 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
}
ngAfterContentInit() {
this.loadLayoutPresets();
this.setupSchema();
this.createDatatableSchema();
if (this.data && this.data.getColumns().length === 0) {
this.data.setColumns(this.columns);
}
if (this.appId) {
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(): void {
let schema = this.getSchema();
if (!this.data) {
this.data = new ObjectDataTableAdapter([], schema);
} else if (this.data.getColumns().length === 0) {
this.data.setColumns(schema);
setCustomDataSource(rows: any[]): void {
if (rows) {
this.rows = rows;
this.hasCustomDataSource = true;
}
}
@@ -189,13 +187,6 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
}
}
setCustomDataSource(rows: ObjectDataRow[]): void {
if (this.data) {
this.data.setRows(rows);
this.hasCustomDataSource = true;
}
}
private isPropertyChanged(changes: SimpleChanges): boolean {
let changed: boolean = true;
@@ -217,6 +208,8 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
if (!this.hasCustomDataSource) {
this.requestNode = this.createRequestNode();
this.load(this.requestNode);
} else {
this.isLoading = false;
}
}
@@ -224,8 +217,7 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
this.isLoading = true;
this.loadTasksByState().subscribe(
(tasks) => {
let instancesRow = this.createDataRow(tasks.data);
this.renderInstances(instancesRow);
this.rows = this.optimizeNames(tasks.data);
this.selectTask(this.landingTaskId);
this.success.emit(tasks);
this.isLoading = false;
@@ -247,57 +239,25 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
: this.taskListService.findTasksByState(this.requestNode);
}
/**
* 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.data.setRows(instances);
}
/**
* Select the task given in input if present
*/
selectTask(taskIdSelected: string): void {
if (!this.isListEmpty()) {
let rows = this.data.getRows();
if (rows.length > 0) {
let dataRow;
if (taskIdSelected) {
dataRow = rows.find((currentRow: any) => {
return currentRow.getValue('id') === taskIdSelected;
});
if (!dataRow) {
dataRow = rows[0];
}
} else {
dataRow = rows[0];
let dataRow;
if (taskIdSelected) {
dataRow = this.rows.find((currentRow: any) => {
return currentRow['id'] === taskIdSelected;
});
if (!dataRow) {
dataRow = this.rows[0];
}
this.data.selectedRow = dataRow;
dataRow.isSelected = true;
this.currentInstanceId = dataRow.getValue('id');
} else {
dataRow = this.rows[0];
}
this.rows[0] = dataRow;
this.currentInstanceId = dataRow['id'];
} else {
if (this.data) {
this.data.selectedRow = null;
}
this.currentInstanceId = null;
}
}
@@ -329,8 +289,7 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
* 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;
}
onRowClick(item: DataRowEvent) {
@@ -360,12 +319,14 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
* Optimize name field
* @param istances
*/
private optimizeNames(istances: any[]): any[] {
istances = istances.map(t => {
t.obj.name = t.obj.name || 'No name';
private optimizeNames(instances: any[]): any[] {
instances = instances.map(t => {
if (!t.name) {
t.name = 'No name';
}
return t;
});
return istances;
return instances;
}
private createRequestNode() {
@@ -386,41 +347,6 @@ export class TaskListComponent implements OnChanges, AfterContentInit, Paginated
return new TaskQueryRequestRepresentationModel(requestNode);
}
private loadLayoutPresets(): void {
const externalSettings = this.appConfig.get('adf-task-list.presets', null);
if (externalSettings) {
this.layoutPresets = Object.assign({}, taskPresetsDefaultModel, externalSettings);
} else {
this.layoutPresets = taskPresetsDefaultModel;
}
}
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;