]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/reporter/simple/sr-my-outputs.component.ts
LP2045292 Color contrast for AngularJS patron bills
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / reporter / simple / sr-my-outputs.component.ts
1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {AuthService} from '@eg/core/auth.service';
3 import {IdlObject, IdlService} from '@eg/core/idl.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {StringComponent} from '@eg/share/string/string.component';
6 import {ToastService} from '@eg/share/toast/toast.service';
7 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
8 import {Pager} from '@eg/share/util/pager';
9 import {GridComponent} from '@eg/share/grid/grid.component';
10 import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
11 import {SimpleReporterService} from './simple-reporter.service';
12
13 @Component({
14     selector: 'eg-sr-outputs',
15     templateUrl: 'sr-my-outputs.component.html',
16 })
17
18 export class SROutputsComponent implements OnInit {
19
20     gridSource: GridDataSource;
21     @ViewChild('srOutputsGrid', { static: true }) outputsGrid: GridComponent;
22     @ViewChild('confirmDelete', { static: false }) confirmDeleteDialog: ConfirmDialogComponent;
23     @ViewChild('deleted', { static: true} ) deletedString: StringComponent;
24     @ViewChild('delete', { static: true} ) confirmDeleteString: StringComponent;
25
26     cellTextGenerator: GridCellTextGenerator;
27
28     constructor(
29         private auth: AuthService,
30         private pcrud: PcrudService,
31         private idl: IdlService,
32         private toast: ToastService,
33         private srSvc: SimpleReporterService,
34     ) {
35         // These values are all replaced via custom templates and cause warnings if not specified here.
36         this.cellTextGenerator = {
37             _output: row => ''
38         };
39
40     }
41
42     ngOnInit() {
43         this.gridSource = this.srSvc.getOutputDatasource();
44
45     }
46
47     // Expects an rt object with fleshed report to grab the template id.
48     outputPath(row: any, file: string) {
49         return `/reporter/${row.template_id}/${row.report_id}/${row.id}/${file}?ses=${this.auth.token()}`;
50     }
51
52     zeroSelectedRows(rows: any) {
53         return rows.length === 0;
54     }
55
56     notOneSelectedRow(rows: any) {
57         return rows.length !== 1;
58     }
59
60     deleteOutputs(rows: any[]) {
61         if ( rows.length <= 0 ) { return; }
62         this.confirmDeleteString.current({ num: rows.length })
63         .then(str => {
64             this.confirmDeleteDialog.dialogBody = str;
65             this.confirmDeleteDialog.open()
66             .subscribe(confirmed => {
67                 if ( confirmed ) { this.doDeleteOutputs(rows.map(x => x._rs)); }
68             });
69         });
70     }
71
72     doDeleteOutputs(outs: IdlObject[]) {
73         const deletedCount = outs.length;
74         this.pcrud.remove(outs).toPromise()
75         .then(res => {
76             this.outputsGrid.reload();
77             this.deletedString.current({num: outs.length})
78             .then(str => {
79                 this.toast.success(str);
80             });
81         });
82
83     }
84
85     refreshGrid($event) {
86         this.outputsGrid.reload();
87     }
88
89 }
90