From 1a06d9f6ed735a3f28f0b8e30e397882f3d98d9f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 17 Sep 2018 14:32:44 -0400 Subject: [PATCH] Ang6 hatch WIP Signed-off-by: Bill Erickson --- .../src/eg2/src/app/share/print/hatch.service.ts | 16 ++++---- .../src/eg2/src/app/share/print/print.component.ts | 45 ++++++++++++---------- .../src/app/staff/sandbox/sandbox.component.html | 2 + .../eg2/src/app/staff/sandbox/sandbox.component.ts | 8 ++++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 38 ++++++++++++++++++ .../sql/Pg/upgrade/XXXX.data.hatch-settings.sql | 43 +++++++++++++++++++++ Open-ILS/web/js/ui/default/staff/services/hatch.js | 4 +- 7 files changed, 126 insertions(+), 30 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.hatch-settings.sql diff --git a/Open-ILS/src/eg2/src/app/share/print/hatch.service.ts b/Open-ILS/src/eg2/src/app/share/print/hatch.service.ts index 2ed9a02683..015088765a 100644 --- a/Open-ILS/src/eg2/src/app/share/print/hatch.service.ts +++ b/Open-ILS/src/eg2/src/app/share/print/hatch.service.ts @@ -17,7 +17,7 @@ export class HatchMessage { constructor(hash: any) { if (hash) { - hash.forEach((val, key) => this[key] = val); + Object.keys(hash).forEach(key => this[key] = hash[key]); } } } @@ -31,21 +31,21 @@ export class HatchService { constructor() { this.isAvailable = null; + this.messages = {}; this.msgId = 1; } - connect() { + connect(): boolean { - if (this.isAvailable) { - // Already connected - return; + if (this.isAvailable !== null) { + return this.isAvailable; } // When the Hatch extension loads, it tacks an attribute onto // the top-level documentElement to indicate it's available. if (!window.document.documentElement.getAttribute('hatch-is-open')) { - this.isAvailable = false; - return; + console.warn('Could not connect to Hatch'); + return this.isAvailable = false; } window.addEventListener('message', event => { @@ -64,7 +64,7 @@ export class HatchService { } }); - this.isAvailable = true; + return this.isAvailable = true; } // Send a request from the browser to Hatch. 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 5faf3ef3b4..e7754abbd3 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 @@ -1,6 +1,7 @@ import {Component, OnInit, TemplateRef, ElementRef, Renderer2} from '@angular/core'; import {PrintService, PrintRequest} from './print.service'; import {StoreService} from '@eg/core/store.service'; +import {ServerStoreService} from '@eg/core/server-store.service'; import {HatchService, HatchMessage} from './hatch.service'; @Component({ @@ -27,6 +28,7 @@ export class PrintComponent implements OnInit { private renderer: Renderer2, private elm: ElementRef, private store: StoreService, + private serverStore: ServerStoreService, private hatch: HatchService, private printer: PrintService) { this.isPrinting = false; @@ -39,10 +41,6 @@ export class PrintComponent implements OnInit { this.htmlContainer = this.renderer.selectRootElement('#eg-print-html-container'); - - if (this.store.getLocalItem('eg.hatch.enable.printing')) { - this.hatch.connect(); - } } handlePrintRequest(printReq: PrintRequest) { @@ -73,7 +71,7 @@ export class PrintComponent implements OnInit { return; } - if (printReq.text && true /* !this.hatch.isActive */) { + if (printReq.text && !this.useHatch()) { // Insert HTML into the browser DOM for in-browser printing only. if (printReq.contentType === 'text/plain') { @@ -115,7 +113,7 @@ export class PrintComponent implements OnInit { show_dialog: printReq.showDialog }); - if (this.store.getLocalItem('eg.hatch.enable.printing')) { + if (this.useHatch()) { this.printViaHatch(printReq); } else { // Here the needed HTML is already in the page. @@ -123,25 +121,32 @@ export class PrintComponent implements OnInit { } } + useHatch(): boolean { + return this.store.getLocalItem('eg.hatch.enable.printing') + && this.hatch.connect(); + } + printViaHatch(printReq: PrintRequest) { // Send a full HTML document to Hatch const html = `${printReq.text}`; - const config = this.store.getLocalItem( - `eg.print.config.${printReq.printContext}`); - - const msg = new HatchMessage({ - action: 'print', - content : html, - settings : config, - contentType : printReq.contentType, - showDialog : printReq.showDialog - }); - this.hatch.sendRequest(msg).then( - ok => console.debug('Print request succeeded'), - err => console.warn('Print request failed') - ); + this.serverStore.getItem(`eg.print.config.${printReq.printContext}`) + .then(config => { + + const msg = new HatchMessage({ + action: 'print', + content: html, + settings: config || {}, + contentType: 'text/html', + showDialog: printReq.showDialog + }); + + this.hatch.sendRequest(msg).then( + ok => console.debug('Print request succeeded'), + err => console.warn('Print request failed', err) + ); + }); } } diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 289ed50268..a6a2a53e6a 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -99,6 +99,8 @@ Hello, {{context.world}}! + +

HERasdfE
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 92b18dc9a9..2b14c5d073 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -147,7 +147,15 @@ export class SandboxComponent implements OnInit { text: 'hello', printContext: 'default' }); + } + printWithDialog() { + this.printer.print({ + template: this.printTemplate, + contextData: {world : this.world}, + printContext: 'default', + showDialog: true + }); } changeDate(date) { diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 949021b83d..4baf33575c 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -19413,5 +19413,43 @@ VALUES ( ) ); +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.print.config.default', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.default', + 'Print config for default context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.receipt', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.receipt', + 'Print config for receipt context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.label', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.label', + 'Print config for label context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.mail', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.mail', + 'Print config for mail context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.offline', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.offline', + 'Print config for offline context', + 'cwst', 'label' + ) +); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.hatch-settings.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.hatch-settings.sql new file mode 100644 index 0000000000..15d9513af7 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.hatch-settings.sql @@ -0,0 +1,43 @@ +BEGIN; + +--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.print.config.default', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.default', + 'Print config for default context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.receipt', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.receipt', + 'Print config for receipt context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.label', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.label', + 'Print config for label context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.mail', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.mail', + 'Print config for mail context', + 'cwst', 'label' + ) +), ( + 'eg.print.config.offline', 'gui', 'object', + oils_i18n_gettext ( + 'eg.print.config.offline', + 'Print config for offline context', + 'cwst', 'label' + ) +); + +COMMIT; 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 467091aaae..5b6f9235d2 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -200,11 +200,11 @@ angular.module('egCoreMod') } service.getPrintConfig = function(context) { - return service.getRemoteItem('eg.print.config.' + context); + return service.getItem('eg.print.config.' + context); } service.setPrintConfig = function(context, config) { - return service.setRemoteItem('eg.print.config.' + context, config); + return service.setItem('eg.print.config.' + context, config); } service.getPrinterOptions = function(name) { -- 2.11.0