From 1ef7af2965dc6c1a1d1fcf6d9c2e5b07d2a6dbd9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 9 May 2019 11:50:19 -0400 Subject: [PATCH] LP1803787 Grid toolbar actions menu component; cleanup Moves the guts of the grid toolbar actions menu (the buttons) to a dedicated component that can be shared by both the actions drop-down menu and the actions popover. This adds support for honoring disableOnRow for the popover actions. And avoids duplication. Adds a sandbox example of using the toolbar action click event and divider. Some minor code cleanup/consistency changes. Signed-off-by: Bill Erickson --- .../src/app/share/grid/grid-body.component.html | 12 ++------- .../eg2/src/app/share/grid/grid-body.component.ts | 4 --- .../share/grid/grid-toolbar-action.component.ts | 15 +++++------ .../grid/grid-toolbar-actions-menu.component.html | 15 +++++++++++ .../grid/grid-toolbar-actions-menu.component.ts | 31 ++++++++++++++++++++++ .../src/app/share/grid/grid-toolbar.component.html | 18 ++----------- .../src/app/share/grid/grid-toolbar.component.ts | 16 ----------- Open-ILS/src/eg2/src/app/share/grid/grid.module.ts | 2 ++ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 4 +-- .../src/app/staff/sandbox/sandbox.component.html | 5 ++++ .../eg2/src/app/staff/sandbox/sandbox.component.ts | 5 ++++ 11 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.html create mode 100644 Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.ts diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html index 18a6a350e9..11cd884f31 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html @@ -1,15 +1,7 @@ - - - - - - - {{action.label}} - - - + + + {{action.label}} + + diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.ts new file mode 100644 index 0000000000..322caba90a --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.ts @@ -0,0 +1,31 @@ +import {Component, Input, OnInit, Host} from '@angular/core'; +import {GridToolbarAction, GridContext} from '@eg/share/grid/grid'; + +/** Models a list of toolbar action menu entries */ + +@Component({ + selector: 'eg-grid-toolbar-actions-menu', + templateUrl: 'grid-toolbar-actions-menu.component.html' +}) + +export class GridToolbarActionsMenuComponent { + + @Input() gridContext: GridContext; + + performAction(action: GridToolbarAction) { + if (action.isGroup || action.isSeparator) { + return; // These don't perform actions + } + const rows = this.gridContext.getSelectedRows(); + action.actionClick.emit(rows); + if (action.action) { action.action(rows); } + } + + shouldDisable(action: GridToolbarAction): boolean { + if (action.disableOnRows) { + return action.disableOnRows(this.gridContext.getSelectedRows()); + } + return false; + } +} + diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html index d35bcafa6d..59db39e40e 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html @@ -36,22 +36,8 @@ class="material-icons mat-icon-in-button">playlist_add_check diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts index a05aaa5ea2..308fdd012a 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts @@ -77,28 +77,12 @@ export class GridToolbarComponent implements OnInit { ); } - performAction(action: GridToolbarAction) { - if (action.isGroup || action.separator) { - return; // These don't perform actions - } - const rows = this.gridContext.getSelectedRows(); - action.onClick.emit(rows); - if (action.action) { action.action(rows); } - } - performButtonAction(button: GridToolbarButton) { const rows = this.gridContext.getSelectedRows(); button.onClick.emit(); if (button.action) { button.action(); } } - shouldDisableAction(action: GridToolbarAction) { - if (action.disableOnRows) { - return action.disableOnRows(this.gridContext.getSelectedRows()); - } - return false; - } - printHtml() { this.gridPrinter.printGrid(); } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.module.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.module.ts index 0773a7e56f..454dcfb0ed 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.module.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.module.ts @@ -9,6 +9,7 @@ import {GridToolbarComponent} from './grid-toolbar.component'; import {GridToolbarButtonComponent} from './grid-toolbar-button.component'; import {GridToolbarCheckboxComponent} from './grid-toolbar-checkbox.component'; import {GridToolbarActionComponent} from './grid-toolbar-action.component'; +import {GridToolbarActionsMenuComponent} from './grid-toolbar-actions-menu.component'; import {GridColumnConfigComponent} from './grid-column-config.component'; import {GridColumnWidthComponent} from './grid-column-width.component'; import {GridPrintComponent} from './grid-print.component'; @@ -26,6 +27,7 @@ import {GridPrintComponent} from './grid-print.component'; GridToolbarButtonComponent, GridToolbarCheckboxComponent, GridToolbarActionComponent, + GridToolbarActionsMenuComponent, GridColumnConfigComponent, GridColumnWidthComponent, GridPrintComponent diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index d1cc9c33ce..0821c9f347 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -931,11 +931,11 @@ export class GridContext { // Actions apply to specific rows export class GridToolbarAction { label: string; - onClick: EventEmitter; + actionClick: EventEmitter; action: (rows: any[]) => any; // DEPRECATED group: string; isGroup: boolean; // used for group placeholder entries - separator: boolean; + isSeparator: boolean; disableOnRows: (rows: any[]) => boolean; } diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 54cd87d11e..95c378a377 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -141,6 +141,11 @@ + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 543e3cb72b..f7de626f68 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -136,6 +136,11 @@ export class SandboxComponent implements OnInit { }); } + // Example of click handler for row action + complimentEvergreen2(rows: IdlObject[]) { + alert('I know, right?'); + } + openEditor() { this.fmRecordEditor.open({size: 'lg'}).then( ok => { console.debug(ok); }, -- 2.11.0