LP1803787 Migrate grid action/button click handlers; lint
authorBill Erickson <berickxx@gmail.com>
Fri, 31 May 2019 15:47:03 +0000 (11:47 -0400)
committerJane Sandberg <sandbej@linnbenton.edu>
Mon, 17 Jun 2019 21:21:55 +0000 (14:21 -0700)
Migrate the basic admin page and sandbox grids to use the click handlers
for grid toolbar buttons and actions, so the actions may be performed
against class methods instead of anonymous functions.

Minor lint repairs.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/print/hatch.service.ts
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-type.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts
Open-ILS/src/eg2/src/app/staff/staff.component.ts

index 0150887..bd087b7 100644 (file)
@@ -27,7 +27,7 @@ export class HatchService {
 
     isAvailable: boolean;
     msgId: number;
-    messages: {[msgid:number]: HatchMessage};
+    messages: {[msgid: number]: HatchMessage};
 
     constructor() {
         this.isAvailable = null;
@@ -62,7 +62,7 @@ export class HatchService {
 
                 this.handleResponse(event.data);
             }
-        }); 
+        });
 
         return this.isAvailable = true;
     }
@@ -87,7 +87,7 @@ export class HatchService {
     // Handle the data sent back to the browser from Hatch.
     handleResponse(data: any) {
 
-        const msg = this.messages[data.msgid]; 
+        const msg = this.messages[data.msgid];
         if (!msg) {
             console.warn(`No Hatch request found with ID ${data.msgid}`);
             return;
index 978b46f..77d007b 100644 (file)
@@ -38,7 +38,7 @@ export class OrgUnitTypeComponent implements OnInit {
 
     loadAoutTree() {
         this.pcrud.search('aout', {depth: 0},
-            {flesh: -1, flesh_fields: {aout: ['children','org_units']}},
+            {flesh: -1, flesh_fields: {aout: ['children', 'org_units']}},
             {anonymous: true}
         ).subscribe(aoutTree => this.ingestAoutTree(aoutTree));
     }
index 720fa0f..aa21644 100644 (file)
   [cellClassCallback]="btGridCellClassCallback"
   [sortable]="true">
   <eg-grid-toolbar-action label="Action that needs a single row" i18n-label
-    [action]="complimentEvergreen" [disableOnRows]="notOneSelectedRow">
+    (onClick)="complimentEvergreen($event)" [disableOnRows]="notOneSelectedRow">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action [isSeparator]="true">
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Another Action" i18n-label
-    (actionClick)="complimentEvergreen2($event)">
+    (onClick)="complimentEvergreen2($event)">
   </eg-grid-toolbar-action>
   <eg-grid-column name="test" [cellTemplate]="cellTmpl" 
     [cellContext]="btGridTestContext" [sortable]="false">
index 7a47a3d..8d67f2e 100644 (file)
 <eg-grid #grid idlClass="{{idlClass}}" [dataSource]="dataSource" 
     [sortable]="true" persistKey="{{persistKey}}" [showLinkSelectors]="true">
   <eg-grid-toolbar-button [disabled]="!canCreate" 
-    label="New {{idlClassDef.label}}" i18n-label [action]="createNew">
+    label="New {{idlClassDef.label}}" i18n-label (onClick)="createNew($event)">
   </eg-grid-toolbar-button>
   <eg-grid-toolbar-button [disabled]="translatableFields.length == 0" 
-    label="Apply Translations" i18n-label [action]="translate">
+    label="Apply Translations" i18n-label (onClick)="translate($event)">
   </eg-grid-toolbar-button>
-  <eg-grid-toolbar-action label="Edit Selected" i18n-label [action]="editSelected">
+  <eg-grid-toolbar-action label="Edit Selected" i18n-label (onClick)="editSelected($event)">
   </eg-grid-toolbar-action>
-  <eg-grid-toolbar-action label="Delete Selected" i18n-label [action]="deleteSelected">
+  <eg-grid-toolbar-action label="Delete Selected" i18n-label (onClick)="deleteSelected($event)">
   </eg-grid-toolbar-action>
 </eg-grid>
 
index 106f364..509f95c 100644 (file)
@@ -76,15 +76,11 @@ export class AdminPageComponent implements OnInit {
 
     idlClassDef: any;
     pkeyField: string;
-    createNew: () => void;
-    deleteSelected: (rows: IdlObject[]) => void;
-    editSelected: (rows: IdlObject[]) => void;
 
     // True if any columns on the object support translations
     translateRowIdx: number;
     translateFieldIdx: number;
     translatableFields: string[];
-    translate: () => void;
 
     contextOrg: IdlObject;
     orgFieldLabel: string;
@@ -175,93 +171,6 @@ export class AdminPageComponent implements OnInit {
         this.grid.onRowActivate.subscribe(
             (idlThing: IdlObject) => this.showEditDialog(idlThing)
         );
-
-        this.editSelected = (idlThings: IdlObject[]) => {
-
-            // Edit each IDL thing one at a time
-            const editOneThing = (thing: IdlObject) => {
-                if (!thing) { return; }
-
-                this.showEditDialog(thing).then(
-                    () => editOneThing(idlThings.shift()));
-            };
-
-            editOneThing(idlThings.shift());
-        };
-
-        this.createNew = () => {
-            this.editDialog.mode = 'create';
-            // We reuse the same editor for all actions.  Be sure
-            // create action does not try to modify an existing record.
-            this.editDialog.recId = null;
-            this.editDialog.record = null;
-            this.editDialog.open({size: this.dialogSize}).then(
-                ok => {
-                    this.createString.current()
-                        .then(str => this.toast.success(str));
-                    this.grid.reload();
-                },
-                rejection => {
-                    if (!rejection.dismissed) {
-                        this.createErrString.current()
-                            .then(str => this.toast.danger(str));
-                    }
-                }
-            );
-        };
-
-        this.deleteSelected = (idlThings: IdlObject[]) => {
-            idlThings.forEach(idlThing => idlThing.isdeleted(true));
-            this.pcrud.autoApply(idlThings).subscribe(
-                val => console.debug('deleted: ' + val),
-                err => {},
-                ()  => this.grid.reload()
-            );
-        };
-
-        // Open the field translation dialog.
-        // Link the next/previous actions to cycle through each translatable
-        // field on each row.
-        this.translate = () => {
-            this.translateRowIdx = 0;
-            this.translateFieldIdx = 0;
-            this.translator.fieldName = this.translatableFields[this.translateFieldIdx];
-            this.translator.idlObject = this.dataSource.data[this.translateRowIdx];
-
-            this.translator.nextString = () => {
-
-                if (this.translateFieldIdx < this.translatableFields.length - 1) {
-                    this.translateFieldIdx++;
-
-                } else if (this.translateRowIdx < this.dataSource.data.length - 1) {
-                    this.translateRowIdx++;
-                    this.translateFieldIdx = 0;
-                }
-
-                this.translator.idlObject =
-                    this.dataSource.data[this.translateRowIdx];
-                this.translator.fieldName =
-                    this.translatableFields[this.translateFieldIdx];
-            };
-
-            this.translator.prevString = () => {
-
-                if (this.translateFieldIdx > 0) {
-                    this.translateFieldIdx--;
-
-                } else if (this.translateRowIdx > 0) {
-                    this.translateRowIdx--;
-                    this.translateFieldIdx = 0;
-                }
-
-                this.translator.idlObject =
-                    this.dataSource.data[this.translateRowIdx];
-                this.translator.fieldName =
-                    this.translatableFields[this.translateFieldIdx];
-            };
-
-            this.translator.open({size: 'lg'});
-        };
     }
 
     checkCreatePerms() {
@@ -371,6 +280,91 @@ export class AdminPageComponent implements OnInit {
         );
     }
 
+    editSelected(idlThings: IdlObject[]) {
+
+        // Edit each IDL thing one at a time
+        const editOneThing = (thing: IdlObject) => {
+            if (!thing) { return; }
+
+            this.showEditDialog(thing).then(
+                () => editOneThing(idlThings.shift()));
+        };
+
+        editOneThing(idlThings.shift());
+    }
+
+    deleteSelected(idlThings: IdlObject[]) {
+        idlThings.forEach(idlThing => idlThing.isdeleted(true));
+        this.pcrud.autoApply(idlThings).subscribe(
+            val => console.debug('deleted: ' + val),
+            err => {},
+            ()  => this.grid.reload()
+        );
+    }
+
+    createNew() {
+        this.editDialog.mode = 'create';
+        // We reuse the same editor for all actions.  Be sure
+        // create action does not try to modify an existing record.
+        this.editDialog.recId = null;
+        this.editDialog.record = null;
+        this.editDialog.open({size: this.dialogSize}).then(
+            ok => {
+                this.createString.current()
+                    .then(str => this.toast.success(str));
+                this.grid.reload();
+            },
+            rejection => {
+                if (!rejection.dismissed) {
+                    this.createErrString.current()
+                        .then(str => this.toast.danger(str));
+                }
+            }
+        );
+    }
+    // Open the field translation dialog.
+    // Link the next/previous actions to cycle through each translatable
+    // field on each row.
+    translate() {
+        this.translateRowIdx = 0;
+        this.translateFieldIdx = 0;
+        this.translator.fieldName = this.translatableFields[this.translateFieldIdx];
+        this.translator.idlObject = this.dataSource.data[this.translateRowIdx];
+
+        this.translator.nextString = () => {
+
+            if (this.translateFieldIdx < this.translatableFields.length - 1) {
+                this.translateFieldIdx++;
+
+            } else if (this.translateRowIdx < this.dataSource.data.length - 1) {
+                this.translateRowIdx++;
+                this.translateFieldIdx = 0;
+            }
+
+            this.translator.idlObject =
+                this.dataSource.data[this.translateRowIdx];
+            this.translator.fieldName =
+                this.translatableFields[this.translateFieldIdx];
+        };
+
+        this.translator.prevString = () => {
+
+            if (this.translateFieldIdx > 0) {
+                this.translateFieldIdx--;
+
+            } else if (this.translateRowIdx > 0) {
+                this.translateRowIdx--;
+                this.translateFieldIdx = 0;
+            }
+
+            this.translator.idlObject =
+                this.dataSource.data[this.translateRowIdx];
+            this.translator.fieldName =
+                this.translatableFields[this.translateFieldIdx];
+        };
+
+        this.translator.open({size: 'lg'});
+    }
 }
 
 
index dc58de1..952a468 100644 (file)
@@ -110,7 +110,7 @@ export class StaffComponent implements OnInit {
      * Make sure to fire the contextmenu Event on Shift+F10
      */
     fireContextMenuEvent(): void {
-        let event = new MouseEvent("contextmenu", {
+        const event = new MouseEvent('contextmenu', {
             bubbles: true,
             cancelable: false,
             view: window,
@@ -118,9 +118,7 @@ export class StaffComponent implements OnInit {
             buttons: 0,
         });
         document.activeElement.dispatchEvent(event);
-    };
-
-
+    }
 
     /*
     @ViewChild('egAccessKeyInfo')