1 import { AfterViewInit, Component, OnInit, ViewChild, Input, SimpleChange } from '@angular/core';
2 import { MatPaginator } from '@angular/material/paginator';
3 import { MatSort } from '@angular/material/sort';
4 import { MatTable, MatTableDataSource } from '@angular/material/table';
5 import { AllReportsDataSource, AllReportsItem } from './report-list-datasource';
6 import { HttpClient } from '@angular/common/http';
7 import { Router } from '@angular/router';
8 import { environment } from '../../../../environments/environment';
9 import { ReportListService } from './report-list.service';
12 selector: 'app-all-reports',
13 templateUrl: './report-list.component.html',
14 styleUrls: ['./report-list.component.css']
16 export class ReportListComponent implements AfterViewInit, OnInit {
17 @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
18 @ViewChild(MatSort, {static: false} as any) sort: MatSort;
19 @ViewChild(MatTable, {static: false} as any) table: MatTable<AllReportsItem>;
21 @Input("reportId") reportId1 : string;
24 dataSource: AllReportsDataSource;
27 finalGETObjRowsArr : [][];
29 reportIdArr : string[];
31 intermediateDisplayedColumns : string[];
32 displayedColumns : string[];
33 finalRowArr : AllReportsItem[];
37 showSpinner : boolean;
42 constructor(private _http : HttpClient, private _router : Router, private _reportListService : ReportListService){
44 this.showDialog = false;
45 this.closable = false;
48 this.initializeReportList();
54 initializeReportList()
57 this.showSpinner = true;
58 this.dataSource = new AllReportsDataSource();
59 this.dataSource1 = new MatTableDataSource();
60 this.intermediateDisplayedColumns = new Array();
63 this.finalGETObj = new Object();
65 this.finalGETObj = new Object();
66 this.finalGETObjRowsArr = new Array();
67 this.rowArr = new Array();
68 this.reportIdArr = new Array();
72 this.finalRowArr = new Array();
75 this._http.get(environment.baseUrl + "raptor.htm?action=report.search.execute&r_page=0")
76 .subscribe((responseObj) => {
77 this.finalGETObj = responseObj;
78 this.finalGETObjRowsArr = this.finalGETObj["rows"];
81 while(this.finalGETObj["columns"][0][j])
83 if(this.finalGETObj["columns"][0][j]["columnId"] !== "no")
85 this.intermediateDisplayedColumns.push(this.finalGETObj["columns"][0][j]["columnId"]);
90 this.displayedColumns = this.intermediateDisplayedColumns;
94 while(this.finalGETObjRowsArr[0][i])
96 this.rowArr = this.finalGETObjRowsArr[0][i];
97 this.rowObj = new Object();
103 if(this.rowArr[j]["columnId"] === "rep_id")
105 this.rowObj["rep_id"] = this.rowArr[j]["searchresultField"]["displayValue"];
106 this.reportIdArr.push(this.rowArr[j]["searchresultField"]["displayValue"]);
109 if(this.rowArr[j]["columnId"] === "rep_name")
111 this.rowObj["rep_name"] = this.rowArr[j]["searchresultField"]["displayValue"];
114 if(this.rowArr[j]["columnId"] === "descr")
116 this.rowObj["descr"] = this.rowArr[j]["searchresultField"]["displayValue"];
119 if(this.rowArr[j]["columnId"] === "owner")
121 this.rowObj["owner"] = this.rowArr[j]["searchresultField"]["displayValue"];
124 if(this.rowArr[j]["columnId"] === "create_date")
126 this.rowObj["create_date"] = this.rowArr[j]["searchresultField"]["displayValue"];
129 if(this.rowArr[j]["columnId"] === "copy")
131 this.rowObj["copy"] = this.rowArr[j]["searchresultField"]["displayValue"]; }
133 if(this.rowArr[j]["columnId"] === "edit")
135 this.rowObj["edit"] = this.rowArr[j]["searchresultField"]["displayValue"];
138 if(this.rowArr[j]["columnId"] === "delete")
140 this.rowObj["delete"] = this.rowArr[j]["searchresultField"]["displayValue"];
143 if(this.rowArr[j]["columnId"] === "schedule")
145 this.rowObj["schedule"] = this.rowArr[j]["searchresultField"]["displayValue"];
148 if(this.rowArr[j]["columnId"] === "run")
150 this.rowObj["run"] = this.rowArr[j]["searchresultField"]["displayValue"];
156 this.finalRowArr.push(this.rowObj);
160 this.showSpinner = false;
162 if(!this.showSpinner)
166 this.dataSource.data = this.finalRowArr;
167 this.dataSource1 = new MatTableDataSource(this.finalRowArr);
168 this.dataSource1.sort = this.sort;
169 this.dataSource1.paginator = this.paginator;
170 this.table.dataSource = this.dataSource;
180 this.dataSource.sort = this.sort;
181 this.dataSource.paginator = this.paginator;
182 this.table.dataSource = this.dataSource;
185 displayReport(reportId : string)
187 this.reportId = reportId;
189 this._router.navigate(["v2/reports", "Edit",reportId]);
195 runReport(reportId : string)
197 this.reportId = reportId;
199 this._router.navigate(['v2/run', reportId]);
203 applyFilter(filterValue: string) {
204 this.dataSource1.filter = filterValue.trim().toLowerCase();
208 confirmDelete(reportId : string)
210 this.showDialog = true;
211 this.closable = true;
213 this.newReportId = reportId;
219 this._reportListService.deleteReport(this.newReportId)
220 .subscribe((responseDelete) => {
221 this.initializeReportList();
222 this.showDialog = !this.showDialog;
223 this.closable = false;
229 this.showDialog = !this.showDialog;
230 this.closable = false;
234 openReportSchedule(reportId:string){
235 this._router.navigate(['v2/schedule_report', reportId]);