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, AfterViewInit {
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;
32 @Input() SQLclosable = true;
33 @Input() Validateclosable = true;
36 constructor(private _http : HttpClient, private _router : Router, private _sqlService : SqlService) {
37 this.showSaveSQLDialog = false;
38 this.SQLPostResponse = true;
39 this.ValidatePostResponse = {};
41 this._sqlService.getSQLTabData(this.reportId1)
42 .subscribe((response) => {
43 console.log(response);
45 this.finalGetObj = response;
46 this.sqlText = this.finalGetObj.query;
51 this.showSaveSQLDialog = false;
52 this.SQLPostResponse = true;
53 this.ValidatePostResponse = {};
55 this._sqlService.getSQLTabData(this.reportId1)
56 .subscribe((response) => {
57 console.log(response);
59 this.finalGetObj = response;
60 this.sqlText = this.finalGetObj.query;
65 console.log("Reached SQL TAB On Changes.");
66 this.showSaveSQLDialog = false;
67 this.SQLPostResponse = true;
68 this.ValidatePostResponse = {};
70 this._sqlService.getSQLTabData(this.reportId1)
71 .subscribe((response) => {
72 console.log(response);
74 this.finalGetObj = response;
75 this.sqlText = this.finalGetObj.query;
81 console.log("Reached SQL TAB On Changes.");
82 this.showSaveSQLDialog = false;
83 this.SQLPostResponse = true;
84 this.ValidatePostResponse = {};
86 this._sqlService.getSQLTabData(this.reportId1)
87 .subscribe((response) => {
88 console.log(response);
90 this.finalGetObj = response;
91 this.sqlText = this.finalGetObj.query;
99 this.SQLPostResponse = true;
100 // this._http.post(environment.baseUrl + "report/wizard/retrieve_data/true",
102 // "query": "SELECT region region, market market, site_state state, count(usid) num_site from cssng_data_addition_5g@e911_e911pro where cell_active='Y' group by region,market,site_state",
106 // , { headers: new HttpHeaders({'Content-Type': 'application/json'})})
107 // .subscribe((response) => {
108 // console.log(response);
111 if(this.SQLPostResponse === true)
113 this.SQLstatus = "Success!";
114 this.SQLmessage = "Your change has been saved! Definition is updated.";
115 this.showSaveSQLDialog = !this.showSaveSQLDialog;
116 this.SQLclosable = true;
120 this.SQLstatus = "Failure!";
121 this.SQLmessage = "Definition could not be updated.";
122 this.showSaveSQLDialog = !this.showSaveSQLDialog;
123 this.SQLclosable = true;
131 //console.log(this.sqlText);
133 this._sqlService.postSQLValidateAndSave(this.sqlText)
134 .subscribe((response) => {
137 this.ValidateResponseString = response["data"]["elements"];
138 this.SetValidateResponseString(this.ValidateResponseString);
139 console.log(this.ValidateResponseString);
141 this.ValidatePostResponse = JSON.parse(response["data"]["elements"]);
143 //console.log(this.ValidatePostResponse["errormessage"]);
145 if(this.ValidatePostResponse["query"] !== undefined)
147 this.showModal = true;
148 this.Validatestatus = "SQL Test Run - Executed!";
149 this.showValidateSQLDialog = !this.showValidateSQLDialog;
150 this.Validateclosable = true;
154 this.showModal = false;
155 this.Validatestatus = "SQL Test Run - Failed!";
156 this.showValidateSQLDialog = !this.showValidateSQLDialog;
157 this.Validateclosable = true;
167 this.showSaveSQLDialog = !this.showSaveSQLDialog;
168 this.SQLclosable = false;
171 closeValidateModal() {
172 this.showValidateSQLDialog = !this.showValidateSQLDialog;
173 this.Validateclosable = false;
175 console.log(this.reportMode);
177 if(this.reportMode === "Create")
179 this._http.get(environment.baseUrl + "report/wizard/retrieve_def_tab_wise_data/InSession")
180 .subscribe((response) => {
181 this._router.navigate(["v2/reports", "Edit",response["reportId"]]);
184 //this._router.navigate(["v2/reports", this.reportId1]);
187 SetValidateResponseString(ValidateResponseString1 : string)
189 this.ValidateResponseString = ValidateResponseString1;
192 GetValidateResponseString()
194 return this.ValidateResponseString;