1 import { Component, OnInit, Input } from '@angular/core';
2 import { FormFieldsService } from './form-fields.service';
5 selector: 'app-form-fields',
6 templateUrl: './form-fields.component.html',
7 styleUrls: ['./form-fields.component.css']
9 export class FormFieldsComponent implements OnInit {
11 @Input("reportId") reportId1 : string;
13 formFieldsListObj : any[];
14 postMoveUpwrdObj : {};
16 orderSeqOfDown : number;
17 orderSeqOfUp : number;
20 sqlAsDefaultValue : Boolean;
21 showDefaultSQLOption : boolean;
22 verifyFieldValueAs : number;
23 predefinedValueList : any[];
24 predefinedValue : string;
27 validationType : string;
31 groupFormField : boolean;
36 fieldDefaultSQL : string;
37 errorStackTrace : any;
39 defaultValue : boolean;
42 showSpinner : boolean;
43 showDialog1 : boolean;
45 validateResponseString : string;
46 showVerifySpinner : boolean;
49 constructor(private _formFieldsService : FormFieldsService) {
50 this.formFieldsListObj = new Array();
51 this.postMoveUpwrdObj = new Object();
52 this.postDownwardObj = new Object();
53 this.showDialog = false;
54 this.showDefaultSQLOption = false;
56 this.predefinedValueList = new Array();
57 this.finalPOSTObj = new Object();
58 this.showSpinner = false;
59 this.showDialog1 = false;
61 this.showVerifySpinner = false;
66 this._formFieldsService.getListOfFormFields()
67 .subscribe((responseFormFields) => {
69 for(let k=0; k<responseFormFields.length; k++)
71 // this.formFieldsListObj.push(responseFormFields[k]);
72 for(let m=0; m<responseFormFields.length; m++)
74 if(responseFormFields[m]["orderSeq"] == k+1)
76 this.formFieldsListObj.push(responseFormFields[m]);
80 console.log(this.formFieldsListObj);
87 if(n == this.formFieldsListObj.length-1)
110 moveUpward( n : number)
112 this.showSpinner = true;
114 console.log("Move Upward" + this.formFieldsListObj[n]["id"]);
115 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
116 .subscribe((responseGetFormFieldn) => {
117 this.postMoveUpwrdObj = responseGetFormFieldn;
119 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n-1]["id"])
120 .subscribe((responseGetFormFieldnmin1) => {
121 this.postDownwardObj = responseGetFormFieldnmin1;
123 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
124 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
126 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
127 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
129 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
130 .subscribe((responsePostn) => {
131 if(responsePostn["message"])
133 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
134 .subscribe((responsePostnmin1) => {
135 if(responsePostnmin1["message"])
138 this.formFieldsListObj = [];
139 this._formFieldsService.getListOfFormFields()
140 .subscribe((finalListResponse) => {
141 for(let k=0; k<finalListResponse.length; k++)
143 // this.formFieldsListObj.push(finalListResponse[k]);
144 for(let m=0; m<finalListResponse.length; m++)
146 if(finalListResponse[m]["orderSeq"] == k+1)
148 this.formFieldsListObj.push(finalListResponse[m]);
152 this.showSpinner = false;
167 moveDownward( n : number)
169 this.showSpinner = true;
171 console.log("Move Upward" + this.formFieldsListObj[n]["id"]);
172 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
173 .subscribe((responseGetFormFieldn) => {
174 this.postMoveUpwrdObj = responseGetFormFieldn;
176 this._formFieldsService.getFormFieldData(this.formFieldsListObj[n+1]["id"])
177 .subscribe((responseGetFormFieldnmin1) => {
178 this.postDownwardObj = responseGetFormFieldnmin1;
180 this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
181 this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
183 this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
184 this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
186 this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
187 .subscribe((responsePostn) => {
188 if(responsePostn["message"])
190 this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
191 .subscribe((responsePostnmin1) => {
192 if(responsePostnmin1["message"])
195 this.formFieldsListObj = [];
196 this._formFieldsService.getListOfFormFields()
197 .subscribe((finalListResponse) => {
198 for(let k=0; k<finalListResponse.length; k++)
200 // this.formFieldsListObj.push(finalListResponse[k]);
201 for(let m=0; m<finalListResponse.length; m++)
203 if(finalListResponse[m]["orderSeq"] == k+1)
205 this.formFieldsListObj.push(finalListResponse[m]);
209 this.showSpinner = false;
223 if(this.sqlAsDefaultValue)
225 this.showDefaultSQLOption = true;
229 this.showDefaultSQLOption = false;
234 setDisplayMode(displayMode : string)
236 console.log(displayMode);
241 this._formFieldsService.getFormFieldData(id)
242 .subscribe((responseFormFieldData) => {
243 console.log(responseFormFieldData);
244 this.validationType = responseFormFieldData["validationType"];
246 if(responseFormFieldData["visible"] === true)
248 this.visible = "YES";
255 this.orderSeq = responseFormFieldData["orderSeq"];
256 this.message = responseFormFieldData["message"];
257 this.groupFormField = responseFormFieldData["groupFormField"];
258 this.fieldType = responseFormFieldData["fieldType"];
259 this.fieldSQL = responseFormFieldData["fieldSQL"];
260 this.fieldName = responseFormFieldData["fieldName"];
261 this.fieldId = responseFormFieldData["fieldId"];
262 this.fieldDefaultSQL = responseFormFieldData["fieldDefaultSQL"];
263 this.errorStackTrace = responseFormFieldData["errorStackTrace"];
264 this.errorMessage = responseFormFieldData["errorMessage"];
266 if(this.fieldDefaultSQL !== null)
268 this.defaultValue = true;
272 this.defaultValue = false;
275 if(responseFormFieldData["predefinedValueList"] == null)
277 this.predefinedValueList = [];
281 this.predefinedValueList = responseFormFieldData["predefinedValueList"];
284 this.showDialog = true;
285 this.closable = true;
293 this.showDialog = true;
294 this.closable = true;
295 this.validationType = "";
296 this.visible = "YES";
298 this.groupFormField = false;
303 this.fieldDefaultSQL = "";
304 this.errorStackTrace = "";
305 this.errorMessage = "";
306 this.defaultValue = false;
307 this.predefinedValueList = [];
309 this.showDialog = true;
310 this.closable = true;
317 this.showDialog = !this.showDialog;
318 this.closable = false;
324 this.showDialog1 = !this.showDialog1;
325 this.showVerifySpinner = false;
328 addToList( attrib : string)
330 // console.log(attrib);
331 this.predefinedValueList.push(
339 deleteFromList(attrib : string)
342 for(let k=0; k<this.predefinedValueList.length; k++)
344 if(this.predefinedValueList[k]["id"] == attrib)
346 // console.log(attrib);
347 this.predefinedValueList.splice(k, 1);
355 this.showSpinner = true;
356 this.showDialog = false;
357 this.finalPOSTObj["validationType"] = this.validationType;
359 if(this.visible == "YES")
361 this.finalPOSTObj["visible"] = true;
365 this.finalPOSTObj["visible"] = false;
368 this.finalPOSTObj["orderSeq"] = this.orderSeq;
369 this.finalPOSTObj["message"] = this.message;
370 this.finalPOSTObj["groupFormField"] = this.groupFormField;
371 this.finalPOSTObj["fieldType"] = this.fieldType;
372 this.finalPOSTObj["fieldSQL"] = this.fieldSQL;
373 this.finalPOSTObj["fieldName"] = this.fieldName;
374 this.finalPOSTObj["fieldId"] = this.fieldId;
376 this.finalPOSTObj["errorStackTrace"] = this.errorStackTrace;
377 this.finalPOSTObj["errorMessage"] = this.errorMessage;
378 this.finalPOSTObj["defaultValue"] = this.defaultValue;
380 if( this.defaultValue === false)
382 this.finalPOSTObj["fieldDefaultSQL"] = null;
386 this.finalPOSTObj["fieldDefaultSQL"] = this.fieldDefaultSQL;
389 this.finalPOSTObj["predefinedValueList"] = this.predefinedValueList;
391 console.log(this.finalPOSTObj);
393 if(this.mode == "Edit")
395 this._formFieldsService.postFormFieldData(this.finalPOSTObj, this.reportId1)
396 .subscribe((responsePost) => {
397 if(responsePost["message"])
399 this._formFieldsService.getListOfFormFields()
400 .subscribe((responseFormFields) => {
401 this.formFieldsListObj = [];
403 while(responseFormFields[m])
405 this.formFieldsListObj.push(responseFormFields[m]);
410 this.showSpinner = false;
419 this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1)
420 .subscribe((responsePost) => {
421 if(responsePost["message"])
423 this._formFieldsService.getListOfFormFields()
424 .subscribe((responseFormFields) => {
425 this.formFieldsListObj = [];
427 while(responseFormFields[m])
429 this.formFieldsListObj.push(responseFormFields[m]);
433 this.showSpinner = false;
443 this.showSpinner = true;
444 this._formFieldsService.deleteFormField(id)
445 .subscribe((responseDeleted) => {
446 if(responseDeleted["message"] == "Formfield Deleted")
448 this._formFieldsService.getListOfFormFields()
449 .subscribe((responseFormFields) => {
450 this.formFieldsListObj = [];
452 while(responseFormFields[m])
454 this.formFieldsListObj.push(responseFormFields[m]);
458 this.showSpinner = false;
465 verify( SQLType : string)
467 this.showVerifySpinner = true;
468 this.showDialog1 = true;
469 if(SQLType == "Default")
472 query : this.fieldDefaultSQL
474 this._formFieldsService.verifySQL(this.queryObj)
475 .subscribe((responseDefaultSQL) => {
476 console.log(responseDefaultSQL);
477 this.validateResponseString = responseDefaultSQL["data"]["elements"];
478 this.showVerifySpinner = false;
484 query : this.fieldSQL
486 this._formFieldsService.verifySQL(this.queryObj)
487 .subscribe((responseSQL) => {
488 console.log(responseSQL);
489 this.validateResponseString = responseSQL["data"]["elements"];
490 this.showVerifySpinner = false;