LP1904036 grid toolbar button supports routerlink
authorBill Erickson <berickxx@gmail.com>
Fri, 16 Apr 2021 16:43:56 +0000 (12:43 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:31 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts

index 62b6dd5..d5fce51 100644 (file)
@@ -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<any>();
         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);
index b9c1d30..7f68063 100644 (file)
@@ -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() {
index 3b10e0d..085b18e 100644 (file)
@@ -1259,6 +1259,7 @@ export class GridToolbarButton {
     onClick: EventEmitter<any []>;
     action: () => any; // DEPRECATED
     disabled: boolean;
+    routerLink: string;
 }
 
 export class GridToolbarCheckbox {