From d03cb19127fe492792c14ec8c9bb79f03eb0a1a7 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 11 Jul 2019 16:38:05 -0400 Subject: [PATCH] LP1825851 server print additions WIP Signed-off-by: Bill Erickson --- .../eg2/src/app/share/util/sample-data.service.ts | 7 +++ .../staff/admin/server/print-template.component.ts | 37 +++++++-------- .../app/staff/catalog/record/record.component.html | 1 + .../src/app/staff/share/holds/grid.component.ts | 29 +++++++++++- .../src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm | 4 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 54 ++++++++++++++++++++++ .../upgrade/XXXX.schema.server-print-templates.sql | 17 +++---- Open-ILS/web/js/ui/default/staff/services/print.js | 2 +- 8 files changed, 118 insertions(+), 33 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts b/Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts index 1efb45f479..66f840c071 100644 --- a/Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts +++ b/Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts @@ -110,6 +110,13 @@ export class SampleDataService { return things; } + + // Returns a random-ish date in the past or the future. + randomDate(future: boolean = false): Date { + const rando = Math.random() * 10000000000; + const time = new Date().getTime(); + return new Date(future ? time + rando : time - rando); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts index d94cb9f98c..5a38c989a9 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts @@ -76,33 +76,28 @@ export class PrintTemplateComponent implements OnInit { classes.forEach(class_ => samples[class_] = this.idl.toHash(this.samples.listOfThings(class_, 10))) - // Flesh some patrons with cards - const patron0 = this.idl.clone(samples.au[0]); - const patron1 = this.idl.clone(samples.au[1]); - const patron2 = this.idl.clone(samples.au[2]); - patron0.card = samples.ac[0]; - patron1.card = samples.ac[1]; - patron2.card = samples.ac[2]; + // Wide holds are hashes instead of IDL objects. + // Add fields as needed. + const wide_holds = [{ + request_time: this.samples.randomDate().toISOString(), + ucard_barcode: samples.ac[0].barcode, + usr_family_name: samples.au[0].family_name, + usr_alias: samples.au[0].alias, + cp_barcode: samples.acp[0].barcode + }, { + request_time: this.samples.randomDate().toISOString(), + ucard_barcode: samples.ac[1].barcode, + usr_family_name: samples.au[1].family_name, + usr_alias: samples.au[1].alias, + cp_barcode: samples.acp[1].barcode + }]; this.sampleData.patron_address = { patron: samples.au[0], address: samples.aua[0] }; - this.sampleData.holds_for_bib = { - title: samples.mwde[0].title, - holds: [ - { - hold: samples.ahr[0], - patron: patron0, - copy: samples.acp[0] - }, { - hold: samples.ahr[1], - patron: patron1, - copy: samples.acp[1] - } - ] - }; + this.sampleData.holds_for_bib = wide_holds; } onTabChange(evt: NgbTabChangeEvent) { diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html index 8be4524985..6833f8d601 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html @@ -53,6 +53,7 @@ diff --git a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts index 1b707c6c4d..d6988dc927 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts @@ -36,7 +36,10 @@ export class HoldsGridComponent implements OnInit { @Input() persistKey: string; @Input() preFetchSetting: string; - // If set, all holds are fetched on grid load and sorting/paging all + + @Input() printTemplate: string; + + // If set, all holds are fetched on grid load and sorting/paging all // happens in the client. If false, sorting and paging occur on // the server. enablePreFetch: boolean; @@ -112,7 +115,8 @@ export class HoldsGridComponent implements OnInit { private net: NetService, private org: OrgService, private store: ServerStoreService, - private auth: AuthService + private auth: AuthService, + private printer: PrintService ) { this.gridDataSource = new GridDataSource(); this.enablePreFetch = null; @@ -392,6 +396,27 @@ export class HoldsGridComponent implements OnInit { } printHolds() { + // Request a page with no limit to get all of the wide holds for + // printing. Call requestPage() directly instead of grid.reload() + // since we may already have the data. + + const pager = new Pager(); + pager.offset = 0; + pager.limit = null; + + if (this.gridDataSource.sort.length == 0) { + this.gridDataSource.sort = this.defaultSort; + } + + this.gridDataSource.requestPage(pager).then(() => { + if (this.gridDataSource.data.length > 0) { + this.printer.print({ + templateName: this.printTemplate || 'holds_for_bib', + contextData: this.gridDataSource.data, + printContext: 'default' + }); + } + }); } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm index 697d95137d..4d42802e56 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm @@ -55,7 +55,9 @@ sub handler { unless $e->checkauth && $e->requestor->wsid; # Let pcrud handle the authz - $e->personality('open-ils.pcrud'); + # TODO: setting ->personality applies globally which breaks other + # Apache mod_perl handlers. Allow for per-editor personalities. + #$e->personality('open-ils.pcrud'); my $tmpl_owner = $cgi->param('template_owner') || $e->requestor->ws_ou; my $tmpl_locale = $cgi->param('template_locale') || 'en-US'; 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 7326e46753..be9d0d6178 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -20010,6 +20010,60 @@ $TEMPLATE$ $TEMPLATE$ ); +INSERT INTO config.print_template + (id, name, locale, active, owner, label, template) +VALUES ( + 2, 'holds_for_bib', 'en-US', FALSE, + (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL), + oils_i18n_gettext(2, 'Holds for Bib Record', 'cpt', 'label'), +$TEMPLATE$ +[%- + USE date; + SET holds = template_data; + # template_data is an arry of wide_hold hashes. +-%] +
+
Holds for record: [% holds.0.title %]
+
+ + + + + + + + + + + + + [% FOR hold IN holds %] + + + + + + + + [% END %] + +
Request DatePatron BarcodePatron LastPatron AliasCurrent Item
[% + date.format(helpers.format_date( + hold.request_time, staff_org_timezone), '%x %r', locale) + %][% hold.ucard_barcode %][% hold.usr_family_name %][% hold.usr_alias %][% hold.cp_barcode %]
+
+
+ [% staff_org.shortname %] + [% date.format(helpers.current_date(client_timezone), '%x %r', locale) %] +
+
Printed by [% staff.first_given_name %]
+
+
+ +$TEMPLATE$ +); + + -- Allow for 1k stock templates SELECT SETVAL('config.print_template_id_seq'::TEXT, 1000); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.server-print-templates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.server-print-templates.sql index 3a42e9c151..a1a534903f 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.server-print-templates.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.server-print-templates.sql @@ -48,13 +48,14 @@ VALUES ( 2, 'holds_for_bib', 'en-US', FALSE, (SELECT id FROM actor.org_unit WHERE parent_ou IS NULL), oils_i18n_gettext(2, 'Holds for Bib Record', 'cpt', 'label'), +$TEMPLATE$ [%- USE date; - SET holds = template_data.holds; - SET title = template_data.title; + SET holds = template_data; + # template_data is an arry of wide_hold hashes. -%]
-
Holds for record: [% title %]
+
Holds for record: [% holds.0.title %]

@@ -72,12 +73,12 @@ VALUES ( - - - - + + + + [% END %] 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 3c3d9b9372..fe36a30769 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -69,7 +69,7 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg if (OpenSRF.locale) { // .append() coerces arguments to strings, so if locale // is null, the server will get the string "null" - formData.append('locale', OpenSRF.locale); + formData.append('template_locale', OpenSRF.locale); } return new Promise((resolve, reject) => { -- 2.11.0
[% date.format(helpers.format_date( - hold.hold.request_time, staff_org_timezone), '%x %r', locale) + hold.request_time, staff_org_timezone), '%x %r', locale) %][% hold.patron.card.barcode %][% hold.patron.family_name %][% hold.patron.alias %][% hold.copy.barcode %][% hold.ucard_barcode %][% hold.usr_family_name %][% hold.usr_alias %][% hold.cp_barcode %]