LP1825891 Use Hatch 'hostname' for workstation reg.
authorBill Erickson <berickxx@gmail.com>
Mon, 22 Apr 2019 21:02:05 +0000 (14:02 -0700)
committerJason Boyer <JBoyer@eoli.info>
Fri, 13 Dec 2019 14:36:28 +0000 (09:36 -0500)
Populate the workstation name with the hostname of the PC when
registring a new workstation for Hatch-enabled workstations.

Note the code gracefully returns null if Hatch returns a 404 (not found)
or Hatch is not active.

Updates the AngJS and Angular workstation admin pages to load the
hostname value when possible.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jason Boyer <JBoyer@eoli.info>
Open-ILS/src/eg2/src/app/core/hatch.service.ts
Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js
Open-ILS/web/js/ui/default/staff/services/hatch.js

index b61ee17..45ba5f4 100644 (file)
@@ -106,6 +106,15 @@ export class HatchService {
         }
     }
 
+    // Returns promise of null if Hatch is not available.
+    hostname(): Promise<string> {
+        const msg = new HatchMessage({action: 'hostname'});
+        return this.sendRequest(msg).then(
+            (m: HatchMessage) => m.response,
+            (err) => null
+        );
+    }
+
     getItem(key: string): Promise<any> {
         const msg = new HatchMessage({action: 'get', key: key});
         return this.sendRequest(msg).then((m: HatchMessage) => m.response);
index afd7940..8f84d28 100644 (file)
@@ -8,6 +8,7 @@ import {AuthService} from '@eg/core/auth.service';
 import {OrgService} from '@eg/core/org.service';
 import {EventService} from '@eg/core/event.service';
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+import {HatchService} from '@eg/core/hatch.service';
 
 // Slim version of the WS that's stored in the cache.
 interface Workstation {
@@ -46,6 +47,7 @@ export class WorkstationsComponent implements OnInit {
         private store: StoreService,
         private auth: AuthService,
         private org: OrgService,
+        private hatch: HatchService,
         private perm: PermService
     ) {}
 
@@ -54,9 +56,14 @@ export class WorkstationsComponent implements OnInit {
 
         .then(wsList => {
             this.workstations = wsList || [];
-            return this.store.getDefaultWorkstation();
 
-        }).then(def => {
+            // Populate the new WS name field with the hostname when available.
+            return this.setNewName();
+
+        }).then(
+            ok => this.store.getDefaultWorkstation()
+
+        ).then(def => {
             this.defaultName = def;
             this.selectedName = this.auth.workstation() || this.defaultName;
             const rm = this.route.snapshot.paramMap.get('remove');
@@ -101,11 +108,10 @@ export class WorkstationsComponent implements OnInit {
 
         this.workstations = this.workstations.filter(w => w.name !== name);
         this.store.setWorkstations(this.workstations);
+    }
 
-        if (this.defaultName === name) {
-            this.defaultName = null;
-            this.store.removeWorkstations();
-        }
+    setNewName() {
+        this.hatch.hostname().then(name => this.newName = name || '');
     }
 
     canDeleteSelected(): boolean {
index 70f87b9..b8d9a95 100644 (file)
@@ -828,6 +828,10 @@ function($scope , $q , $window , $location , egCore , egAlertDialog , workstatio
 
     console.log('set context org to ' + $scope.contextOrg);
 
+    egCore.hatch.hostname().then(function(name) {
+        $scope.newWSName = name || '';
+    });
+
     // fetch workstation reg perms
     egCore.perm.hasPermAt('REGISTER_WORKSTATION', true)
     .then(function(orgList) { 
index c7e2f39..6b56520 100644 (file)
@@ -989,6 +989,19 @@ angular.module('egCoreMod')
         return deferred.promise;
     }
 
+    service.hostname = function() {
+        if (service.hatchAvailable) {
+            return service.attemptHatchDelivery({action : 'hostname'})
+            .then(
+                function(name) { return name; },
+                // Gracefully handle case where Hatch has not yet been 
+                // updated to include the hostname command.
+                function() {return null}
+            );
+        } 
+        return $q.when(null);
+    }
+
     // The only requirement for opening Hatch is that the DOM be loaded.
     // Open the connection now so its state will be immediately available.
     service.openHatch();