1 import {Component, OnInit, Input, Output, EventEmitter, OnDestroy} 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, Router} 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 import {isInteger, toInteger} from '@ng-bootstrap/ng-bootstrap/util/util';
12 selector: 'app-definition',
13 templateUrl: './definition.component.html',
14 styleUrls: ['./definition.component.css'],
17 export class DefinitionComponent implements OnInit, OnDestroy {
19 @Input() closable = true;
20 @Input('reportId') reportId1: string;
21 @Input('reportMode') reportMode: string;
22 @Output() outputReportType = new EventEmitter<any>();
28 reportDescription: string;
32 reportDefinition: string;
34 hideFormFields: boolean;
39 heightContainer: number;
40 widthContainer: number;
41 allowScheduler: boolean;
42 sizedByContent: boolean;
43 hideFormFields1: boolean;
45 hideReportData: boolean;
48 disableColumnSort: boolean;
49 runTimeFormNum: number;
51 reportSubTitle: string;
65 definitionPostResponse1: any;
66 definitionPostResponse: any;
71 dashboardLayoutHTML: any;
72 pilotModalComponent: DefinitionSaveDialogComponent;
73 IncomingReportId: number;
74 displayOptionsArr: {}[] = [];
76 constructor(private _http: HttpClient, private _route: ActivatedRoute, private _definitionService: DefinitionService, private _router: Router) {
77 this.showSpinner = true;
78 this.IncomingReportId = -1;
79 this.dashboardObj = [];
80 this.dashboardLayoutHTML = '';
81 this.displayOptionsArr = [];
85 if (this.reportMode == 'Copy') {
91 sessionStorage.clear();
92 const myItem = localStorage.getItem('id');
94 localStorage.setItem('id', myItem);
96 this.showDialog = false;
97 this.showSpinner = true;
98 this._route.params.subscribe(params => {
99 if (params['reportId'] !== undefined) {
100 this.IncomingReportId = params['reportId'];
101 this.reportId1 = params['reportId'];
104 if (this.IncomingReportId == -1 && this.reportMode == 'Create') {
105 this._definitionService.getDefinitionPageDetails(this.IncomingReportId, this.reportMode)
106 .subscribe((response) => {
107 this.finalGetObj = response;
108 this.reportId = response['reportId'];
109 this.reportName = response['reportName'];
110 this.reportDescription = response['reportDescr'];
111 this.reportType = response['reportType'];
112 this.dataSrc = response['dbInfo'];
113 this.helpText = response['formHelpText'];
114 this.reportDefinition = response['repDefType'];
115 this.pageSize = response['pageSize'];
116 this.hideFormFields1 = response['hideFormFieldsAfterRun'];
117 this.maxRows = response['maxRowsInExcelCSVDownload'];
118 this.colsFrozen = response['frozenColumns'];
119 this.gridAlign = response['dataGridAlign'];
120 this.emptyMessage = response['emptyMessage'];
121 if (response['dashboardLayoutJSON']) {
122 this.dashboardObj = JSON.parse(response['dashboardLayoutJSON']);
123 this.dashboardLayoutHTML = response['dashboardLayoutHTML'];
125 if (response['displayArea']) {
126 for (let i = 0; i < response["displayArea"].length; i++) {
127 if (response['displayArea'][i]['selected'] === true) {
128 this.displayArea = response['displayArea'][i]['name'];
132 this.heightContainer = response['dataContainerHeight'];
133 this.widthContainer = response['dataContainerWidth'];
134 this.allowScheduler = (response['allowScheduler'] == 'Y' ? true : false);
135 this.sizedByContent = (response['sizedByContent'] == 'Y' ? true : false);
136 this.displayOptionsArr = response['displayOptions'];
137 if (this.displayOptionsArr !== null) {
138 if (this.displayOptionsArr.length > 0) {
139 for (let cont of this.displayOptionsArr) {
140 if (cont['name'] == 'HideFormFields') {
141 this.hideFormFields = cont['selected'];
143 if (cont['name'] == 'HideChart') {
144 this.hideChart = cont['selected'];
146 if (cont['name'] == 'HideReportData') {
147 this.hideReportData = cont['selected'];
149 if (cont['name'] == 'HideExcel') {
150 this.hideExcel = cont['selected'];
152 if (cont['name'] == 'HidePdf') {
153 this.hidePDF = cont['selected'];
158 this.disableColumnSort = response['runtimeColSortDisabled'];
159 this.runTimeFormNum = response['numFormCols'];
160 this.reportTitle = response['reportTitle'];
161 this.reportSubTitle = response['reportSubTitle'];
162 this.oneTime = (response['oneTimeRec'] == 'Y' ? true : false);
163 this.hourly = (response['hourlyRec'] == 'Y' ? true : false);
164 this.daily = (response['dailyRec'] == 'Y' ? true : false);
165 this.MonFri = (response['dailyMFRec'] == 'Y' ? true : false);
166 this.Weekly = (response['weeklyRec'] == 'Y' ? true : false);
167 this.Monthly = (response['monthlyRec'] == 'Y' ? true : false);
168 this.showSpinner = false;
171 if ((this.IncomingReportId !== -1 && this.reportMode == 'Edit')) {
172 this._definitionService.getDefinitionPageDetails(this.IncomingReportId, this.reportMode)
173 .subscribe((response) => {
174 this.finalGetObj = response;
175 this.reportId = response['reportId'];
176 this.reportName = response['reportName'];
177 this.reportDescription = response['reportDescr'];
178 this.reportType = response['reportType'];
179 if (this.reportMode == 'Copy') {
180 this.finalPostObj['reportId'] = -1;
181 this.IncomingReportId = -1;
184 if (this.reportType === 'Linear') {
185 this.dataSrc = response['dbInfo'];
186 this.helpText = response['formHelpText'];
187 this.reportDefinition = response['repDefType'];
188 this.pageSize = response['pageSize'];
189 this.hideFormFields1 = response['hideFormFieldsAfterRun'];
190 this.maxRows = response['maxRowsInExcelCSVDownload'];
191 this.colsFrozen = response['frozenColumns'];
192 this.gridAlign = response['dataGridAlign'];
193 this.emptyMessage = response['emptyMessage'];
194 if (response['displayArea']) {
195 for (let i = 0; i < response["displayArea"].length; i++) {
196 if (response['displayArea'][i]['selected'] === true) {
197 this.displayArea = response['displayArea'][i]['name'];
201 this.heightContainer = response['dataContainerHeight'];
202 this.widthContainer = response['dataContainerWidth'];
203 this.allowScheduler = (response['allowScheduler'] == 'Y' ? true : false);
204 this.sizedByContent = (response['sizedByContent'] == 'Y' ? true : false);
205 this.displayOptionsArr = response['displayOptions'];
206 for (let cont of this.displayOptionsArr) {
207 if (cont['name'] == 'HideFormFields') {
208 this.hideFormFields = cont['selected'];
210 if (cont['name'] == 'HideChart') {
211 this.hideChart = cont['selected'];
213 if (cont['name'] == 'HideReportData') {
214 this.hideReportData = cont['selected'];
216 if (cont['name'] == 'HideExcel') {
217 this.hideExcel = cont['selected'];
219 if (cont['name'] == 'HidePdf') {
220 this.hidePDF = cont['selected'];
223 this.disableColumnSort = response['runtimeColSortDisabled'];
224 this.runTimeFormNum = response['numFormCols'];
226 this.reportTitle = response['reportTitle'];
227 this.reportSubTitle = response['reportSubTitle'];
228 this.oneTime = (response['oneTimeRec'] == 'Y' ? true : false);
229 this.hourly = (response['hourlyRec'] == 'Y' ? true : false);
230 this.daily = (response['dailyRec'] == 'Y' ? true : false);
231 this.MonFri = (response['dailyMFRec'] == 'Y' ? true : false);
232 this.Weekly = (response['weeklyRec'] == 'Y' ? true : false);
233 this.Monthly = (response['monthlyRec'] == 'Y' ? true : false);
235 if (response['dashboardLayoutJSON']) {
236 this.dashboardObj = JSON.parse(response['dashboardLayoutJSON']);
238 if (response['dashboardLayoutHTML']) {
239 this.dashboardLayoutHTML = response['dashboardLayoutHTML'];
242 this.showSpinner = false;
245 if (this.reportMode == 'Copy') {
246 this._definitionService.copyReportById(this.IncomingReportId)
247 .subscribe((response) => {
248 this._definitionService.getDefinitionPageDetails(this.IncomingReportId, this.reportMode)
249 .subscribe((response) => {
250 this.finalGetObj = response;
252 this.reportName = response['reportName'];
253 this.reportDescription = response['reportDescr'];
254 this.reportType = response['reportType'];
255 if (this.reportType === 'Linear') {
256 this.dataSrc = response['dbInfo'];
257 this.helpText = response['formHelpText'];
258 this.reportDefinition = response['repDefType'];
259 this.pageSize = response['pageSize'];
260 this.hideFormFields1 = response['hideFormFieldsAfterRun'];
261 this.maxRows = response['maxRowsInExcelCSVDownload'];
262 this.colsFrozen = response['frozenColumns'];
263 this.gridAlign = response['dataGridAlign'];
264 this.emptyMessage = response['emptyMessage'];
265 if (response['displayArea']) {
266 for (let i = 0; i < response["displayArea"].length; i++) {
267 if (response['displayArea'][i]['selected'] === true) {
268 this.displayArea = response['displayArea'][i]['name'];
272 this.heightContainer = response['dataContainerHeight'];
273 this.widthContainer = response['dataContainerWidth'];
274 this.allowScheduler = (response['allowScheduler'] == 'Y' ? true : false);
275 this.sizedByContent = (response['sizedByContent'] == 'Y' ? true : false);
276 this.displayOptionsArr = response['displayOptions'];
277 for (let cont of this.displayOptionsArr) {
278 if (cont['name'] == 'HideFormFields') {
279 this.hideFormFields = cont['selected'];
281 if (cont['name'] == 'HideChart') {
282 this.hideChart = cont['selected'];
284 if (cont['name'] == 'HideReportData') {
285 this.hideReportData = cont['selected'];
287 if (cont['name'] == 'HideExcel') {
288 this.hideExcel = cont['selected'];
290 if (cont['name'] == 'HidePdf') {
291 this.hidePDF = cont['selected'];
294 this.disableColumnSort = response['runtimeColSortDisabled'];
295 this.runTimeFormNum = response['numFormCols'];
297 this.reportTitle = response['reportTitle'];
298 this.reportSubTitle = response['reportSubTitle'];
299 this.oneTime = (response['oneTimeRec'] == 'Y' ? true : false);
300 this.hourly = (response['hourlyRec'] == 'Y' ? true : false);
301 this.daily = (response['dailyRec'] == 'Y' ? true : false);
302 this.MonFri = (response['dailyMFRec'] == 'Y' ? true : false);
303 this.Weekly = (response['weeklyRec'] == 'Y' ? true : false);
304 this.Monthly = (response['monthlyRec'] == 'Y' ? true : false);
306 if (response['dashboardLayoutJSON']) {
307 this.dashboardObj = JSON.parse(response['dashboardLayoutJSON']);
309 if (response['dashboardLayoutHTML']) {
310 this.dashboardLayoutHTML = response['dashboardLayoutHTML'];
313 this.showSpinner = false;
315 this.showSpinner = false;
321 saveDefinitionInfo() {
322 if ((this.IncomingReportId == -1 && this.reportMode == 'Create')) {
323 this.finalPostObj['tabName'] = 'Definition';
324 this.finalPostObj['tabId'] = 'Def';
325 this.finalPostObj['reportId'] = this.reportId;
326 this.finalPostObj['reportName'] = this.reportName;
327 this.finalPostObj['reportDescr'] = this.reportDescription;
328 this.finalPostObj['reportType'] = this.reportType;
329 this.finalPostObj['reportTypeList'] = null;
330 this.finalPostObj['dbInfo'] = this.dataSrc;
331 this.finalPostObj['formHelpText'] = this.helpText;
332 this.finalPostObj['pageSize'] = this.pageSize;
333 this.finalPostObj['dbInfoList'] = [
340 this.finalPostObj['displayArea'] = [
344 'selected': (this.displayArea == 'HOME' ? true : false)
349 'selected': (this.displayArea == 'CUSTOMER' ? true : false)
354 'selected': (this.displayArea == 'REPORTS' ? true : false)
357 this.finalPostObj['hideFormFieldsAfterRun'] = this.hideFormFields1;
358 this.finalPostObj['maxRowsInExcelCSVDownload'] = this.maxRows;
359 this.finalPostObj['frozenColumns'] = this.colsFrozen;
360 this.finalPostObj['dataGridAlign'] = this.gridAlign;
361 this.finalPostObj['emptyMessage'] = this.emptyMessage;
362 this.finalPostObj['dataContainerHeight'] = this.heightContainer;
363 this.finalPostObj['dataContainerWidth'] = this.widthContainer;
364 this.finalPostObj['displayOptions'] = [
366 'name': 'HideFormFields',
367 'selected': (this.hideFormFields == undefined ? false : this.hideFormFields)
371 'selected': (this.hideChart == undefined ? false : this.hideChart)
374 'name': 'HideReportData',
375 'selected': (this.hideReportData == undefined ? false : this.hideReportData)
379 'selected': (this.hideExcel == undefined ? false : this.hideExcel)
383 'selected': (this.hidePDF == undefined ? false : this.hidePDF)
386 this.finalPostObj['runtimeColSortDisabled'] = this.disableColumnSort;
387 this.finalPostObj['numFormCols'] = this.runTimeFormNum;
388 this.finalPostObj['reportTitle'] = this.reportTitle;
389 this.finalPostObj['reportSubTitle'] = this.reportSubTitle;
390 this.finalPostObj['oneTimeRec'] = this.oneTime;
391 this.finalPostObj['hourlyRec'] = this.hourly;
392 this.finalPostObj['dailyRec'] = this.daily;
393 this.finalPostObj['dailyMFRec'] = this.MonFri;
394 this.finalPostObj['weeklyRec'] = this.Weekly;
395 this.finalPostObj['monthlyRec'] = this.Monthly;
396 this.finalPostObj['allowScheduler'] = (this.allowScheduler == true ? 'Y' : 'N');
397 this.finalPostObj['sizedByContent'] = (this.sizedByContent == true ? 'Y' : 'N');
398 this.finalPostObj['repDefType'] = this.reportDefinition;
399 if (this.reportType === 'Dashboard') {
400 this.finalPostObj['dashboardLayoutJSON'] = JSON.stringify(this.dashboardObj);
401 this.finalPostObj['dashboardLayoutHTML'] = this.dashboardLayoutHTML;
403 this._http.post(environment.baseUrl + 'report/wizard/save_def_tab_data/Create', this.finalPostObj, {headers: new HttpHeaders({'Content-Type': 'application/json'})})
404 .subscribe((response) => {
405 if (response['message'] === 'Success Definition of given report is saved in session.') {
406 this.status = 'Success!';
407 this.message = 'Your change has been saved! Definition is updated.';
408 if (this.reportType == 'Dashboard') {
410 stackTrace = response['anyStacktrace'];
411 stackTrace = stackTrace.substring(0, stackTrace.indexOf('-'));
412 this.reportId = parseInt(stackTrace);
413 this._router.navigate(['v2/reports', 'Edit', this.reportId]);
415 this.showDialog = !this.showDialog;
416 this.closable = true;
418 this.status = 'Failure!';
419 this.message = 'Definition could not be updated.';
420 this.showDialog = !this.showDialog;
421 this.closable = true;
425 if ((this.IncomingReportId !== -1 && this.reportMode == 'Edit') || this.reportMode == 'Copy') {
426 this.finalPostObj['tabName'] = 'Definition';
427 this.finalPostObj['tabId'] = 'Def';
428 this.finalPostObj['reportId'] = this.reportId;
429 this.finalPostObj['reportName'] = this.reportName;
430 this.finalPostObj['reportDescr'] = this.reportDescription;
431 this.finalPostObj['reportType'] = this.reportType;
432 if (this.reportMode == 'Copy') {
433 this.finalPostObj['reportId'] = -1;
434 this.IncomingReportId = -1;
436 if (this.reportType === 'Dashboard') {
437 this.finalPostObj['dashboardLayoutJSON'] = JSON.stringify(this.dashboardObj);
438 this.finalPostObj['dashboardLayoutHTML'] = this.dashboardLayoutHTML;
440 this.finalPostObj['reportTypeList'] = null;
441 this.finalPostObj['dbInfo'] = this.dataSrc;
442 this.finalPostObj['formHelpText'] = this.helpText;
443 this.finalPostObj['pageSize'] = this.pageSize;
444 this.finalPostObj['dbInfoList'] = [
451 this.finalPostObj['displayArea'] = [
455 'selected': (this.displayArea == 'HOME' ? true : false)
460 'selected': (this.displayArea == 'CUSTOMER' ? true : false)
465 'selected': (this.displayArea == 'REPORTS' ? true : false)
468 this.finalPostObj['hideFormFieldsAfterRun'] = this.hideFormFields1;
469 this.finalPostObj['maxRowsInExcelCSVDownload'] = this.maxRows;
470 this.finalPostObj['frozenColumns'] = this.colsFrozen;
471 this.finalPostObj['dataGridAlign'] = this.gridAlign;
472 this.finalPostObj['emptyMessage'] = this.emptyMessage;
473 this.finalPostObj['dataContainerHeight'] = this.heightContainer;
474 this.finalPostObj['dataContainerWidth'] = this.widthContainer;
475 this.finalPostObj['displayOptions'] = [
477 'name': 'HideFormFields',
478 'selected': (this.hideFormFields == undefined ? false : this.hideFormFields)
482 'selected': (this.hideChart == undefined ? false : this.hideChart)
485 'name': 'HideReportData',
486 'selected': (this.hideReportData == undefined ? false : this.hideReportData)
490 'selected': (this.hideExcel == undefined ? false : this.hideExcel)
494 'selected': (this.hidePDF == undefined ? false : this.hidePDF)
497 this.finalPostObj['runtimeColSortDisabled'] = this.disableColumnSort;
498 this.finalPostObj['numFormCols'] = this.runTimeFormNum;
499 this.finalPostObj['reportTitle'] = this.reportTitle;
500 this.finalPostObj['reportSubTitle'] = this.reportSubTitle;
501 this.finalPostObj['oneTimeRec'] = this.oneTime;
502 this.finalPostObj['hourlyRec'] = this.hourly;
503 this.finalPostObj['dailyRec'] = this.daily;
504 this.finalPostObj['dailyMFRec'] = this.MonFri;
505 this.finalPostObj['weeklyRec'] = this.Weekly;
506 this.finalPostObj['monthlyRec'] = this.Monthly;
507 this.finalPostObj['allowScheduler'] = (this.allowScheduler == true ? 'Y' : 'N');
508 this.finalPostObj['sizedByContent'] = (this.sizedByContent == true ? 'Y' : 'N');
509 this.finalPostObj['repDefType'] = this.reportDefinition;
511 this._definitionService.portDefinitionPageDetails(this.IncomingReportId, this.finalPostObj)
512 .subscribe((response) => {
513 if (response['message'] === 'Success Definition of given report is saved in session.') {
514 this.status = 'Success!';
515 this.message = 'Your change has been saved! Definition is updated.';
516 if (this.reportMode == 'Copy') {
518 stackTrace = response['anyStacktrace'];
519 stackTrace = stackTrace.substring(0, stackTrace.indexOf('-'));
520 this.reportId = parseInt(stackTrace);
521 this._router.navigate(['v2/reports', 'Edit', this.reportId]);
523 this.showDialog = !this.showDialog;
524 this.closable = true;
525 if (this.reportType == 'Dashboard') {
529 this.status = 'Failure!';
530 this.message = 'Definition could not be updated.';
531 this.showDialog = !this.showDialog;
532 this.closable = true;
539 this.showDialog = !this.showDialog;
540 this.closable = false;
543 onTransferDashboardObj(transferredDashboardObj: any) {
544 this.dashboardObj = transferredDashboardObj;
549 this._definitionService.clearSession()
550 .subscribe((response) => {
551 console.log(response);
552 this._router.navigate(['v2/report-list']);
558 let outPutValues = [];
559 outPutValues['reportType'] = this.reportType;
560 this.outputReportType.emit(outPutValues);