appDS2.controller('reportStepController', function($scope,$http,$location, $routeParams, $q, $modal,$log,$window, raptorReportFactory, stepFormFactory) { /*****************Init values*********************/ $scope.reportIdURL = $routeParams.reportId; $scope.isEdit = ($scope.reportIdURL==null||$scope.reportIdURL=='')?false:true; $scope.isDefReady = $scope.isEdit; $scope.activeTabsId = 'definition'; $scope.pageMsg ='' $scope.stepNum = 0; $scope.stepTabs=[ { title: 'Definition', id: 'definition', uniqueId: 'uniqueStep1', tabPanelId: 'definitionTab', disabled: false }, { title: 'SQL', id: 'sql', uniqueId: 'uniqueStep2', tabPanelId: 'sqlTab', disabled: (!$scope.isDefReady) }, { title: 'Columns', id: 'columns', uniqueId: 'uniqueTab3x', tabPanelId: 'columnsTab', disabled: (!$scope.isDefReady) }, { title: 'Form Fields', id: 'formFields', uniqueId: 'uniqueTab4x', tabPanelId: 'formFieldsTab', disabled: (!$scope.isDefReady) }, { title: 'Security', id: 'security', uniqueId: 'uniqueTab5x', tabPanelId: 'securityTab', disabled: (!$scope.isDefReady) }, { title: 'Log', id: 'log', uniqueId: 'uniqueTab6x', tabPanelId: 'logTab', disabled: (!$scope.isDefReady) }, { title: 'Run', id: 'run', uniqueId: 'uniqueTab7x', tabPanelId: 'runTab', disabled: (!$scope.isDefReady) } ]; $scope.$watch('activeTabsId', function (newVal, oldVal) { if(newVal !== oldVal) { $scope.init(); } }); $scope.renderStep = function(stepNum){ var containerElement = angular.element(document.getElementById("stepView")); containerElement.empty(); $scope.stepNum = stepNum; var jsonSrcName = getJsonSrcName(stepNum); stepFormFactory.renderForm(jsonSrcName, containerElement, $scope); } $scope.next = function(){ $scope.stepNum = $scope.stepNum +1; $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id; }; $scope.previous = function(){ $scope.stepNum = $scope.stepNum -1; $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id; } /*******************Step 1 Definitions****************/ $scope.displayOptions={ hideFormFields:false, hideChart:false, hideReportData:false, hideExcel:false, hidePdf:false } $scope.reportIdURL = $routeParams.reportId; $scope.definitionData={}; $scope.definitionData.displayOptions=[ {name:'HideFormFields', selected:false}, {name:'HideChart', selected:false}, {name:'HideReportData', selected:false}, {name:'HideExcel', selected:false}, {name:'HidePdf', selected:false} ] $scope.pageSizeValues=['10','25','50','100','500']; $scope.pageSizeOptions =[]; $scope.maxRowValues = ['500','1000','2000','3000','4000','5000','10000','15000','20000','25000','30000','35000','40000','45000','50000','65000'] $scope.maxRowOptions =[]; $scope.frozenColValues = ['0','1','2','3','4']; $scope.frozenColOptions =[]; $scope.dataGridAlignValues = ['Left','Right','Center']; $scope.dataGridAlignOptions =[]; $scope.dataContainerValues = ['10','20','30','40','50','60','70','80','90','100','110','120','130','140','150','160','170','180','190','200']; $scope.dataContainerOptions =[]; $scope.runTimeFormNumValues = ['1','2','3','4']; $scope.runTimeFormNumOptions =[]; /******create*****/ if(!$scope.isEdit){ $scope.definitionData.reportType = 'Linear'; $scope.definitionData.dbInfo = 'Local'; } /****end create***/ /*functions*/ $scope.getDefinitionById = function(id) { $scope.showLoader=true; raptorReportFactory.getDefinitionByReportId(id).then(function(data){ $scope.showLoader=false; $scope.definitionData = data; $scope.showLoader = false; for(x in data.displayOptions){ if(data.displayOptions[x].name=='HideFormFields') $scope.displayOptions.hideFormFields = data.displayOptions[x].selected; else if(data.displayOptions[x].name=='HideChart') $scope.displayOptions.hideChart = data.displayOptions[x].selected; else if(data.displayOptions[x].name=='HideReportData') $scope.displayOptions.hideReportData = data.displayOptions[x].selected; else if(data.displayOptions[x].name=='HideExcel') $scope.displayOptions.hideExcel = data.displayOptions[x].selected; else if(data.displayOptions[x].name=='HidePdf') $scope.displayOptions.hidePdf = data.displayOptions[x].selected; } $scope.definitionData.frozenColumns = $scope.definitionData.frozenColumns+''; $scope.definitionData.numFormCols = $scope.definitionData.numFormCols+''; $scope.definitionData.allowScheduler = data.allowScheduler=='Y'?true:false; $scope.definitionData.sizedByContent = data.sizedByContent=='Y'?true:false; $scope.definitionData.oneTimeRec = data.oneTimeRec=='Y'?true:false; $scope.definitionData.hourlyRec = data.hourlyRec=='Y'?true:false; $scope.definitionData.dailyRec = data.dailyRec=='Y'?true:false; $scope.definitionData.dailyMFRec = data.dailyMFRec=='Y'?true:false; $scope.definitionData.weeklyRec = data.weeklyRec=='Y'?true:false; $scope.definitionData.monthlyRec = data.monthlyRec=='Y'?true:false; if($scope.definitionData.reportTitle==null || $scope.definitionData.reportTitle=='') $scope.definitionData.reportTitle = $scope.definitionData.reportName; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getDefinitionById failed."); $scope.showLoader = false; }); } $scope.constructureDefDropDown = function(){ for(i in $scope.pageSizeValues){ var v = { value :$scope.pageSizeValues[i], text :$scope.pageSizeValues[i] } $scope.pageSizeOptions.push(v); } for(i in $scope.maxRowValues){ var v = { value :$scope.maxRowValues[i], text :$scope.maxRowValues[i] } $scope.maxRowOptions.push(v); } for(i in $scope.frozenColValues){ var v = { value :$scope.frozenColValues[i]+'', text :$scope.frozenColValues[i] } $scope.frozenColOptions.push(v); } for(i in $scope.dataGridAlignValues){ var v = { value :$scope.dataGridAlignValues[i].toLowerCase(), text :$scope.dataGridAlignValues[i] } $scope.dataGridAlignOptions.push(v); } for(i in $scope.dataContainerValues){ var v = { value :$scope.dataContainerValues[i], text :$scope.dataContainerValues[i] } $scope.dataContainerOptions.push(v); } for(i in $scope.runTimeFormNumValues){ var v = { value :$scope.runTimeFormNumValues[i], text :$scope.runTimeFormNumValues[i] } $scope.runTimeFormNumOptions.push(v); } } $scope.constructDef = function(){ var data =Object.assign({}, $scope.definitionData); for(x in $scope.definitionData.displayOptions){ if($scope.definitionData.displayOptions[x].name=='HideFormFields') data.displayOptions[x].selected = $scope.displayOptions.hideFormFields else if($scope.definitionData.displayOptions[x].name=='HideChart') data.displayOptions[x].selected = $scope.displayOptions.hideChart else if($scope.definitionData.displayOptions[x].name=='HideReportData') data.displayOptions[x].selected = $scope.displayOptions.hideReportData else if($scope.definitionData.displayOptions[x].name=='HideExcel') data.displayOptions[x].selected = $scope.displayOptions.hideExcel else if($scope.definitionData.displayOptions[x].name=='HidePdf') data.displayOptions[x].selected = $scope.displayOptions.hidePdf } if(data.pageSize==null || data.pageSize.startsWith("Select")) data.pageSize = null; if(data.maxRowsInExcelCSVDownload==null || data.maxRowsInExcelCSVDownload.startsWith("Select")) data.maxRowsInExcelCSVDownload = null; if(data.frozenColumns==null || data.frozenColumns.startsWith("Select")) data.frozenColumns = null; if(data.dataGridAlign==null || data.dataGridAlign.startsWith("Select")) data.dataGridAlign = null; if(data.dataContainerHeight==null || data.dataContainerHeight.startsWith("Select")) data.dataContainerHeight = null; if(data.dataContainerWidth ==null || data.dataContainerWidth.startsWith("Select")) data.dataContainerWidth = null; if(data.numFormCols ==null || data.numFormCols.startsWith("Select")) data.numFormCols = null; if(!$scope.isEdit) data.reportId=-1; if(data.reportTitle==null || data.reportTitle=='') data.reportTitle = data.reportName; return data; } $scope.updateDef = function(){ $scope.showLoader=true; var dataToSave = $scope.constructDef(); raptorReportFactory.updateDefinition(dataToSave,$scope.isEdit).then(function(data){ $scope.successPopUp('Definition is updated'); for(x in $scope.stepTabs){ $scope.stepTabs[x].disabled=false; } $scope.showLoader=false; },function(error){ $scope.errorPopUp(error); $log.error("report-step-controller: updateDefinition by Id failed."); }); } /*******************Step1 Ends****************/ /*******************Step2 SQL****************/ $scope.pageisCreating = false; $scope.sqlScript={ value:'' }; $scope.sqlTestTableData=''; /*function*/ $scope.getSql = function(){ $scope.showLoader = true; raptorReportFactory.getSqlInSession().then(function(data){ $scope.sqlInSessionJSON = data; $scope.sqlScript.value = data.query; $scope.showLoader = false; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getSearchData failed."); }); } $scope.testRunSql = function(){ $scope.showLoader=true; var queryJSON = {query: $scope.sqlScript.value}; queryJSON = JSON.stringify(queryJSON); raptorReportFactory.testRunSQL(queryJSON).then(function(data){ $scope.showLoader=false; var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html', windowClass:'modal-docked', sizeClass: 'modal-large', controller: testRunSqlController, resolve:{ queriedData: function(){ return data; } } }); modalInstance.result.finally(function () { if(!$scope.isEdit){ $scope.showLoader=true; $scope.pageisCreating = true; $scope.pageMsg = 'Please wait while we are creating the report. Page will be reloaded after the creation is done.' raptorReportFactory.getDefinitionInSession().then(function(data){ var newReportId = data.reportId; if(newReportId!=null && newReportId!='' && newReportId!=-1) $window.location.href = "#/report_wizard/"+newReportId; $scope.showLoader = false; $scope.pageisCreating = false; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: get Definition In Session failed."); $scope.showLoader = false; }); } }); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: test run SQL failed."); }); } /*******************Step2 End****************/ /*******************Step3 Column****************/ $scope.colTableRowData=''; $scope.isEditCol= true; $scope.getColumn = function(){ $scope.showLoader = true; raptorReportFactory.getColumnList().then(function(data){ $scope.colTableRowData = data; $scope.showLoader = false; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: get column list failed."); }); } $scope.openColumnPopup = function (rowData) { var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html', windowClass:'modal-docked', sizeClass: 'modal-jumbo', controller: openColumnPopupController, resolve:{ colData: function(){ return rowData; } } }); modalInstance.result.finally(function () { $scope.getColumn(); }); }; /*******************Step3 End****************/ /*******************Step4 Starts Form Fields****************/ $scope.dataProcessing = false; $scope.formFieldData = []; $scope.getFormFieldList = function(){ $scope.showLoader= true; $scope.formFieldData = []; raptorReportFactory.getFormFieldList().then(function(data){ $scope.showLoader= false; $scope.formFieldData = data; $scope.formFieldData.sort(function(obj1, obj2) { // Ascending: first age less than the previous return obj1.orderSeq - obj2.orderSeq; }); $scope.showLoader = false; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: get formfields failed."); $scope.showLoader = false; }); } $scope.formFieldReOrder = function(upID, downID){ $scope.moveUpFF={}; $scope.moveDownFF={}; $scope.showLoader=true; raptorReportFactory.getFormFieldEditInfoById(upID).then(function(data){ $scope.moveUpFF = data; raptorReportFactory.getFormFieldEditInfoById(downID).then(function(data){ $scope.moveDownFF = data; var downOrder = $scope.moveDownFF.orderSeq; $scope.moveDownFF.orderSeq = $scope.moveUpFF.orderSeq; $scope.moveUpFF.orderSeq = downOrder; raptorReportFactory.saveFormFieldEditInfo($scope.moveDownFF).then(function(data){ raptorReportFactory.saveFormFieldEditInfo($scope.moveUpFF).then(function(data){ $scope.successPopUp(''); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); }).finally(function() { $scope.showLoader=false; $scope.getFormFieldList(); }) },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); }); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getColumnEditInfoById failed."); }); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getColumnEditInfoById failed."); }) } $scope.formFieldVerifySQL= function(sqlScript){ var queryJSON = {query: sqlScript}; queryJSON = JSON.stringify(queryJSON); raptorReportFactory.formFieldVerifySQL(queryJSON).then(function(data){ var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html', sizeClass: 'modal-large', controller: formFieldVerifySQLController, resolve:{ queriedData: function(){ return data; } } }) },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: test run SQL failed."); }); } $scope.openFormFieldPopup = function (rowData,type) { $scope.type= type; var modalInstance = $modal.open({ scope: $scope, animation: true, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html', sizeClass: 'modal-large', controller: openFormFieldPopupController, resolve:{ fieldData: function(){ return rowData; } } }); modalInstance.result.finally(function () { $scope.getFormFieldList(); }); }; $scope.addFormField = function(){ $scope.openFormFieldPopup('','add'); } $scope.deleteFormField = function(rowData) { var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html', sizeClass: 'modal-small', controller: deleteFormFieldController, resolve:{ rowData: function(){ return rowData; } } }); modalInstance.result.then(function () { $scope.getFormFieldList(); }, function () { }); } /*******************Step4 End****************/ /*******************Step5 Starts Security****************/ $scope.ynOptions = [ {value:"true", text:"Yes"}, {value:"false", text:"No"} ]; $scope.addReportUserId={ id:'' }; $scope.addReportRoleId={ id:'' }; $scope.loadSecurityPage = function() { $scope.showLoader = true; raptorReportFactory.resetSecurityLoadingCounter(); //API call 1: raptorReportFactory.getSecurityReportOwnerList().then(function(data){ $scope.reportOwnerList = data; raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getSecurityReportOwnerList failed."); }); //API call 2: get report role list raptorReportFactory.getReportRoleList().then(function(data){ $scope.reportRoleList = data; raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getReportRoleList failed."); }); //API call 3: get security page basic info raptorReportFactory.getReportSecurityInfo().then(function(data){ $scope.reportSecurityInfo = data; $scope.reportOwnerId ={id: $scope.reportSecurityInfo.ownerId}; raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getReportSecurityInfo failed."); $scope.showLoader = false;}); //API call 4: retrieve security users raptorReportFactory.getReportSecurityUsers().then(function(data){ $scope.reportSecurityUsers = data; for (var i=0; i<$scope.reportSecurityUsers.length;i++) { $scope.reportSecurityUsers[i]["accessAllowed"] = !$scope.reportSecurityUsers[i]["readOnly"]; $scope.reportSecurityUsers[i].runAccess = true; // need to check why 1702 version is making it true always } raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: reportSecurityUsers failed."); }); //API call 5: retrieve security roles raptorReportFactory.getReportSecurityRoles().then(function(data){ $scope.reportSecurityRoles = data; for (var i=0; i<$scope.reportSecurityRoles.length;i++) { $scope.reportSecurityRoles[i]["accessAllowed"] = !$scope.reportSecurityRoles[i]["readOnly"]; $scope.reportSecurityRoles[i].runAccess = true; // need to check why 1702 version is making it true always } raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: reportSecurityRoles failed."); }); } $scope.addReportSecurityUser = function(userId) { $scope.showLoader=true; raptorReportFactory.addReportSecurityUser(userId).then(function(data){ $scope.loadSecurityPage(); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: addReportSecurityUser failed."); }).finally(function() { $scope.showLoader=false; }); } $scope.removeReportSecurityUser = function(securityUser) { var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html', sizeClass: 'modal-small', controller: removeReportSecurityUserController, resolve:{ securityUser: function(){ return securityUser; } } }); modalInstance.result.then(function () { $scope.loadSecurityPage(); }, function () { }); }; $scope.addReportSecurityRole = function(roleId) { raptorReportFactory.addReportSecurityRole(roleId).then(function(data){ $scope.loadSecurityPage(); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: addReportSecurityRole failed."); }); } $scope.removeReportSecurityRole = function(securityRole) { var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html', sizeClass: 'modal-small', controller: removeReportSecurityRoleController, resolve:{ securityRole: function(){ return securityRole; } } }); modalInstance.result.then(function () { $scope.loadSecurityPage(); }, function () { }); } $scope.saveReportSecurityInfo = function() { $scope.showLoader = true; var securityInfo = {'userId':$scope.reportSecurityInfo.ownerId+"",'isPublic':$scope.reportSecurityInfo.isPublic}; raptorReportFactory.updateReportSecurityInfo(securityInfo).then(function(data){ $scope.successPopUp(''); $scope.loadSecurityPage(); },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: updateReportSecurityInfo failed."); }); }; $scope.toggleUserEditAccessActive = function(rowData) { var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html', sizeClass: 'modal-small', controller: toggleUserEditAccessActiveController, resolve:{ rowData: function(){ return rowData; } } }); } $scope.toggleRoleEditAccessActive = function(rowData) { var modalInstance = $modal.open({ scope: $scope, animation: $scope.animationsEnabled, templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html', sizeClass: 'modal-small', controller: toggleRoleEditAccessActiveController, resolve:{ rowData: function(){ return rowData; } } }); } /*******************Step5 End****************/ /*******************Step6 Starts****************/ $scope.logs = []; $scope.getReportID = function(){ $scope.showLoader = true; raptorReportFactory.getReportLogs($routeParams.reportId).then(function(data){ $scope.logs = data; $scope.showLoader = false; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getReportID failed."+ error); }); } /*******************Step6 End****************/ /*******************Step7 Starts Run****************/ $scope.loadDefinitionInSession = function(){ $scope.showLoader = true; raptorReportFactory.getDefinitionInSession().then(function(data){ $scope.reportId = data.reportId; $scope.showLoader = false; },function(error){ $scope.errorPopUp(error); $log.error("raptorReportFactory: getDefinitionInSession failed."); $scope.showLoader = false; }); } $scope.runReport = function(){ $window.location.href = "#/report_run/c_master="+$scope.reportId+"&refresh=Y"; } /*******************Step7 End****************/ /********************Init*************/ $scope.init = function(){ if ($routeParams.reportMode=="copy") { raptorReportFactory.copyReportById($routeParams.reportId).then(function(data){ $scope.isEdit = true; $scope.reportId = -1; $scope.getDefinitionById(-1); },function(error){ $log.error("raptorReportFactory: deleteFormFieldById failed."); }); } /*else if ($routeParams.reportMode=="import") { $scope.$emit('RefreshInsession'); }*/ if($scope.activeTabsId=='definition'){ /*Step 1*/ $scope.constructureDefDropDown(); if($scope.isEdit) $scope.getDefinitionById($scope.reportIdURL); //edit else $scope.getDefinitionById(-1); //create }else if($scope.activeTabsId=='sql'){ /*Step 2*/ $scope.getSql(); }else if($scope.activeTabsId=='columns'){ $scope.getColumn(); }else if($scope.activeTabsId=='formFields'){ $scope.getFormFieldList(); }else if($scope.activeTabsId=='security'){ $scope.loadSecurityPage(); }else if($scope.activeTabsId=='log'){ $scope.getReportID(); }else if($scope.activeTabsId=='run'){ $scope.reportId = $scope.reportIdURL; if($scope.reportId==null || $scope.reportId=='') $scope.loadDefinitionInSession(); } } $scope.successPopUp = function (msg) { var modalInstance = $modal.open({ templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html', controller: ModalInstanceCtrl, sizeClass: 'modal-small', resolve: { msg: function () { var message = { title: '', text: msg }; return message; } } }); }; $scope.errorPopUp = function (msg) { var modalInstance = $modal.open({ templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html', controller: ModalInstanceCtrl, sizeClass: 'modal-small', resolve: { msg: function () { return msg; } } }); }; $scope.init(); });