From a69e3510d103cde6ca524d5b8e3d1cce6ef2ac37 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 16 Apr 2021 12:43:56 -0400 Subject: [PATCH] LP1904036 grid toolbar button supports routerlink Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../app/share/grid/grid-toolbar-button.component.ts | 6 ++++-- .../eg2/src/app/share/grid/grid-toolbar.component.ts | 19 +++++++++++++------ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts index 62b6dd5f13..d5fce519b9 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts @@ -18,6 +18,8 @@ export class GridToolbarButtonComponent implements OnInit { // DEPRECATED: Pass a reference to a function that is called on click. @Input() action: () => any; + // Provide a router link instead of an onClick handler + @Input() routerLink: string; @Input() set disabled(d: boolean) { // Support asynchronous disabled values by appling directly @@ -33,16 +35,16 @@ export class GridToolbarButtonComponent implements OnInit { constructor(@Host() private grid: GridComponent) { this.onClick = new EventEmitter(); this.button = new GridToolbarButton(); - this.button.onClick = this.onClick; } ngOnInit() { - if (!this.grid) { console.warn('GridToolbarButtonComponent needs a [grid]'); return; } + this.button.onClick = this.onClick; + this.button.routerLink = this.routerLink; this.button.label = this.label; this.button.action = this.action; this.grid.context.toolbarButtons.push(this.button); 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 b9c1d30728..7f68063f90 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 @@ -1,4 +1,5 @@ import {Component, Input, OnInit} from '@angular/core'; +import {Router} from '@angular/router'; import {DomSanitizer, SafeUrl} from '@angular/platform-browser'; import {GridToolbarButton, GridToolbarAction, GridContext} from '@eg/share/grid/grid'; import {GridColumnWidthComponent} from './grid-column-width.component'; @@ -16,15 +17,16 @@ export class GridToolbarComponent implements OnInit { @Input() gridPrinter: GridPrintComponent; @Input() disableSaveSettings = false; - renderedGroups: {[group: string]: boolean}; + renderedGroups: {[group: string]: boolean} = {}; csvExportInProgress: boolean; csvExportUrl: SafeUrl; csvExportFileName: string; - constructor(private sanitizer: DomSanitizer) { - this.renderedGroups = {}; - } + constructor( + private router: Router, + private sanitizer: DomSanitizer + ) {} ngOnInit() { this.sortActions(); @@ -78,8 +80,13 @@ export class GridToolbarComponent implements OnInit { performButtonAction(button: GridToolbarButton) { const rows = this.gridContext.getSelectedRows(); - button.onClick.emit(rows); - if (button.action) { button.action(); } + console.log('BUTTON ACTION', button.routerLink); + if (button.routerLink) { + this.router.navigate([button.routerLink]); + } else { + button.onClick.emit(rows); + if (button.action) { button.action(); } + } } printHtml() { 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 3b10e0d69f..085b18e7c9 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -1259,6 +1259,7 @@ export class GridToolbarButton { onClick: EventEmitter; action: () => any; // DEPRECATED disabled: boolean; + routerLink: string; } export class GridToolbarCheckbox { -- 2.11.0