From: Bill Erickson Date: Mon, 27 Dec 2021 18:04:37 +0000 (-0500) Subject: LP1955838 Hatch Native Browser Printing Option X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0dc26a9c5e22b66ecf087c4131d754c53e8a5466;p=evergreen%2Ftadl.git LP1955838 Hatch Native Browser Printing Option Adds a new printer option to the Hatch printer settings page called "Browser Printer". When selected for a print context, all print request using that context are printed via window.print() instead of going through Hatch for printing. Signed-off-by: Bill Erickson Signed-off-by: Michele Morgan --- diff --git a/Open-ILS/src/eg2/src/app/share/print/print.component.ts b/Open-ILS/src/eg2/src/app/share/print/print.component.ts index bf0fb3a6d7..faf8acd462 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.component.ts +++ b/Open-ILS/src/eg2/src/app/share/print/print.component.ts @@ -6,7 +6,9 @@ import {HatchService, HatchMessage} from '@eg/core/hatch.service'; import {ToastService} from '@eg/share/toast/toast.service'; import {StringService} from '@eg/share/string/string.service'; import {HtmlToTxtService} from '@eg/share/util/htmltotxt.service'; + const HATCH_FILE_WRITER_PRINTER = 'hatch_file_writer'; +const HATCH_BROWSER_PRINTING_PRINTER = 'hatch_browser_printing'; @Component({ selector: 'eg-print', @@ -66,6 +68,22 @@ export class PrintComponent implements OnInit { .then(use => this.useHatchPrinting = (use && this.hatch.connect())); } + // Resolves to true if a) Hatch is usable and b) the requested print + // context is not using the 'native brower printing' printer. + checkHatchEnabledForRequest(printReq: PrintRequest): Promise { + return this.checkHatchEnabled().then(enabled => { + if (!enabled) { return false; } + + return this.serverStore.getItem(`eg.print.config.${printReq.printContext}`) + .then(config => { + return ( + !config || + config.printer !== HATCH_BROWSER_PRINTING_PRINTER + ); + }); + }); + } + handlePrintRequest(printReq: PrintRequest) { if (this.isPrinting) { @@ -158,7 +176,7 @@ export class PrintComponent implements OnInit { return promise.then(() => { - return this.checkHatchEnabled().then(enabled => { + return this.checkHatchEnabledForRequest(printReq).then(enabled => { // Insert HTML into the browser DOM for in-browser printing. if (printReq.text && !enabled) { @@ -209,7 +227,7 @@ export class PrintComponent implements OnInit { show_dialog: printReq.showDialog }); - return this.checkHatchEnabled().then(enabled => { + return this.checkHatchEnabledForRequest(printReq).then(enabled => { if (enabled) { this.printViaHatch(printReq); } else { diff --git a/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 b/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 index 4e4063201f..3a21e3eba4 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 @@ -73,7 +73,11 @@ [% l('Hatch File Writer') %] - + + [% l('Browser Printing') %] + + {{printer.name}} @@ -88,7 +92,9 @@ value="[% l('No Printer Selected') %]"> - + @@ -116,8 +122,17 @@ additional settings are required.[% END %] +
+
+ [% |l %]Hatch Browser Printing sends print requests directly +to the browser, bypassing the external Hatch print mechanism. No additional +settings are required.[% END %] +
+
+
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 4e4b906ed9..527e6b03ba 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 @@ -279,7 +279,7 @@ function($scope , egCore) { } function loadPrinterOptions(name) { - if (name == 'hatch_file_writer') { + if (name == 'hatch_file_writer' || name == 'hatch_browser_printing') { $scope.printerOptions = {}; } else { egCore.hatch.getPrinterOptions(name).then( @@ -322,6 +322,14 @@ function($scope , egCore) { ); } + $scope.useBrowserPrinting = function() { + return ( + $scope.printConfig[$scope.context] && + $scope.printConfig[$scope.context].printer == 'hatch_browser_printing' + ); + } + + // Load startup data.... // Don't bother talking to Hatch if it's not there. if (!egCore.hatch.hatchAvailable) return; @@ -337,6 +345,8 @@ function($scope , egCore) { name: 'hatch_file_writer' }); + printers.push({name: 'hatch_browser_printing'}); + var def = $scope.getPrinterByAttr('is-default', true); if (!def && printers.length) def = printers[0]; 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 5eeaadd2c1..0788268ae6 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -101,6 +101,15 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg return service.fleshPrintScope(args.scope) .then(function() { return egHatch.usePrinting(); }) .then(function(useHatch) { + if (!useHatch) { return false; } + return egHatch.getPrintConfig(args.context || 'default') + .then(function(config) { + // Avoid using Hatch if the print context calls + // for native browser printing. + return config.printer != 'hatch_browser_printing'; + }); + }) + .then(function(useHatch) { var promise = useHatch ? service.print_via_hatch(args) : service.print_via_browser(args);