From: Bill Erickson Date: Mon, 26 Nov 2018 18:21:36 +0000 (+0000) Subject: LP1803787 Grid actions context menu X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e5e0ebd44ee1736f64f6337a59f9578dbc78d365;p=working%2FEvergreen.git LP1803787 Grid actions context menu Display a context menu including the grid actions for selected rows links when right-clicking on a grid item. Note the popover displays oriented to the bottom of the item instead of the mouse click, which is not supported at time of dev. Signed-off-by: Bill Erickson --- 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 b7284fe6f0..ca5d1f8cd8 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,3 +1,17 @@ + + + + + + + + + {{action.label}} + + + + + @@ -25,10 +39,20 @@ + +
diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts index e4829cee01..0486b88923 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts @@ -1,7 +1,8 @@ import {Component, Input, OnInit, Host} from '@angular/core'; import {GridContext, GridColumn, GridRowSelector, - GridColumnSet, GridDataSource} from './grid'; + GridToolbarAction, GridColumnSet, GridDataSource} from './grid'; import {GridComponent} from './grid.component'; +import {NgbPopover} from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'eg-grid-body', @@ -12,7 +13,13 @@ export class GridBodyComponent implements OnInit { @Input() context: GridContext; - constructor(@Host() private grid: GridComponent) {} + // Track the context menus so we can manually close them + // when another popover is opened. + contextMenus: NgbPopover[]; + + constructor(@Host() private grid: GridComponent) { + this.contextMenus = []; + } ngOnInit() {} @@ -49,7 +56,14 @@ export class GridBodyComponent implements OnInit { } } - onRowClick($event: any, row: any, idx: number) { + handleRowClick($event: any, row: any) { + + if (this.context.disableSelect) { + // Avoid any appearance or click behavior when row + // selection is disabled. + return; + } + const index = this.context.getRowIndex(row); if (this.context.disableMultiSelect) { @@ -65,7 +79,10 @@ export class GridBodyComponent implements OnInit { } else { this.context.selectOneRow(index); } + } + onRowClick($event: any, row: any, idx: number) { + this.handleRowClick($event, row); this.grid.onRowClick.emit(row); } @@ -73,5 +90,32 @@ export class GridBodyComponent implements OnInit { this.grid.onRowActivate.emit(row); } + performAction(action: GridToolbarAction) { + action.action(this.context.getSelectedRows()); + } + + // Apply row selection, track the new menu if needed, + // manually close any existing open menus, open selected menu. + onRowContextClick($event, row: any, contextMenu: NgbPopover) { + $event.preventDefault(); // prevent browser context menu + + if (this.context.toolbarActions.length === 0) { + // No actions to render. + return; + } + + this.handleRowClick($event, row); + + const existing = this.contextMenus.filter(m => m === contextMenu)[0]; + if (!existing) { + this.contextMenus.push(contextMenu); + } + + // Force any previously opened menus to close, which does + // not naturally occur via context-click. + this.contextMenus.forEach(m => m.close()); + + contextMenu.open({gridContext: this.context}); + } }