From 7c1a336274cfa24c27a750993a589b12c526d822 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 22 Apr 2019 14:02:05 -0700 Subject: [PATCH] LP1825891 Use Hatch 'hostname' for workstation reg. 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 Signed-off-by: Jason Boyer --- Open-ILS/src/eg2/src/app/core/hatch.service.ts | 9 +++++++++ .../workstation/workstations/workstations.component.ts | 18 ++++++++++++------ .../web/js/ui/default/staff/admin/workstation/app.js | 4 ++++ Open-ILS/web/js/ui/default/staff/services/hatch.js | 13 +++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/core/hatch.service.ts b/Open-ILS/src/eg2/src/app/core/hatch.service.ts index b61ee176e4..45ba5f4cd7 100644 --- a/Open-ILS/src/eg2/src/app/core/hatch.service.ts +++ b/Open-ILS/src/eg2/src/app/core/hatch.service.ts @@ -106,6 +106,15 @@ export class HatchService { } } + // Returns promise of null if Hatch is not available. + hostname(): Promise { + const msg = new HatchMessage({action: 'hostname'}); + return this.sendRequest(msg).then( + (m: HatchMessage) => m.response, + (err) => null + ); + } + getItem(key: string): Promise { const msg = new HatchMessage({action: 'get', key: key}); return this.sendRequest(msg).then((m: HatchMessage) => m.response); diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts index afd7940f17..8f84d28467 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.ts @@ -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 { diff --git a/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js b/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js index 70f87b9f8e..b8d9a95100 100644 --- a/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js +++ b/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js @@ -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) { diff --git a/Open-ILS/web/js/ui/default/staff/services/hatch.js b/Open-ILS/web/js/ui/default/staff/services/hatch.js index c7e2f39485..6b565201b6 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -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(); -- 2.11.0