]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts
d4e1d034a3fb443718401e2f10404d153232da08
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-print.component.ts
1 import {Component, Input, TemplateRef, ViewChild} from '@angular/core';
2 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
3 import {PrintService} from '@eg/share/print/print.service';
4 import {GridContext} from '@eg/share/grid/grid';
5
6 @Component({
7   selector: 'eg-grid-print',
8   templateUrl: './grid-print.component.html'
9 })
10
11 /**
12  */
13 export class GridPrintComponent {
14
15     @Input() gridContext: GridContext;
16     @ViewChild('printTemplate', { static: true }) private printTemplate: TemplateRef<any>;
17     @ViewChild('progressDialog', { static: true })
18         private progressDialog: ProgressDialogComponent;
19
20     constructor(private printer: PrintService) {}
21
22     printGrid() {
23         this.progressDialog.open();
24         const columns = this.gridContext.columnSet.displayColumns();
25         const textItems = {columns: columns, rows: []};
26
27         // Warn on missing print value generators for cells using templates.
28         columns.forEach(col => {
29             if (col.cellTemplate && !col.cellPrintValue) {
30                 console.warn("No print value generator set for: " + col.name);
31             }
32         });
33
34         this.gridContext.getAllRowsAsText().subscribe(
35             row => {
36               this.progressDialog.increment();
37               textItems.rows.push(row);
38             },
39             err => this.progressDialog.close(),
40             ()  => {
41                 this.progressDialog.close();
42                 this.printer.print({
43                     template: this.printTemplate,
44                     contextData: textItems,
45                     printContext: 'default'
46                 });
47             }
48         );
49     }
50 }
51
52