From: Bill Erickson Date: Wed, 10 Jul 2019 21:40:38 +0000 (-0400) Subject: LP1825851 server print additions WIP X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6dc5f5b23478be4de293dc99328849025ffb106d;p=working%2FEvergreen.git LP1825851 server print additions WIP Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/print/print.service.ts b/Open-ILS/src/eg2/src/app/share/print/print.service.ts index d4d0263d1c..79762af3d3 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.service.ts +++ b/Open-ILS/src/eg2/src/app/share/print/print.service.ts @@ -5,6 +5,7 @@ import {LocaleService} from '@eg/core/locale.service'; import {AuthService} from '@eg/core/auth.service'; declare var js2JSON: (jsThing: any) => string; +declare var OpenSRF; const PRINT_TEMPLATE_PATH = '/print_template'; @@ -74,6 +75,12 @@ export class PrintService { formData.append('template_data', js2JSON(printReq.contextData)); formData.append('locale', this.locale.currentLocaleCode()); + // Sometimes we want to know the time zone of the browser, + // regardless of any org unit settings. + if (OpenSRF.tz) { + formData.append('client_timezone', OpenSRF.tz); + } + return new Promise((resolve, reject) => { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm index 457a0f5917..7cfc448318 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm @@ -5,13 +5,19 @@ use Apache2::Const -compile => use Apache2::RequestRec; use CGI; use HTML::Defang; +use DateTime; +use DateTime::Format::ISO8601; +use Unicode::Normalize; use OpenSRF::Utils::JSON; use OpenSRF::System; use OpenSRF::Utils::SettingsClient; use OpenILS::Utils::CStoreEditor q/:funcs/; use OpenSRF::Utils::Logger q/$logger/; use OpenILS::Application::AppUtils; +use OpenILS::Utils::DateTime qw/:datetime/; + my $U = 'OpenILS::Application::AppUtils'; +my $helpers; my $bs_config; my $enable_cache; # Enable process-level template caching @@ -53,6 +59,7 @@ sub handler { my $owner = $cgi->param('owner') || $e->requestor->ws_ou; my $locale = $cgi->param('locale') || 'en-US'; + my $client_timezone = $cgi->param('client_timezone'); my $template_id = $cgi->param('template_id'); my $template_name = $cgi->param('template_name'); my $template_data = $cgi->param('template_data'); @@ -70,11 +77,23 @@ sub handler { return Apache2::Const::HTTP_BAD_REQUEST; } + my ($staff_org) = $U->fetch_org_unit($e->requestor->ws_ou); + my $output = ''; my $tt = Template->new; my $tmpl = $template->template; - my $stat = $tt->process(\$tmpl, {template_data => $data}, \$output); + my $context = { + locale => $locale, + client_timezone => $client_timezone, + staff => $e->requestor, + staff_org => $staff_org, + staff_org_timezone => get_org_timezone($staff_org->id), + helpers => $helpers, + template_data => $data + }; + + my $stat = $tt->process(\$tmpl, $context, \$output); if ($stat) { # OK my $ctype = $template->content_type; @@ -96,6 +115,20 @@ sub handler { } } +my %org_timezone_cache; +sub get_org_timezone { + my ($e, $org_id) = @_; + + if (!$org_timezone_cache{$org_id}) { + $org_timezone_cache{$org_id} = + $U->ou_ancestor_setting_value($org_id, 'lib.timezone') + || DateTime->now(time_zone => 'local')->time_zone->name; + } + + return $org_timezone_cache{$org_id}; +} + + # Find the template closest to the specific org unit owner. my %template_cache; sub find_template { @@ -141,4 +174,37 @@ sub find_template { return undef; } +# Utility / helper functions passed into every template + +$helpers = { + + # turns a date w/ optional timezone modifier into something + # TT can understand + format_date => sub { + my $date = shift; + my $tz = shift; + + $date->set_time_zone($tz) if $tz; + $date = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($date)); + return sprintf( + "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.4d", + $date->hour, + $date->minute, + $date->second, + $date->day, + $date->month, + $date->year + ); + } + + format_current_date => sub { + my $tz = shift || 'local'; + my $date = DateTime->new(time_zone => $tz); + return $helpers->format_date($date); + } +}; + + + + 1; 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 f191566e82..96ce9985cd 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 @@ -42,6 +42,56 @@ $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.holds; +-%] +
+
Holds for record: [% holds.0.title %]
+
+ + + + + + + + + + + + + [% FOR hold IN holds %] + + + + + + + + +
Request DatePatron BarcodePatron LastPatron AliasCurrent Item
[% + date.format(helpers.format_date( + hold.hold.request_time, staff_org_timezone), '%x %r', locale) + %][% hold.patron.barcode %][% hold.patron.last %][% hold.patron.alias %][% hold.copy.barcode %]
+
+
+ [% staff_org.shortname %] + [% date.format(helpers.format_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);