Fixed the Policy API issues and Bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / BRMSParamDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 app.controller('brmsParamDictGridController', function ($scope, PolicyAppService,modalService, $modal){
21         $( "#dialog" ).hide();
22
23         PolicyAppService.getData('getDictionary/get_BRMSParamData').then(function (data) {
24                 var j = data;
25                 $scope.data = JSON.parse(j.data);
26                 console.log($scope.data);
27                 $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas);
28                 console.log($scope.brmsParamDictionaryDatas);
29         }, function (error) {
30                 console.log("failed");
31         });
32
33         PolicyAppService.getData('get_LockDownData').then(function(data){
34                 var j = data;
35                 $scope.data = JSON.parse(j.data);
36                 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
37                 if($scope.lockdowndata[0].lockdown == true){
38                         $scope.brmsParamDictionaryGrid.columnDefs[0].visible = false;
39                         $scope.gridApi.grid.refresh();
40                 }else{
41                         $scope.brmsParamDictionaryGrid.columnDefs[0].visible = true;
42                         $scope.gridApi.grid.refresh();
43                 }
44         },function(error){
45                 console.log("failed");
46         });
47
48         $scope.brmsParamDictionaryGrid = {
49                         data : 'brmsParamDictionaryDatas',
50                         enableFiltering: true,
51                         exporterCsvFilename: 'BRMSParamDictionary.csv',
52                         enableGridMenu: true,
53                         enableSelectAll: true,
54                         columnDefs: [{
55                                 field: 'id', enableFiltering: false, headerCellTemplate: '' +
56                                 '<button id=\'New\' ng-click="grid.appScope.createNewBRMSParamWindow()" class="btn btn-success">' + 'Create</button>',
57                                 cellTemplate:
58                                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteBRMSParam(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
59                         },
60                         { field: 'ruleName', displayName : 'Rule Name', sort: { direction: 'asc', priority: 0 }},
61                         { field: 'description'},
62                         {field: 'userCreatedBy.userName', displayName : 'Created By'},
63                         {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
64                         ],
65                         exporterMenuPdf: false,
66                         exporterPdfDefaultStyle: {fontSize: 9},
67                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
68                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
69                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
70                         exporterPdfFooter: function ( currentPage, pageCount ) {
71                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
72                         },
73                         exporterPdfCustomFormatter: function ( docDefinition ) {
74                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
75                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
76                                 return docDefinition;
77                         },
78                         exporterPdfOrientation: 'portrait',
79                         exporterPdfPageSize: 'LETTER',
80                         exporterPdfMaxGridWidth: 500,
81                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
82                         onRegisterApi: function(gridApi){
83                                 $scope.gridApi = gridApi;
84                         }
85         };
86
87         $scope.editBRMSParam = null;
88         $scope.createNewBRMSParamWindow = function(){
89                 $scope.editBRMSParam = null;
90                 var modalInstance = $modal.open({
91                         backdrop: 'static', keyboard: false,
92                         templateUrl : 'add_brmsParam_popup.html',
93                         controller: 'editBRMSParamController',
94                         resolve: {
95                                 message: function () {
96                                         var message = {
97                                                         brmsParamDictionaryDatas: $scope.editBRMSParam
98                                         };
99                                         return message;
100                                 }
101                         }
102                 });
103                 modalInstance.result.then(function(response){
104                         console.log('response', response);
105                         $scope.brmsParamDictionaryDatas=response.brmsParamDictionaryDatas;
106                 });
107         };
108
109         $scope.deleteBRMSParam = function(data) {
110                 var uuu = "searchDictionary";
111                 var postData={data: data, type: "brmsParam"};
112                 var searchString = "\n";
113                 $.ajax({
114                         type : 'POST',
115                         url : uuu,
116                         dataType: 'json',
117                         contentType: 'application/json',
118                         data: JSON.stringify(postData),
119                         success : function(resultList){
120                                 $scope.$apply(function(){
121                                         $scope.list =resultList.result;});
122                                 $scope.searchData = JSON.stringify(resultList.result);
123                                 $scope.searchDatas = JSON.parse($scope.searchData);        
124                                 $scope.success = true;
125                                 var i;
126                                 if($scope.searchDatas.length > 0){
127                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
128                                                 searchString += $scope.searchDatas[i] + "\n";
129                                         }       
130                                 }else{
131                                         searchString += "No Policies is Using this Value"
132                                 }
133
134                                 console.log($scope.list);
135                                 if($scope.success){
136                                         modalService.popupConfirmWin("Confirm","You are about to delete the BRMS Param Name:  "+data.ruleName+". \n used in the following policie(s)\n "+searchString+" \n Do you want to continue?",
137                                                         function(){
138                                                 var uuu = "deleteDictionary/brms_dictionary/remove_brmsParam";
139                                                 var postData={data: data};
140                                                 $.ajax({
141                                                         type : 'POST',
142                                                         url : uuu,
143                                                         dataType: 'json',
144                                                         contentType: 'application/json',
145                                                         data: JSON.stringify(postData),
146                                                         success : function(data){
147                                                                 $scope.$apply(function(){$scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;});
148                                                         },
149                                                         error : function(data){
150                                                                 console.log(data);
151                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
152                                                         }
153                                                 });
154
155                                         })}
156                         },
157                         error : function(data){
158                                 alert("Error while Searching.");
159                         }
160                 });
161         };
162
163 });