1c2d443e1b2003c16f67e1b6a22a803ea03f9372
[portal/sdk.git] /
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';
10
11 @Component( {
12     selector: 'app-all-reports',
13     templateUrl: './report-list.component.html',
14     styleUrls: ['./report-list.component.css']
15 } )
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;
22     dataSource1: any;
23     finalGETObj: {};
24     finalGETObjRowsArr: [][];
25     rowArr: {}[];
26     reportIdArr: string[];
27     toggle: boolean;
28     intermediateDisplayedColumns: string[];
29     displayedColumns = ["rep_id", "rep_name", "descr", "owner", "create_date", "copy", "edit", "delete", "schedule", "run"];
30     finalRowArr: AllReportsItem[];
31     rowObj: any;
32     reportId: string;
33     toggle1: boolean;
34     showSpinner: boolean;
35     showDialog: boolean;
36     closable: boolean;
37     delete: boolean;
38     newReportId: string;
39     constructor( private _http: HttpClient, private _router: Router, private _reportListService: ReportListService ) {
40         this.showDialog = false;
41         this.closable = false;
42         this.delete = false;
43         this.initializeReportList();
44     }
45     
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();
56         this.toggle = false;
57         this.toggle1 = false;
58         this.finalRowArr = new Array();
59         this._reportListService.getAllReports()
60             .subscribe(( responseObj ) => {
61                 this.finalGETObj = responseObj;
62                 this.finalGETObjRowsArr = this.finalGETObj["rows"];
63                 let j = 0;
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"] );
67                     }
68                     j++;
69                 }
70                 this.displayedColumns = this.intermediateDisplayedColumns;
71                 let i = 0;
72                 while ( this.finalGETObjRowsArr[0][i] ) {
73                     this.rowArr = this.finalGETObjRowsArr[0][i];
74                     this.rowObj = new Object();
75                     let j = 0;
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"] );
80                         }
81
82                         if ( this.rowArr[j]["columnId"] === "rep_name" ) {
83                             this.rowObj["rep_name"] = this.rowArr[j]["searchresultField"]["displayValue"];
84                         }
85
86                         if ( this.rowArr[j]["columnId"] === "descr" ) {
87                             this.rowObj["descr"] = this.rowArr[j]["searchresultField"]["displayValue"];
88                         }
89
90                         if ( this.rowArr[j]["columnId"] === "owner" ) {
91                             this.rowObj["owner"] = this.rowArr[j]["searchresultField"]["displayValue"];
92                         }
93
94                         if ( this.rowArr[j]["columnId"] === "create_date" ) {
95                             this.rowObj["create_date"] = this.rowArr[j]["searchresultField"]["displayValue"];
96                         }
97
98                         if ( this.rowArr[j]["columnId"] === "copy" ) {
99                             this.rowObj["copy"] = this.rowArr[j]["searchresultField"]["displayValue"];
100                         }
101
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"];
105                         }
106
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"];
110                         }
111
112                         if ( this.rowArr[j]["columnId"] === "schedule" ) {
113                             this.rowObj["schedule"] = this.rowArr[j]["searchresultField"]["displayValue"];
114                         }
115
116                         if ( this.rowArr[j]["columnId"] === "run" ) {
117                             this.rowObj["run"] = this.rowArr[j]["searchresultField"]["displayValue"];
118                         }
119                         j++;
120                     }
121                     this.finalRowArr.push( this.rowObj );
122                     i++;
123                 }
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;
131                 }
132             } );
133     }
134
135     ngOnInit() {
136         sessionStorage.clear();
137         const myItem = localStorage.getItem('id');
138         localStorage.clear();
139         localStorage.setItem('id', myItem);
140         this.toggle = false;
141     }
142
143     ngAfterViewInit() {
144         this.dataSource.sort = this.sort;
145         this.dataSource.paginator = this.paginator;
146         this.table.dataSource = this.dataSource;
147     }
148
149     displayReport( reportId: string ) {
150         this.reportId = reportId;
151         this._router.navigate( ["v2/reports", "Edit", reportId] );
152     }
153
154     runReport( reportId: string ) {
155         this.reportId = reportId;
156         this._router.navigate( ['v2/run', reportId] );
157     }
158
159     applyFilter( filterValue: string ) {
160         this.dataSource1.filter = filterValue.trim().toLowerCase();
161     }
162
163
164     confirmDelete( reportId: string ) {
165         this.showDialog = true;
166         this.closable = true;
167         this.newReportId = reportId;
168     }
169
170
171     deleteReport() {
172         this._reportListService.deleteReport( this.newReportId )
173             .subscribe(( responseDelete ) => {
174                 this.initializeReportList();
175                 this.showDialog = !this.showDialog;
176                 this.closable = false;
177
178             } );
179     }
180
181     close() {
182         this.showDialog = !this.showDialog;
183         this.closable = false;
184     }
185     
186     openReportSchedule( reportId: string ) {
187         this._router.navigate( ['v2/schedule_report', reportId] );
188     }
189
190  copydisplayReport(reportId : string)
191   {
192     this.reportId = reportId;
193     this._router.navigate(["v2/reports", "Copy",reportId]);     
194   }
195
196 }