LP1825851 server print additions WIP
authorBill Erickson <berickxx@gmail.com>
Thu, 11 Jul 2019 20:38:05 +0000 (16:38 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 11 Jul 2019 20:38:05 +0000 (16:38 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/util/sample-data.service.ts
Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/grid.component.ts
Open-ILS/src/perlmods/lib/OpenILS/WWW/PrintTemplate.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.server-print-templates.sql
Open-ILS/web/js/ui/default/staff/services/print.js

index 1efb45f..66f840c 100644 (file)
@@ -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);
+    }
 }
 
 
index d94cb9f..5a38c98 100644 (file)
@@ -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) {
index 8be4524..6833f8d 100644 (file)
@@ -53,6 +53,7 @@
         <ng-template ngbTabContent>
           <eg-holds-grid [recordId]="recordId"
             preFetchSetting="catalog.record.holds.prefetch"
+            printTemplate="holds_for_bib"
             persistKey="cat.catalog.wide_holds"
             [defaultSort]="[{name:'request_time',dir:'asc'}]"
             [initialPickupLib]="currentSearchOrg()"></eg-holds-grid>
index 1b707c6..d6988dc 100644 (file)
@@ -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'
+                });
+            }
+        });
     }
 }
 
index 697d951..4d42802 100644 (file)
@@ -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';
index 7326e46..be9d0d6 100644 (file)
@@ -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.
+-%]
+<div>
+  <div>Holds for record: [% holds.0.title %]</div>
+  <hr/>
+  <style>#holds-for-bib-table td { padding: 5px; }</style>
+  <table id="holds-for-bib-table">
+    <thead>
+      <tr>
+        <th>Request Date</th>
+        <th>Patron Barcode</th>
+        <th>Patron Last</th>
+        <th>Patron Alias</th>
+        <th>Current Item</th>
+      </tr>
+    </thead>
+    <tbody>
+      [% FOR hold IN holds %]
+      <tr>
+        <td>[% 
+          date.format(helpers.format_date(
+            hold.request_time, staff_org_timezone), '%x %r', locale) 
+        %]</td>
+        <td>[% hold.ucard_barcode %]</td>
+        <td>[% hold.usr_family_name %]</td>
+        <td>[% hold.usr_alias %]</td>
+        <td>[% hold.cp_barcode %]</td>
+      </tr>
+      [% END %]
+    </tbody>
+  </table>
+  <hr/>
+  <div>
+    [% staff_org.shortname %] 
+    [% date.format(helpers.current_date(client_timezone), '%x %r', locale) %]
+  </div>
+  <div>Printed by [% staff.first_given_name %]</div>
+</div>
+<br/>
+
+$TEMPLATE$
+);
+
+
 -- Allow for 1k stock templates
 SELECT SETVAL('config.print_template_id_seq'::TEXT, 1000);
 
index 3a42e9c..a1a5349 100644 (file)
@@ -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.
 -%]
 <div>
-  <div>Holds for record: [% title %]</div>
+  <div>Holds for record: [% holds.0.title %]</div>
   <hr/>
   <style>#holds-for-bib-table td { padding: 5px; }</style>
   <table id="holds-for-bib-table">
@@ -72,12 +73,12 @@ VALUES (
       <tr>
         <td>[% 
           date.format(helpers.format_date(
-            hold.hold.request_time, staff_org_timezone), '%x %r', locale) 
+            hold.request_time, staff_org_timezone), '%x %r', locale) 
         %]</td>
-        <td>[% hold.patron.card.barcode %]</td>
-        <td>[% hold.patron.family_name %]</td>
-        <td>[% hold.patron.alias %]</td>
-        <td>[% hold.copy.barcode %]</td>
+        <td>[% hold.ucard_barcode %]</td>
+        <td>[% hold.usr_family_name %]</td>
+        <td>[% hold.usr_alias %]</td>
+        <td>[% hold.cp_barcode %]</td>
       </tr>
       [% END %]
     </tbody>
index 3c3d9b9..fe36a30 100644 (file)
@@ -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) => {