LP1955838 Hatch Native Browser Printing Option
authorBill Erickson <berickxx@gmail.com>
Mon, 27 Dec 2021 18:04:37 +0000 (13:04 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 25 Jul 2022 17:32:12 +0000 (13:32 -0400)
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 <berickxx@gmail.com>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Open-ILS/src/eg2/src/app/share/print/print.component.ts
Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js
Open-ILS/web/js/ui/default/staff/services/print.js

index bf0fb3a..faf8acd 100644 (file)
@@ -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<boolean> {
+        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 {
index 4e40632..3a21e3e 100644 (file)
                         <span ng-if="printer.name == 'hatch_file_writer'">
                           [% l('Hatch File Writer') %]
                         </span>
-                        <span ng-if="printer.name != 'hatch_file_writer'">
+                        <span ng-if="printer.name == 'hatch_browser_printing'">
+                          [% l('Browser Printing') %]
+                        </span>
+                        <span ng-if="printer.name != 'hatch_file_writer' 
+                          && printer.name != 'hatch_browser_printing'">
                           {{printer.name}}
                         </span>
                       </a>
@@ -88,7 +92,9 @@
                   value="[% l('No Printer Selected') %]">
                 <input ng-if="useFileWriter()" type="text" disabled="disabled"
                   class="form-control" value="[% l('Hatch File Writer') %]"/>
-                <input ng-if="printConfig[context].printer && !useFileWriter()" 
+                <input ng-if="useBrowserPrinting()" type="text" disabled="disabled"
+                  class="form-control" value="[% l('Browser Printing') %]"/>
+                <input ng-if="printConfig[context].printer && !useFileWriter() && !useBrowserPrinting()" 
                   type="text" class="form-control" disabled="disabled"
                   value="{{printConfig[context].printer}}">
               </div><!-- /input-group -->
@@ -116,8 +122,17 @@ additional settings are required.[% END %]
             </div>
           </div>
 
+          <div class="pad-vert" 
+            ng-show="!isTestView && hatchIsOpen() && useBrowserPrinting()">
+            <div class="alert alert-info">
+              [% |l %]Hatch Browser Printing sends print requests directly
+to the browser, bypassing the external Hatch print mechanism. No additional 
+settings are required.[% END %]
+            </div>
+          </div>
+
           <div class="row" 
-            ng-show="!isTestView && hatchIsOpen() && !useFileWriter()"
+            ng-show="!isTestView && hatchIsOpen() && !useFileWriter() && !useBrowserPrinting()"
             <div class="col-md-10">
               <div class="row">
                 <div class="col-md-1"></div>
index 4e4b906..527e6b0 100644 (file)
@@ -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];
 
index 5eeaadd..0788268 100644 (file)
@@ -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);