1 import {Component, OnInit, Input, AfterViewInit, ViewEncapsulation} from '@angular/core';
2 import {HttpClient, HttpHeaders} from '@angular/common/http';
3 import {environment} from '../../../../../../environments/environment';
4 import {Router} from '@angular/router';
5 import {SqlService} from './sql.service';
6 import {error} from 'util';
9 selector: 'app-sqlcomponent',
10 templateUrl: './sql.component.html',
11 styleUrls: ['./sql.component.css'],
12 encapsulation: ViewEncapsulation.None,
14 export class SQLComponent implements OnInit {
16 @Input('reportId') reportId1: string;
17 @Input('reportMode') reportMode: string;
20 showSaveSQLDialog: boolean;
22 ValidatePostResponse: any;
23 showValidateSQLDialog: boolean;
25 Validatestatus: string;
27 Validatemessage: string;
30 ValidateResponseString: string;
34 showErrorSqlMessage: boolean;
35 errorMessageString = '';
37 @Input() SQLclosable = true;
38 @Input() Validateclosable = true;
41 constructor(private _http: HttpClient, private _router: Router, private _sqlService: SqlService) {
42 this.showSaveSQLDialog = false;
43 this.SQLPostResponse = true;
44 this.ValidatePostResponse = {};
45 this.showErrorSqlMessage = false;
49 this.showSpinner = true;
50 this.showSaveSQLDialog = false;
51 this.SQLPostResponse = true;
52 this.ValidatePostResponse = {};
53 this._sqlService.getSQLTabData(this.reportId1)
54 .subscribe((response) => {
55 this.showSpinner = true;
56 this.finalGetObj = response;
57 this.sqlText = this.finalGetObj.query;
58 this.showSpinner = false;
64 this.showSaveSQLDialog = false;
65 this.SQLPostResponse = true;
66 this.ValidatePostResponse = {};
67 this._sqlService.getSQLTabData(this.reportId1)
68 .subscribe((response) => {
69 this.showSpinner = true;
70 this.finalGetObj = response;
71 this.sqlText = this.finalGetObj.query;
73 this.showSpinner = false;
79 this.SQLPostResponse = true;
80 if (this.SQLPostResponse === true) {
81 this.SQLstatus = 'Success!';
82 this.SQLmessage = 'Your change has been saved! Definition is updated.';
83 this.showSaveSQLDialog = !this.showSaveSQLDialog;
84 this.SQLclosable = true;
86 this.SQLstatus = 'Failure!';
87 this.SQLmessage = 'Definition could not be updated.';
88 this.showSaveSQLDialog = !this.showSaveSQLDialog;
89 this.SQLclosable = true;
95 this._sqlService.postSQLValidateAndSave(this.sqlText)
96 .subscribe((response) => {
97 this.showSpinner = true;
98 this.ValidateResponseString = response['data']['elements'];
99 this.SetValidateResponseString(this.ValidateResponseString);
100 this.ValidatePostResponse = JSON.parse(response['data']['elements']);
101 if (this.ValidatePostResponse['query'] !== undefined) {
102 this.showErrorSqlMessage = false;
103 this.showModal = true;
104 this.Validatestatus = 'SQL Test Run - Executed!';
105 this.showValidateSQLDialog = !this.showValidateSQLDialog;
106 this.Validateclosable = true;
108 this.showErrorSqlMessage = false;
109 this.showModal = false;
110 this.Validatestatus = 'SQL Test Run - Failed!';
111 this.showValidateSQLDialog = !this.showValidateSQLDialog;
112 this.Validateclosable = true;
114 this.showSpinner = false;
116 this.errorMessageString = error.error;
117 this.ValidatePostResponse = {};
118 this.ValidateResponseString = '';
119 this.showErrorSqlMessage = true;
120 this.showModal = false;
121 this.Validatestatus = 'SQL Test Run - Failed!';
122 this.showValidateSQLDialog = !this.showValidateSQLDialog;
123 this.Validateclosable = true;
128 this.showSaveSQLDialog = !this.showSaveSQLDialog;
129 this.SQLclosable = false;
132 closeValidateModal() {
133 if (this.reportMode === 'Create') {
134 if (this.Validatestatus == 'SQL Test Run - Failed!') {
135 this.sqlText = this.sqlText;
137 this._http.get(environment.baseUrl + 'report/wizard/retrieve_def_tab_wise_data/InSession')
138 .subscribe((response) => {
139 console.log(response);
140 this._router.navigate(['v2/reports', 'Edit', response['reportId']]);
144 this.showValidateSQLDialog = !this.showValidateSQLDialog;
145 this.Validateclosable = false;
148 SetValidateResponseString(ValidateResponseString1: string) {
149 this.ValidateResponseString = ValidateResponseString1;
152 GetValidateResponseString() {
153 return this.ValidateResponseString;