]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-print.component.ts
LP1830973 Angular 8 updates
[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         this.gridContext.getAllRowsAsText().subscribe(
28             row => {
29               this.progressDialog.increment();
30               textItems.rows.push(row);
31             },
32             err => this.progressDialog.close(),
33             ()  => {
34                 this.progressDialog.close();
35                 this.printer.print({
36                     template: this.printTemplate,
37                     contextData: textItems,
38                     printContext: 'default'
39                 });
40             }
41         );
42     }
43 }
44
45