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.showSaveSQLDialog = false;
50 this.SQLPostResponse = true;
51 this.ValidatePostResponse = {};
52 this._sqlService.getSQLTabData(this.reportId1)
53 .subscribe((response) => {
54 this.showSpinner = true;
55 this.finalGetObj = response;
56 this.sqlText = this.finalGetObj.query;
57 this.showSpinner = false;
63 this.showSaveSQLDialog = false;
64 this.SQLPostResponse = true;
65 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;
78 this.SQLPostResponse = true;
79 if (this.SQLPostResponse === true) {
80 this.SQLstatus = 'Success!';
81 this.SQLmessage = 'Your change has been saved! Definition is updated.';
82 this.showSaveSQLDialog = !this.showSaveSQLDialog;
83 this.SQLclosable = true;
85 this.SQLstatus = 'Failure!';
86 this.SQLmessage = 'Definition could not be updated.';
87 this.showSaveSQLDialog = !this.showSaveSQLDialog;
88 this.SQLclosable = true;
94 this._sqlService.postSQLValidateAndSave(this.sqlText)
95 .subscribe((response) => {
96 this.showSpinner = true;
97 this.ValidateResponseString = response['data']['elements'];
98 this.SetValidateResponseString(this.ValidateResponseString);
99 this.ValidatePostResponse = JSON.parse(response['data']['elements']);
100 if (this.ValidatePostResponse['query'] !== undefined) {
101 this.showErrorSqlMessage = false;
102 this.showModal = true;
103 this.Validatestatus = 'SQL Test Run - Executed!';
104 this.showValidateSQLDialog = !this.showValidateSQLDialog;
105 this.Validateclosable = true;
107 this.showErrorSqlMessage = false;
108 this.showModal = false;
109 this.Validatestatus = 'SQL Test Run - Failed!';
110 this.showValidateSQLDialog = !this.showValidateSQLDialog;
111 this.Validateclosable = true;
113 this.showSpinner = false;
115 this.errorMessageString = error.error;
116 this.ValidatePostResponse = {};
117 this.ValidateResponseString = '';
118 this.showErrorSqlMessage = true;
119 this.showModal = false;
120 this.Validatestatus = 'SQL Test Run - Failed!';
121 this.showValidateSQLDialog = !this.showValidateSQLDialog;
122 this.Validateclosable = true;
127 this.showSaveSQLDialog = !this.showSaveSQLDialog;
128 this.SQLclosable = false;
131 closeValidateModal() {
132 if (this.reportMode === 'Create') {
133 if (this.Validatestatus == 'SQL Test Run - Failed!') {
134 this.sqlText = this.sqlText;
136 this._http.get(environment.baseUrl + 'report/wizard/retrieve_def_tab_wise_data/InSession')
137 .subscribe((response) => {
138 // console.log(response);
139 this._router.navigate(['v2/reports', 'Edit', response['reportId']]);
143 this.showValidateSQLDialog = !this.showValidateSQLDialog;
144 this.Validateclosable = false;
147 SetValidateResponseString(ValidateResponseString1: string) {
148 this.ValidateResponseString = ValidateResponseString1;
151 GetValidateResponseString() {
152 return this.ValidateResponseString;