mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Maurizio Vitale
parent
2f12f518ef
commit
d4f57b8786
@@ -287,6 +287,43 @@ describe('DataTable', () => {
|
||||
expect(dataTable.resetSelection).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should select first row when selectFirstRow set to true', () => {
|
||||
dataTable.selectFirstRow = true;
|
||||
dataTable.rows = [{ name: 'TEST1' }, { name: 'FAKE2' }, { name: 'TEST2' }, { name: 'FAKE2' }];
|
||||
dataTable.data = new ObjectDataTableAdapter([],
|
||||
[new ObjectDataColumn({ key: 'name' })]
|
||||
);
|
||||
fixture.detectChanges();
|
||||
const rows = dataTable.data.getRows();
|
||||
expect(rows[0].isSelected).toBeTruthy();
|
||||
expect(rows[1].isSelected).toBeFalsy();
|
||||
expect(rows[2].isSelected).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not select first row when selectFirstRow set to false', () => {
|
||||
dataTable.selectFirstRow = false;
|
||||
const dataRows =
|
||||
[
|
||||
{ name: 'TEST1' },
|
||||
{ name: 'FAKE2' },
|
||||
{ name: 'TEST2' },
|
||||
{ name: 'FAKE2' }
|
||||
];
|
||||
dataTable.data = new ObjectDataTableAdapter(dataRows,
|
||||
[new ObjectDataColumn({ key: 'name' })]
|
||||
);
|
||||
|
||||
dataTable.ngOnChanges({
|
||||
rows: new SimpleChange(null, dataRows, false)
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
const rows = dataTable.data.getRows();
|
||||
expect(rows[0].isSelected).toBeFalsy();
|
||||
expect(rows[1].isSelected).toBeFalsy();
|
||||
expect(rows[2].isSelected).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should select only one row with [single] selection mode', (done) => {
|
||||
dataTable.selectionMode = 'single';
|
||||
dataTable.data = new ObjectDataTableAdapter(
|
||||
|
@@ -71,6 +71,14 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
@Input()
|
||||
sorting: any[] = [];
|
||||
|
||||
/** The columns that the datatable will show. */
|
||||
@Input()
|
||||
columns: any[] = [];
|
||||
|
||||
/* Toggles default selection of the first row */
|
||||
@Input()
|
||||
selectFirstRow: boolean = true;
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
@@ -158,8 +166,6 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
private clickObserver: Observer<DataRowEvent>;
|
||||
private click$: Observable<DataRowEvent>;
|
||||
|
||||
private schema: DataColumn[] = [];
|
||||
|
||||
private differ: any;
|
||||
private rowMenuCache: object = {};
|
||||
|
||||
@@ -293,7 +299,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
}
|
||||
|
||||
private initTable() {
|
||||
this.data = new ObjectDataTableAdapter(this.rows, this.schema);
|
||||
this.data = new ObjectDataTableAdapter(this.rows, this.columns);
|
||||
this.setupData(this.data);
|
||||
this.rowMenuCache = {};
|
||||
}
|
||||
@@ -323,16 +329,32 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
this.resetSelection();
|
||||
}
|
||||
this.data.setRows(this.convertToRowsData(rows));
|
||||
this.selectFirst();
|
||||
}
|
||||
}
|
||||
|
||||
private selectFirst() {
|
||||
if (this.selectFirstRow) {
|
||||
if (this.data && this.data.getRows().length > 0) {
|
||||
let row = this.data.getRows()[0];
|
||||
row.isSelected = true;
|
||||
this.data.selectedRow = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private setTableSchema() {
|
||||
if (this.columnList && this.columnList.columns) {
|
||||
this.schema = this.columnList.columns.map(c => <DataColumn> c);
|
||||
let schema = [];
|
||||
if (!this.columns || this.columns.length === 0) {
|
||||
schema = this.getSchemaFromHtml();
|
||||
} else {
|
||||
schema = this.columns.concat(this.getSchemaFromHtml());
|
||||
}
|
||||
|
||||
if (this.data && this.schema && this.schema.length > 0) {
|
||||
this.data.setColumns(this.schema);
|
||||
this.columns = schema;
|
||||
|
||||
if (this.data && this.columns && this.columns.length > 0) {
|
||||
this.data.setColumns(this.columns);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,6 +364,14 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
}
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
onRowClick(row: DataRow, e: MouseEvent) {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
|
80
lib/core/datatable/data/data-table.schema.ts
Normal file
80
lib/core/datatable/data/data-table.schema.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ContentChild, Input } from '@angular/core';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { DataColumnListComponent } from '../../data-column/data-column-list.component';
|
||||
import { DataColumn } from './data-column.model';
|
||||
import { ObjectDataColumn } from './object-datacolumn.model';
|
||||
|
||||
export abstract class DataTableSchema {
|
||||
|
||||
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
|
||||
|
||||
/** Custom preset column schema in JSON format. */
|
||||
@Input()
|
||||
presetColumn: string;
|
||||
|
||||
columns: any;
|
||||
|
||||
private layoutPresets = {};
|
||||
|
||||
constructor(private appConfigService: AppConfigService,
|
||||
protected presetKey: string,
|
||||
protected presetsModel: any) { }
|
||||
|
||||
public createDatatableSchema(): void {
|
||||
this.loadLayoutPresets();
|
||||
if (!this.columns || this.columns.length === 0) {
|
||||
this.columns = this.mergeJsonAndHtmlSchema();
|
||||
}
|
||||
}
|
||||
|
||||
public loadLayoutPresets(): void {
|
||||
const externalSettings = this.appConfigService.get(this.presetKey, null);
|
||||
if (externalSettings) {
|
||||
this.layoutPresets = Object.assign({}, this.presetsModel, externalSettings);
|
||||
} else {
|
||||
this.layoutPresets = this.presetsModel;
|
||||
}
|
||||
}
|
||||
|
||||
public mergeJsonAndHtmlSchema(): any {
|
||||
let customSchemaColumns = [];
|
||||
customSchemaColumns = this.getSchemaFromConfig(this.presetColumn).concat(this.getSchemaFromHtml(this.columnList));
|
||||
if (customSchemaColumns.length === 0) {
|
||||
customSchemaColumns = this.getDefaultLayoutPreset();
|
||||
}
|
||||
return customSchemaColumns;
|
||||
}
|
||||
|
||||
public getSchemaFromHtml(columnList: DataColumnListComponent): any {
|
||||
let schema = [];
|
||||
if (columnList && columnList.columns && columnList.columns.length > 0) {
|
||||
schema = columnList.columns.map(c => <DataColumn> c);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
public getSchemaFromConfig(presetColoumn: string): DataColumn[] {
|
||||
return presetColoumn ? (this.layoutPresets[presetColoumn]).map(col => new ObjectDataColumn(col)) : [];
|
||||
}
|
||||
|
||||
private getDefaultLayoutPreset(): DataColumn[] {
|
||||
return (this.layoutPresets['default']).map(col => new ObjectDataColumn(col));
|
||||
}
|
||||
}
|
@@ -35,6 +35,7 @@ export * from './components/datatable/date-cell.component';
|
||||
export * from './components/datatable/empty-list.component';
|
||||
export * from './components/datatable/filesize-cell.component';
|
||||
export * from './components/datatable/location-cell.component';
|
||||
export * from './data/data-table.schema';
|
||||
|
||||
export * from './directives/loading-template.directive';
|
||||
export * from './directives/no-content-template.directive';
|
||||
|
Reference in New Issue
Block a user