LP#1646166 Hatch settings migration
authorBill Erickson <berickxx@gmail.com>
Thu, 19 Jan 2017 16:31:12 +0000 (11:31 -0500)
committerKathy Lussier <klussier@masslnc.org>
Thu, 16 Feb 2017 20:21:36 +0000 (15:21 -0500)
Support copying all settings from local storage to Hatch and vice versa
in the Hatch admin UI.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/admin/workstation/index.tt2
Open-ILS/src/templates/staff/admin/workstation/t_hatch.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js
Open-ILS/web/js/ui/default/staff/services/hatch.js

index 2d8b357..44842ea 100644 (file)
@@ -21,6 +21,8 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
   s.PRINT_TEMPLATES_FAIL_EXPORT = "[% l('There are no customized print template to export') %]";
   s.PRINT_TEMPLATES_SUCCESS_IMPORT = "[% l('Imported one or more print template(s)') %]";
   s.PRINT_TEMPLATES_FAIL_IMPORT = "[% l('Failed to import any print template(s)') %]";
+  s.HATCH_SETTINGS_MIGRATION_SUCCESS = "[% l('Settings successfully migrated') %]";
+  s.HATCH_SETTINGS_MIGRATION_FAILURE = "[% l('Settings migration failed') %]";
 }]);
 </script>
 [% END %]
index d8d87ea..836c893 100644 (file)
@@ -12,7 +12,7 @@
   </div>
 
   <div class="row">
-    <div class="col-md-6">
+    <div class="col-md-4">
       <div class="checkbox">
         <label>
           <input type="checkbox" 
@@ -24,7 +24,7 @@
   </div>
 
   <div class="row new-entry">
-    <div class="col-md-6">
+    <div class="col-md-4">
       <div class="checkbox">
         <label>
           <input type="checkbox" 
         </label>
       </div>
     </div>
+    <div class="col-md-3">
+      <button class="btn btn-default" ng-click="copy_to_hatch()">
+        [% l('Copy Local Storage Settings To Hatch') %]
+      </button>
+    </div>
+    <div class="col-md-3">
+      <button class="btn btn-default" ng-click="copy_to_local()">
+        [% l('Copy Hatch Settings To Local Storage') %]
+      </button>
+    </div>
   </div>
 
   <div class="row new-entry">
-    <div class="col-md-6">
+    <div class="col-md-4">
       <div class="checkbox">
         <label>
           <input type="checkbox" 
index 75804a6..a25d719 100644 (file)
@@ -851,8 +851,8 @@ function($scope , $q , $window , $location , egCore , egAlertDialog , workstatio
 }])
 
 .controller('HatchCtrl',
-       ['$scope','egCore',
-function($scope , egCore) {
+       ['$scope','egCore','ngToast',
+function($scope , egCore , ngToast) {
     var hatch = egCore.hatch;  // convenience
 
     $scope.hatch_available = hatch.hatchAvailable;
@@ -877,6 +877,24 @@ function($scope , egCore) {
         hatch.setLocalItem('eg.hatch.enable.offline', newval);
     });
 
+    $scope.copy_to_hatch = function() {
+        hatch.copySettingsToHatch().then(
+            function() {
+                ngToast.create(egCore.strings.HATCH_SETTINGS_MIGRATION_SUCCESS)},
+            function() {
+                ngToast.warning(egCore.strings.HATCH_SETTINGS_MIGRATION_FAILURE)}
+        );
+    }
+
+    $scope.copy_to_local = function() {
+        hatch.copySettingsToLocal().then(
+            function() {
+                ngToast.create(egCore.strings.HATCH_SETTINGS_MIGRATION_SUCCESS)},
+            function() {
+                ngToast.warning(egCore.strings.HATCH_SETTINGS_MIGRATION_FAILURE)}
+        );
+    }
+
 }])
 
 
index 769f801..0dc1677 100644 (file)
@@ -274,7 +274,7 @@ angular.module('egCoreMod')
      * tmp values are removed during logout or browser close.
      */
     service.setItem = function(key, value) {
-        if (service.useSettings())
+        if (!service.useSettings())
             return $q.when(service.setLocalItem(key, value));
 
         if (service.hatchAvailable)
@@ -447,6 +447,58 @@ angular.module('egCoreMod')
         service.setLocalItem('eg.hatch.login_keys', keys);
     }
 
+    // Copy all stored settings from localStorage to Hatch.
+    // If 'move' is true, delete the local settings once cloned.
+    service.copySettingsToHatch = function(move) {
+        var deferred = $q.defer();
+        var keys = service.getLocalKeys();
+
+        angular.forEach(keys, function(key) {
+
+            // Hatch keys are local-only
+            if (key.match(/^eg.hatch/)) return;
+
+            console.debug("Copying to Hatch Storage: " + key);
+            service.setRemoteItem(key, service.getLocalItem(key))
+            .then(function() { // key successfully cloned.
+
+                // delete the local copy if requested.
+                if (move) service.removeLocalItem(key);
+
+                // resolve the promise after processing the last key.
+                if (key == keys[keys.length-1]) 
+                    deferred.resolve();
+            });
+        });
+
+        return deferred.promise;
+    }
+
+    // Copy all stored settings from Hatch to localStorage.
+    // If 'move' is true, delete the Hatch settings once cloned.
+    service.copySettingsToLocal = function(move) {
+        var deferred = $q.defer();
+
+        service.getRemoteKeys().then(function(keys) {
+            angular.forEach(keys, function(key) {
+                service.getRemoteItem(key).then(function(val) {
+
+                    console.debug("Copying to Local Storage: " + key);
+                    service.setLocalItem(key, val);
+
+                    // delete the remote copy if requested.
+                    if (move) service.removeRemoteItem(key);
+
+                    // resolve the promise after processing the last key.
+                    if (key == keys[keys.length-1]) 
+                        deferred.resolve();
+                });
+            });
+        });
+
+        return deferred.promise;
+    }
+
     // 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();