1e1cecdb1516a412359348f6a06d2de3e5523727
[portal/sdk.git] /
1 import { Component, OnInit, Input } from '@angular/core';
2 import { FormFieldsService } from './form-fields.service';
3
4 @Component({
5   selector: 'app-form-fields',
6   templateUrl: './form-fields.component.html',
7   styleUrls: ['./form-fields.component.css']
8 })
9 export class FormFieldsComponent implements OnInit {
10
11   @Input("reportId") reportId1 : string;
12
13   formFieldsListObj : any[];
14   postMoveUpwrdObj : {};
15   postDownwardObj : {};
16   orderSeqOfDown : number;
17   orderSeqOfUp : number;
18   showDialog : boolean;
19   closable : boolean;
20   sqlAsDefaultValue : Boolean;
21   showDefaultSQLOption : boolean;
22   verifyFieldValueAs : number;
23   predefinedValueList : any[];
24   predefinedValue : string;
25   tabId : string;
26   tabName : string;
27   validationType : string;
28   visible : string;
29   orderSeq : number;
30   message : any;
31   groupFormField : boolean;
32   fieldType : string;
33   fieldSQL : string;
34   fieldName : string;
35   fieldId : string;
36   fieldDefaultSQL : string;
37   errorStackTrace : any;
38   errorMessage : any;
39   defaultValue : boolean;
40   finalPOSTObj : any;
41   mode : string;
42   showSpinner : boolean;
43   showDialog1 : boolean;
44   queryObj : {};
45   validateResponseString : string;
46   showVerifySpinner : boolean;
47
48
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;
55     this.closable = true;
56     this.predefinedValueList = new Array();
57     this.finalPOSTObj = new Object();
58     this.showSpinner = false;
59     this.showDialog1 = false;
60     this.queryObj = {};
61     this.showVerifySpinner = false;
62   }
63
64   ngOnInit() {
65
66     this._formFieldsService.getListOfFormFields()
67     .subscribe((responseFormFields) => {
68
69       for(let k=0; k<responseFormFields.length; k++)
70       {
71         // this.formFieldsListObj.push(responseFormFields[k]);
72                             for(let m=0; m<responseFormFields.length; m++)
73                             {
74                             if(responseFormFields[m]["orderSeq"] == k+1)
75                             {
76                                 this.formFieldsListObj.push(responseFormFields[m]);
77                             } 
78                           }
79       }
80       console.log(this.formFieldsListObj);
81     });
82   }
83   
84
85   isLast( n : number)
86   {
87     if(n == this.formFieldsListObj.length-1)
88     {
89       return true;
90     }
91     else
92     {
93       return false;
94     }
95   }
96
97   isFirst( n : number)
98   {
99     if(n == 0)
100     {
101       return true;
102     }
103     else
104     {
105       return false;
106     }
107   }
108
109
110   moveUpward( n : number)
111   {
112     this.showSpinner = true;
113     
114     console.log("Move Upward" + this.formFieldsListObj[n]["id"]);
115     this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
116     .subscribe((responseGetFormFieldn) => {
117         this.postMoveUpwrdObj = responseGetFormFieldn;
118
119               this._formFieldsService.getFormFieldData(this.formFieldsListObj[n-1]["id"])
120               .subscribe((responseGetFormFieldnmin1) => {
121                   this.postDownwardObj = responseGetFormFieldnmin1;
122
123                   this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
124                   this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
125             
126                   this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
127                   this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
128                   
129                   this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
130                   .subscribe((responsePostn) => {
131                     if(responsePostn["message"])
132                     {
133                       this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
134                       .subscribe((responsePostnmin1) => {
135                       if(responsePostnmin1["message"])
136                       {
137                         
138                       this.formFieldsListObj = [];
139                       this._formFieldsService.getListOfFormFields()
140                       .subscribe((finalListResponse) => {
141                         for(let k=0; k<finalListResponse.length; k++)
142                         {
143                         //  this.formFieldsListObj.push(finalListResponse[k]);
144                             for(let m=0; m<finalListResponse.length; m++)
145                             {
146                             if(finalListResponse[m]["orderSeq"] == k+1)
147                             {
148                                 this.formFieldsListObj.push(finalListResponse[m]);
149                             } 
150                           }
151                           }
152                           this.showSpinner = false;
153                       });
154                       }
155                     });
156                     }
157                     });
158
159               });
160             });
161
162  
163      
164
165   }
166
167   moveDownward( n : number)
168   {
169     this.showSpinner = true;
170     
171     console.log("Move Upward" + this.formFieldsListObj[n]["id"]);
172     this._formFieldsService.getFormFieldData(this.formFieldsListObj[n]["id"])
173     .subscribe((responseGetFormFieldn) => {
174         this.postMoveUpwrdObj = responseGetFormFieldn;
175
176               this._formFieldsService.getFormFieldData(this.formFieldsListObj[n+1]["id"])
177               .subscribe((responseGetFormFieldnmin1) => {
178                   this.postDownwardObj = responseGetFormFieldnmin1;
179
180                   this.orderSeqOfDown = this.postMoveUpwrdObj["orderSeq"];
181                   this.orderSeqOfUp = this.postDownwardObj["orderSeq"];
182             
183                   this.postMoveUpwrdObj["orderSeq"] = this.orderSeqOfUp;
184                   this.postDownwardObj["orderSeq"] = this.orderSeqOfDown;
185                   
186                   this._formFieldsService.postFormFieldData(this.postDownwardObj, this.reportId1)
187                   .subscribe((responsePostn) => {
188                     if(responsePostn["message"])
189                     {
190                       this._formFieldsService.postFormFieldData(this.postMoveUpwrdObj, this.reportId1)
191                       .subscribe((responsePostnmin1) => {
192                       if(responsePostnmin1["message"])
193                       {
194                         
195                       this.formFieldsListObj = [];
196                       this._formFieldsService.getListOfFormFields()
197                       .subscribe((finalListResponse) => {
198                         for(let k=0; k<finalListResponse.length; k++)
199                         {
200                         //  this.formFieldsListObj.push(finalListResponse[k]);
201                             for(let m=0; m<finalListResponse.length; m++)
202                             {
203                             if(finalListResponse[m]["orderSeq"] == k+1)
204                             {
205                                 this.formFieldsListObj.push(finalListResponse[m]);
206                             } 
207                           }
208                           }
209                           this.showSpinner = false;
210                       });
211                       }
212                     });
213                     }
214                     });
215
216               });
217             });
218
219   }
220
221   ngDoCheck()
222   {
223     if(this.sqlAsDefaultValue)
224     {
225       this.showDefaultSQLOption = true;
226     }
227     else
228     {
229       this.showDefaultSQLOption = false;
230     }
231     
232   }
233
234   setDisplayMode(displayMode : string)
235   {
236     console.log(displayMode);
237   }
238
239   edit(id : string)
240   {
241       this._formFieldsService.getFormFieldData(id)
242     .subscribe((responseFormFieldData) => {
243       console.log(responseFormFieldData);
244       this.validationType = responseFormFieldData["validationType"];
245
246       if(responseFormFieldData["visible"] === true)
247       {
248         this.visible = "YES";
249       }
250       else
251       {
252         this.visible = "NO";
253       }
254
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"];
265
266       if(this.fieldDefaultSQL !== null)
267       {
268         this.defaultValue = true;
269       }
270       else
271       {
272         this.defaultValue = false;
273       }
274
275       if(responseFormFieldData["predefinedValueList"] == null)
276       {
277         this.predefinedValueList = [];
278       }
279       else
280       {
281         this.predefinedValueList = responseFormFieldData["predefinedValueList"];
282       }
283
284       this.showDialog = true;
285       this.closable = true;
286       this.mode = "Edit";
287     });
288   
289   }
290
291   add()
292   {
293     this.showDialog = true;
294     this.closable = true;
295     this.validationType = "";
296     this.visible = "YES";
297       this.message = "";
298       this.groupFormField = false;
299       this.fieldType = "";
300       this.fieldSQL = "";
301       this.fieldName = "";
302       this.fieldId = "";
303       this.fieldDefaultSQL = "";
304       this.errorStackTrace = "";
305       this.errorMessage = "";
306       this.defaultValue = false;
307       this.predefinedValueList = [];
308
309       this.showDialog = true;
310       this.closable = true;
311
312       this.mode = "Add";
313       
314   }
315
316   close() {
317     this.showDialog = !this.showDialog;
318     this.closable = false;
319
320   }
321
322   closeValidateModal()
323   {
324     this.showDialog1 = !this.showDialog1;
325     this.showVerifySpinner = false;
326   }
327
328   addToList( attrib : string)
329   {
330     // console.log(attrib);
331     this.predefinedValueList.push(
332       {
333         "id" : attrib, 
334         "name" : attrib,
335         "selected" : false
336       });
337   }
338
339   deleteFromList(attrib : string)
340   {
341     
342     for(let k=0; k<this.predefinedValueList.length; k++)
343     {
344       if(this.predefinedValueList[k]["id"] == attrib)
345       {
346         // console.log(attrib);
347         this.predefinedValueList.splice(k, 1);
348       }
349     }
350   }
351
352
353   save()
354   {
355     this.showSpinner = true;
356     this.showDialog = false;
357       this.finalPOSTObj["validationType"] = this.validationType;
358
359       if(this.visible == "YES")
360       {
361         this.finalPOSTObj["visible"] = true;
362       }
363       else
364       {
365         this.finalPOSTObj["visible"] = false;
366       }
367
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;
375       
376       this.finalPOSTObj["errorStackTrace"] = this.errorStackTrace;
377       this.finalPOSTObj["errorMessage"] = this.errorMessage;
378       this.finalPOSTObj["defaultValue"] = this.defaultValue;
379
380       if( this.defaultValue === false)
381       {
382         this.finalPOSTObj["fieldDefaultSQL"] = null;
383       }
384       else
385       {
386         this.finalPOSTObj["fieldDefaultSQL"] = this.fieldDefaultSQL;
387       }
388
389       this.finalPOSTObj["predefinedValueList"] = this.predefinedValueList;
390
391       console.log(this.finalPOSTObj);
392
393       if(this.mode == "Edit")
394       {
395       this._formFieldsService.postFormFieldData(this.finalPOSTObj, this.reportId1)
396       .subscribe((responsePost) => {
397         if(responsePost["message"])
398         {
399           this._formFieldsService.getListOfFormFields()
400           .subscribe((responseFormFields) => {
401             this.formFieldsListObj = [];
402             let m=0;
403             while(responseFormFields[m])
404             {
405               this.formFieldsListObj.push(responseFormFields[m]);
406               m++;
407             }
408
409            
410           this.showSpinner = false;
411           
412           });
413           
414         }
415       });
416     }
417     else
418     {
419       this._formFieldsService.addFormFieldData(this.finalPOSTObj, this.reportId1)
420       .subscribe((responsePost) => {
421         if(responsePost["message"])
422         {
423           this._formFieldsService.getListOfFormFields()
424           .subscribe((responseFormFields) => {
425             this.formFieldsListObj = [];
426             let m=0;
427             while(responseFormFields[m])
428             {
429               this.formFieldsListObj.push(responseFormFields[m]);
430               m++;
431             }
432
433           this.showSpinner = false;
434           
435           });
436         }
437       });
438     }
439   }
440
441   delete( id : string)
442   {
443     this.showSpinner = true;
444     this._formFieldsService.deleteFormField(id)
445     .subscribe((responseDeleted) => {
446         if(responseDeleted["message"] == "Formfield  Deleted")
447         {
448           this._formFieldsService.getListOfFormFields()
449           .subscribe((responseFormFields) => {
450             this.formFieldsListObj = [];
451             let m=0;
452             while(responseFormFields[m])
453             {
454               this.formFieldsListObj.push(responseFormFields[m]);
455               m++;
456             }
457
458             this.showSpinner = false;
459             
460           });
461         }
462     })
463   }
464
465   verify( SQLType : string)
466   {
467     this.showVerifySpinner = true;
468     this.showDialog1 = true;
469     if(SQLType == "Default")
470     {
471       this.queryObj = {
472         query : this.fieldDefaultSQL
473       };
474       this._formFieldsService.verifySQL(this.queryObj)
475       .subscribe((responseDefaultSQL) => {
476         console.log(responseDefaultSQL);
477         this.validateResponseString = responseDefaultSQL["data"]["elements"];
478         this.showVerifySpinner = false;
479       });
480     }
481     else
482     {
483       this.queryObj = {
484         query : this.fieldSQL
485       };
486       this._formFieldsService.verifySQL(this.queryObj)
487       .subscribe((responseSQL) => {
488         console.log(responseSQL);
489         this.validateResponseString = responseSQL["data"]["elements"];
490         this.showVerifySpinner = false;
491       });
492     }
493     
494   }
495
496 }