a23823e329af427f8a8ce8850e028942dfb6b9f5
[portal/sdk.git] /
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.isCopy = false;
6         $scope.isDefReady = $scope.isEdit;
7         $scope.activeTabsId = 'definition';
8         $scope.pageMsg =''
9         $scope.stepNum = 0;
10         $scope.stepTabs=[
11                  {
12              title: 'Definition',
13              id: 'definition',
14              uniqueId: 'uniqueStep1',
15              tabPanelId: 'definitionTab',
16              disabled: false
17              
18          }, {
19              title: 'SQL',
20              id: 'sql',
21              uniqueId: 'uniqueStep2',
22              tabPanelId: 'sqlTab',
23              disabled: (!$scope.isDefReady)
24          }, {
25              title: 'Columns',
26              id: 'columns',
27              uniqueId: 'uniqueTab3x',
28              tabPanelId: 'columnsTab',
29              disabled: (!$scope.isDefReady)
30          }, {
31              title: 'Form Fields',
32              id: 'formFields',
33              uniqueId: 'uniqueTab4x',
34              tabPanelId: 'formFieldsTab',
35              disabled: (!$scope.isDefReady)
36          }, {
37              title: 'Security',
38              id: 'security',
39              uniqueId: 'uniqueTab5x',
40              tabPanelId: 'securityTab',
41              disabled: (!$scope.isDefReady)
42          }, {
43              title: 'Log',
44              id: 'log',
45              uniqueId: 'uniqueTab6x',
46              tabPanelId: 'logTab',
47              disabled: (!$scope.isDefReady)
48          }, {
49              title: 'Run',
50              id: 'run',
51              uniqueId: 'uniqueTab7x',
52              tabPanelId: 'runTab',
53              disabled: (!$scope.isDefReady)
54          }
55          
56         ];
57         $scope.$watch('activeTabsId', function (newVal, oldVal) {
58                 if(newVal !== oldVal) {
59                         $scope.init();
60                 }
61         });      
62
63         $scope.renderStep = function(stepNum){
64         var containerElement = angular.element(document.getElementById("stepView"));
65         containerElement.empty();
66         $scope.stepNum = stepNum;
67         var jsonSrcName = getJsonSrcName(stepNum);
68         stepFormFactory.renderForm(jsonSrcName, containerElement, $scope);
69     }
70          $scope.next = function(){
71                 $scope.stepNum = $scope.stepNum +1;
72         $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id;
73     };   
74             
75             
76     $scope.previous = function(){
77                 $scope.stepNum = $scope.stepNum -1;
78         $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id;       
79         }
80         
81         /*******************Step 1 Definitions****************/
82         $scope.displayOptions={
83                         hideFormFields:false,
84                         hideChart:false,
85                         hideReportData:false,
86                         hideExcel:false,
87                         hidePdf:false
88         }
89         $scope.reportIdURL = $routeParams.reportId;
90         $scope.definitionData={};
91         $scope.definitionData.displayOptions=[
92                 {name:'HideFormFields', selected:false},
93                 {name:'HideChart', selected:false},
94                 {name:'HideReportData', selected:false},
95                 {name:'HideExcel', selected:false},
96                 {name:'HidePdf', selected:false}
97         ]
98         
99 /*      $scope.definitionData.dbSrcOptions=[
100                 {text:'local', value:'local', selected:true},
101                 {text:'e911dev_leto07', value:'e911dev_leto07', selected:false},
102         ]*/
103         
104         $scope.pageSizeValues=['10','25','50','100','500'];
105         $scope.pageSizeOptions =[];
106         $scope.dbSrcOptions =[];
107         $scope.maxRowValues = ['500','1000','2000','3000','4000','5000','10000','15000','20000','25000','30000','35000','40000','45000','50000','65000']
108         $scope.maxRowOptions =[];
109         $scope.frozenColValues = ['0','1','2','3','4'];
110         $scope.frozenColOptions =[];
111         $scope.dataGridAlignValues = ['Left','Right','Center'];
112         $scope.dataGridAlignOptions =[];
113         $scope.dataContainerValues = ['10','20','30','40','50','60','70','80','90','100','110','120','130','140','150','160','170','180','190','200'];
114         $scope.dataContainerOptions =[];
115         $scope.runTimeFormNumValues = ['1','2','3','4'];
116         $scope.runTimeFormNumOptions =[];
117         /******create*****/
118         if(!$scope.isEdit){
119                 $scope.definitionData.reportType = 'Linear';
120                 //$scope.definitionData.dbInfo = 'Local';
121                 //$scope.definitionData.dbSrcOptions = ['Local'];
122         }
123         /****end create***/
124         
125         /*functions*/
126         $scope.getDefinitionById = function(id) {
127                 $scope.showLoader=true;
128                 raptorReportFactory.getDefinitionByReportId(id).then(function(data){
129                         $scope.showLoader=false;
130                         $scope.definitionData = data;
131                         $scope.definitionData.dbSrc=data.dbInfo;
132                         $scope.definitionData.dbSrcOptions = data.dbInfoList;
133                         console.log($scope.definitionData.dbSrcOptions[0].name);
134
135                         $scope.showLoader = false;
136                         for(x in data.displayOptions){
137                                 if(data.displayOptions[x].name=='HideFormFields')
138                                         $scope.displayOptions.hideFormFields = data.displayOptions[x].selected;
139                                 else if(data.displayOptions[x].name=='HideChart')
140                                         $scope.displayOptions.hideChart = data.displayOptions[x].selected;
141                                 else if(data.displayOptions[x].name=='HideReportData')
142                                         $scope.displayOptions.hideReportData = data.displayOptions[x].selected;
143                                 else if(data.displayOptions[x].name=='HideExcel')
144                                         $scope.displayOptions.hideExcel = data.displayOptions[x].selected;
145                                 else if(data.displayOptions[x].name=='HidePdf')
146                                         $scope.displayOptions.hidePdf = data.displayOptions[x].selected;
147                         }
148                         
149                         $scope.definitionData.frozenColumns = $scope.definitionData.frozenColumns+'';
150                         $scope.definitionData.numFormCols = $scope.definitionData.numFormCols+'';
151                         $scope.definitionData.allowScheduler = data.allowScheduler=='Y'?true:false;
152                         $scope.definitionData.sizedByContent = data.sizedByContent=='Y'?true:false;
153                         
154                         $scope.definitionData.oneTimeRec = data.oneTimeRec=='Y'?true:false;
155                         $scope.definitionData.hourlyRec = data.hourlyRec=='Y'?true:false;
156                         $scope.definitionData.dailyRec = data.dailyRec=='Y'?true:false;
157                         $scope.definitionData.dailyMFRec = data.dailyMFRec=='Y'?true:false;
158                         $scope.definitionData.weeklyRec = data.weeklyRec=='Y'?true:false;
159                         $scope.definitionData.monthlyRec = data.monthlyRec=='Y'?true:false;
160                         
161                         if($scope.definitionData.reportTitle==null || $scope.definitionData.reportTitle=='')
162                                 $scope.definitionData.reportTitle = $scope.definitionData.reportName;
163                 },function(error){
164                         $scope.errorPopUp(error);
165                         $log.error("raptorReportFactory: getDefinitionById failed.");
166                         $scope.showLoader = false;
167                 });
168         }
169
170         $scope.constructureDefDropDown = function(){
171
172                 for(i in $scope.pageSizeValues){
173                         var v = {
174                                 value :$scope.pageSizeValues[i],
175                                 text :$scope.pageSizeValues[i]
176                         }
177                         $scope.pageSizeOptions.push(v);
178                 }
179                 for(i in $scope.maxRowValues){
180                         var v = {
181                                 value :$scope.maxRowValues[i],
182                                 text :$scope.maxRowValues[i]
183                         }
184                         $scope.maxRowOptions.push(v);
185                 }
186                 for(i in $scope.frozenColValues){
187                         var v = {
188                                 value :$scope.frozenColValues[i]+'',
189                                 text :$scope.frozenColValues[i]
190                         }
191                         $scope.frozenColOptions.push(v);
192                 }
193                 for(i in $scope.dataGridAlignValues){
194                         var v = {
195                                 value :$scope.dataGridAlignValues[i].toLowerCase(),
196                                 text :$scope.dataGridAlignValues[i]
197                         }
198                         $scope.dataGridAlignOptions.push(v);
199                 }
200                 for(i in $scope.dataContainerValues){
201                         var v = {
202                                 value :$scope.dataContainerValues[i],
203                                 text :$scope.dataContainerValues[i]
204                         }
205                         $scope.dataContainerOptions.push(v);
206                 }
207                 for(i in $scope.runTimeFormNumValues){
208                         var v = {
209                                 value :$scope.runTimeFormNumValues[i],
210                                 text :$scope.runTimeFormNumValues[i]
211                         }
212                         $scope.runTimeFormNumOptions.push(v);
213                 }
214         }
215
216         $scope.constructDef = function(){
217                 var data =Object.assign({}, $scope.definitionData);
218                 if($scope.definitionData.dbSrc){
219                         console.log("Hello World ", $scope.definitionData.dbSrc);
220                         data.dbInfo = $scope.definitionData.dbSrc;
221                 }
222                 for(x in $scope.definitionData.displayOptions){
223                         if($scope.definitionData.displayOptions[x].name=='HideFormFields')
224                                 data.displayOptions[x].selected = $scope.displayOptions.hideFormFields
225                         else if($scope.definitionData.displayOptions[x].name=='HideChart')
226                                 data.displayOptions[x].selected = $scope.displayOptions.hideChart
227                         else if($scope.definitionData.displayOptions[x].name=='HideReportData')
228                                 data.displayOptions[x].selected = $scope.displayOptions.hideReportData
229                         else if($scope.definitionData.displayOptions[x].name=='HideExcel')
230                                 data.displayOptions[x].selected = $scope.displayOptions.hideExcel
231                         else if($scope.definitionData.displayOptions[x].name=='HidePdf')
232                                 data.displayOptions[x].selected = $scope.displayOptions.hidePdf
233                 }
234                 if(data.pageSize==null || data.pageSize.startsWith("Select"))
235                         data.pageSize = null;
236                 if(data.maxRowsInExcelCSVDownload==null || data.maxRowsInExcelCSVDownload.startsWith("Select"))
237                         data.maxRowsInExcelCSVDownload = null;
238                 if(data.frozenColumns==null || data.frozenColumns.startsWith("Select"))
239                         data.frozenColumns = null;
240                 if(data.dataGridAlign==null || data.dataGridAlign.startsWith("Select"))
241                         data.dataGridAlign = null;
242                 if(data.dataContainerHeight==null || data.dataContainerHeight.startsWith("Select"))
243                         data.dataContainerHeight = null;
244                 if(data.dataContainerWidth ==null || data.dataContainerWidth.startsWith("Select"))
245                         data.dataContainerWidth = null;
246                 if(data.numFormCols ==null || data.numFormCols.startsWith("Select"))
247                         data.numFormCols = null;
248                 
249                 if(!$scope.isEdit)
250                         data.reportId=-1;
251                 if(data.reportTitle==null || data.reportTitle=='')
252                         data.reportTitle = data.reportName;
253                 return data;
254         }
255         $scope.updateDef = function(){
256                 $scope.showLoader=true;
257                 var dataToSave = $scope.constructDef();
258                 raptorReportFactory.updateDefinition(dataToSave,$scope.isEdit).then(function(data){
259                         $scope.successPopUp('Definition is updated');
260                         for(x in $scope.stepTabs){
261                                 $scope.stepTabs[x].disabled=false;
262                         }
263                         $scope.showLoader=false;
264                         if(isCopy){
265                                 var newReportId = data.anyStacktrace.split("-")[0];
266                                 if(newReportId!=null && newReportId!='' && newReportId!=-1)
267                                         $window.location.href = "#/report_wizard/"+newReportId;
268                         }
269                 },function(error){
270                         $scope.errorPopUp(error);
271                         $log.error("report-step-controller: updateDefinition by Id failed.");
272                 });
273         }
274         /*******************Step1 Ends****************/
275         /*******************Step2 SQL****************/
276         $scope.pageisCreating = false;
277         $scope.sqlScript={
278                         value:''
279         };
280         $scope.sqlTestTableData='';
281         /*function*/
282         $scope.getSql = function(){
283                 $scope.showLoader = true;
284                 raptorReportFactory.getSqlInSession().then(function(data){
285                         $scope.sqlInSessionJSON = data;
286                         $scope.sqlScript.value = data.query;
287                         $scope.showLoader = false;
288                 },function(error){
289                         $scope.errorPopUp(error);
290                         $log.error("raptorReportFactory: getSearchData failed.");
291                 });
292         }
293         $scope.testRunSql = function(){
294                 $scope.showLoader=true;
295                 var queryJSON = {query: $scope.sqlScript.value};
296                 queryJSON = JSON.stringify(queryJSON);
297                 raptorReportFactory.testRunSQL(queryJSON).then(function(data){
298                         $scope.showLoader=false;
299                         var modalInstance = $modal.open({
300                                 scope: $scope,
301                                 animation: $scope.animationsEnabled,
302                                 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html',
303                                 windowClass:'modal-docked',
304                                 sizeClass: 'modal-large',
305                                 controller: testRunSqlController,
306                                 resolve:{
307                                         queriedData: function(){
308                                                 return data;
309                                         }
310                                 }
311                         });
312                         
313                         modalInstance.result.finally(function () {      
314                                 if(!$scope.isEdit){
315                                         $scope.showLoader=true;
316                                         $scope.pageisCreating = true;
317                                         $scope.pageMsg = 'Please wait while we are creating the report. Page will be reloaded after the creation is done.'
318                                         raptorReportFactory.getDefinitionInSession().then(function(data){
319                                                 var newReportId = data.reportId;
320                                                 if(newReportId!=null && newReportId!='' && newReportId!=-1)
321                                                         $window.location.href = "#/report_wizard/"+newReportId;
322                                                 
323                                                 $scope.showLoader = false;
324                                                 $scope.pageisCreating = false;
325                                         },function(error){
326                                                 $scope.errorPopUp(error);
327                                                 $log.error("raptorReportFactory: get Definition In Session failed.");
328                                                 $scope.showLoader = false;
329                                         });             
330                                 }                               
331                         });
332
333                 },function(error){
334                         $scope.errorPopUp(error);
335                         $log.error("raptorReportFactory: test run SQL failed.");
336                 });             
337         }
338         
339         /*******************Step2 End****************/
340         /*******************Step3 Column****************/
341         $scope.colTableRowData='';
342         $scope.isEditCol= true;
343         
344         $scope.getColumn = function(){
345                 $scope.showLoader = true;
346                 raptorReportFactory.getColumnList().then(function(data){
347                         $scope.colTableRowData = data;
348                         $scope.showLoader = false;
349                 },function(error){
350                         $scope.errorPopUp(error);
351                         $log.error("raptorReportFactory: get column list failed.");           
352                 });     
353         }
354                 
355         $scope.openColumnPopup = function (rowData) {
356                 var modalInstance = $modal.open({
357                         scope: $scope,
358                         animation: $scope.animationsEnabled,
359                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html',
360                         windowClass:'modal-docked',
361                         sizeClass: 'modal-jumbo',
362                         controller: openColumnPopupController,
363                         resolve:{
364                                 colData: function(){
365                                         return rowData;
366                                 }
367                         }
368                 });
369                 modalInstance.result.finally(function () {
370                         $scope.getColumn();
371                 });
372         };
373
374         /*******************Step3 End****************/
375         /*******************Step4 Starts Form Fields****************/
376         
377         $scope.dataProcessing = false;
378         $scope.formFieldData = [];
379         $scope.getFormFieldList = function(){
380                 $scope.showLoader= true;
381                 $scope.formFieldData = [];
382                 raptorReportFactory.getFormFieldList().then(function(data){
383                         $scope.showLoader= false;
384                         $scope.formFieldData = data;
385                         $scope.formFieldData.sort(function(obj1, obj2) {
386                                 // Ascending: first age less than the previous
387                                 return obj1.orderSeq - obj2.orderSeq;
388                         });
389
390                         $scope.showLoader = false;
391                 },function(error){
392                         $scope.errorPopUp(error);
393                         $log.error("raptorReportFactory: get formfields failed."); 
394                         $scope.showLoader = false;
395                 });
396         }
397         
398         $scope.formFieldReOrder = function(upID, downID){
399                 
400                 $scope.moveUpFF={};
401                 $scope.moveDownFF={};
402                 $scope.showLoader=true;
403                 raptorReportFactory.getFormFieldEditInfoById(upID).then(function(data){
404                         $scope.moveUpFF = data;
405                         raptorReportFactory.getFormFieldEditInfoById(downID).then(function(data){
406                                 $scope.moveDownFF = data;
407                                 var downOrder = $scope.moveDownFF.orderSeq;
408                                 $scope.moveDownFF.orderSeq = $scope.moveUpFF.orderSeq;
409                                 $scope.moveUpFF.orderSeq = downOrder;
410                                 raptorReportFactory.saveFormFieldEditInfo($scope.moveDownFF).then(function(data){
411                                         raptorReportFactory.saveFormFieldEditInfo($scope.moveUpFF).then(function(data){
412                                                 $scope.successPopUp('');
413                                         },function(error){
414                                                 $scope.errorPopUp(error);
415                                                 $log.error("raptorReportFactory: saveFormFieldEditInfo failed.");
416                                         }).finally(function() {
417                                                 $scope.showLoader=false; 
418                                                 $scope.getFormFieldList();
419                                         })
420                                 },function(error){
421                                         $scope.errorPopUp(error);
422                                         $log.error("raptorReportFactory: saveFormFieldEditInfo failed.");
423                                 });             
424                                 
425                         },function(error){
426                                 $scope.errorPopUp(error);
427                                 $log.error("raptorReportFactory: getColumnEditInfoById failed.");
428                         });     
429                 },function(error){
430                         $scope.errorPopUp(error);
431                         $log.error("raptorReportFactory: getColumnEditInfoById failed.");
432                 })
433                 
434                 
435         }
436         
437         $scope.formFieldVerifySQL= function(sqlScript){
438                 var queryJSON = {query: sqlScript};
439                 queryJSON = JSON.stringify(queryJSON);
440                 raptorReportFactory.formFieldVerifySQL(queryJSON).then(function(data){
441                         var modalInstance = $modal.open({
442                                 scope: $scope,
443                                 animation: $scope.animationsEnabled,
444                                 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html',
445                                 sizeClass: 'modal-large',
446                                 controller: formFieldVerifySQLController,
447                                 resolve:{
448                                         queriedData: function(){
449                                                 return data;
450                                         }
451                                 }
452                         })                      
453
454                 },function(error){
455                         $scope.errorPopUp(error);
456                         $log.error("raptorReportFactory: test run SQL failed.");
457                 });             
458         }
459         
460         
461         $scope.openFormFieldPopup = function (rowData,type) {   
462                 $scope.type= type;
463                 var modalInstance = $modal.open({
464                         scope: $scope,
465                         animation: true,
466                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html',
467                         sizeClass: 'modal-large',
468                         controller: openFormFieldPopupController,
469                         resolve:{
470                                 fieldData: function(){
471                                         return rowData;
472                                 }
473                         }
474                 });
475
476                 modalInstance.result.finally(function () {
477                         $scope.getFormFieldList();
478                 });
479         };
480         $scope.addFormField = function(){
481                 $scope.openFormFieldPopup('','add');
482         }
483         
484
485         $scope.deleteFormField = function(rowData) {            
486                 var modalInstance = $modal.open({
487                         scope: $scope,
488                         animation: $scope.animationsEnabled,
489                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html',
490                         sizeClass: 'modal-small',
491                         controller: deleteFormFieldController,
492                         resolve:{
493                                 rowData: function(){
494                                         return rowData;
495                                 }
496                         }
497                 });
498                 modalInstance.result.then(function () {
499                         $scope.getFormFieldList();
500                 }, function () {
501                 });             
502         }
503
504         /*******************Step4 End****************/
505         /*******************Step5 Starts Security****************/
506         $scope.ynOptions = [
507                 {value:"true", text:"Yes"},
508                 {value:"false", text:"No"}                                                       
509         ];
510         $scope.addReportUserId={
511                         id:''
512         };
513         $scope.addReportRoleId={
514                         id:''
515         };
516         $scope.loadSecurityPage = function() {
517                 $scope.showLoader = true;
518                 raptorReportFactory.resetSecurityLoadingCounter();
519
520                 //API call 1:
521                 raptorReportFactory.getSecurityReportOwnerList().then(function(data){
522                         $scope.reportOwnerList = data;
523                         raptorReportFactory.icrementSecurityLoadingCounter();
524                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
525                 },function(error){
526                         $scope.errorPopUp(error);
527                         $log.error("raptorReportFactory: getSecurityReportOwnerList failed."); 
528                 });
529
530                 //API call 2: get report role list
531                 raptorReportFactory.getReportRoleList().then(function(data){
532                         $scope.reportRoleList = data;
533                         raptorReportFactory.icrementSecurityLoadingCounter();
534                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
535                 },function(error){
536                         $scope.errorPopUp(error);
537                         $log.error("raptorReportFactory: getReportRoleList failed."); 
538                 });     
539
540                 //API call 3: get security page basic info
541                 raptorReportFactory.getReportSecurityInfo().then(function(data){
542                         $scope.reportSecurityInfo = data;
543                         $scope.reportOwnerId ={id: $scope.reportSecurityInfo.ownerId};          
544                         raptorReportFactory.icrementSecurityLoadingCounter();
545                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
546                 },function(error){
547                         $scope.errorPopUp(error);
548                         $log.error("raptorReportFactory: getReportSecurityInfo failed."); 
549                         $scope.showLoader = false;});
550
551                 //API call 4: retrieve security users
552                 raptorReportFactory.getReportSecurityUsers().then(function(data){
553
554                         $scope.reportSecurityUsers = data;
555                         for (var i=0; i<$scope.reportSecurityUsers.length;i++) {
556                                 $scope.reportSecurityUsers[i]["accessAllowed"] = !$scope.reportSecurityUsers[i]["readOnly"];
557                                 $scope.reportSecurityUsers[i].runAccess = true; // need to check why 1702 version is making it true always
558                         }
559                         raptorReportFactory.icrementSecurityLoadingCounter();
560                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
561                 },function(error){
562                         $scope.errorPopUp(error);
563                         $log.error("raptorReportFactory: reportSecurityUsers failed."); 
564                 });
565
566                 //API call 5: retrieve security roles
567                 raptorReportFactory.getReportSecurityRoles().then(function(data){
568                         $scope.reportSecurityRoles = data;
569                         for (var i=0; i<$scope.reportSecurityRoles.length;i++) {
570                                 $scope.reportSecurityRoles[i]["accessAllowed"] = !$scope.reportSecurityRoles[i]["readOnly"];
571                                 $scope.reportSecurityRoles[i].runAccess = true; // need to check why 1702 version is making it true always
572                         }
573
574                         raptorReportFactory.icrementSecurityLoadingCounter();
575                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};                      
576                 },function(error){
577                         $scope.errorPopUp(error);
578                         $log.error("raptorReportFactory: reportSecurityRoles failed."); 
579                 });             
580         }
581         $scope.addReportSecurityUser = function(userId) {       
582                 $scope.showLoader=true; 
583                 raptorReportFactory.addReportSecurityUser(userId).then(function(data){
584                         $scope.loadSecurityPage();
585                 },function(error){
586                         $scope.errorPopUp(error);
587                         $log.error("raptorReportFactory: addReportSecurityUser failed.");
588                 }).finally(function() {
589                         $scope.showLoader=false; 
590                 });
591         }
592
593         $scope.removeReportSecurityUser = function(securityUser) {
594                 var modalInstance = $modal.open({
595                         scope: $scope,
596                         animation: $scope.animationsEnabled,
597                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html',
598                         sizeClass: 'modal-small',
599                         controller: removeReportSecurityUserController,
600                         resolve:{
601                                 securityUser: function(){
602                                         return securityUser;
603                                 }
604                         }
605                 });
606                 modalInstance.result.then(function () {
607                         $scope.loadSecurityPage();
608                 }, function () {
609                 });
610         };      
611         $scope.addReportSecurityRole = function(roleId) {       
612                 raptorReportFactory.addReportSecurityRole(roleId).then(function(data){
613                         $scope.loadSecurityPage();
614                 },function(error){
615                         $scope.errorPopUp(error);
616                         $log.error("raptorReportFactory: addReportSecurityRole failed.");
617                 });     
618         }       
619
620         
621         $scope.removeReportSecurityRole = function(securityRole) {
622                 var modalInstance = $modal.open({
623                         scope: $scope,
624                         animation: $scope.animationsEnabled,
625                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html',
626                         sizeClass: 'modal-small',
627                         controller: removeReportSecurityRoleController,
628                         resolve:{
629                                 securityRole: function(){
630                                         return securityRole;
631                                 }
632                         }
633                 });
634                 modalInstance.result.then(function () {
635                         $scope.loadSecurityPage();
636                 }, function () {
637                 });
638         }                       
639
640         $scope.saveReportSecurityInfo = function() {
641                 $scope.showLoader = true;
642                 var securityInfo = {'userId':$scope.reportSecurityInfo.ownerId+"",'isPublic':$scope.reportSecurityInfo.isPublic};
643                 raptorReportFactory.updateReportSecurityInfo(securityInfo).then(function(data){
644                         $scope.successPopUp('');
645                         $scope.loadSecurityPage();
646                 },function(error){
647                         $scope.errorPopUp(error);
648                         $log.error("raptorReportFactory: updateReportSecurityInfo failed.");
649                 });     
650         };
651         
652         $scope.toggleUserEditAccessActive = function(rowData) {
653                 var modalInstance = $modal.open({
654                         scope: $scope,
655                         animation: $scope.animationsEnabled,
656                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html',
657                         sizeClass: 'modal-small',
658                         controller: toggleUserEditAccessActiveController,
659                         resolve:{
660                                 rowData: function(){
661                                         return rowData;
662                                 }
663                         }
664                 });     
665         }
666
667         $scope.toggleRoleEditAccessActive = function(rowData) {
668                 var modalInstance = $modal.open({
669                         scope: $scope,
670                         animation: $scope.animationsEnabled,
671                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html',
672                         sizeClass: 'modal-small',
673                         controller: toggleRoleEditAccessActiveController,
674                         resolve:{
675                                 rowData: function(){
676                                         return rowData;
677                                 }
678                         }
679                 });
680         }
681         
682         /*******************Step5 End****************/
683         /*******************Step6 Starts****************/
684         $scope.logs = [];
685         $scope.getReportID = function(){
686                 $scope.showLoader = true;
687                 raptorReportFactory.getReportLogs($routeParams.reportId).then(function(data){
688                         $scope.logs = data;
689                         $scope.showLoader = false;
690                         
691                 },function(error){
692                         $scope.errorPopUp(error);
693                         $log.error("raptorReportFactory: getReportID failed."+ error);  
694                 });
695         }
696                         
697         
698         /*******************Step6 End****************/
699         /*******************Step7 Starts Run****************/
700         $scope.loadDefinitionInSession = function(){
701                 $scope.showLoader = true;
702                 raptorReportFactory.getDefinitionInSession().then(function(data){
703                         $scope.reportId = data.reportId;
704                         $scope.showLoader = false;
705                 },function(error){
706                         $scope.errorPopUp(error);
707                         $log.error("raptorReportFactory: getDefinitionInSession failed."); 
708                         $scope.showLoader = false;
709                 });
710         }
711         $scope.runReport = function(){
712                 $window.location.href = "#/report_run/c_master="+$scope.reportId+"&refresh=Y";
713         }
714         /*******************Step7 End****************/
715         
716         /********************Init*************/
717         $scope.init = function(){
718                 if ($routeParams.reportMode=="copy") {
719                         $scope.isCopy = true;
720                         raptorReportFactory.copyReportById($routeParams.reportId).then(function(data){
721                                 $scope.isEdit = true;
722                                 $scope.reportId = -1;                           
723                                 $scope.getDefinitionById(-1);
724                         },function(error){
725                                 $log.error("raptorReportFactory: deleteFormFieldById failed.");
726                         });                                                                                                     
727                 } /*else if ($routeParams.reportMode=="import") {
728                         $scope.$emit('RefreshInsession');
729                 }*/
730                 
731                 
732                 if($scope.activeTabsId=='definition'){ /*Step 1*/
733                         $scope.constructureDefDropDown();               
734                         if($scope.isEdit)
735                                 $scope.getDefinitionById($scope.reportIdURL); //edit
736                         else
737                                 $scope.getDefinitionById(-1); //create
738                 }else if($scope.activeTabsId=='sql'){ /*Step 2*/
739                         $scope.getSql();
740                 }else if($scope.activeTabsId=='columns'){
741                         $scope.getColumn();
742                 }else if($scope.activeTabsId=='formFields'){
743                         $scope.getFormFieldList();
744                 }else if($scope.activeTabsId=='security'){
745                         $scope.loadSecurityPage();
746                 }else if($scope.activeTabsId=='log'){
747                         $scope.getReportID();
748                 }else if($scope.activeTabsId=='run'){
749                         $scope.reportId = $scope.reportIdURL;
750                         if($scope.reportId==null || $scope.reportId=='')
751                                 $scope.loadDefinitionInSession();
752                 }
753         }
754         
755         $scope.successPopUp = function (msg) {
756         var modalInstance = $modal.open({
757                         templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html',
758                         controller: ModalInstanceCtrl,
759                         sizeClass: 'modal-small',
760                         resolve: {
761                                 msg: function () {
762                                         var message = {
763                                                 title:    '',
764                                 text:     msg
765                         };
766                                         return message;                                 
767                 }
768                 }
769                 });
770     };
771     
772     $scope.errorPopUp = function (msg) {
773         var modalInstance = $modal.open({
774                         templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html',
775                         controller: ModalInstanceCtrl,
776                         sizeClass: 'modal-small',
777                         resolve: {
778                                 msg: function () {
779                                         return msg;                                     
780                 }
781                 }
782                 });
783     };
784     
785         $scope.init();
786 });