43f877c349ac775481f1e0762e68755d1f905569
[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.isDefReady = $scope.isEdit;
6         $scope.activeTabsId = 'definition';
7         $scope.pageMsg =''
8         $scope.stepNum = 0;
9         $scope.stepTabs=[
10                  {
11              title: 'Definition',
12              id: 'definition',
13              uniqueId: 'uniqueStep1',
14              tabPanelId: 'definitionTab',
15              disabled: false
16              
17          }, {
18              title: 'SQL',
19              id: 'sql',
20              uniqueId: 'uniqueStep2',
21              tabPanelId: 'sqlTab',
22              disabled: (!$scope.isDefReady)
23          }, {
24              title: 'Columns',
25              id: 'columns',
26              uniqueId: 'uniqueTab3x',
27              tabPanelId: 'columnsTab',
28              disabled: (!$scope.isDefReady)
29          }, {
30              title: 'Form Fields',
31              id: 'formFields',
32              uniqueId: 'uniqueTab4x',
33              tabPanelId: 'formFieldsTab',
34              disabled: (!$scope.isDefReady)
35          }, {
36              title: 'Security',
37              id: 'security',
38              uniqueId: 'uniqueTab5x',
39              tabPanelId: 'securityTab',
40              disabled: (!$scope.isDefReady)
41          }, {
42              title: 'Log',
43              id: 'log',
44              uniqueId: 'uniqueTab6x',
45              tabPanelId: 'logTab',
46              disabled: (!$scope.isDefReady)
47          }, {
48              title: 'Run',
49              id: 'run',
50              uniqueId: 'uniqueTab7x',
51              tabPanelId: 'runTab',
52              disabled: (!$scope.isDefReady)
53          }
54          
55         ];
56         $scope.$watch('activeTabsId', function (newVal, oldVal) {
57                 if(newVal !== oldVal) {
58                         $scope.init();
59                 }
60         });      
61
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);
68     }
69          $scope.next = function(){
70                 $scope.stepNum = $scope.stepNum +1;
71         $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id;
72     };   
73             
74             
75     $scope.previous = function(){
76                 $scope.stepNum = $scope.stepNum -1;
77         $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id;       
78         }
79         
80         /*******************Step 1 Definitions****************/
81         $scope.displayOptions={
82                         hideFormFields:false,
83                         hideChart:false,
84                         hideReportData:false,
85                         hideExcel:false,
86                         hidePdf:false
87         }
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}
96         ]
97         
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 =[];
110         /******create*****/
111         if(!$scope.isEdit){
112                 $scope.definitionData.reportType = 'Linear';
113                 $scope.definitionData.dbInfo = 'Local';
114         }
115         /****end create***/
116         
117         /*functions*/
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;
135                         }
136                         
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;
141                         
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;
148                         
149                         if($scope.definitionData.reportTitle==null || $scope.definitionData.reportTitle=='')
150                                 $scope.definitionData.reportTitle = $scope.definitionData.reportName;
151                 },function(error){
152                         $scope.errorPopUp(error);
153                         $log.error("raptorReportFactory: getDefinitionById failed.");
154                         $scope.showLoader = false;
155                 });
156         }
157
158         $scope.constructureDefDropDown = function(){
159                 for(i in $scope.pageSizeValues){
160                         var v = {
161                                 value :$scope.pageSizeValues[i],
162                                 text :$scope.pageSizeValues[i]
163                         }
164                         $scope.pageSizeOptions.push(v);
165                 }
166                 for(i in $scope.maxRowValues){
167                         var v = {
168                                 value :$scope.maxRowValues[i],
169                                 text :$scope.maxRowValues[i]
170                         }
171                         $scope.maxRowOptions.push(v);
172                 }
173                 for(i in $scope.frozenColValues){
174                         var v = {
175                                 value :$scope.frozenColValues[i]+'',
176                                 text :$scope.frozenColValues[i]
177                         }
178                         $scope.frozenColOptions.push(v);
179                 }
180                 for(i in $scope.dataGridAlignValues){
181                         var v = {
182                                 value :$scope.dataGridAlignValues[i].toLowerCase(),
183                                 text :$scope.dataGridAlignValues[i]
184                         }
185                         $scope.dataGridAlignOptions.push(v);
186                 }
187                 for(i in $scope.dataContainerValues){
188                         var v = {
189                                 value :$scope.dataContainerValues[i],
190                                 text :$scope.dataContainerValues[i]
191                         }
192                         $scope.dataContainerOptions.push(v);
193                 }
194                 for(i in $scope.runTimeFormNumValues){
195                         var v = {
196                                 value :$scope.runTimeFormNumValues[i],
197                                 text :$scope.runTimeFormNumValues[i]
198                         }
199                         $scope.runTimeFormNumOptions.push(v);
200                 }
201         }
202
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
216                 }
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;
231                 
232                 if(!$scope.isEdit)
233                         data.reportId=-1;
234                 if(data.reportTitle==null || data.reportTitle=='')
235                         data.reportTitle = data.reportName;
236                 return data;
237         }
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;
245                         }
246                         $scope.showLoader=false;
247                 },function(error){
248                         $scope.errorPopUp(error);
249                         $log.error("report-step-controller: updateDefinition by Id failed.");
250                 });
251         }
252         /*******************Step1 Ends****************/
253         /*******************Step2 SQL****************/
254         $scope.pageisCreating = false;
255         $scope.sqlScript={
256                         value:''
257         };
258         $scope.sqlTestTableData='';
259         /*function*/
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;
266                 },function(error){
267                         $scope.errorPopUp(error);
268                         $log.error("raptorReportFactory: getSearchData failed.");
269                 });
270         }
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({
278                                 scope: $scope,
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,
284                                 resolve:{
285                                         queriedData: function(){
286                                                 return data;
287                                         }
288                                 }
289                         });
290                         
291                         modalInstance.result.finally(function () {      
292                                 if(!$scope.isEdit){
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;
300                                                 
301                                                 $scope.showLoader = false;
302                                                 $scope.pageisCreating = false;
303                                         },function(error){
304                                                 $scope.errorPopUp(error);
305                                                 $log.error("raptorReportFactory: get Definition In Session failed.");
306                                                 $scope.showLoader = false;
307                                         });             
308                                 }                               
309                         });
310
311                 },function(error){
312                         $scope.errorPopUp(error);
313                         $log.error("raptorReportFactory: test run SQL failed.");
314                 });             
315         }
316         
317         /*******************Step2 End****************/
318         /*******************Step3 Column****************/
319         $scope.colTableRowData='';
320         $scope.isEditCol= true;
321         
322         $scope.getColumn = function(){
323                 $scope.showLoader = true;
324                 raptorReportFactory.getColumnList().then(function(data){
325                         $scope.colTableRowData = data;
326                         $scope.showLoader = false;
327                 },function(error){
328                         $scope.errorPopUp(error);
329                         $log.error("raptorReportFactory: get column list failed.");           
330                 });     
331         }
332                 
333         $scope.openColumnPopup = function (rowData) {
334                 var modalInstance = $modal.open({
335                         scope: $scope,
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,
341                         resolve:{
342                                 colData: function(){
343                                         return rowData;
344                                 }
345                         }
346                 });
347                 modalInstance.result.finally(function () {
348                         $scope.getColumn();
349                 });
350         };
351
352         /*******************Step3 End****************/
353         /*******************Step4 Starts Form Fields****************/
354         
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;
366                         });
367
368                         $scope.showLoader = false;
369                 },function(error){
370                         $scope.errorPopUp(error);
371                         $log.error("raptorReportFactory: get formfields failed."); 
372                         $scope.showLoader = false;
373                 });
374         }
375         
376         $scope.formFieldReOrder = function(upID, downID){
377                 
378                 $scope.moveUpFF={};
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('');
391                                         },function(error){
392                                                 $scope.errorPopUp(error);
393                                                 $log.error("raptorReportFactory: saveFormFieldEditInfo failed.");
394                                         }).finally(function() {
395                                                 $scope.showLoader=false; 
396                                                 $scope.getFormFieldList();
397                                         })
398                                 },function(error){
399                                         $scope.errorPopUp(error);
400                                         $log.error("raptorReportFactory: saveFormFieldEditInfo failed.");
401                                 });             
402                                 
403                         },function(error){
404                                 $scope.errorPopUp(error);
405                                 $log.error("raptorReportFactory: getColumnEditInfoById failed.");
406                         });     
407                 },function(error){
408                         $scope.errorPopUp(error);
409                         $log.error("raptorReportFactory: getColumnEditInfoById failed.");
410                 })
411                 
412                 
413         }
414         
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({
420                                 scope: $scope,
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,
425                                 resolve:{
426                                         queriedData: function(){
427                                                 return data;
428                                         }
429                                 }
430                         })                      
431
432                 },function(error){
433                         $scope.errorPopUp(error);
434                         $log.error("raptorReportFactory: test run SQL failed.");
435                 });             
436         }
437         
438         
439         $scope.openFormFieldPopup = function (rowData,type) {   
440                 $scope.type= type;
441                 var modalInstance = $modal.open({
442                         scope: $scope,
443                         animation: true,
444                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html',
445                         sizeClass: 'modal-large',
446                         controller: openFormFieldPopupController,
447                         resolve:{
448                                 fieldData: function(){
449                                         return rowData;
450                                 }
451                         }
452                 });
453
454                 modalInstance.result.finally(function () {
455                         $scope.getFormFieldList();
456                 });
457         };
458         $scope.addFormField = function(){
459                 $scope.openFormFieldPopup('','add');
460         }
461         
462
463         $scope.deleteFormField = function(rowData) {            
464                 var modalInstance = $modal.open({
465                         scope: $scope,
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,
470                         resolve:{
471                                 rowData: function(){
472                                         return rowData;
473                                 }
474                         }
475                 });
476                 modalInstance.result.then(function () {
477                         $scope.getFormFieldList();
478                 }, function () {
479                 });             
480         }
481
482         /*******************Step4 End****************/
483         /*******************Step5 Starts Security****************/
484         $scope.ynOptions = [
485                 {value:"true", text:"Yes"},
486                 {value:"false", text:"No"}                                                       
487         ];
488         $scope.addReportUserId={
489                         id:''
490         };
491         $scope.addReportRoleId={
492                         id:''
493         };
494         $scope.loadSecurityPage = function() {
495                 $scope.showLoader = true;
496                 raptorReportFactory.resetSecurityLoadingCounter();
497
498                 //API call 1:
499                 raptorReportFactory.getSecurityReportOwnerList().then(function(data){
500                         $scope.reportOwnerList = data;
501                         raptorReportFactory.icrementSecurityLoadingCounter();
502                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
503                 },function(error){
504                         $scope.errorPopUp(error);
505                         $log.error("raptorReportFactory: getSecurityReportOwnerList failed."); 
506                 });
507
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;};
513                 },function(error){
514                         $scope.errorPopUp(error);
515                         $log.error("raptorReportFactory: getReportRoleList failed."); 
516                 });     
517
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;};
524                 },function(error){
525                         $scope.errorPopUp(error);
526                         $log.error("raptorReportFactory: getReportSecurityInfo failed."); 
527                         $scope.showLoader = false;});
528
529                 //API call 4: retrieve security users
530                 raptorReportFactory.getReportSecurityUsers().then(function(data){
531
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
536                         }
537                         raptorReportFactory.icrementSecurityLoadingCounter();
538                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};
539                 },function(error){
540                         $scope.errorPopUp(error);
541                         $log.error("raptorReportFactory: reportSecurityUsers failed."); 
542                 });
543
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
550                         }
551
552                         raptorReportFactory.icrementSecurityLoadingCounter();
553                         if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;};                      
554                 },function(error){
555                         $scope.errorPopUp(error);
556                         $log.error("raptorReportFactory: reportSecurityRoles failed."); 
557                 });             
558         }
559         $scope.addReportSecurityUser = function(userId) {       
560                 $scope.showLoader=true; 
561                 raptorReportFactory.addReportSecurityUser(userId).then(function(data){
562                         $scope.loadSecurityPage();
563                 },function(error){
564                         $scope.errorPopUp(error);
565                         $log.error("raptorReportFactory: addReportSecurityUser failed.");
566                 }).finally(function() {
567                         $scope.showLoader=false; 
568                 });
569         }
570
571         $scope.removeReportSecurityUser = function(securityUser) {
572                 var modalInstance = $modal.open({
573                         scope: $scope,
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,
578                         resolve:{
579                                 securityUser: function(){
580                                         return securityUser;
581                                 }
582                         }
583                 });
584                 modalInstance.result.then(function () {
585                         $scope.loadSecurityPage();
586                 }, function () {
587                 });
588         };      
589         $scope.addReportSecurityRole = function(roleId) {       
590                 raptorReportFactory.addReportSecurityRole(roleId).then(function(data){
591                         $scope.loadSecurityPage();
592                 },function(error){
593                         $scope.errorPopUp(error);
594                         $log.error("raptorReportFactory: addReportSecurityRole failed.");
595                 });     
596         }       
597
598         
599         $scope.removeReportSecurityRole = function(securityRole) {
600                 var modalInstance = $modal.open({
601                         scope: $scope,
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,
606                         resolve:{
607                                 securityRole: function(){
608                                         return securityRole;
609                                 }
610                         }
611                 });
612                 modalInstance.result.then(function () {
613                         $scope.loadSecurityPage();
614                 }, function () {
615                 });
616         }                       
617
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();
624                 },function(error){
625                         $scope.errorPopUp(error);
626                         $log.error("raptorReportFactory: updateReportSecurityInfo failed.");
627                 });     
628         };
629         
630         $scope.toggleUserEditAccessActive = function(rowData) {
631                 var modalInstance = $modal.open({
632                         scope: $scope,
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,
637                         resolve:{
638                                 rowData: function(){
639                                         return rowData;
640                                 }
641                         }
642                 });     
643         }
644
645         $scope.toggleRoleEditAccessActive = function(rowData) {
646                 var modalInstance = $modal.open({
647                         scope: $scope,
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,
652                         resolve:{
653                                 rowData: function(){
654                                         return rowData;
655                                 }
656                         }
657                 });
658         }
659         
660         /*******************Step5 End****************/
661         /*******************Step6 Starts****************/
662         $scope.logs = [];
663         $scope.getReportID = function(){
664                 $scope.showLoader = true;
665                 raptorReportFactory.getReportLogs($routeParams.reportId).then(function(data){
666                         $scope.logs = data;
667                         $scope.showLoader = false;
668                         
669                 },function(error){
670                         $scope.errorPopUp(error);
671                         $log.error("raptorReportFactory: getReportID failed."+ error);  
672                 });
673         }
674                         
675         
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;
683                 },function(error){
684                         $scope.errorPopUp(error);
685                         $log.error("raptorReportFactory: getDefinitionInSession failed."); 
686                         $scope.showLoader = false;
687                 });
688         }
689         $scope.runReport = function(){
690                 $window.location.href = "#/report_run/c_master="+$scope.reportId+"&refresh=Y";
691         }
692         /*******************Step7 End****************/
693         
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);
701                         },function(error){
702                                 $log.error("raptorReportFactory: deleteFormFieldById failed.");
703                         });                                                                                                     
704                 } /*else if ($routeParams.reportMode=="import") {
705                         $scope.$emit('RefreshInsession');
706                 }*/
707                 
708                 
709                 if($scope.activeTabsId=='definition'){ /*Step 1*/
710                         $scope.constructureDefDropDown();               
711                         if($scope.isEdit)
712                                 $scope.getDefinitionById($scope.reportIdURL); //edit
713                         else
714                                 $scope.getDefinitionById(-1); //create
715                 }else if($scope.activeTabsId=='sql'){ /*Step 2*/
716                         $scope.getSql();
717                 }else if($scope.activeTabsId=='columns'){
718                         $scope.getColumn();
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();
729                 }
730         }
731         
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',
737                         resolve: {
738                                 msg: function () {
739                                         var message = {
740                                                 title:    '',
741                                 text:     msg
742                         };
743                                         return message;                                 
744                 }
745                 }
746                 });
747     };
748     
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',
754                         resolve: {
755                                 msg: function () {
756                                         return msg;                                     
757                 }
758                 }
759                 });
760     };
761     
762         $scope.init();
763 });