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;
39 keyWordAssistance: any[];
42 constructor(private _http: HttpClient, private _router: Router, private _sqlService: SqlService) {
43 this.showSaveSQLDialog = false;
44 this.SQLPostResponse = true;
45 this.ValidatePostResponse = {};
46 this.showErrorSqlMessage = false;
47 this.keyWordAssistance = [];
52 this.showSaveSQLDialog = false;
53 this.SQLPostResponse = true;
54 this.ValidatePostResponse = {};
55 this.keyWordAssistance.push( 'SELECT', 'DISTINCT', 'FROM', 'WHERE',
56 'GROUP BY', 'HAVING', 'ORDER BY', 'ASC', 'DESC', 'AND', 'OR', 'NOT', 'EXISTS',
57 'IS', 'NULL', 'IN', 'BETWEEN', 'COUNT(', 'SUM(', 'AVG(', 'MAX(', 'MIN(', 'NVL(',
58 'DECODE(', 'SYSDATE', 'TO_CHAR(', 'TO_NUMBER(', 'TO_DATE(',
59 'TRUNC(', 'ROUND(', 'ABS(', 'SUBSTR(', 'REPLACE(', 'LOWER(', 'UPPER(',
60 'LTRM(', 'RTRIM(', 'LPAD(', 'RPAD(', 'linkToReport');
61 this._sqlService.getSQLTabData(this.reportId1)
62 .subscribe((response) => {
63 this.showSpinner = true;
64 this.finalGetObj = response;
65 this.sqlText = this.finalGetObj.query;
66 this.showSpinner = false;
72 this.showSaveSQLDialog = false;
73 this.SQLPostResponse = true;
74 this.ValidatePostResponse = {};
75 this._sqlService.getSQLTabData(this.reportId1)
76 .subscribe((response) => {
77 this.showSpinner = true;
78 this.finalGetObj = response;
79 this.sqlText = this.finalGetObj.query;
81 this.showSpinner = false;
87 this.SQLPostResponse = true;
88 if (this.SQLPostResponse === true) {
89 this.SQLstatus = 'Success!';
90 this.SQLmessage = 'Your change has been saved! Definition is updated.';
91 this.showSaveSQLDialog = !this.showSaveSQLDialog;
92 this.SQLclosable = true;
94 this.SQLstatus = 'Failure!';
95 this.SQLmessage = 'Definition could not be updated.';
96 this.showSaveSQLDialog = !this.showSaveSQLDialog;
97 this.SQLclosable = true;
103 this._sqlService.postSQLValidateAndSave(this.sqlText)
104 .subscribe((response) => {
105 this.showSpinner = true;
106 this.ValidateResponseString = response['data']['elements'];
107 this.SetValidateResponseString(this.ValidateResponseString);
108 this.ValidatePostResponse = JSON.parse(response['data']['elements']);
109 if (this.ValidatePostResponse['query'] !== undefined) {
110 this.showErrorSqlMessage = false;
111 this.showModal = true;
112 this.Validatestatus = 'SQL Test Run - Executed!';
113 this.showValidateSQLDialog = !this.showValidateSQLDialog;
114 this.Validateclosable = true;
116 this.showErrorSqlMessage = false;
117 this.showModal = false;
118 this.Validatestatus = 'SQL Test Run - Failed!';
119 this.showValidateSQLDialog = !this.showValidateSQLDialog;
120 this.Validateclosable = true;
122 this.showSpinner = false;
124 this.errorMessageString = error.error;
125 this.ValidatePostResponse = {};
126 this.ValidateResponseString = '';
127 this.showErrorSqlMessage = true;
128 this.showModal = false;
129 this.Validatestatus = 'SQL Test Run - Failed!';
130 this.showValidateSQLDialog = !this.showValidateSQLDialog;
131 this.Validateclosable = true;
136 this.showSaveSQLDialog = !this.showSaveSQLDialog;
137 this.SQLclosable = false;
140 closeValidateModal() {
141 if (this.reportMode === 'Create') {
142 if (this.Validatestatus == 'SQL Test Run - Failed!') {
143 this.sqlText = this.sqlText;
145 this._http.get(environment.baseUrl + 'report/wizard/retrieve_def_tab_wise_data/InSession')
146 .subscribe((response) => {
147 console.log(response);
148 this._router.navigate(['v2/app/reports', 'Edit', response['reportId']]);
152 this.showValidateSQLDialog = !this.showValidateSQLDialog;
153 this.Validateclosable = false;
156 SetValidateResponseString(ValidateResponseString1: string) {
157 this.ValidateResponseString = ValidateResponseString1;
160 GetValidateResponseString() {
161 return this.ValidateResponseString;
164 addText(word: string) {
165 this.sqlText = this.sqlText + ' ' + word + ' ';