From 038cd40207c5f63001bae2b68defdf44163c352d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 5 Sep 2018 16:04:19 -0400 Subject: [PATCH] LP#1775466 AngularJS updates for Angular integration 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 Signed-off-by: Galen Charlton --- Open-ILS/src/templates/staff/navbar.tt2 | 14 ++++++- .../web/js/ui/default/staff/services/auth.js | 4 ++ .../web/js/ui/default/staff/services/hatch.js | 22 ++++++++++- .../web/js/ui/default/staff/services/print.js | 37 +++++++++++-------- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Open-ILS/src/templates/staff/navbar.tt2 b/Open-ILS/src/templates/staff/navbar.tt2 index a5d988839a..7d9e1cef71 100644 --- a/Open-ILS/src/templates/staff/navbar.tt2 +++ b/Open-ILS/src/templates/staff/navbar.tt2 @@ -251,6 +251,18 @@ [% l('Search the Catalog') %] + +
  • @@ -484,7 +496,7 @@
  • - + [% l('Acquisitions Administration') %] diff --git a/Open-ILS/web/js/ui/default/staff/services/auth.js b/Open-ILS/web/js/ui/default/staff/services/auth.js index c46e37e7a1..03e5d43534 100644 --- a/Open-ILS/web/js/ui/default/staff/services/auth.js +++ b/Open-ILS/web/js/ui/default/staff/services/auth.js @@ -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) { 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 bb124795d7..467091aaae 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -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) { diff --git a/Open-ILS/web/js/ui/default/staff/services/print.js b/Open-ILS/web/js/ui/default/staff/services/print.js index fee4c8af8a..d12a6cd84f 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -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); -- 2.43.2