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
|
import {Component, OnInit, Input, AfterViewInit, ViewEncapsulation} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {environment} from '../../../../../../environments/environment';
import {Router} from '@angular/router';
import {SqlService} from './sql.service';
import {error} from 'util';
@Component({
selector: 'app-sqlcomponent',
templateUrl: './sql.component.html',
styleUrls: ['./sql.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class SQLComponent implements OnInit {
@Input('reportId') reportId1: string;
@Input('reportMode') reportMode: string;
showSaveSQLDialog: boolean;
SQLPostResponse: any;
ValidatePostResponse: any;
showValidateSQLDialog: boolean;
SQLstatus: string;
Validatestatus: string;
SQLmessage: string;
Validatemessage: string;
sqlText: string;
showModal: boolean;
ValidateResponseString: string;
finalGetObj: any;
showSpinner: boolean;
showErrorSqlMessage: boolean;
errorMessageString = '';
@Input() SQLclosable = true;
@Input() Validateclosable = true;
constructor(private _http: HttpClient, private _router: Router, private _sqlService: SqlService) {
this.showSaveSQLDialog = false;
this.SQLPostResponse = true;
this.ValidatePostResponse = {};
this.showErrorSqlMessage = false;
}
ngOnInit() {
this.showSaveSQLDialog = false;
this.SQLPostResponse = true;
this.ValidatePostResponse = {};
this._sqlService.getSQLTabData(this.reportId1)
.subscribe((response) => {
this.showSpinner = true;
this.finalGetObj = response;
this.sqlText = this.finalGetObj.query;
this.showSpinner = false;
});
}
ngOnChanges() {
this.showSaveSQLDialog = false;
this.SQLPostResponse = true;
this.ValidatePostResponse = {};
this._sqlService.getSQLTabData(this.reportId1)
.subscribe((response) => {
this.showSpinner = true;
this.finalGetObj = response;
this.sqlText = this.finalGetObj.query;
this.showSpinner = false;
});
}
saveSQL() {
this.SQLPostResponse = true;
if (this.SQLPostResponse === true) {
this.SQLstatus = 'Success!';
this.SQLmessage = 'Your change has been saved! Definition is updated.';
this.showSaveSQLDialog = !this.showSaveSQLDialog;
this.SQLclosable = true;
} else {
this.SQLstatus = 'Failure!';
this.SQLmessage = 'Definition could not be updated.';
this.showSaveSQLDialog = !this.showSaveSQLDialog;
this.SQLclosable = true;
}
}
validate() {
this._sqlService.postSQLValidateAndSave(this.sqlText)
.subscribe((response) => {
this.showSpinner = true;
this.ValidateResponseString = response['data']['elements'];
this.SetValidateResponseString(this.ValidateResponseString);
this.ValidatePostResponse = JSON.parse(response['data']['elements']);
if (this.ValidatePostResponse['query'] !== undefined) {
this.showErrorSqlMessage = false;
this.showModal = true;
this.Validatestatus = 'SQL Test Run - Executed!';
this.showValidateSQLDialog = !this.showValidateSQLDialog;
this.Validateclosable = true;
} else {
this.showErrorSqlMessage = false;
this.showModal = false;
this.Validatestatus = 'SQL Test Run - Failed!';
this.showValidateSQLDialog = !this.showValidateSQLDialog;
this.Validateclosable = true;
}
this.showSpinner = false;
}, error => {
this.errorMessageString = error.error;
this.ValidatePostResponse = {};
this.ValidateResponseString = '';
this.showErrorSqlMessage = true;
this.showModal = false;
this.Validatestatus = 'SQL Test Run - Failed!';
this.showValidateSQLDialog = !this.showValidateSQLDialog;
this.Validateclosable = true;
});
}
closeSaveModal() {
this.showSaveSQLDialog = !this.showSaveSQLDialog;
this.SQLclosable = false;
}
closeValidateModal() {
if (this.reportMode === 'Create') {
if (this.Validatestatus == 'SQL Test Run - Failed!') {
this.sqlText = this.sqlText;
} else {
this._http.get(environment.baseUrl + 'report/wizard/retrieve_def_tab_wise_data/InSession')
.subscribe((response) => {
// console.log(response);
this._router.navigate(['v2/reports', 'Edit', response['reportId']]);
});
}
}
this.showValidateSQLDialog = !this.showValidateSQLDialog;
this.Validateclosable = false;
}
SetValidateResponseString(ValidateResponseString1: string) {
this.ValidateResponseString = ValidateResponseString1;
}
GetValidateResponseString() {
return this.ValidateResponseString;
}
}
|