From 8aed577d1f09f4a11b611387b253ed382dbced71 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 15 Apr 2019 18:11:46 -0400 Subject: [PATCH] LP1825851 Server managed/processed print templates Adds a new database table config.print_template (and IDL class) for storing configurable, org-specific print templates. Adds a web service which accepts POSTed print data and generates a print-ready document. Includes example Apache configs. Teaches the AngJS and Angular apps to use the new web service for generting output. Adds and Angular print template administration interface. Example setup using HTML::Restrict for scrubbing unwanted HTML elements and attributes from print documents for security. Signed-off-by: Bill Erickson --- Open-ILS/examples/apache_24/eg_startup.in | 3 + Open-ILS/examples/apache_24/eg_vhost.conf.in | 8 + Open-ILS/examples/fm_IDL.xml | 29 ++++ Open-ILS/src/eg2/src/app/core/idl.service.ts | 40 +++++ .../app/share/fm-editor/fm-editor.component.html | 4 +- .../src/app/share/fm-editor/fm-editor.component.ts | 2 +- .../src/eg2/src/app/share/print/print.component.ts | 66 ++++++-- .../src/eg2/src/app/share/print/print.service.ts | 58 ++++++- .../eg2/src/app/share/util/sample-data.service.ts | 65 ++++++++ .../server/admin-server-splash.component.html | 3 + .../app/staff/admin/server/admin-server.module.ts | 6 +- .../admin/server/print-template.component.html | 94 +++++++++++ .../staff/admin/server/print-template.component.ts | 182 +++++++++++++++++++++ .../src/app/staff/admin/server/routing.module.ts | 4 + .../src/app/staff/sandbox/sandbox.component.html | 3 + .../eg2/src/app/staff/sandbox/sandbox.component.ts | 21 ++- .../eg2/src/app/staff/sandbox/sandbox.module.ts | 2 + .../share/admin-page/admin-page.component.html | 1 + .../staff/share/admin-page/admin-page.component.ts | 6 +- .../src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm | 168 +++++++++++++++++++ .../upgrade/XXXX.schema.server-print-templates.sql | 63 +++++++ .../share/print_templates/t_patron_address.tt2 | 25 --- .../js/ui/default/staff/admin/workstation/app.js | 2 +- .../web/js/ui/default/staff/circ/patron/app.js | 2 +- Open-ILS/web/js/ui/default/staff/services/print.js | 81 ++++++++- 25 files changed, 878 insertions(+), 60 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.server-print-templates.sql delete mode 100644 Open-ILS/src/templates/staff/share/print_templates/t_patron_address.tt2 diff --git a/Open-ILS/examples/apache_24/eg_startup.in b/Open-ILS/examples/apache_24/eg_startup.in index 855159e16f..316034a424 100755 --- a/Open-ILS/examples/apache_24/eg_startup.in +++ b/Open-ILS/examples/apache_24/eg_startup.in @@ -15,6 +15,9 @@ use OpenILS::WWW::IDL2js ('@sysconfdir@/opensrf_core.xml'); use OpenILS::WWW::FlatFielder; use OpenILS::WWW::PhoneList ('@sysconfdir@/opensrf_core.xml'); +# Pass second argument of '1' to disable template caching. +use OpenILS::WWW::PrintTemplate ('/openils/conf/opensrf_core.xml', 0); + # - Uncomment the following 2 lines to make use of the IP redirection code # - The IP file should to contain a map with the following format: # - actor.org_unit.shortname diff --git a/Open-ILS/examples/apache_24/eg_vhost.conf.in b/Open-ILS/examples/apache_24/eg_vhost.conf.in index 95d0702b6d..0d32754c9c 100644 --- a/Open-ILS/examples/apache_24/eg_vhost.conf.in +++ b/Open-ILS/examples/apache_24/eg_vhost.conf.in @@ -773,6 +773,14 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] + + SetHandler perl-script + PerlHandler OpenILS::WWW::PrintTemplate + Options +ExecCGI + PerlSendHeader On + Require all granted + + diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 1f510735fb..cd78d61251 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -12813,6 +12813,35 @@ SELECT usr, + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/core/idl.service.ts b/Open-ILS/src/eg2/src/app/core/idl.service.ts index 56b8b90e1f..468ae2dbe3 100644 --- a/Open-ILS/src/eg2/src/app/core/idl.service.ts +++ b/Open-ILS/src/eg2/src/app/core/idl.service.ts @@ -156,5 +156,45 @@ export class IdlService { } return null; } + + toHash(obj: any, flatten?: boolean): any { + + if (typeof obj !== 'object' || obj === null) { + return obj; + } + + if (Array.isArray(obj)) { + return obj.map(item => this.toHash(item)); + } + + const fieldNames = obj._isfieldmapper ? + Object.keys(this.classes[obj.classname].field_map) : + Object.keys(obj); + + const hash: any = {}; + fieldNames.forEach(field => { + + var val = this.toHash( + typeof obj[field] === 'function' ? obj[field]() : obj[field], + flatten + ); + + if (val === undefined) { return; } + + if (flatten && val !== null && + typeof val === 'object' && !Array.isArray(val)) { + + Object.keys(val).forEach(key => { + let fname = field + '.' + key; + hash[fname] = val[key]; + }); + + } else { + hash[field] = val; + } + }); + + return hash; + } } diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html index aad65d15d6..166bc40d29 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html @@ -10,10 +10,10 @@