workstation reg / display additions
authorBill Erickson <berick@esilibrary.com>
Wed, 30 Apr 2014 16:43:51 +0000 (12:43 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 30 Apr 2014 16:43:51 +0000 (12:43 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/admin/workstation/index.tt2
Open-ILS/src/templates/staff/admin/workstation/t_splash.tt2
Open-ILS/src/templates/staff/t_login.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js
Open-ILS/web/js/ui/default/staff/app.js
Open-ILS/web/js/ui/default/staff/navbar.js
Open-ILS/web/js/ui/default/staff/services/env.js
Open-ILS/web/js/ui/default/staff/services/org.js
Open-ILS/web/js/ui/default/staff/services/printstore.js

index 64d7fe8..9adc8fb 100644 (file)
@@ -13,7 +13,8 @@
 angular.module('egCoreMod')
 .factory('egAppStrings', function() {return {
 PREFS_REMOVE_KEY_CONFIRM : 
-  '[% l('Delete content for key "[_1]"?', '{{deleteKey}}') %]'
+  '[% l('Delete content for key "[_1]"?', '{{deleteKey}}') %]',
+DEFAULT_WS_LABEL : '[% l('[_1] (Default)') %]'
 }});
 </script>
 [% END %]
index e5e4602..0c26f02 100644 (file)
@@ -1,5 +1,8 @@
 <br/>
 <style>
+  #admin-workstation-container .row {
+    margin-top: 5px;
+  }
   #admin-workstation-container .new-entry {
     margin-top: 10px;
     padding-top: 10px;
 
   <div class="row">
     <div class="col-md-6">
-      <div class="checkbox">
-        <label>
-          <input type="checkbox" ng-class="{disabled : !userHasAdminPerm}"
-            ng-model="usesWorkstation" ng-change="updateHatchRequired()">
-[% l('This workstation requires a workstation name?') %]
-        </label>
+      [% l('Registered Workstations') %]
+    </div>
+  </div>
+  <div class="row">
+    <div class="col-md-6">
+      <div class="input-group">
+        <select class="form-control" ng-model="selectedWS">
+          <option ng-repeat="ws in workstations" value="{{ws.id}}"
+            ng-selected="ws.id == defaultWS.id">
+            {{getWSLabel(ws)}}
+          </option>
+        </select>
+        <div class="input-group-btn">
+          <button class="btn btn-default">
+            [% l('Login') %]
+          </button>
+        </div>
+        <div class="input-group-btn">
+          <button class="btn btn-default" ng-click="setDefaultWS()">
+            [% l('Set as Default') %]
+          </button>
+        </div>
+        <div class="input-group-btn">
+          <button class="btn btn-default btn-warning">
+            [% l('Delete') %]
+          </button>
+        </div>
       </div>
     </div>
   </div>
+
+  <div class="row new-entry">
+    <div class="col-md-6">
+      [% l('Register a New Workstation') %]
+    </div>
+  </div>
   <div class="row">
     <div class="col-md-6">
-      <input type='text' class='form-control'  
-        ng-disabled="!userHasAdminPerm || !usesWorkstation"
-        title="[% l('Workstation Name') %]"
-        placeholder="[% l('Workstation Name') %]"
-        ng-change='updateWorkstation()' ng-model='workstationName'/>
+      <div class="input-group">
+        <div class="input-group-btn">
+          <eg-org-selector 
+            selected="contextOrg"
+            org-changed="wsOrgChanged">
+          </eg-org-selector>
+        </div>
+        <input type='text' class='form-control'  
+          title="[% l('Workstation Name') %]"
+          placeholder="[% l('Workstation Name') %]"
+          ng-model='newWSName'/>
+        <div class="input-group-btn">
+          <button class="btn btn-default" ng-click="registerWS()">
+            [% l('Register') %]
+          </button>
+        </div>
+      </div>
     </div>
   </div>
 
index a29b7bc..0bddfab 100644 (file)
             <div class="form-group row">
               <label class="col-md-4 control-label" for="login-workstation">[% l('Workstation') %]</label>
               <div class="col-md-8">
-                <input type="text" id="login-workstation" class="form-control"
-                  placeHolder="Optional.  Also try ?ws=<name>"
-                  ng-model="args.workstation"/>
-              </div>
+                <select ng-model="workstations" class="form-control">
+                </select>
+              <div>
             </div>
 
             <div class="form-group row">
index 9ecad91..2793706 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 angular.module('egWorkstationAdmin', 
-    ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod','egUserMod'])
+    ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod'])
 
 .config(['$routeProvider','$locationProvider','$compileProvider', 
  function($routeProvider , $locationProvider , $compileProvider) {
@@ -36,33 +36,84 @@ angular.module('egWorkstationAdmin',
 }])
 
 .controller('SplashCtrl',
-       ['$scope','egPrintStore','egUser','egEnv','egAuth',
-function($scope , egPrintStore , egUser , egEnv , egAuth) {
+       ['$scope','egPrintStore','egAuth','egOrg','egPerm','egEvent','egNet','egAppStrings',
+function($scope , egPrintStore , egAuth , egOrg , egPerm , egEvent , egNet , egAppStrings) {
+
+    var permMap = {};
+    var wsPerms = [
+        'ADMIN_WORKSTATION', //FIXME: create
+        'REGISTER_WORKSTATION',
+        'UPDATE_WORKSTATION',
+        'DELETE_WORKSTATION'
+    ]
 
     $scope.userHasAdminPerm = false;
-    egUser.hasPermHere('ADMIN_WORKSTATION')
-    .then(function(bool) { $scope.userHasAdminPerm = bool });
+    egPerm.hasPermAt(wsPerms)
+    .then(function(permMap) { 
+        //$scope.userHasAdminPerm = bool 
+    });
 
-    var workstation;
-    if (egEnv.aws) { // TODO: move this to egAuth
-        workstation = egEnv.aws.map[egAuth.user().wsid()];
+    // fetch the stored WS info
+    egPrintStore.getItem('eg.conf.workstation.all')
+    .then(function(all) {
+        $scope.workstations = all || [];
+        return egPrintStore.getItem('eg.conf.workstation.default');
+    })
+    .then(function(def) { 
+        console.log('loaded default WS ' + ws);
+        $scope.defaultWS = def 
+    });
 
-        // strip the org unit component of the name
-        $scope.workstationName = workstation.name().split(/-/)[1]; 
+    if (ws = egAuth.workstation()) {
+        $scope.activeWS = ws;
+        $scope.contextOrg = egOrg.get(ws.owning_lib);
     }
-    
-    $scope.hatchURL = egPrintStore.hatchURL();
-    $scope.hatchRequired = 
-        egPrintStore.getLocalItem('eg.conf.hatch.required');
 
-    $scope.updateHatchRequired = function() {
-        egPrintStore.setLocalItem(
-            'eg.conf.hatch.required', $scope.hatchRequired);
+    $scope.getWSLabel = function(ws) {
+        return ws.name; // FIXME: appstrings
     }
 
-    $scope.updateHatchURL = function() {
-        egPrintStore.setLocalItem(
-            'eg.conf.hatch.url', $scope.hatchURL);
+    $scope.setDefaultWS = function() {
+        console.log('selected ' + $scope.selectedWS);
+        var ws = $scope.workstations.filter(
+            function(w) { return w.id == $scope.selectedWS })[0];
+        egPrintStore.setItem(
+            'eg.conf.workstation.default', 
+            // avoid storing angular $$hashkey
+            {id : ws.id, name : ws.name, owning_lib : ws.owning_lib})
+        .then(function() { $scope.defaultWS = ws });
+    }
+
+    $scope.registerWS = function() {
+        var newName = $scope.contextOrg.shortname() + '-' + $scope.newWSName;
+        egNet.request(
+            'open-ils.actor',
+            'open-ils.actor.workstation.register',
+            egAuth.token(), newName, $scope.contextOrg.id())
+        .then(function(resp) {
+            var evt = egEvent.parse(resp);
+            if (evt) {
+                if (evt.textcode == 'WORKSTATION_NAME_EXISTS') {
+                    // TODO: override call
+                } else {
+                    // TODO: improvide permission error display
+                    alert(evt);
+                }
+            } else if (resp) {
+                $scope.workstations.push(
+                    {   id : resp,
+                        name : newName, 
+                        owning_lib : $scope.contextOrg.id()
+                    }
+                );
+                return egPrintStore.setItem(
+                    'eg.conf.workstation.all', $scope.workstations);
+            }
+        });
+    }
+
+    $scope.wsOrgChanged = function(org) {
+        $scope.contextOrg = org;
     }
 
     $scope.updateUsesWorkstation = function() {
@@ -78,7 +129,21 @@ function($scope , egPrintStore , egUser , egEnv , egAuth) {
         */
     }
 
+    // ---------------------
+    // Hatch Configs
+    $scope.hatchURL = egPrintStore.hatchURL();
+    $scope.hatchRequired = 
+        egPrintStore.getLocalItem('eg.conf.hatch.required');
 
+    $scope.updateHatchRequired = function() {
+        egPrintStore.setLocalItem(
+            'eg.conf.hatch.required', $scope.hatchRequired);
+    }
+
+    $scope.updateHatchURL = function() {
+        egPrintStore.setLocalItem(
+            'eg.conf.hatch.url', $scope.hatchURL);
+    }
 }])
 
 .controller('PrintingCtrl',
@@ -214,8 +279,8 @@ function($scope , egPrintStore) {
 }])
 
 .controller('StoredPrefsCtrl',
-       ['$scope','egUser','egPrintStore','egConfirmDialog','egAppStrings','$q',
-function($scope , egUser , egPrintStore , egConfirmDialog , egAppStrings , $q) {
+       ['$scope','$q','egAuth','egPrintStore','egConfirmDialog','egAppStrings','egPerm',
+function($scope , $q , egAuth , egPrintStore , egConfirmDialog , egAppStrings , egPerm) {
     console.log('StoredPrefsCtrl');
 
     $scope.setContext = function(ctx) {
@@ -225,7 +290,7 @@ function($scope , egUser , egPrintStore , egConfirmDialog , egAppStrings , $q) {
 
     // grab the edit perm
     $scope.userHasDeletePerm = false;
-    egUser.hasPermHere('ADMIN_WORKSTATION')
+    egPerm.hasPermHere('ADMIN_WORKSTATION')
     .then(function(bool) { $scope.userHasDeletePerm = bool });
 
     // fetch the keys
index c5acf5f..0e50104 100644 (file)
@@ -45,12 +45,37 @@ angular.module('egHome', ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod'])
     /* inject services into our controller.  Spelling them
      * out like this allows the auto-magic injector to work
      * even if the code has been minified */
-    ['$scope', '$location', '$window', 'egAuth',
-    function($scope, $location, $window, egAuth) {
+           ['$scope','$location','$window','egAuth','egPrintStore',
+    function($scope , $location , $window , egAuth , egPrintStore) {
         $scope.focusMe = true;
 
-        // for now, workstations may be passed in via URL param
-        $scope.args = {workstation : $location.search().ws};
+        egPrintStore.getItem('eg.conf.workstation.all')
+        .then(function(all) {
+                $scope.workstations = ['abc', 'dev', 'foo']; // TODO
+            if (all && all.length) {
+                $scope.workstations = all.map(function(a) { return a.name });
+
+                if (ws = $location.search().ws) {
+                    // user requested a workstation via URL
+                    var match = all.filter(
+                        function(w) {return ws == w.name} )[0];
+
+                    if (match) {
+                        // requested WS registered on this client
+                        $scope.args = {workstation : match.name};
+                    } else {
+                        // the requested WS is not registered on this client
+                        $scope.wsNotRegistered = true;
+                    }
+                } else {
+                    // no workstation requested; use the default
+                    egPrintStore.get('eg.conf.workstation.all.default')
+                    .then(function(ws) {
+                        $scope.args = {workstation : ws.name}
+                    });
+                }
+            } 
+        })
 
         $scope.login = function(args) {
             args.type = 'staff';
index ce7c7e3..f58cc47 100644 (file)
@@ -40,10 +40,8 @@ function NavCtrl($scope, $window, $location, egStartup, egAuth, egEnv) {
             $scope.username = egAuth.user().usrname();
 
             // TODO: move workstation into egAuth
-            if (egEnv.aws) {
-                $scope.workstation = 
-                    egEnv.aws.map[egAuth.user().wsid()].name();
-            }
+            if (ws = egAuth.workstation())
+                $scope.workstation = ws.name();
         }
     );
 }
index 0e1f2b7..e24a6f1 100644 (file)
@@ -104,8 +104,9 @@ function($q,  egAuth,  egPCRUD,  egIDL) {
             );
         },
         aws : function() {
-            // by default, load only the workstation for the authenticated 
-            // user.  to load all workstations, override this loader.
+            // FIXME: this will come from local storage, not the server
+            // load thee workstation for the authenticated user and
+            // insert the value into egAuth.workstation().
             // TODO: auth.session.retrieve should be capable of returning
             // the session with the workstation fleshed.
             if (!egAuth.user().wsid()) { 
@@ -113,7 +114,7 @@ function($q,  egAuth,  egPCRUD,  egIDL) {
                 return $q.when();
             }
             return egPCRUD.retrieve('aws', egAuth.user().wsid())
-            .then(function(ws) {service.absorbList([ws], 'aws')});
+            .then(function(ws) {egAuth.workstation(ws)});
         }
     };
 
index b8a9cf0..438d112 100644 (file)
@@ -21,6 +21,10 @@ function($q,  egEnv,  egAuth,  egNet) {
         return egEnv.aou.list;
     };
 
+    service.tree = function() {
+        return egEnv.aou.tree;
+    }
+
     // list of org_unit objects or IDs for ancestors + me
     service.ancestors = function(node_or_id, as_id) {
         var node = service.get(node_or_id);
index a537de3..c07d493 100644 (file)
  * local requests return immediate values, since local requests are
  * never asynchronous.
  *
+ * BEWARE: never store "fieldmapper" objects, since their structure
+ * may change over time as the IDL changes.  Always flatten objects
+ * into key/value pairs before calling set*Item()
+ *
  */
 angular.module('egCoreMod')