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';
14 selector: 'eg-sr-outputs',
15 templateUrl: 'sr-my-outputs.component.html',
18 export class SROutputsComponent implements OnInit {
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;
26 cellTextGenerator: GridCellTextGenerator;
29 private auth: AuthService,
30 private pcrud: PcrudService,
31 private idl: IdlService,
32 private toast: ToastService,
33 private srSvc: SimpleReporterService,
35 // These values are all replaced via custom templates and cause warnings if not specified here.
36 this.cellTextGenerator = {
43 this.gridSource = this.srSvc.getOutputDatasource();
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()}`;
52 zeroSelectedRows(rows: any) {
53 return rows.length === 0;
56 notOneSelectedRow(rows: any) {
57 return rows.length !== 1;
60 deleteOutputs(rows: any[]) {
61 if ( rows.length <= 0 ) { return; }
62 this.confirmDeleteString.current({ num: rows.length })
64 this.confirmDeleteDialog.dialogBody = str;
65 this.confirmDeleteDialog.open()
66 .subscribe(confirmed => {
67 if ( confirmed ) { this.doDeleteOutputs(rows.map(x => x._rs)); }
72 doDeleteOutputs(outs: IdlObject[]) {
73 const deletedCount = outs.length;
74 this.pcrud.remove(outs).toPromise()
76 this.outputsGrid.reload();
77 this.deletedString.current({num: outs.length})
79 this.toast.success(str);
86 this.outputsGrid.reload();