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('notes');
94 localStorage.setItem('notes', 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 if (undefined != this.reportTitle && this.reportTitle.length > 0) {
389 this.finalPostObj['reportTitle'] = this.reportTitle;
391 this.finalPostObj['reportTitle'] = this.reportName;
393 this.finalPostObj['reportSubTitle'] = this.reportSubTitle;
394 this.finalPostObj['oneTimeRec'] = this.oneTime;
395 this.finalPostObj['hourlyRec'] = this.hourly;
396 this.finalPostObj['dailyRec'] = this.daily;
397 this.finalPostObj['dailyMFRec'] = this.MonFri;
398 this.finalPostObj['weeklyRec'] = this.Weekly;
399 this.finalPostObj['monthlyRec'] = this.Monthly;
400 this.finalPostObj['allowScheduler'] = (this.allowScheduler == true ? 'Y' : 'N');
401 this.finalPostObj['sizedByContent'] = (this.sizedByContent == true ? 'Y' : 'N');
402 this.finalPostObj['repDefType'] = this.reportDefinition;
403 if (this.reportType === 'Dashboard') {
404 this.dashboardObj = this.dashboardObj.sort(function (a, b) {
405 if (a['x'] === b['x']) {
406 return a['y'] - b['y'];
408 return a['x'] - b['x'];
411 this.finalPostObj['dashboardLayoutJSON'] = JSON.stringify(this.dashboardObj);
412 this.finalPostObj['dashboardLayoutHTML'] = this.dashboardLayoutHTML;
414 this._http.post(environment.baseUrl + 'report/wizard/save_def_tab_data/Create', this.finalPostObj, {headers: new HttpHeaders({'Content-Type': 'application/json'})})
415 .subscribe((response) => {
416 if (response['message'] === 'Success Definition of given report is saved in session.') {
417 this.status = 'Success!';
418 this.message = 'Your change has been saved! Definition is updated.';
419 if (this.reportType == 'Dashboard') {
421 stackTrace = response['anyStacktrace'];
422 stackTrace = stackTrace.substring(0, stackTrace.indexOf('-'));
423 this.reportId = parseInt(stackTrace);
424 this._router.navigate(['v2/app/reports', 'Edit', this.reportId]);
426 this.showDialog = !this.showDialog;
427 this.closable = true;
429 this.status = 'Failure!';
430 this.message = 'Definition could not be updated.';
431 this.showDialog = !this.showDialog;
432 this.closable = true;
436 if ((this.IncomingReportId !== -1 && this.reportMode == 'Edit') || this.reportMode == 'Copy') {
437 this.finalPostObj['tabName'] = 'Definition';
438 this.finalPostObj['tabId'] = 'Def';
439 this.finalPostObj['reportId'] = this.reportId;
440 this.finalPostObj['reportName'] = this.reportName;
441 this.finalPostObj['reportDescr'] = this.reportDescription;
442 this.finalPostObj['reportType'] = this.reportType;
443 if (this.reportMode == 'Copy') {
444 this.finalPostObj['reportId'] = -1;
445 this.IncomingReportId = -1;
447 if (this.reportType === 'Dashboard') {
448 this.dashboardObj = this.dashboardObj.sort(function (a, b) {
449 if (a['x'] === b['x']) {
450 return a['y'] - b['y'];
452 return a['x'] - b['x'];
455 this.finalPostObj['dashboardLayoutJSON'] = JSON.stringify(this.dashboardObj);
456 this.finalPostObj['dashboardLayoutHTML'] = this.dashboardLayoutHTML;
458 this.finalPostObj['reportTypeList'] = null;
459 this.finalPostObj['dbInfo'] = this.dataSrc;
460 this.finalPostObj['formHelpText'] = this.helpText;
461 this.finalPostObj['pageSize'] = this.pageSize;
462 this.finalPostObj['dbInfoList'] = [
469 this.finalPostObj['displayArea'] = [
473 'selected': (this.displayArea == 'HOME' ? true : false)
478 'selected': (this.displayArea == 'CUSTOMER' ? true : false)
483 'selected': (this.displayArea == 'REPORTS' ? true : false)
486 this.finalPostObj['hideFormFieldsAfterRun'] = this.hideFormFields1;
487 this.finalPostObj['maxRowsInExcelCSVDownload'] = this.maxRows;
488 this.finalPostObj['frozenColumns'] = this.colsFrozen;
489 this.finalPostObj['dataGridAlign'] = this.gridAlign;
490 this.finalPostObj['emptyMessage'] = this.emptyMessage;
491 this.finalPostObj['dataContainerHeight'] = this.heightContainer;
492 this.finalPostObj['dataContainerWidth'] = this.widthContainer;
493 this.finalPostObj['displayOptions'] = [
495 'name': 'HideFormFields',
496 'selected': (this.hideFormFields == undefined ? false : this.hideFormFields)
500 'selected': (this.hideChart == undefined ? false : this.hideChart)
503 'name': 'HideReportData',
504 'selected': (this.hideReportData == undefined ? false : this.hideReportData)
508 'selected': (this.hideExcel == undefined ? false : this.hideExcel)
512 'selected': (this.hidePDF == undefined ? false : this.hidePDF)
515 this.finalPostObj['runtimeColSortDisabled'] = this.disableColumnSort;
516 this.finalPostObj['numFormCols'] = this.runTimeFormNum;
517 if ( this.reportTitle.length > 0) {
518 this.finalPostObj['reportTitle'] = this.reportTitle;
520 this.finalPostObj['reportTitle'] = this.reportName;;
522 this.finalPostObj['reportSubTitle'] = this.reportSubTitle;
523 this.finalPostObj['oneTimeRec'] = this.oneTime;
524 this.finalPostObj['hourlyRec'] = this.hourly;
525 this.finalPostObj['dailyRec'] = this.daily;
526 this.finalPostObj['dailyMFRec'] = this.MonFri;
527 this.finalPostObj['weeklyRec'] = this.Weekly;
528 this.finalPostObj['monthlyRec'] = this.Monthly;
529 this.finalPostObj['allowScheduler'] = (this.allowScheduler == true ? 'Y' : 'N');
530 this.finalPostObj['sizedByContent'] = (this.sizedByContent == true ? 'Y' : 'N');
531 this.finalPostObj['repDefType'] = this.reportDefinition;
533 this._definitionService.portDefinitionPageDetails(this.IncomingReportId, this.finalPostObj)
534 .subscribe((response) => {
535 if (response['message'] === 'Success Definition of given report is saved in session.') {
536 this.status = 'Success!';
537 this.message = 'Your change has been saved! Definition is updated.';
538 if (this.reportMode == 'Copy') {
540 stackTrace = response['anyStacktrace'];
541 stackTrace = stackTrace.substring(0, stackTrace.indexOf('-'));
542 this.reportId = parseInt(stackTrace);
543 this._router.navigate(['v2/app/reports', 'Edit', this.reportId]);
545 this.showDialog = !this.showDialog;
546 this.closable = true;
547 if (this.reportType == 'Dashboard') {
551 this.status = 'Failure!';
552 this.message = 'Definition could not be updated.';
553 this.showDialog = !this.showDialog;
554 this.closable = true;
561 this.showDialog = !this.showDialog;
562 this.closable = false;
565 onTransferDashboardObj(transferredDashboardObj: any) {
566 this.dashboardObj = transferredDashboardObj;
571 this._definitionService.clearSession()
572 .subscribe((response) => {
573 console.log(response);
574 this._router.navigate(['v2/app/report-list']);
580 let outPutValues = [];
581 outPutValues['reportType'] = this.reportType;
582 this.outputReportType.emit(outPutValues);