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>;
20 @Input( "reportId" ) reportId1: string;
21 dataSource: AllReportsDataSource;
24 finalGETObjRowsArr: [][];
26 reportIdArr: string[];
28 intermediateDisplayedColumns: string[];
29 displayedColumns = ["rep_id", "rep_name", "descr", "owner", "create_date", "copy", "edit", "delete", "schedule", "run"];
30 finalRowArr: AllReportsItem[];
39 constructor( private _http: HttpClient, private _router: Router, private _reportListService: ReportListService ) {
40 this.showDialog = false;
41 this.closable = false;
43 this.initializeReportList();
46 initializeReportList() {
47 this.showSpinner = true;
48 this.dataSource = new AllReportsDataSource();
49 this.dataSource1 = new MatTableDataSource();
50 this.intermediateDisplayedColumns = new Array();
51 this.finalGETObj = new Object();
52 this.finalGETObj = new Object();
53 this.finalGETObjRowsArr = new Array();
54 this.rowArr = new Array();
55 this.reportIdArr = new Array();
58 this.finalRowArr = new Array();
59 this._reportListService.getAllReports()
60 .subscribe(( responseObj ) => {
61 this.finalGETObj = responseObj;
62 this.finalGETObjRowsArr = this.finalGETObj["rows"];
64 while ( this.finalGETObj["columns"][0][j] ) {
65 if ( this.finalGETObj["columns"][0][j]["columnId"] !== "no" ) {
66 this.intermediateDisplayedColumns.push( this.finalGETObj["columns"][0][j]["columnId"] );
70 this.displayedColumns = this.intermediateDisplayedColumns;
72 while ( this.finalGETObjRowsArr[0][i] ) {
73 this.rowArr = this.finalGETObjRowsArr[0][i];
74 this.rowObj = new Object();
76 while ( this.rowArr[j] ) {
77 if ( this.rowArr[j]["columnId"] === "rep_id" ) {
78 this.rowObj["rep_id"] = this.rowArr[j]["searchresultField"]["displayValue"];
79 this.reportIdArr.push( this.rowArr[j]["searchresultField"]["displayValue"] );
82 if ( this.rowArr[j]["columnId"] === "rep_name" ) {
83 this.rowObj["rep_name"] = this.rowArr[j]["searchresultField"]["displayValue"];
86 if ( this.rowArr[j]["columnId"] === "descr" ) {
87 this.rowObj["descr"] = this.rowArr[j]["searchresultField"]["displayValue"];
90 if ( this.rowArr[j]["columnId"] === "owner" ) {
91 this.rowObj["owner"] = this.rowArr[j]["searchresultField"]["displayValue"];
94 if ( this.rowArr[j]["columnId"] === "create_date" ) {
95 this.rowObj["create_date"] = this.rowArr[j]["searchresultField"]["displayValue"];
98 if ( this.rowArr[j]["columnId"] === "copy" ) {
99 this.rowObj["copy"] = this.rowArr[j]["searchresultField"]["displayValue"];
102 if ( this.rowArr[j]["columnId"] === "edit" ) {
103 this.rowObj["edit"] = this.rowArr[j]["searchresultField"]["displayValue"];
104 this.rowObj["canEdit"] = this.rowArr[j]["searchresultField"]["authorized"];
107 if ( this.rowArr[j]["columnId"] === "delete" ) {
108 this.rowObj["delete"] = this.rowArr[j]["searchresultField"]["displayValue"];
109 this.rowObj["canDelete"] = this.rowArr[j]["searchresultField"]["authorized"];
112 if ( this.rowArr[j]["columnId"] === "schedule" ) {
113 this.rowObj["schedule"] = this.rowArr[j]["searchresultField"]["displayValue"];
116 if ( this.rowArr[j]["columnId"] === "run" ) {
117 this.rowObj["run"] = this.rowArr[j]["searchresultField"]["displayValue"];
121 this.finalRowArr.push( this.rowObj );
124 this.showSpinner = false;
125 if ( !this.showSpinner ) {
126 this.dataSource.data = this.finalRowArr;
127 this.dataSource1 = new MatTableDataSource( this.finalRowArr );
128 this.dataSource1.sort = this.sort;
129 this.dataSource1.paginator = this.paginator;
130 this.table.dataSource = this.dataSource;
136 sessionStorage.clear();
137 const myItem = localStorage.getItem('id');
138 localStorage.clear();
139 localStorage.setItem('id', myItem);
144 this.dataSource.sort = this.sort;
145 this.dataSource.paginator = this.paginator;
146 this.table.dataSource = this.dataSource;
149 displayReport( reportId: string ) {
150 this.reportId = reportId;
151 this._router.navigate( ["v2/reports", "Edit", reportId] );
154 runReport( reportId: string ) {
155 this.reportId = reportId;
156 this._router.navigate( ['v2/run', reportId] );
159 applyFilter( filterValue: string ) {
160 this.dataSource1.filter = filterValue.trim().toLowerCase();
164 confirmDelete( reportId: string ) {
165 this.showDialog = true;
166 this.closable = true;
167 this.newReportId = reportId;
172 this._reportListService.deleteReport( this.newReportId )
173 .subscribe(( responseDelete ) => {
174 this.initializeReportList();
175 this.showDialog = !this.showDialog;
176 this.closable = false;
182 this.showDialog = !this.showDialog;
183 this.closable = false;
186 openReportSchedule( reportId: string ) {
187 this._router.navigate( ['v2/schedule_report', reportId] );
190 copydisplayReport(reportId : string)
192 this.reportId = reportId;
193 this._router.navigate(["v2/reports", "Copy",reportId]);