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: './sqlcomponent.component.html',
10 styleUrls: ['./sqlcomponent.component.css']
12 export class SQLComponentComponent 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._http.post(environment.baseUrl + "report/wizard/retrieve_data/true",
101 "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",
105 , { headers: new HttpHeaders({'Content-Type': 'application/json'})})
106 .subscribe((response) => {
107 console.log(response);
110 if(this.SQLPostResponse === true)
112 this.SQLstatus = "Success!";
113 this.SQLmessage = "Your change has been saved! Definition is updated.";
114 this.showSaveSQLDialog = !this.showSaveSQLDialog;
115 this.SQLclosable = true;
119 this.SQLstatus = "Failure!";
120 this.SQLmessage = "Definition could not be updated.";
121 this.showSaveSQLDialog = !this.showSaveSQLDialog;
122 this.SQLclosable = true;
130 //console.log(this.sqlText);
132 this._sqlService.postSQLValidateAndSave(this.sqlText)
133 .subscribe((response) => {
136 this.ValidateResponseString = response["data"]["elements"];
137 this.SetValidateResponseString(this.ValidateResponseString);
138 console.log(this.ValidateResponseString);
140 this.ValidatePostResponse = JSON.parse(response["data"]["elements"]);
142 //console.log(this.ValidatePostResponse["errormessage"]);
144 if(this.ValidatePostResponse["query"] !== undefined)
146 this.showModal = true;
147 this.Validatestatus = "SQL Test Run - Executed!";
148 this.showValidateSQLDialog = !this.showValidateSQLDialog;
149 this.Validateclosable = true;
153 this.showModal = false;
154 this.Validatestatus = "SQL Test Run - Failed!";
155 this.showValidateSQLDialog = !this.showValidateSQLDialog;
156 this.Validateclosable = true;
166 this.showSaveSQLDialog = !this.showSaveSQLDialog;
167 this.SQLclosable = false;
170 closeValidateModal() {
171 this.showValidateSQLDialog = !this.showValidateSQLDialog;
172 this.Validateclosable = false;
174 console.log(this.reportMode);
176 if(this.reportMode === "Create")
178 this._http.get(environment.baseUrl + "report/wizard/retrieve_def_tab_wise_data/InSession")
179 .subscribe((response) => {
180 this._router.navigate(["v2/reports", "Edit",response["reportId"]]);
183 //this._router.navigate(["v2/reports", this.reportId1]);
186 SetValidateResponseString(ValidateResponseString1 : string)
188 this.ValidateResponseString = ValidateResponseString1;
191 GetValidateResponseString()
193 return this.ValidateResponseString;