1 appDS2.controller('reportStepController', function($scope,$http,$location, $routeParams, $q, $modal,$log,$window, raptorReportFactory, stepFormFactory) {
2 /*****************Init values*********************/
3 $scope.reportIdURL = $routeParams.reportId;
4 $scope.isEdit = ($scope.reportIdURL==null||$scope.reportIdURL=='')?false:true;
5 $scope.isDefReady = $scope.isEdit;
6 $scope.activeTabsId = 'definition';
13 uniqueId: 'uniqueStep1',
14 tabPanelId: 'definitionTab',
20 uniqueId: 'uniqueStep2',
22 disabled: (!$scope.isDefReady)
26 uniqueId: 'uniqueTab3x',
27 tabPanelId: 'columnsTab',
28 disabled: (!$scope.isDefReady)
32 uniqueId: 'uniqueTab4x',
33 tabPanelId: 'formFieldsTab',
34 disabled: (!$scope.isDefReady)
38 uniqueId: 'uniqueTab5x',
39 tabPanelId: 'securityTab',
40 disabled: (!$scope.isDefReady)
44 uniqueId: 'uniqueTab6x',
46 disabled: (!$scope.isDefReady)
50 uniqueId: 'uniqueTab7x',
52 disabled: (!$scope.isDefReady)
56 $scope.$watch('activeTabsId', function (newVal, oldVal) {
57 if(newVal !== oldVal) {
62 $scope.renderStep = function(stepNum){
63 var containerElement = angular.element(document.getElementById("stepView"));
64 containerElement.empty();
65 $scope.stepNum = stepNum;
66 var jsonSrcName = getJsonSrcName(stepNum);
67 stepFormFactory.renderForm(jsonSrcName, containerElement, $scope);
69 $scope.next = function(){
70 $scope.stepNum = $scope.stepNum +1;
71 $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id;
75 $scope.previous = function(){
76 $scope.stepNum = $scope.stepNum -1;
77 $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id;
80 /*******************Step 1 Definitions****************/
81 $scope.displayOptions={
88 $scope.reportIdURL = $routeParams.reportId;
89 $scope.definitionData={};
90 $scope.definitionData.displayOptions=[
91 {name:'HideFormFields', selected:false},
92 {name:'HideChart', selected:false},
93 {name:'HideReportData', selected:false},
94 {name:'HideExcel', selected:false},
95 {name:'HidePdf', selected:false}
98 $scope.pageSizeValues=['10','25','50','100','500'];
99 $scope.pageSizeOptions =[];
100 $scope.maxRowValues = ['500','1000','2000','3000','4000','5000','10000','15000','20000','25000','30000','35000','40000','45000','50000','65000']
101 $scope.maxRowOptions =[];
102 $scope.frozenColValues = ['0','1','2','3','4'];
103 $scope.frozenColOptions =[];
104 $scope.dataGridAlignValues = ['Left','Right','Center'];
105 $scope.dataGridAlignOptions =[];
106 $scope.dataContainerValues = ['10','20','30','40','50','60','70','80','90','100','110','120','130','140','150','160','170','180','190','200'];
107 $scope.dataContainerOptions =[];
108 $scope.runTimeFormNumValues = ['1','2','3','4'];
109 $scope.runTimeFormNumOptions =[];
112 $scope.definitionData.reportType = 'Linear';
113 $scope.definitionData.dbInfo = 'Local';
118 $scope.getDefinitionById = function(id) {
119 $scope.showLoader=true;
120 raptorReportFactory.getDefinitionByReportId(id).then(function(data){
121 $scope.showLoader=false;
122 $scope.definitionData = data;
123 $scope.showLoader = false;
124 for(x in data.displayOptions){
125 if(data.displayOptions[x].name=='HideFormFields')
126 $scope.displayOptions.hideFormFields = data.displayOptions[x].selected;
127 else if(data.displayOptions[x].name=='HideChart')
128 $scope.displayOptions.hideChart = data.displayOptions[x].selected;
129 else if(data.displayOptions[x].name=='HideReportData')
130 $scope.displayOptions.hideReportData = data.displayOptions[x].selected;
131 else if(data.displayOptions[x].name=='HideExcel')
132 $scope.displayOptions.hideExcel = data.displayOptions[x].selected;
133 else if(data.displayOptions[x].name=='HidePdf')
134 $scope.displayOptions.hidePdf = data.displayOptions[x].selected;
137 $scope.definitionData.frozenColumns = $scope.definitionData.frozenColumns+'';
138 $scope.definitionData.numFormCols = $scope.definitionData.numFormCols+'';
139 $scope.definitionData.allowScheduler = data.allowScheduler=='Y'?true:false;
140 $scope.definitionData.sizedByContent = data.sizedByContent=='Y'?true:false;
142 $scope.definitionData.oneTimeRec = data.oneTimeRec=='Y'?true:false;
143 $scope.definitionData.hourlyRec = data.hourlyRec=='Y'?true:false;
144 $scope.definitionData.dailyRec = data.dailyRec=='Y'?true:false;
145 $scope.definitionData.dailyMFRec = data.dailyMFRec=='Y'?true:false;
146 $scope.definitionData.weeklyRec = data.weeklyRec=='Y'?true:false;
147 $scope.definitionData.monthlyRec = data.monthlyRec=='Y'?true:false;
149 if($scope.definitionData.reportTitle==null || $scope.definitionData.reportTitle=='')
150 $scope.definitionData.reportTitle = $scope.definitionData.reportName;
152 $scope.errorPopUp(error);
153 $log.error("raptorReportFactory: getDefinitionById failed.");
154 $scope.showLoader = false;
158 $scope.constructureDefDropDown = function(){
159 for(i in $scope.pageSizeValues){
161 value :$scope.pageSizeValues[i],
162 text :$scope.pageSizeValues[i]
164 $scope.pageSizeOptions.push(v);
166 for(i in $scope.maxRowValues){
168 value :$scope.maxRowValues[i],
169 text :$scope.maxRowValues[i]
171 $scope.maxRowOptions.push(v);
173 for(i in $scope.frozenColValues){
175 value :$scope.frozenColValues[i]+'',
176 text :$scope.frozenColValues[i]
178 $scope.frozenColOptions.push(v);
180 for(i in $scope.dataGridAlignValues){
182 value :$scope.dataGridAlignValues[i].toLowerCase(),
183 text :$scope.dataGridAlignValues[i]
185 $scope.dataGridAlignOptions.push(v);
187 for(i in $scope.dataContainerValues){
189 value :$scope.dataContainerValues[i],
190 text :$scope.dataContainerValues[i]
192 $scope.dataContainerOptions.push(v);
194 for(i in $scope.runTimeFormNumValues){
196 value :$scope.runTimeFormNumValues[i],
197 text :$scope.runTimeFormNumValues[i]
199 $scope.runTimeFormNumOptions.push(v);
203 $scope.constructDef = function(){
204 var data =Object.assign({}, $scope.definitionData);
205 for(x in $scope.definitionData.displayOptions){
206 if($scope.definitionData.displayOptions[x].name=='HideFormFields')
207 data.displayOptions[x].selected = $scope.displayOptions.hideFormFields
208 else if($scope.definitionData.displayOptions[x].name=='HideChart')
209 data.displayOptions[x].selected = $scope.displayOptions.hideChart
210 else if($scope.definitionData.displayOptions[x].name=='HideReportData')
211 data.displayOptions[x].selected = $scope.displayOptions.hideReportData
212 else if($scope.definitionData.displayOptions[x].name=='HideExcel')
213 data.displayOptions[x].selected = $scope.displayOptions.hideExcel
214 else if($scope.definitionData.displayOptions[x].name=='HidePdf')
215 data.displayOptions[x].selected = $scope.displayOptions.hidePdf
217 if(data.pageSize==null || data.pageSize.startsWith("Select"))
218 data.pageSize = null;
219 if(data.maxRowsInExcelCSVDownload==null || data.maxRowsInExcelCSVDownload.startsWith("Select"))
220 data.maxRowsInExcelCSVDownload = null;
221 if(data.frozenColumns==null || data.frozenColumns.startsWith("Select"))
222 data.frozenColumns = null;
223 if(data.dataGridAlign==null || data.dataGridAlign.startsWith("Select"))
224 data.dataGridAlign = null;
225 if(data.dataContainerHeight==null || data.dataContainerHeight.startsWith("Select"))
226 data.dataContainerHeight = null;
227 if(data.dataContainerWidth ==null || data.dataContainerWidth.startsWith("Select"))
228 data.dataContainerWidth = null;
229 if(data.numFormCols ==null || data.numFormCols.startsWith("Select"))
230 data.numFormCols = null;
234 if(data.reportTitle==null || data.reportTitle=='')
235 data.reportTitle = data.reportName;
238 $scope.updateDef = function(){
239 $scope.showLoader=true;
240 var dataToSave = $scope.constructDef();
241 raptorReportFactory.updateDefinition(dataToSave,$scope.isEdit).then(function(data){
242 $scope.successPopUp('Definition is updated');
243 for(x in $scope.stepTabs){
244 $scope.stepTabs[x].disabled=false;
246 $scope.showLoader=false;
248 $scope.errorPopUp(error);
249 $log.error("report-step-controller: updateDefinition by Id failed.");
252 /*******************Step1 Ends****************/
253 /*******************Step2 SQL****************/
254 $scope.pageisCreating = false;
258 $scope.sqlTestTableData='';
260 $scope.getSql = function(){
261 $scope.showLoader = true;
262 raptorReportFactory.getSqlInSession().then(function(data){
263 $scope.sqlInSessionJSON = data;
264 $scope.sqlScript.value = data.query;
265 $scope.showLoader = false;
267 $scope.errorPopUp(error);
268 $log.error("raptorReportFactory: getSearchData failed.");
271 $scope.testRunSql = function(){
272 $scope.showLoader=true;
273 var queryJSON = {query: $scope.sqlScript.value};
274 queryJSON = JSON.stringify(queryJSON);
275 raptorReportFactory.testRunSQL(queryJSON).then(function(data){
276 $scope.showLoader=false;
277 var modalInstance = $modal.open({
279 animation: $scope.animationsEnabled,
280 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html',
281 windowClass:'modal-docked',
282 sizeClass: 'modal-large',
283 controller: testRunSqlController,
285 queriedData: function(){
291 modalInstance.result.finally(function () {
293 $scope.showLoader=true;
294 $scope.pageisCreating = true;
295 $scope.pageMsg = 'Please wait while we are creating the report. Page will be reloaded after the creation is done.'
296 raptorReportFactory.getDefinitionInSession().then(function(data){
297 var newReportId = data.reportId;
298 if(newReportId!=null && newReportId!='' && newReportId!=-1)
299 $window.location.href = "#/report_wizard/"+newReportId;
301 $scope.showLoader = false;
302 $scope.pageisCreating = false;
304 $scope.errorPopUp(error);
305 $log.error("raptorReportFactory: get Definition In Session failed.");
306 $scope.showLoader = false;
312 $scope.errorPopUp(error);
313 $log.error("raptorReportFactory: test run SQL failed.");
317 /*******************Step2 End****************/
318 /*******************Step3 Column****************/
319 $scope.colTableRowData='';
320 $scope.isEditCol= true;
322 $scope.getColumn = function(){
323 $scope.showLoader = true;
324 raptorReportFactory.getColumnList().then(function(data){
325 $scope.colTableRowData = data;
326 $scope.showLoader = false;
328 $scope.errorPopUp(error);
329 $log.error("raptorReportFactory: get column list failed.");
333 $scope.openColumnPopup = function (rowData) {
334 var modalInstance = $modal.open({
336 animation: $scope.animationsEnabled,
337 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html',
338 windowClass:'modal-docked',
339 sizeClass: 'modal-jumbo',
340 controller: openColumnPopupController,
347 modalInstance.result.finally(function () {
352 /*******************Step3 End****************/
353 /*******************Step4 Starts Form Fields****************/
355 $scope.dataProcessing = false;
356 $scope.formFieldData = [];
357 $scope.getFormFieldList = function(){
358 $scope.showLoader= true;
359 $scope.formFieldData = [];
360 raptorReportFactory.getFormFieldList().then(function(data){
361 $scope.showLoader= false;
362 $scope.formFieldData = data;
363 $scope.formFieldData.sort(function(obj1, obj2) {
364 // Ascending: first age less than the previous
365 return obj1.orderSeq - obj2.orderSeq;
368 $scope.showLoader = false;
370 $scope.errorPopUp(error);
371 $log.error("raptorReportFactory: get formfields failed.");
372 $scope.showLoader = false;
376 $scope.formFieldReOrder = function(upID, downID){
379 $scope.moveDownFF={};
380 $scope.showLoader=true;
381 raptorReportFactory.getFormFieldEditInfoById(upID).then(function(data){
382 $scope.moveUpFF = data;
383 raptorReportFactory.getFormFieldEditInfoById(downID).then(function(data){
384 $scope.moveDownFF = data;
385 var downOrder = $scope.moveDownFF.orderSeq;
386 $scope.moveDownFF.orderSeq = $scope.moveUpFF.orderSeq;
387 $scope.moveUpFF.orderSeq = downOrder;
388 raptorReportFactory.saveFormFieldEditInfo($scope.moveDownFF).then(function(data){
389 raptorReportFactory.saveFormFieldEditInfo($scope.moveUpFF).then(function(data){
390 $scope.successPopUp('');
392 $scope.errorPopUp(error);
393 $log.error("raptorReportFactory: saveFormFieldEditInfo failed.");
394 }).finally(function() {
395 $scope.showLoader=false;
396 $scope.getFormFieldList();
399 $scope.errorPopUp(error);
400 $log.error("raptorReportFactory: saveFormFieldEditInfo failed.");
404 $scope.errorPopUp(error);
405 $log.error("raptorReportFactory: getColumnEditInfoById failed.");
408 $scope.errorPopUp(error);
409 $log.error("raptorReportFactory: getColumnEditInfoById failed.");
415 $scope.formFieldVerifySQL= function(sqlScript){
416 var queryJSON = {query: sqlScript};
417 queryJSON = JSON.stringify(queryJSON);
418 raptorReportFactory.formFieldVerifySQL(queryJSON).then(function(data){
419 var modalInstance = $modal.open({
421 animation: $scope.animationsEnabled,
422 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html',
423 sizeClass: 'modal-large',
424 controller: formFieldVerifySQLController,
426 queriedData: function(){
433 $scope.errorPopUp(error);
434 $log.error("raptorReportFactory: test run SQL failed.");
439 $scope.openFormFieldPopup = function (rowData,type) {
441 var modalInstance = $modal.open({
444 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html',
445 sizeClass: 'modal-large',
446 controller: openFormFieldPopupController,
448 fieldData: function(){
454 modalInstance.result.finally(function () {
455 $scope.getFormFieldList();
458 $scope.addFormField = function(){
459 $scope.openFormFieldPopup('','add');
463 $scope.deleteFormField = function(rowData) {
464 var modalInstance = $modal.open({
466 animation: $scope.animationsEnabled,
467 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html',
468 sizeClass: 'modal-small',
469 controller: deleteFormFieldController,
476 modalInstance.result.then(function () {
477 $scope.getFormFieldList();
482 /*******************Step4 End****************/
483 /*******************Step5 Starts Security****************/
485 {value:"true", text:"Yes"},
486 {value:"false", text:"No"}
488 $scope.addReportUserId={
491 $scope.addReportRoleId={
494 $scope.loadSecurityPage = function() {
495 $scope.showLoader = true;
496 raptorReportFactory.resetSecurityLoadingCounter();
499 raptorReportFactory.getSecurityReportOwnerList().then(function(data){
500 $scope.reportOwnerList = data;
501 raptorReportFactory.icrementSecurityLoadingCounter();
502 if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
504 $scope.errorPopUp(error);
505 $log.error("raptorReportFactory: getSecurityReportOwnerList failed.");
508 //API call 2: get report role list
509 raptorReportFactory.getReportRoleList().then(function(data){
510 $scope.reportRoleList = data;
511 raptorReportFactory.icrementSecurityLoadingCounter();
512 if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
514 $scope.errorPopUp(error);
515 $log.error("raptorReportFactory: getReportRoleList failed.");
518 //API call 3: get security page basic info
519 raptorReportFactory.getReportSecurityInfo().then(function(data){
520 $scope.reportSecurityInfo = data;
521 $scope.reportOwnerId ={id: $scope.reportSecurityInfo.ownerId};
522 raptorReportFactory.icrementSecurityLoadingCounter();
523 if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
525 $scope.errorPopUp(error);
526 $log.error("raptorReportFactory: getReportSecurityInfo failed.");
527 $scope.showLoader = false;});
529 //API call 4: retrieve security users
530 raptorReportFactory.getReportSecurityUsers().then(function(data){
532 $scope.reportSecurityUsers = data;
533 for (var i=0; i<$scope.reportSecurityUsers.length;i++) {
534 $scope.reportSecurityUsers[i]["accessAllowed"] = !$scope.reportSecurityUsers[i]["readOnly"];
535 $scope.reportSecurityUsers[i].runAccess = true; // need to check why 1702 version is making it true always
537 raptorReportFactory.icrementSecurityLoadingCounter();
538 if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
540 $scope.errorPopUp(error);
541 $log.error("raptorReportFactory: reportSecurityUsers failed.");
544 //API call 5: retrieve security roles
545 raptorReportFactory.getReportSecurityRoles().then(function(data){
546 $scope.reportSecurityRoles = data;
547 for (var i=0; i<$scope.reportSecurityRoles.length;i++) {
548 $scope.reportSecurityRoles[i]["accessAllowed"] = !$scope.reportSecurityRoles[i]["readOnly"];
549 $scope.reportSecurityRoles[i].runAccess = true; // need to check why 1702 version is making it true always
552 raptorReportFactory.icrementSecurityLoadingCounter();
553 if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
555 $scope.errorPopUp(error);
556 $log.error("raptorReportFactory: reportSecurityRoles failed.");
559 $scope.addReportSecurityUser = function(userId) {
560 $scope.showLoader=true;
561 raptorReportFactory.addReportSecurityUser(userId).then(function(data){
562 $scope.loadSecurityPage();
564 $scope.errorPopUp(error);
565 $log.error("raptorReportFactory: addReportSecurityUser failed.");
566 }).finally(function() {
567 $scope.showLoader=false;
571 $scope.removeReportSecurityUser = function(securityUser) {
572 var modalInstance = $modal.open({
574 animation: $scope.animationsEnabled,
575 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html',
576 sizeClass: 'modal-small',
577 controller: removeReportSecurityUserController,
579 securityUser: function(){
584 modalInstance.result.then(function () {
585 $scope.loadSecurityPage();
589 $scope.addReportSecurityRole = function(roleId) {
590 raptorReportFactory.addReportSecurityRole(roleId).then(function(data){
591 $scope.loadSecurityPage();
593 $scope.errorPopUp(error);
594 $log.error("raptorReportFactory: addReportSecurityRole failed.");
599 $scope.removeReportSecurityRole = function(securityRole) {
600 var modalInstance = $modal.open({
602 animation: $scope.animationsEnabled,
603 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html',
604 sizeClass: 'modal-small',
605 controller: removeReportSecurityRoleController,
607 securityRole: function(){
612 modalInstance.result.then(function () {
613 $scope.loadSecurityPage();
618 $scope.saveReportSecurityInfo = function() {
619 $scope.showLoader = true;
620 var securityInfo = {'userId':$scope.reportSecurityInfo.ownerId+"",'isPublic':$scope.reportSecurityInfo.isPublic};
621 raptorReportFactory.updateReportSecurityInfo(securityInfo).then(function(data){
622 $scope.successPopUp('');
623 $scope.loadSecurityPage();
625 $scope.errorPopUp(error);
626 $log.error("raptorReportFactory: updateReportSecurityInfo failed.");
630 $scope.toggleUserEditAccessActive = function(rowData) {
631 var modalInstance = $modal.open({
633 animation: $scope.animationsEnabled,
634 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html',
635 sizeClass: 'modal-small',
636 controller: toggleUserEditAccessActiveController,
645 $scope.toggleRoleEditAccessActive = function(rowData) {
646 var modalInstance = $modal.open({
648 animation: $scope.animationsEnabled,
649 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html',
650 sizeClass: 'modal-small',
651 controller: toggleRoleEditAccessActiveController,
660 /*******************Step5 End****************/
661 /*******************Step6 Starts****************/
663 $scope.getReportID = function(){
664 $scope.showLoader = true;
665 raptorReportFactory.getReportLogs($routeParams.reportId).then(function(data){
667 $scope.showLoader = false;
670 $scope.errorPopUp(error);
671 $log.error("raptorReportFactory: getReportID failed."+ error);
676 /*******************Step6 End****************/
677 /*******************Step7 Starts Run****************/
678 $scope.loadDefinitionInSession = function(){
679 $scope.showLoader = true;
680 raptorReportFactory.getDefinitionInSession().then(function(data){
681 $scope.reportId = data.reportId;
682 $scope.showLoader = false;
684 $scope.errorPopUp(error);
685 $log.error("raptorReportFactory: getDefinitionInSession failed.");
686 $scope.showLoader = false;
689 $scope.runReport = function(){
690 $window.location.href = "#/report_run/c_master="+$scope.reportId+"&refresh=Y";
692 /*******************Step7 End****************/
694 /********************Init*************/
695 $scope.init = function(){
696 if ($routeParams.reportMode=="copy") {
697 raptorReportFactory.copyReportById($routeParams.reportId).then(function(data){
698 $scope.isEdit = true;
699 $scope.reportId = -1;
700 $scope.getDefinitionById(-1);
702 $log.error("raptorReportFactory: deleteFormFieldById failed.");
704 } /*else if ($routeParams.reportMode=="import") {
705 $scope.$emit('RefreshInsession');
709 if($scope.activeTabsId=='definition'){ /*Step 1*/
710 $scope.constructureDefDropDown();
712 $scope.getDefinitionById($scope.reportIdURL); //edit
714 $scope.getDefinitionById(-1); //create
715 }else if($scope.activeTabsId=='sql'){ /*Step 2*/
717 }else if($scope.activeTabsId=='columns'){
719 }else if($scope.activeTabsId=='formFields'){
720 $scope.getFormFieldList();
721 }else if($scope.activeTabsId=='security'){
722 $scope.loadSecurityPage();
723 }else if($scope.activeTabsId=='log'){
724 $scope.getReportID();
725 }else if($scope.activeTabsId=='run'){
726 $scope.reportId = $scope.reportIdURL;
727 if($scope.reportId==null || $scope.reportId=='')
728 $scope.loadDefinitionInSession();
732 $scope.successPopUp = function (msg) {
733 var modalInstance = $modal.open({
734 templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html',
735 controller: ModalInstanceCtrl,
736 sizeClass: 'modal-small',
749 $scope.errorPopUp = function (msg) {
750 var modalInstance = $modal.open({
751 templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html',
752 controller: ModalInstanceCtrl,
753 sizeClass: 'modal-small',