LP#1775466 AngularJS updates for Angular integration
authorBill Erickson <berickxx@gmail.com>
Wed, 5 Sep 2018 20:04:19 +0000 (16:04 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 6 Sep 2018 20:56:04 +0000 (16:56 -0400)
Changes include:

* Navbar links to Angular acquisitions admin page.
* Auth cookie migration tool for moving AngularJS cookies from /eg/staff
  to /.
* Store last printed receipt (etc) in its final compiled form so it can
  be directly reprinted without having to recompile (via AngularJS).
  This allows the reprint-last action to work in the Angular app.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/navbar.tt2
Open-ILS/web/js/ui/default/staff/services/auth.js
Open-ILS/web/js/ui/default/staff/services/hatch.js
Open-ILS/web/js/ui/default/staff/services/print.js

index a5d9888..7d9e1ce 100644 (file)
               [% l('Search the Catalog') %]
             </a>
           </li>
+          <!--
+            Link to experimental Angular staff catalog.
+            Leaving disabled until more functionality can be fleshed out.
+          -->
+          <!--
+          <li>
+            <a href="/eg2/staff/catalog/search" target="_self">
+              <span class="glyphicon glyphicon-search"></span>
+              <span>[% l('Staff Catalog (Experimental)') %]</span>
+            </a>
+          </li>
+          -->
           <li>
             <a href="./cat/bucket/record/view" target="_self">
               <span class="glyphicon glyphicon-list-alt"></span>
             </a>
           </li>
           <li>
-            <a href="./admin/acq/index" target="_self">
+            <a href="/eg2/staff/admin/acq/splash">
               <span class="glyphicon glyphicon-usd"></span>
               [% l('Acquisitions Administration') %]
             </a>
index c46e37e..03e5d43 100644 (file)
@@ -63,6 +63,10 @@ function($q , $timeout , $rootScope , $window , $location , egNet , egHatch) {
      * authtoken is found, otherwise rejected */
     service.testAuthToken = function() {
         var deferred = $q.defer();
+
+        // Move legacy cookies from /eg/staff to / before fetching the token.
+        egHatch.migrateAuthCookies();
+
         var token = service.token();
 
         if (token) {
index bb12479..467091a 100644 (file)
@@ -352,6 +352,24 @@ angular.module('egCoreMod')
         }
     }
 
+    // Force auth cookies to live under path "/" instead of "/eg/staff"
+    // so they may be shared with the Angular app.
+    // There's no way to tell under what path a cookie is stored in
+    // the browser, all we can do is migrate it regardless.
+    service.migrateAuthCookies = function() {
+        [   'eg.auth.token', 
+            'eg.auth.time', 
+            'eg.auth.token.oc', 
+            'eg.auth.time.oc'
+        ].forEach(function(key) {
+            var val = service.getLoginSessionItem(key);
+            if (val) {
+                $cookies.remove(key, {path: '/eg/staff/'});
+                service.setLoginSessionItem(key, val);
+            }
+        });
+    }
+
     service.getLoginSessionItem = function(key) {
         var val = $cookies.get(key);
         if (val == null) return;
@@ -651,7 +669,7 @@ angular.module('egCoreMod')
         service.addLoginSessionKey(key);
         if (jsonified === undefined ) 
             jsonified = JSON.stringify(value);
-        $cookies.put(key, jsonified);
+        $cookies.put(key, jsonified, {path: '/'});
     }
 
     // Set the value for the given key.  
@@ -721,7 +739,7 @@ angular.module('egCoreMod')
 
     service.removeLoginSessionItem = function(key) {
         service.removeLoginSessionKey(key);
-        $cookies.remove(key);
+        $cookies.remove(key, {path: '/'});
     }
 
     service.removeSessionItem = function(key) {
index fee4c8a..d12a6cd 100644 (file)
@@ -156,20 +156,17 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
                   content;
 
         }).then(function(content) {
-            service.last_print.content = content;
-            service.last_print.content_type = type;
-            service.last_print.printScope = printScope
-
-            egHatch.setItem('eg.print.last_printed', service.last_print);
 
             // Ingest the content into the page DOM.
-            return service.ingest_print_content(
-                service.last_print.content_type,
-                service.last_print.content,
-                service.last_print.printScope
-            );
+            return service.ingest_print_content(type, content, printScope);
+
+        }).then(function(html) { 
+
+            // Note browser ignores print context
+            service.last_print.content = html;
+            service.last_print.content_type = type;
+            egHatch.setItem('eg.print.last_printed', service.last_print);
 
-        }).then(function() { 
             $window.print();
         });
     }
@@ -192,9 +189,7 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
                 } else {
                     promise.then(function () {
                         service.ingest_print_content(
-                            service.last_print.content_type,
-                            service.last_print.content,
-                            service.last_print.printScope
+                            null, null, null, service.last_print.content
                         ).then(function() { $window.print() });
                     });
                 }
@@ -300,7 +295,19 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
                 // For local printing, this lets us print directly from the
                 // DOM with print CSS.
                 // Returns a promise reolved with the compiled HTML as a string.
-                egPrint.ingest_print_content = function(type, content, printScope) {
+                //
+                // If a pre-compiled HTML string is provided, it's inserted
+                // as-is into the DOM for browser printing without any 
+                // additional interpolation.  This is useful for reprinting,
+                // previously compiled content.
+                egPrint.ingest_print_content = 
+                    function(type, content, printScope, compiledHtml) {
+
+                    if (compiledHtml) {
+                        $scope.elm.html(compiledHtml);
+                        return $q.when(compiledHtml);
+                    }
+                        
                     $scope.elm.html(content);
 
                     var sub_scope = $scope.$new(true);