mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
cancellable events for DataTable and DocumentList (#1682)
* cancellable events for DataTable and DocumentList * more typed events and code fixes * code fixes
This commit is contained in:
committed by
Eugenio Romano
parent
3e342863fd
commit
4ca18bc8f9
@@ -21,6 +21,8 @@ import { CoreModule } from 'ng2-alfresco-core';
|
||||
export * from './src/data/index';
|
||||
export * from './src/components/index';
|
||||
export * from './src/components/pagination/index';
|
||||
export * from './src/components/datatable/data-cell.event';
|
||||
export * from './src/components/datatable/data-row-action.event';
|
||||
|
||||
import { DataTableComponent } from './src/components/datatable/datatable.component';
|
||||
import { NoContentTemplateComponent } from './src/components/datatable/no-content-template.component';
|
||||
|
@@ -0,0 +1,42 @@
|
||||
/*!
|
||||
* @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 { BaseEvent } from 'ng2-alfresco-core';
|
||||
import { DataColumn, DataRow } from '../../data/datatable-adapter';
|
||||
|
||||
export class DataCellEvent extends BaseEvent<DataCellEventModel> {
|
||||
|
||||
constructor(row: DataRow, col: DataColumn, actions: any[]) {
|
||||
super();
|
||||
this.value = new DataCellEventModel(row, col, actions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class DataCellEventModel {
|
||||
|
||||
readonly row: DataRow;
|
||||
readonly col: DataColumn;
|
||||
actions: any[];
|
||||
|
||||
constructor(row: DataRow, col: DataColumn, actions: any[]) {
|
||||
this.row = row;
|
||||
this.col = col;
|
||||
this.actions = actions || [];
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
/*!
|
||||
* @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 { BaseEvent } from 'ng2-alfresco-core';
|
||||
import { DataRow } from '../../data/datatable-adapter';
|
||||
|
||||
export class DataRowActionEvent extends BaseEvent<DataRowActionModel> {
|
||||
|
||||
constructor(row: DataRow, action: any) {
|
||||
super();
|
||||
this.value = new DataRowActionModel(row, action);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class DataRowActionModel {
|
||||
|
||||
row: DataRow;
|
||||
action: any;
|
||||
|
||||
constructor(row: DataRow, action: any) {
|
||||
this.row = row;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
@@ -16,14 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit, Input, Output, EventEmitter, TemplateRef } from '@angular/core';
|
||||
import {
|
||||
DataTableAdapter,
|
||||
DataRow,
|
||||
DataColumn,
|
||||
DataSorting,
|
||||
DataRowEvent,
|
||||
ObjectDataTableAdapter
|
||||
} from '../../data/index';
|
||||
import { DataTableAdapter, DataRow, DataColumn, DataSorting, DataRowEvent, ObjectDataTableAdapter } from '../../data/index';
|
||||
import { DataCellEvent } from './data-cell.event';
|
||||
import { DataRowActionEvent } from './data-row-action.event';
|
||||
|
||||
declare var componentHandler;
|
||||
|
||||
@@ -57,13 +52,13 @@ export class DataTableComponent implements OnInit {
|
||||
rowDblClick: EventEmitter<DataRowEvent> = new EventEmitter<DataRowEvent>();
|
||||
|
||||
@Output()
|
||||
showRowContextMenu: EventEmitter<any> = new EventEmitter();
|
||||
showRowContextMenu: EventEmitter<DataCellEvent> = new EventEmitter<DataCellEvent>();
|
||||
|
||||
@Output()
|
||||
showRowActionsMenu: EventEmitter<any> = new EventEmitter();
|
||||
showRowActionsMenu: EventEmitter<DataCellEvent> = new EventEmitter<DataCellEvent>();
|
||||
|
||||
@Output()
|
||||
executeRowAction: EventEmitter<any> = new EventEmitter();
|
||||
executeRowAction: EventEmitter<DataRowActionEvent> = new EventEmitter<DataRowActionEvent>();
|
||||
|
||||
noContentTemplate: TemplateRef<any>;
|
||||
isSelectAllChecked: boolean = false;
|
||||
@@ -92,10 +87,7 @@ export class DataTableComponent implements OnInit {
|
||||
this.data.selectedRow = row;
|
||||
}
|
||||
|
||||
this.rowClick.emit({
|
||||
value: row,
|
||||
event: e
|
||||
});
|
||||
this.rowClick.emit(new DataRowEvent(row, e));
|
||||
}
|
||||
|
||||
onRowDblClick(row: DataRow, e?: Event) {
|
||||
@@ -103,10 +95,7 @@ export class DataTableComponent implements OnInit {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
this.rowDblClick.emit({
|
||||
value: row,
|
||||
event: e
|
||||
});
|
||||
this.rowDblClick.emit(new DataRowEvent(row, e));
|
||||
}
|
||||
|
||||
onColumnHeaderClick(column: DataColumn) {
|
||||
@@ -150,7 +139,7 @@ export class DataTableComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
isIconValue(row: DataRow, col: DataColumn) {
|
||||
isIconValue(row: DataRow, col: DataColumn): boolean {
|
||||
if (row && col) {
|
||||
let value = row.getValue(col.key);
|
||||
return value && value.startsWith('material-icons://');
|
||||
@@ -158,7 +147,7 @@ export class DataTableComponent implements OnInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
asIconValue(row: DataRow, col: DataColumn) {
|
||||
asIconValue(row: DataRow, col: DataColumn): string {
|
||||
if (this.isIconValue(row, col)) {
|
||||
let value = row.getValue(col.key) || '';
|
||||
return value.replace('material-icons://', '');
|
||||
@@ -166,11 +155,11 @@ export class DataTableComponent implements OnInit {
|
||||
return null;
|
||||
}
|
||||
|
||||
iconAltTextKey(value: string) {
|
||||
iconAltTextKey(value: string): string {
|
||||
return 'ICONS.' + value.substring(value.lastIndexOf('/') + 1).replace(/\.[a-z]+/, '');
|
||||
}
|
||||
|
||||
isColumnSorted(col: DataColumn, direction: string) {
|
||||
isColumnSorted(col: DataColumn, direction: string): boolean {
|
||||
if (col && direction) {
|
||||
let sorting = this.data.getSorting();
|
||||
return sorting && sorting.key === col.key && sorting.direction === direction;
|
||||
@@ -178,20 +167,19 @@ export class DataTableComponent implements OnInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
getContextMenuActions(row: DataRow, col: DataColumn) {
|
||||
let args = { row: row, col: col, actions: [] };
|
||||
this.showRowContextMenu.emit({ args: args });
|
||||
return args.actions;
|
||||
getContextMenuActions(row: DataRow, col: DataColumn): any[] {
|
||||
let event = new DataCellEvent(row, col, []);
|
||||
this.showRowContextMenu.emit(event);
|
||||
return event.value.actions;
|
||||
}
|
||||
|
||||
getRowActions(row: DataRow, col: DataColumn) {
|
||||
let args = { row: row, col: col, actions: [] };
|
||||
this.showRowActionsMenu.emit({ args: args });
|
||||
return args.actions;
|
||||
getRowActions(row: DataRow, col: DataColumn): any[] {
|
||||
let event = new DataCellEvent(row, col, []);
|
||||
this.showRowActionsMenu.emit(event);
|
||||
return event.value.actions;
|
||||
}
|
||||
|
||||
onExecuteRowAction(row: DataRow, action: any) {
|
||||
let args = { row: row, action: action };
|
||||
this.executeRowAction.emit({ args: args });
|
||||
this.executeRowAction.emit(new DataRowActionEvent(row, action));
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
import { TemplateRef } from '@angular/core';
|
||||
import { BaseUIEvent } from 'ng2-alfresco-core';
|
||||
|
||||
export interface DataTableAdapter {
|
||||
selectedRow: DataRow;
|
||||
@@ -53,7 +54,12 @@ export class DataSorting {
|
||||
}
|
||||
}
|
||||
|
||||
export interface DataRowEvent {
|
||||
value?: DataRow;
|
||||
event?: Event;
|
||||
export class DataRowEvent extends BaseUIEvent<DataRow> {
|
||||
|
||||
constructor(value: DataRow, domEvent: Event) {
|
||||
super();
|
||||
this.value = value;
|
||||
this.event = domEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user