Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / raptor / ebz / report_search.js
1 app.controller("reportSearchController", ['$scope','$rootScope','$http','$timeout',function ($scope,$rootScope,$http,$timeout) { 
2     
3         $http.get('raptor.htm?action=report.search.execute&r_page=0').then(
4                 function(result){$scope.searchdData = result.data;                
5         });
6           
7         $scope.runReport = function(){
8                         var searchParams = '';
9                         if($scope.reportId && $scope.reportId!=''){
10                                 searchParams = '&rep_id='+$scope.reportId+'&rep_id_options='+$scope.operatorRepId.index;
11                         }
12                         if($scope.reportName && $scope.reportName!=''){
13                                 searchParams = searchParams+'&rep_name='+$scope.reportName+'&rep_name_options='+$scope.operatorRepName.index;
14                         }
15
16                         console.log('raptor.htm?action=report.search.execute&r_page='+(paginationOptions.pageNumber-1)+searchParams);
17                         $http.get('raptor.htm?action=report.search.execute&r_page='+(paginationOptions.pageNumber-1)+searchParams).then(
18                                         function(result){$scope.searchdData = result.data;                
19                                 });
20                         //quantum/raptor.htm?action=report.search.execute&rep_id=1000&rep_id_options=2&rep_name=cross&rep_name_options=2
21         };
22
23
24         var paginationOptions = {
25                     pageNumber: 1,
26                     pageSize: 5,
27                     sort: null
28         };
29           
30         $scope.gridOptions = {
31           paginationPageSizes: [5],
32           paginationPageSize: 5,
33           useExternalPagination: true,
34           columnDefs: [],
35           data: [],
36           enableGridMenu: true,
37           enableSelectAll: true,
38           exporterMenuPdf: false,
39           exporterMenuCsv: false,
40           exporterCsvFilename: 'myFile.csv',
41           exporterPdfDefaultStyle: {fontSize: 9},
42           exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
43           exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
44           exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
45           exporterPdfFooter: function ( currentPage, pageCount ) {
46             return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
47           },
48           exporterPdfCustomFormatter: function ( docDefinition ) {
49             docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
50             docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
51             return docDefinition;
52           },
53           exporterPdfOrientation: 'portrait',
54           exporterPdfPageSize: 'LETTER',
55           exporterPdfMaxGridWidth: 500,
56           exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
57           onRegisterApi: function(gridApi) {
58                     $scope.gridApi = gridApi;
59                     gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
60                               paginationOptions.pageNumber = newPage;
61                               paginationOptions.pageSize = pageSize;
62                               $scope.runReport();
63                             });
64                           }
65                         };
66
67
68         var getPage = function() {
69                 $scope.gridOptions.columnDefs = [];
70                 $scope.searchdData.columns[0].forEach(function(entry) {
71                         if(entry.columnTitle=='Run'){
72                                 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId+'==drillDownLink', enableSorting: false,
73                                 cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="#/report_run/{{COL_FIELD.substr(39)}}" class="ion-arrow-right-b" style="font-size:20px;"></a></div>'
74                                 });
75                         } else if(entry.columnTitle=='Edit'){
76                                 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId+'==drillDownLink', enableSorting: false,
77                                         cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="{{COL_FIELD}}" class="ion-edit" style="font-size:20px;"></a></div>'
78                                 });
79                         } else if(entry.columnTitle=='Delete'){
80                                 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId+'==drillDownLink', enableSorting: false,
81                                         cellTemplate: '<div class="ui-grid-cell-contents"><a href=""  ng-click="grid.appScope.deleteReport(COL_FIELD,row)" class="ion-trash-b" style="font-size:20px;"></a></div>'
82                                 });
83                         }  else if(entry.columnTitle=='Copy'){
84                                 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId+'==drillDownLink', enableSorting: false,
85                                         cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="{{COL_FIELD}}" class="ion-document-text" style="font-size:20px;"></a></div>'
86                                 });
87                         } else if(entry.columnTitle=='Schedule'){
88                                 //$scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId+'==drillDownLink',
89                                         //  cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="{{COL_FIELD}}" class="full-linear-icon-calendar" style="font-size:20px;font-weight: bold;"></a></div>'
90                                 //});
91                         } else if(entry.columnTitle=='No'){
92                         } else {
93                                         $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId+'==displayValue'});
94                         }
95                 });
96                 $scope.gridOptions.data = $scope.searchdData.rows[0];
97                 $scope.gridOptions.paginationPageSizes= [$scope.searchdData.metaReport.pageSize];
98                 $scope.gridOptions.paginationPageSize= $scope.searchdData.metaReport.pageSize;
99                 $scope.gridOptions.totalItems = $scope.searchdData.metaReport.totalSize;
100         };
101
102         $scope.$watch("searchdData",function(newValue,oldValue) {
103                 if($scope.searchdData){
104                         getPage();
105                 }
106         });
107
108         $scope.operatorsRepId = [{index: 0, value: 'Equal To', title: 'Equal To', alias:'Equal To'},
109                          {index: 1, value: 'Less Than', title: 'Less Than', alias:'Less Than'},
110                          {index: 2, value: 'Greater Than', title: 'Greater Than', alias:'Greater Than'}];
111         $scope.operatorsRepName = [{index: 0, value: 'Starts With', title: 'Starts With', alias:'Starts With'},
112                         {index:1, value: 'Ends With', title: 'Ends With', alias:'Ends With'},
113                         {index: 2, value: 'Contains', title: 'Contains', alias:'Contains'}];
114         
115         $scope.deleteReport = function(reportDeleteUrl,row) {
116                 if (confirm("Please confirm: Are you sure you want to delete report #" + reportDeleteUrl.substr(41) + "?")) {
117                         $http.get(reportDeleteUrl).then(
118                                         function(result){
119                                                 if(result.data=='deleted:true'){
120                                                         var index = $scope.gridOptions.data.indexOf(row.entity);
121                                                         $scope.gridOptions.data.splice(index, 1);
122                                                         alert("Report deleted.");
123                                                 } else {
124                                                         alert("Report not deleted.");
125                                                 }
126                                         }
127                                 );
128                 }
129         };
130
131         $timeout(function() {
132                 $rootScope.isViewRendering = false;
133                 });
134
135
136 }]);