58f3e45ca7bd8031a4181feffd7b228d498306ab
[portal/sdk.git] /
1 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2 import { HttpClient, HttpHeaders } from '@angular/common/http';
3 import {  NgbModal } from '@ng-bootstrap/ng-bootstrap';
4 import { DefinitionSaveDialogComponent } from './definition-save-dialog/definition-save-dialog.component';
5 import {ActivatedRoute} from "@angular/router";
6 import { environment } from '../../../../../../environments/environment';
7 import { DefinitionService } from './definition.service';
8 import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
9
10 @Component({
11   selector: 'app-definition',
12   templateUrl: './definition.component.html',
13   styleUrls: ['./definition.component.css'],
14   providers: [ NgbModal]
15 })
16 export class DefinitionComponent implements OnInit {
17
18  
19
20
21   showSpinner : boolean;
22   
23   @Input() closable = true;
24
25   @Input("reportId") reportId1 : string;
26   @Input ("reportMode") reportMode : string;
27
28   
29   finalPostObj = {};
30   finalGetObj = {};
31
32   isEdit : boolean;
33   reportId : number;
34   reportName : string;
35   reportDescription : string;
36   reportType : string;
37   dataSrc : string;
38   helpText : string;
39   reportDefinition : string;
40   pageSize : number;
41   hideFormFields : boolean;
42   maxRows : number;
43   colsFrozen : number;
44   gridAlign : string;
45   emptyMessage : string;
46   heightContainer : number;
47   widthContainer : number;
48   allowScheduler : boolean;
49   sizedByContent : boolean;
50   hideFormFields1 : boolean;
51   hideChart : boolean;
52   hideReportData : boolean;
53   hideExcel : boolean;
54   hidePDF : boolean;
55   disableColumnSort : boolean;
56   runTimeFormNum : number;
57   reportTitle : string;
58   reportSubTitle : string;
59   oneTime : boolean;
60   hourly : boolean;
61   daily : boolean;
62   MonFri : boolean;
63   Weekly : boolean;
64   Monthly : boolean;
65
66   oneTime1 : boolean;
67   hourly1 : boolean;
68   daily1 : boolean;
69   MonFri1 : boolean;
70   Weekly1 : boolean;
71   Monthly1 : boolean;
72
73   displayArea : string;
74   definitionPostResponse1 : any;
75
76   definitionPostResponse : any;
77
78   showDialog : boolean;
79   status : string;
80   message : string;
81   dashboardObj : any;
82   dashboardLayoutHTML : any;
83
84   pilotModalComponent : DefinitionSaveDialogComponent;
85
86   IncomingReportId : number;
87   displayOptionsArr : {}[] = [];
88
89   constructor(private _http : HttpClient, private _route : ActivatedRoute, private _definitionService : DefinitionService) { 
90     this.showSpinner = true;
91     this.IncomingReportId = -1;
92     this.dashboardObj = [];
93     this.dashboardLayoutHTML = "";
94   }
95
96
97   ngOnInit() {
98     this.isEdit = true;
99     this.showDialog = false;
100     this.showSpinner = true;
101     this._route.params.subscribe(params => {
102       
103       if(params["reportId"] !== undefined)
104       {
105       this.IncomingReportId = params["reportId"];
106       this.reportId1 = params["reportId"];
107       }
108     });
109     if(this.IncomingReportId == -1 && this.reportMode == "Create")
110     {
111       this._definitionService.getDefinitionPageDetails(this.IncomingReportId, this.reportMode)
112     .subscribe((response) => {
113       this.finalGetObj = response;
114
115       this.reportId = response["reportId"];
116       this.reportName = response["reportName"];
117       this.reportDescription = response["reportDescr"];
118       this.reportType = response["reportType"];
119       this.dataSrc = response["dbInfo"];
120       this.helpText = response["formHelpText"];
121       this.reportDefinition = response["repDefType"];
122       this.pageSize = response["pageSize"];
123       this.hideFormFields1 = response["hideFormFieldsAfterRun"];
124       this.maxRows = response["maxRowsInExcelCSVDownload"];
125       this.colsFrozen = response["frozenColumns"];
126       this.gridAlign = response["dataGridAlign"];
127       this.emptyMessage = response["emptyMessage"];
128
129       if(response["dashboardLayoutJSON"])
130       {
131         this.dashboardObj = JSON.parse(response["dashboardLayoutJSON"]);
132         this.dashboardLayoutHTML = response["dashboardLayoutHTML"];
133       }
134
135       if(response["displayArea"])
136       {
137       for(let i=0; i<response["displayArea"].length; i++)
138       {
139         if(response["displayArea"][i]["selected"] === true)
140         {
141           this.displayArea = response["displayArea"][i]["name"];
142         }
143       }
144       }
145
146       this.heightContainer = response["dataContainerHeight"];
147       this.widthContainer = response["dataContainerWidth"];
148       this.allowScheduler = (response["allowScheduler"] == "Y" ? true : false);
149       this.sizedByContent = (response["sizedByContent"] == "Y" ? true : false);
150
151       this.displayOptionsArr = response["displayOptions"];
152
153
154       for(let cont of this.displayOptionsArr)
155       {
156         if(cont["name"] == "HideFormFields")
157         {
158           this.hideFormFields = cont["selected"];
159         }
160         if(cont["name"] == "HideChart")
161         {
162           this.hideChart = cont["selected"];
163         }
164         if(cont["name"] == "HideReportData")
165         {
166           this.hideReportData = cont["selected"];
167         }
168         if(cont["name"] == "HideExcel")
169         {
170           this.hideExcel = cont["selected"];
171         }
172         if(cont["name"] == "HidePdf")
173         {
174           this.hidePDF = cont["selected"];
175         }
176       }
177
178       this.disableColumnSort = response["runtimeColSortDisabled"];
179       this.runTimeFormNum = response["numFormCols"];
180       this.reportTitle = response["reportTitle"];
181       this.reportSubTitle = response["reportSubTitle"];
182       this.oneTime = (response["oneTimeRec"] == "Y" ? true : false );
183       this.hourly = (response["hourlyRec"] == "Y" ? true : false );
184       this.daily = (response["dailyRec"] == "Y" ? true : false );
185       this.MonFri = (response["dailyMFRec"] == "Y" ? true : false );
186       this.Weekly = (response["weeklyRec"] == "Y" ? true : false );
187       this.Monthly = (response["monthlyRec"] == "Y" ? true : false );
188
189       this.showSpinner = false;
190
191     });
192     }
193
194     if(this.IncomingReportId !== -1 && this.reportMode == "Edit")
195     {
196       this._definitionService.getDefinitionPageDetails(this.IncomingReportId, this.reportMode)
197     .subscribe((response) => {
198       this.finalGetObj = response;
199
200       this.reportId = response["reportId"];
201       this.reportName = response["reportName"];
202       this.reportDescription = response["reportDescr"];
203       this.reportType = response["reportType"];
204
205       if(this.reportType === "Linear")
206       {
207       this.dataSrc = response["dbInfo"];
208       this.helpText = response["formHelpText"];
209       this.reportDefinition = response["repDefType"];
210       this.pageSize = response["pageSize"];
211       this.hideFormFields1 = response["hideFormFieldsAfterRun"];
212       this.maxRows = response["maxRowsInExcelCSVDownload"];
213       this.colsFrozen = response["frozenColumns"];
214       this.gridAlign = response["dataGridAlign"];
215       this.emptyMessage = response["emptyMessage"];
216
217       if(response["displayArea"])
218       {
219       for(let i=0; i<response["displayArea"].length; i++)
220       {
221         if(response["displayArea"][i]["selected"] === true)
222         {
223           this.displayArea = response["displayArea"][i]["name"];
224         }
225       }
226     }
227       
228       
229       
230       this.heightContainer = response["dataContainerHeight"];
231       this.widthContainer = response["dataContainerWidth"];
232       this.allowScheduler = (response["allowScheduler"] == "Y" ? true : false);
233       this.sizedByContent = (response["sizedByContent"] == "Y" ? true : false);
234
235       this.displayOptionsArr = response["displayOptions"];
236
237       for(let cont of this.displayOptionsArr)
238       {
239         if(cont["name"] == "HideFormFields")
240         {
241           this.hideFormFields = cont["selected"];
242         }
243         if(cont["name"] == "HideChart")
244         {
245           this.hideChart = cont["selected"];
246         }
247         if(cont["name"] == "HideReportData")
248         {
249           this.hideReportData = cont["selected"];
250         }
251         if(cont["name"] == "HideExcel")
252         {
253           this.hideExcel = cont["selected"];
254         }
255         if(cont["name"] == "HidePdf")
256         {
257           this.hidePDF = cont["selected"];
258         }
259       }
260
261       this.disableColumnSort = response["runtimeColSortDisabled"];
262       this.runTimeFormNum = response["numFormCols"];;
263       this.reportTitle = response["reportTitle"];
264       this.reportSubTitle = response["reportSubTitle"];
265       this.oneTime = (response["oneTimeRec"] == "Y" ? true : false );
266       this.hourly = (response["hourlyRec"] == "Y" ? true : false );
267       this.daily = (response["dailyRec"] == "Y" ? true : false );
268       this.MonFri = (response["dailyMFRec"] == "Y" ? true : false );
269       this.Weekly = (response["weeklyRec"] == "Y" ? true : false );
270       this.Monthly = (response["monthlyRec"] == "Y" ? true : false );
271   }
272   else
273   {
274     if(response["dashboardLayoutJSON"])
275       {
276         this.dashboardObj = JSON.parse(response["dashboardLayoutJSON"]);
277         
278       }
279
280       if(response["dashboardLayoutHTML"])
281       {
282         this.dashboardLayoutHTML = response["dashboardLayoutHTML"];
283
284       }
285
286   }
287
288       this.showSpinner = false;
289
290     });
291   }
292
293
294   }
295
296
297   saveDefinitionInfo(){
298
299     if(this.IncomingReportId == -1 && this.reportMode == "Create")
300     {
301       this.finalPostObj["tabName"] = "Definition";
302     this.finalPostObj["tabId"] = "Def";
303     this.finalPostObj["reportId"] = this.reportId;
304     this.finalPostObj["reportName"] = this.reportName;
305     this.finalPostObj["reportDescr"] = this.reportDescription;
306     this.finalPostObj["reportType"] = this.reportType;
307     this.finalPostObj["reportTypeList"] = null;
308     this.finalPostObj["dbInfo"] = this.dataSrc;
309     this.finalPostObj["formHelpText"] = this.helpText;
310     this.finalPostObj["pageSize"] = this.pageSize;
311
312     this.finalPostObj["dbInfoList"] = [
313       {
314       "id": "local",
315       "name": "local",
316       "selected": false
317       }
318       ];
319     this.finalPostObj["displayArea"] = [
320       {
321       "id": "HOME",
322       "name": "HOME",
323       "selected": (this.displayArea == "HOME" ? true : false)
324       },
325       {
326       "id": "CUSTOMER",
327       "name": "CUSTOMER",
328       "selected": (this.displayArea == "CUSTOMER" ? true : false)
329       },
330       {
331       "id": "REPORTS",
332       "name": "REPORTS",
333       "selected": (this.displayArea == "REPORTS" ? true : false)
334       }
335       ];
336     this.finalPostObj["hideFormFieldsAfterRun"] = this.hideFormFields1;
337     this.finalPostObj["maxRowsInExcelCSVDownload"] = this.maxRows;
338     this.finalPostObj["frozenColumns"] = this.colsFrozen;
339     this.finalPostObj["dataGridAlign"] = this.gridAlign;
340     this.finalPostObj["emptyMessage"] = this.emptyMessage;
341     this.finalPostObj["dataContainerHeight"] = this.heightContainer;
342     this.finalPostObj["dataContainerWidth"] = this.widthContainer;
343     this.finalPostObj["displayOptions"] = [
344       {
345       "name": "HideFormFields",
346       "selected": (this.hideFormFields == undefined ? false : this.hideFormFields )
347       },
348       {
349       "name": "HideChart",
350       "selected": (this.hideChart == undefined ? false : this.hideChart )
351       },
352       {
353       "name": "HideReportData",
354       "selected": (this.hideReportData == undefined ? false : this.hideReportData )
355       },
356       {
357       "name": "HideExcel",
358       "selected": (this.hideExcel == undefined ? false : this.hideExcel )
359       },
360       {
361       "name": "HidePdf",
362       "selected": (this.hidePDF == undefined ? false : this.hidePDF )
363       }
364       ];
365     this.finalPostObj["runtimeColSortDisabled"] = this.disableColumnSort;
366     this.finalPostObj["numFormCols"] = this.runTimeFormNum;
367     this.finalPostObj["reportTitle"] = this.reportTitle;
368     this.finalPostObj["reportSubTitle"] = this.reportSubTitle;
369     this.finalPostObj["oneTimeRec"] = this.oneTime;
370     this.finalPostObj["hourlyRec"] = this.hourly;    
371     this.finalPostObj["dailyRec"] = this.daily;
372     this.finalPostObj["dailyMFRec"] = this.MonFri;
373     this.finalPostObj["weeklyRec"] = this.Weekly;
374     this.finalPostObj["monthlyRec"] = this.Monthly;
375     this.finalPostObj["allowScheduler"] = (this.allowScheduler == true ? "Y" : "N" );
376     this.finalPostObj["sizedByContent"] = (this.sizedByContent == true ? "Y" : "N" );
377     this.finalPostObj["repDefType"] = this.reportDefinition;
378
379     this._http.post(environment.baseUrl + "report/wizard/save_def_tab_data/Create", this.finalPostObj, { headers: new HttpHeaders({'Content-Type': 'application/json'})})
380     .subscribe((response) => {
381     if(response["message"] === "Success Definition of given report is saved in session.")
382     {
383       this.status = "Success!";
384       this.message = "Your change has been saved! Definition is updated.";
385         this.showDialog = !this.showDialog;
386         this.closable = true; 
387     }
388     else
389     {
390       this.status = "Failure!";
391       this.message = "Definition could not be updated.";
392         this.showDialog = !this.showDialog;
393         this.closable = true;
394     } 
395     });
396
397     }
398     if(this.IncomingReportId !== -1 && this.reportMode == "Edit")
399     {
400       
401     this.finalPostObj["tabName"] = "Definition";
402     this.finalPostObj["tabId"] = "Def";
403     this.finalPostObj["reportId"] = this.reportId;
404     this.finalPostObj["reportName"] = this.reportName;
405     this.finalPostObj["reportDescr"] = this.reportDescription;
406     this.finalPostObj["reportType"] = this.reportType;
407
408     if(this.reportType === "Dashboard")
409     {
410       this.finalPostObj["dashboardLayoutJSON"] = JSON.stringify(this.dashboardObj);
411       this.finalPostObj["dashboardLayoutHTML"] = this.dashboardLayoutHTML;
412
413     }
414     else
415     {
416     
417     this.finalPostObj["reportTypeList"] = null;
418     this.finalPostObj["dbInfo"] = this.dataSrc;
419     this.finalPostObj["formHelpText"] = this.helpText;
420     this.finalPostObj["pageSize"] = this.pageSize;
421
422     this.finalPostObj["dbInfoList"] = [
423       {
424       "id": "local",
425       "name": "local",
426       "selected": false
427       }
428       ];
429     this.finalPostObj["displayArea"] = [
430       {
431       "id": "HOME",
432       "name": "HOME",
433       "selected": (this.displayArea == "HOME" ? true : false)
434       },
435       {
436       "id": "CUSTOMER",
437       "name": "CUSTOMER",
438       "selected": (this.displayArea == "CUSTOMER" ? true : false)
439       },
440       {
441       "id": "REPORTS",
442       "name": "REPORTS",
443       "selected": (this.displayArea == "REPORTS" ? true : false)
444       }
445       ];
446     this.finalPostObj["hideFormFieldsAfterRun"] = this.hideFormFields1;
447     this.finalPostObj["maxRowsInExcelCSVDownload"] = this.maxRows;
448     this.finalPostObj["frozenColumns"] = this.colsFrozen;
449     this.finalPostObj["dataGridAlign"] = this.gridAlign;
450     this.finalPostObj["emptyMessage"] = this.emptyMessage;
451     this.finalPostObj["dataContainerHeight"] = this.heightContainer;
452     this.finalPostObj["dataContainerWidth"] = this.widthContainer;
453     this.finalPostObj["displayOptions"] = [
454       {
455       "name": "HideFormFields",
456       "selected": (this.hideFormFields == undefined ? false : this.hideFormFields )
457       },
458       {
459       "name": "HideChart",
460       "selected": (this.hideChart == undefined ? false : this.hideChart )
461       },
462       {
463       "name": "HideReportData",
464       "selected": (this.hideReportData == undefined ? false : this.hideReportData )
465       },
466       {
467       "name": "HideExcel",
468       "selected": (this.hideExcel == undefined ? false : this.hideExcel )
469       },
470       {
471       "name": "HidePdf",
472       "selected": (this.hidePDF == undefined ? false : this.hidePDF )
473       }
474       ];
475     this.finalPostObj["runtimeColSortDisabled"] = this.disableColumnSort;
476     this.finalPostObj["numFormCols"] = this.runTimeFormNum;
477     this.finalPostObj["reportTitle"] = this.reportTitle;
478     this.finalPostObj["reportSubTitle"] = this.reportSubTitle;
479     this.finalPostObj["oneTimeRec"] = this.oneTime;
480     this.finalPostObj["hourlyRec"] = this.hourly;    
481     this.finalPostObj["dailyRec"] = this.daily;
482     this.finalPostObj["dailyMFRec"] = this.MonFri;
483     this.finalPostObj["weeklyRec"] = this.Weekly;
484     this.finalPostObj["monthlyRec"] = this.Monthly;
485     this.finalPostObj["allowScheduler"] = (this.allowScheduler == true ? "Y" : "N" );
486     this.finalPostObj["sizedByContent"] = (this.sizedByContent == true ? "Y" : "N" );
487     this.finalPostObj["repDefType"] = this.reportDefinition;
488     }
489
490
491     this._definitionService.portDefinitionPageDetails(this.IncomingReportId, this.finalPostObj)
492     .subscribe((response) => {
493
494     if(response["message"] === "Success Definition of given report is saved in session.")
495     {
496       this.status = "Success!";
497       this.message = "Your change has been saved! Definition is updated.";
498         this.showDialog = !this.showDialog;
499         this.closable = true; 
500     }
501     else
502     {
503       this.status = "Failure!";
504       this.message = "Definition could not be updated.";
505         this.showDialog = !this.showDialog;
506         this.closable = true;
507     } 
508     });
509
510     }
511
512   }
513
514   close() {
515     this.showDialog = !this.showDialog;
516     this.closable = false;
517   }
518
519   onTransferDashboardObj(transferredDashboardObj : any)
520   {
521     this.dashboardObj = transferredDashboardObj;
522
523   }
524
525
526
527
528 }