summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/report-list.component.ts
blob: 01c1254ae53a3c74f92f4696c8e56eaccd5e5562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { AfterViewInit, Component, OnInit, ViewChild, Input, SimpleChange } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTable, MatTableDataSource } from '@angular/material/table';
import { AllReportsDataSource, AllReportsItem } from './report-list-datasource';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { environment } from '../../../../environments/environment';
import { ReportListService } from './report-list.service';

@Component( {
    selector: 'app-all-reports',
    templateUrl: './report-list.component.html',
    styleUrls: ['./report-list.component.css']
} )
export class ReportListComponent implements AfterViewInit, OnInit {
    @ViewChild( MatPaginator, { static: false } as any ) paginator: MatPaginator;
    @ViewChild( MatSort, { static: false } as any ) sort: MatSort;
    @ViewChild( MatTable, { static: false } as any ) table: MatTable<AllReportsItem>;
    @Input('reportId') reportId1: string;
    dataSource: AllReportsDataSource;
    dataSource1: any;
    finalGETObj: {};
    finalGETObjRowsArr: [][];
    rowArr: {}[];
    reportIdArr: string[];
    toggle: boolean;
    intermediateDisplayedColumns: string[];
    displayedColumns = ['rep_id', 'rep_name', 'descr', 'owner', 'create_date', 'copy', 'edit', 'delete', 'schedule', 'run'];
    finalRowArr: AllReportsItem[];
    rowObj: any;
    reportId: string;
    toggle1: boolean;
    showSpinner: boolean;
    showDialog: boolean;
    closable: boolean;
    delete: boolean;
    newReportId: string;
    constructor( private _http: HttpClient, private _router: Router, private _reportListService: ReportListService ) {
        this.showDialog = false;
        this.closable = false;
        this.delete = false;
        this.initializeReportList();
    }

    initializeReportList() {
        this.showSpinner = true;
        this.dataSource = new AllReportsDataSource();
        this.dataSource1 = new MatTableDataSource();
        this.intermediateDisplayedColumns = [];
        this.finalGETObj = {};
        this.finalGETObj = {};
        this.finalGETObjRowsArr = [];
        this.rowArr = [];
        this.reportIdArr = [];
        this.toggle = false;
        this.toggle1 = false;
        this.finalRowArr = [];
        this._reportListService.getAllReports()
            .subscribe(( responseObj ) => {
                this.finalGETObj = responseObj;
                this.finalGETObjRowsArr = this.finalGETObj['rows'];
                let j = 0;
                while (this.finalGETObj['columns'][0][j]) {
                    if (this.finalGETObj['columns'][0][j]['columnId'] !== 'no') {
                        this.intermediateDisplayedColumns.push(this.finalGETObj['columns'][0][j]['columnId']);
                    }
                    j++;
                }
                this.displayedColumns = this.intermediateDisplayedColumns;
                let i = 0;
                while ( this.finalGETObjRowsArr[0][i] ) {
                    this.rowArr = this.finalGETObjRowsArr[0][i];
                    this.rowObj = {};
                    let j = 0;
                    while ( this.rowArr[j] ) {
                        if (this.rowArr[j]['columnId'] === 'rep_id') {
                            this.rowObj['rep_id'] = this.rowArr[j]['searchresultField']['displayValue'];
                            this.reportIdArr.push(this.rowArr[j]['searchresultField']['displayValue']);
                        }

                        if (this.rowArr[j]['columnId'] === 'rep_name') {
                            this.rowObj['rep_name'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }

                        if (this.rowArr[j]['columnId'] === 'descr') {
                            this.rowObj['descr'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }

                        if (this.rowArr[j]['columnId'] === 'owner') {
                            this.rowObj['owner'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }

                        if (this.rowArr[j]['columnId'] === 'create_date') {
                            this.rowObj['create_date'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }

                        if (this.rowArr[j]['columnId'] === 'copy') {
                            this.rowObj['copy'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }

                        if (this.rowArr[j]['columnId'] === 'edit') {
                            this.rowObj['edit'] = this.rowArr[j]['searchresultField']['displayValue'];
                            this.rowObj['canEdit'] = this.rowArr[j]['searchresultField']['authorized'];
                        }

                        if (this.rowArr[j]['columnId'] === 'delete') {
                            this.rowObj['delete'] = this.rowArr[j]['searchresultField']['displayValue'];
                            this.rowObj['canDelete'] = this.rowArr[j]['searchresultField']['authorized'];
                        }

                        if (this.rowArr[j]['columnId'] === 'schedule') {
                            this.rowObj['schedule'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }

                        if (this.rowArr[j]['columnId'] === 'run') {
                            this.rowObj['run'] = this.rowArr[j]['searchresultField']['displayValue'];
                        }
                        j++;
                    }
                    this.finalRowArr.push( this.rowObj );
                    i++;
                }
                this.showSpinner = false;
                if ( !this.showSpinner ) {
                    this.dataSource.data = this.finalRowArr;
                    this.dataSource1 = new MatTableDataSource( this.finalRowArr );
                    this.dataSource1.sort = this.sort;
                    this.dataSource1.paginator = this.paginator;
                    this.table.dataSource = this.dataSource;
                }
            } );
    }

    ngOnInit() {
        sessionStorage.clear();
        const myItem = localStorage.getItem('notes');
        localStorage.clear();
        localStorage.setItem('notes', myItem);
        this.toggle = false;
    }

    ngAfterViewInit() {
        this.dataSource.sort = this.sort;
        this.dataSource.paginator = this.paginator;
        this.table.dataSource = this.dataSource;
    }

    displayReport( reportId: string ) {
        this.reportId = reportId;
        this._router.navigate(['v2/app/reports', 'Edit', reportId]);
    }

    runReport( reportId: string ) {
        this.reportId = reportId;
        this._router.navigate(['v2/run', reportId]);
    }

    applyFilter( filterValue: string ) {
        this.dataSource1.filter = filterValue.trim().toLowerCase();
    }


    confirmDelete( reportId: string ) {
        this.showDialog = true;
        this.closable = true;
        this.newReportId = reportId;
    }


    deleteReport() {
        this._reportListService.deleteReport( this.newReportId )
            .subscribe(( responseDelete ) => {
                this.initializeReportList();
                this.showDialog = !this.showDialog;
                this.closable = false;

            } );
    }

    close() {
        this.showDialog = !this.showDialog;
        this.closable = false;
    }

    openReportSchedule( reportId: string ) {
        this._router.navigate( ['v2/app/schedule_report', reportId] );
    }

    copydisplayReport(reportId: string) {
    this.reportId = reportId;
        this._router.navigate(['v2/app/reports', 'Copy', reportId]);
  }

}