83c051dba6f1d29145d0205bd2392e24f9d2cd3a
[portal/sdk.git] /
1 appDS2.factory('raptorReportFactory', function($http, $q) {
2         return {
3                 getDefinitionByReportId: function(reportId) {
4                         return $http({
5                                 method: "GET",
6                 url: "report/wizard/retrieve_def_tab_wise_data/"+reportId,                      
7                         }).then(function(response) {
8                                 if (typeof response.data === 'object') {
9                                         return response.data;
10                                 } else {
11                                         return $q.reject("raptorReportFactory: getDefinitionByReportId did not return a valid JSON object.");
12                                 }
13                         }, function(response) {
14                                 // something went wrong
15                                 return $q.reject("raptorReportFactory: getDefinitionByReportId callback failed");
16                         });                     
17                 },                      
18                 getDefinitionByReportId: function(reportId) {
19                         return $http({
20                                 method: "GET",
21                 url: "report/wizard/retrieve_def_tab_wise_data/"+reportId,                      
22                         }).then(function(response) {
23                                 if (typeof response.data === 'object') {
24                                         return response.data;
25                                 } else {
26                                         return $q.reject("raptorReportFactory: getDefinitionByReportId did not return a valid JSON object.");
27                                 }
28                         }, function(response) {
29                                 // something went wrong
30                                 return $q.reject("raptorReportFactory: getDefinitionByReportId callback failed");
31                         });                     
32                 },      
33                 getDefinitionInSession: function() {
34                         return $http({
35                                 method: "GET",
36                 url: "report/wizard/retrieve_def_tab_wise_data/InSession",                      
37                         }).then(function(response) {
38                                 if (typeof response.data === 'object') {
39                                         return response.data;
40                                 } else {
41                                         return $q.reject("raptorReportFactory: getDefinitionInSession did not return a valid JSON object.");
42                                 }
43                         }, function(response) {
44                                 // something went wrong
45                                 return $q.reject("raptorReportFactory: getDefinitionInSession callback failed");
46                         });                     
47                 },                              
48
49                 createNewDefinition: function() {
50                         return $http({
51                                 method: "GET",
52                 url: "report/wizard/retrieve_def_tab_wise_data/Create",                 
53                         }).then(function(response) {
54                                 if (typeof response.data === 'object') {
55                                         return response.data;
56                                 } else {
57                                         return $q.reject("raptorReportFactory: createNewDefinition did not return a valid JSON object.");
58                                 }
59                         }, function(response) {
60                                 // something went wrong
61                                 return $q.reject("raptorReportFactory: createNewDefinition callback failed");
62                         });                     
63                 },
64                 updateDefinition: function(updatedJson,isUpdate) {
65                         return $http({
66                                 method: "POST",
67                 url: (isUpdate?("report/wizard/save_def_tab_data/"+updatedJson.reportId):"report/wizard/save_def_tab_data/Create"),
68                 data: updatedJson                       
69                         }).then(function(response) {
70                                 if (typeof response.data === 'object') {
71                                         return response.data;
72                                 } else {
73                                         return $q.reject("raptorReportFactory: updateDefinition did not return a valid JSON object.");
74                                 }
75                                 return response.data;
76                         }, function(response) {
77                                 // something went wrong
78                                 return $q.reject("raptorReportFactory: updateDefinition callback failed");
79                         });
80                 },
81                 saveNewDefinition: function(updatedJson) {
82                         return $http({
83                                 method: "POST",
84                 url: "report/wizard/save_def_tab_data/InSession",
85                 data: updatedJson                       
86                         }).then(function(response) {
87                                 if (typeof response.data === 'object') {
88                                         return response.data;
89                                 } else {
90                                         return $q.reject("raptorReportFactory: saveNewDefinition did not return a valid JSON object.");
91                                 }
92                         }, function(response) {
93                                 // something went wrong
94                                 return $q.reject("raptorReportFactory: saveNewDefinition callback failed");
95                         });
96                 },              
97                 getSqlInSession: function() {
98                         return $http({
99                                 method: "GET",
100                 url: "report/wizard/retrieve_sql_tab_wise_data/InSession",                      
101                         }).then(function(response) {
102                                 if (typeof response.data === 'object') {
103                                         return response.data;
104                                 } else {
105                                         return $q.reject("raptorReportFactory: getSqlInSession did not return a valid JSON object.");
106                                 }
107                         }, function(response) {
108                                 // something went wrong
109                                 return $q.reject("raptorReportFactory: getSqlInSession callback failed");
110                         });                     
111                 },              
112                 testRunSQL: function(queryJSON) {
113                         return $http({
114                                 method: "POST",
115                 url: "report/wizard/retrieve_data/true",
116                 data: queryJSON                 
117                         }).then(function(response) {
118                                 if (typeof response.data === 'object') {                                        
119                                         return JSON.parse(response.data.data.elements);
120                                 } else {
121                                         return $q.reject("raptorReportFactory: testRunSQL did not return a valid JSON object.");
122                                 }
123                                 return response.data;
124                         }, function(response) {
125                                 // something went wrong
126                                 return $q.reject("raptorReportFactory: testRunSQL callback failed");
127                         });
128                 },              
129                 formFieldVerifySQL: function(queryJSON) {
130                         return $http({
131                                 method: "POST",
132                 url: "report/wizard/retrieve_data/false",
133                 data: queryJSON                 
134                         }).then(function(response) {
135                                 if (typeof response.data === 'object') {
136                                         return JSON.parse(response.data.data.elements);
137                                 } else {
138                                         return $q.reject("raptorReportFactory: formFieldVerifySQL did not return a valid JSON object.");
139                                 }
140                                 return response.data;
141                         }, function(response) {
142                                 // something went wrong
143                                 return $q.reject("raptorReportFactory: formFieldVerifySQL callback failed");                            
144                         });
145                 },
146                 getColumnList: function() {
147                         return $http({
148                                 method: "GET",
149                 url: "report/wizard/list_columns",
150                         }).then(function(response) {
151                                 if (typeof response.data === 'object') {
152                                         return response.data;
153                                 } else {
154                                         return $q.reject("raptorReportFactory: getColumnList did not return a valid JSON object.");
155                                 }
156                                 return response.data;
157                         }, function(response) {
158                                 // something went wrong
159                                 return $q.reject("raptorReportFactory: getColumnList callback failed");                         
160                         });
161                 },
162                 getDrillDownReportList: function() {
163                         return $http({
164                                 method: "GET",
165                 url: "report/wizard/list_drilldown_reports",
166                         }).then(function(response) {
167                                 if (typeof response.data === 'object') {
168                                         return response.data;
169                                 } else {
170                                         return $q.reject("raptorReportFactory: getDrillDownReportList did not return a valid JSON object.");
171                                 }
172                                 return response.data;
173                         }, function(response) {
174                                 // something went wrong
175                                 return $q.reject("raptorReportFactory: getDrillDownReportList callback failed");                                
176                         });
177                 },
178                 getChildReportFormField: function(reportId) {
179                         return $http({
180                                 method: "GET",
181                 url: "report/wizard/list_child_report_ff/"+reportId,
182                         }).then(function(response) {
183                                 if (typeof response.data === 'object') {
184                                         return response.data;
185                                 } else {
186                                         return $q.reject("raptorReportFactory: getDrillDownReportList did not return a valid JSON object.");
187                                 }
188                                 return response.data;
189                         }, function(response) {
190                                 // something went wrong
191                                 return $q.reject("raptorReportFactory: getDrillDownReportList callback failed");                                
192                         });
193                 },              
194                 getChildReportColumn: function(reportId) {
195                         return $http({
196                                 method: "GET",
197                 url: "report/wizard/list_child_report_col/"+reportId,
198                         }).then(function(response) {
199                                 if (typeof response.data === 'object') {
200                                         return response.data;
201                                 } else {
202                                         return $q.reject("raptorReportFactory: getChildReportColumn did not return a valid JSON object.");
203                                 }
204                                 return response.data;
205                         }, function(response) {
206                                 // something went wrong
207                                 return $q.reject("raptorReportFactory: getChildReportColumn callback failed");                          
208                         });
209                 },              
210                 getColumnEditInfoById: function(columnId){
211                         return $http({
212                                 method: "GET",
213                 url: "report/wizard/retrieve_col_tab_wise_data/"+columnId,
214                         }).then(function(response) {
215                                 if (typeof response.data === 'object') {
216                                         return response.data;
217                                 } else {
218                                         return $q.reject("raptorReportFactory: getColumnEditInfoById did not return a valid JSON object.");
219                                 }
220                         }, function(response) {
221                                 // something went wrong
222                                 return $q.reject("raptorReportFactory:  getColumnEditInfoById callback failed");                                
223                         });                     
224                 },
225                 saveColumnEditInfo: function(updatedColumnJson){
226                         return $http({
227                                 method: "POST",
228                 url: "report/wizard/save_col_tab_data",
229                 data: updatedColumnJson
230                         }).then(function(response) {
231                                 if (typeof response.data === 'object') {
232                                         return response.data;
233                                 } else {
234                                         return $q.reject("raptorReportFactory: saveColumnEditInfo did not return a valid JSON object.");
235                                 }
236                         }, function(response) {
237                                 // something went wrong
238                                 return $q.reject("raptorReportFactory: saveColumnEditInfo callback failed");
239                         });                     
240                 },              
241                 postImportXml: function(importXMLJSON){
242                         return $http({
243                                 method: "POST",
244                 url: "report/wizard/import_report",
245                 data: importXMLJSON
246                         }).then(function(response) {
247                                 if (typeof response.data === 'object') {
248                                         return response.data;
249                                 } else {
250                                         return $q.reject("raptorReportFactory: importXml did not return a valid JSON object.");
251                                 }
252                         }, function(response) {
253                                 // something went wrong
254                                 return $q.reject("raptorReportFactory: importXml callback failed");
255                         });                     
256                 },
257                 copyReportById: function(reportId) {
258                         return $http({
259                                 method: "GET",
260                 url: "report/wizard/copy_report/"+reportId,                     
261                         }).then(function(response) {
262                                 if (typeof response.data === 'object') {
263                                         return response.data;
264                                 } else {
265                                         return $q.reject("raptorReportFactory: copyReportById did not return a valid JSON object.");
266                                 }
267                         }, function(response) {
268                                 // something went wrong
269                                 return $q.reject("raptorReportFactory: copyReportById callback failed");
270                         });                     
271                 },                              
272                 saveFormFieldEditInfo: function(updatedFormFieldJson){
273                         return $http({
274                                 method: "POST",
275                 url: "report/wizard/save_formfield_tab_data",
276                 data: updatedFormFieldJson
277                         }).then(function(response) {
278                                 if (typeof response.data === 'object') {
279                                         return response.data;
280                                 } else {
281                                         return $q.reject("raptorReportFactory: saveFormFieldEditInfo did not return a valid JSON object.");
282                                 }
283                         }, function(response) {
284                                 // something went wrong
285                                 return $q.reject("raptorReportFactory: saveFormFieldEditInfo callback failed");
286                         });                     
287                 },
288                 getFormFieldList: function() {
289                         return $http({
290                                 method: "GET",
291                 url: "report/wizard/list_formfields",                   
292                         }).then(function(response) {
293                                 if (typeof response.data === 'object') {
294                                         return response.data;
295                                 } else {
296                                         return $q.reject("raptorReportFactory: getFormFieldList did not return a valid JSON object.");
297                                 }
298                         }, function(response) {
299                                 // something went wrong
300                                 return $q.reject("raptorReportFactory: getFormFieldList callback failed");                              
301                         });                     
302                 },
303                 getFormFieldEditInfoById: function(fieldId){
304                         return $http({
305                                 method: "GET",
306                 url: "report/wizard/retrieve_form_tab_wise_data/"+fieldId,
307                         }).then(function(response) {
308                                 if (typeof response.data === 'object') {
309                                         return response.data;
310                                 } else {
311                                         return $q.reject("raptorReportFactory: getColumnEditInfoById did not return a valid JSON object.");
312                                 }
313                                 return response.data;
314                         }, function(response) {
315                                 // something went wrong
316                                 return $q.reject("raptorReportFactory: getFormFieldEditInfoById callback failed");                              
317                         });                     
318                 },              
319                 deleteFormFieldById: function(fieldId){
320                         return $http({
321                                 method: "GET",
322                 url: "report/wizard/retrieve_form_tab_wise_data/"+fieldId+"/delete",
323                         }).then(function(response) {
324                                 if (typeof response.data === 'object') {
325                                         return response.data;
326                                 } else {
327                                         return $q.reject("raptorReportFactory: deleteFormFieldById did not return a valid JSON object.");
328                                 }
329                                 return response.data;
330                         }, function(response) {
331                                 // something went wrong
332                                 return $q.reject("raptorReportFactory: deleteFormFieldById callback failed");                           
333                         });                     
334                 },              
335                 getColumns: function() {
336                         return $http
337                                         .get('raptor.htm?action=report.search.execute&r_page=0')
338                                         .then(function(response) {
339                                                 if (typeof response.data === 'object') {
340                                                         return response.data;
341                                                 } else {
342                                                         return $q.reject("raptorReportFactory: getColumns did not return a valid JSON object.");
343                                                 }
344                                         }, function(response) {
345                                                 // something went wrong
346                                                 return $q.reject("raptorReportFactory: getColumns callback failed");                            
347                                         });
348                 },
349                 
350                 getSearchData : function() {
351                         return $http
352                                         .get('raptor.htm?action=report.search.execute&r_page=0')
353                                         .then(function(response) {
354                                                 if (typeof response.data === 'object') {
355                                                         return response.data;
356                                                 } else {
357                                                         return $q.reject("raptorReportFactory: getSearchData did not return a valid JSON object.");
358                                                 }
359                                         }, function(response) {
360                                                 // something went wrong
361                                                 return $q.reject("raptorReportFactory: getSearchData callback failed");                         
362                                         });
363                 },
364                 
365                 getSecurityReportOwnerList: function() {
366                         return $http
367                                         .get('report/wizard/security/retrieveReportOwner')
368                                         .then(function(response) {
369                                                 if (typeof response.data === 'object') {
370                                                         return response.data;
371                                                 } else {
372                                                         return $q.reject("raptorReportFactory: getSecurityReportOwnerList did not return a valid JSON object.");
373                                                 }
374                                         }, function(response) {
375                                                 // something went wrong
376                                                 return $q.reject("raptorReportFactory: getSecurityReportOwnerList callback failed");                            
377                                         });
378                 },
379                 getReportRoleList: function() {
380                         return $http
381                                         .get('report/wizard/security/retrieveReportRoleList')
382                                         .then(function(response) {
383                                                 if (typeof response.data === 'object') {
384                                                         return response.data;
385                                                 } else {
386                                                         return $q.reject("raptorReportFactory: getReportRoleList did not return a valid JSON object.");
387                                                 }
388                                         }, function(response) {
389                                                 // something went wrong
390                                                 return $q.reject("raptorReportFactory: getReportRoleList callback failed");                             
391                                         });
392                 },
393                 getReportSecurityInfo: function() {
394                         return $http
395                                         .get('report/wizard/security/getReportSecurityInfo')
396                                         .then(function(response) {
397                                                 if (typeof response.data === 'object') {
398                                                         return response.data;
399                                                 } else {
400                                                         return $q.reject("raptorReportFactory: getReportSecurityInfo did not return a valid JSON object.");
401                                                 }
402                                         }, function(response) {
403                                                 // something went wrong
404                                                 return $q.reject("raptorReportFactory: getReportSecurityInfo callback failed");                         
405                                         });
406                 },
407                 getReportSecurityUsers: function() {
408                         return $http
409                                         .get('report/wizard/security/retrieveReportUserList')
410                                         .then(function(response) {
411                                                 if (typeof response.data === 'object') {
412                                                         return response.data;
413                                                 } else {
414                                                         return $q.reject("raptorReportFactory: getReportSecurityUsers did not return a valid JSON object.");
415                                                 }
416                                         }, function(response) {
417                                                 // something went wrong
418                                                 return $q.reject("raptorReportFactory: getReportSecurityUsers callback failed");                                
419                                         });
420                 },              
421                 
422                 getReportSecurityRoles: function() {
423                         return $http
424                                         .get('report/wizard/security/getReportSecurityRoles')
425                                         .then(function(response) {
426                                                 if (typeof response.data === 'object') {
427                                                         return response.data;
428                                                 } else {
429                                                         return $q.reject("raptorReportFactory: getReportSecurityUsers did not return a valid JSON object.");
430                                                 }
431                                         }, function(response) {
432                                                 // something went wrong
433                                                 return $q.reject("raptorReportFactory: getReportSecurityUsers callback failed");                                
434                                         });
435                 },              
436                                 
437                 
438                 getSearchDataAtPage : function(pageSearchParameter) {
439                         return $http
440                                         .get('raptor.htm?action=report.search.execute&r_page='+pageSearchParameter)
441                                         .then(function(response) {
442                                                 if (typeof response.data === 'object') {
443                                                         return response.data;
444                                                 } else {
445                                                         return $q.reject("raptorReportFactory: getSearchDataAtPage did not return a valid JSON object.");
446                                                 }
447                                         }, function(response) {
448                                                 // something went wrong
449                                                 return $q.reject("raptorReportFactory: getSearchDataAtPage callback failed");                           
450                                         });
451                 },
452                 setDrillDownPopupOptions: function(drillDownURL,drillDownParams) {
453                         this.drillDownURL = drillDownURL;
454                         this.drillDownParams = drillDownParams;
455                 },      
456                 getReportDeleteStatus : function(deleteUrl) {
457                         return $http.get(deleteUrl).then(function(response) {
458                                 if (typeof response.data === 'object') {
459                                         return response.data;
460                                 } else {
461                                         return $q.reject("raptorReportFactory: getReportDeleteStatus did not return a valid JSON object.");
462                                 }
463
464                         }, function(response) {
465                                 // something went wrong
466                                 return $q.reject("raptorReportFactory: getReportDeleteStatus callback failed");                         
467                         });
468                 },
469                 addReportSecurityUser: function(UserId) {
470                                 return $http({
471                                         method: "POST",
472                         url: "report/security/addReportUser",
473                         data: UserId                    
474                                 }).then(function(response) {
475                                         if (typeof response.data === 'object') {
476                                                 return response.data;
477                                         } else {
478                                                 return $q.reject("raptorReportFactory: addReportSecurityUser did not return a valid JSON object.");
479                                         }
480                                 }, function(response) {
481                                         // something went wrong
482                                         return $q.reject("raptorReportFactory: saveNewDefinition callback failed");
483                                 });
484                         },
485                         removeReportSecurityUser: function(UserId) {
486                                 return $http({
487                                         method: "POST",
488                         url: "report/security/removeReportUser",
489                         data: UserId                    
490                                 }).then(function(response) {
491                                         if (typeof response.data === 'object') {
492                                                 return response.data;
493                                         } else {
494                                                 return $q.reject("raptorReportFactory: removeReportSecurityUser did not return a valid JSON object.");
495                                         }
496                                 }, function(response) {
497                                         // something went wrong
498                                         return $q.reject("raptorReportFactory: saveNewDefinition callback failed");
499                                 });
500                         },
501                         addReportSecurityRole: function(RoleId) {
502                                 return $http({
503                                         method: "POST",
504                         url: "report/security/addReportRole",
505                         data: RoleId                    
506                                 }).then(function(response) {
507                                         if (typeof response.data === 'object') {
508                                                 return response.data;
509                                         } else {
510                                                 return $q.reject("raptorReportFactory: addReportSecurityRole did not return a valid JSON object.");
511                                         }
512                                 }, function(response) {
513                                         // something went wrong
514                                         return $q.reject("raptorReportFactory: saveNewDefinition callback failed");
515                                 });
516                         },
517                         removeReportSecurityRole: function(RoleId) {
518                                 return $http({
519                                         method: "POST",
520                         url: "report/security/removeReportRole",
521                         data: RoleId                    
522                                 }).then(function(response) {
523                                         if (typeof response.data === 'object') {
524                                                 return response.data;
525                                         } else {
526                                                 return $q.reject("raptorReportFactory: removeReportSecurityRole did not return a valid JSON object.");
527                                         }
528                                 }, function(response) {
529                                         // something went wrong
530                                         return $q.reject("raptorReportFactory: removeReportSecurityRole callback failed");
531                                 });
532                         },
533                         updateReportSecurityInfo: function(securityInfo) {
534                                 return $http({
535                                         method: "POST",
536                         url: "report/security/updateReportSecurityInfo",
537                         data: securityInfo                      
538                                 }).then(function(response) {
539                                         if (typeof response.data === 'object') {
540                                                 return response.data;
541                                         } else {
542                                                 return $q.reject("raptorReportFactory: updateReportSecurityInfo did not return a valid JSON object.");
543                                         }
544                                 }, function(response) {
545                                         // something went wrong
546                                         return $q.reject("raptorReportFactory: updateReportSecurityInfo callback failed");
547                                 });
548                         },
549
550                         toggleUserEditAccess: function(reportUser) {
551                                 var readOnly = reportUser.accessAllowed?"N":"Y"; 
552                                 return $http({
553                                         method: "POST",
554                         url:"report/security/toggleUserEditAccess/"+reportUser.id,
555                         data: readOnly                  
556                                 }).then(function(response) {
557                                         if (typeof response.data === 'object') {
558                                                 return response.data;
559                                         } else {
560                                                 return $q.reject("raptorReportFactory: toggleUserEditAccess did not return a valid JSON object.");
561                                         }
562                                 }, function(response) {
563                                         // something went wrong
564                                         return $q.reject("raptorReportFactory: toggleUserEditAccess callback failed");
565                                 });
566                         },
567                         toggleRoleEditAccess: function(reportRole) {
568                                 var readOnly = reportRole.accessAllowed?"N":"Y"; 
569                                 return $http({
570                                         method: "POST",
571                         url:"report/security/toggleRoleEditAccess/"+reportRole.id,
572                         data: readOnly                  
573                                 }).then(function(response) {
574                                         if (typeof response.data === 'object') {
575                                                 return response.data;
576                                         } else {
577                                                 return $q.reject("raptorReportFactory: toggleRoleEditAccess did not return a valid JSON object.");
578                                         }
579                                 }, function(response) {
580                                         // something went wrong
581                                         return $q.reject("raptorReportFactory: toggleRoleEditAccess callback failed");
582                                 });
583                         },                                              
584                         resetSecurityLoadingCounter: function() {
585                                 this.securityPageApiCounter = 0;
586                                 this.securityPageApiTotalCount = 5;
587                         },      
588                         icrementSecurityLoadingCounter: function() {
589                                 this.securityPageApiCounter = this.securityPageApiCounter+1;
590                         },
591                         checkSecurityLoadingCounter: function() {
592                                 return (this.securityPageApiCounter ==this.securityPageApiTotalCount);
593                         }
594         };
595 });