1 import { Component, OnInit, Input, AfterViewInit } 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';
8 selector: 'app-sqlcomponent',
9 templateUrl: './sql.component.html',
10 styleUrls: ['./sql.component.css']
12 export class SQLComponent implements OnInit {
14 @Input("reportId") reportId1 : string;
15 @Input("reportMode") reportMode : string;
18 showSaveSQLDialog: boolean;
19 SQLPostResponse : any;
20 ValidatePostResponse : any;
21 showValidateSQLDialog : boolean;
23 Validatestatus : string;
25 Validatemessage : string;
28 ValidateResponseString : string;
31 showSpinner : boolean;
33 @Input() SQLclosable = true;
34 @Input() Validateclosable = true;
37 constructor(private _http : HttpClient, private _router : Router, private _sqlService : SqlService) {
38 this.showSaveSQLDialog = false;
39 this.SQLPostResponse = true;
40 this.ValidatePostResponse = {};
44 this.showSaveSQLDialog = false;
45 this.SQLPostResponse = true;
46 this.ValidatePostResponse = {};
48 this._sqlService.getSQLTabData(this.reportId1)
49 .subscribe((response) => {
50 this.showSpinner = true;
52 this.finalGetObj = response;
53 this.sqlText = this.finalGetObj.query;
55 this.showSpinner = false;
62 this.showSaveSQLDialog = false;
63 this.SQLPostResponse = true;
64 this.ValidatePostResponse = {};
66 this._sqlService.getSQLTabData(this.reportId1)
67 .subscribe((response) => {
68 this.showSpinner = true;
69 this.finalGetObj = response;
70 this.sqlText = this.finalGetObj.query;
72 this.showSpinner = false;
80 this.SQLPostResponse = true;
82 if(this.SQLPostResponse === true)
84 this.SQLstatus = "Success!";
85 this.SQLmessage = "Your change has been saved! Definition is updated.";
86 this.showSaveSQLDialog = !this.showSaveSQLDialog;
87 this.SQLclosable = true;
91 this.SQLstatus = "Failure!";
92 this.SQLmessage = "Definition could not be updated.";
93 this.showSaveSQLDialog = !this.showSaveSQLDialog;
94 this.SQLclosable = true;
102 this._sqlService.postSQLValidateAndSave(this.sqlText)
103 .subscribe((response) => {
104 this.showSpinner = true;
106 this.ValidateResponseString = response["data"]["elements"];
107 this.SetValidateResponseString(this.ValidateResponseString);
109 this.ValidatePostResponse = JSON.parse(response["data"]["elements"]);
111 if(this.ValidatePostResponse["query"] !== undefined)
113 this.showModal = true;
114 this.Validatestatus = "SQL Test Run - Executed!";
115 this.showValidateSQLDialog = !this.showValidateSQLDialog;
116 this.Validateclosable = true;
120 this.showModal = false;
121 this.Validatestatus = "SQL Test Run - Failed!";
122 this.showValidateSQLDialog = !this.showValidateSQLDialog;
123 this.Validateclosable = true;
125 this.showSpinner = false;
133 this.showSaveSQLDialog = !this.showSaveSQLDialog;
134 this.SQLclosable = false;
137 closeValidateModal() {
138 if(this.reportMode === "Create")
140 if(this.Validatestatus == "SQL Test Run - Failed!")
142 this.sqlText = this.sqlText;
146 this._http.get(environment.baseUrl + "report/wizard/retrieve_def_tab_wise_data/InSession")
147 .subscribe((response) => {
149 console.log(response);
151 this._router.navigate(["v2/reports", "Edit",response["reportId"]]);
155 this.showValidateSQLDialog = !this.showValidateSQLDialog;
156 this.Validateclosable = false;
159 SetValidateResponseString(ValidateResponseString1 : string)
161 this.ValidateResponseString = ValidateResponseString1;
164 GetValidateResponseString()
166 return this.ValidateResponseString;