[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / dictionaryGridController / BRMSParamDictGridController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP 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                         exporterFieldCallback: function(grid, row, col, input) {
79                                 if( col.name == 'createdDate' || col.name == 'modifiedDate') {
80                                         var date = new Date(input);
81                                         return date.toString("yyyy-MM-dd HH:MM:ss a");
82                                 } else {
83                                         return input;
84                                 }
85                         },
86                         exporterPdfOrientation: 'portrait',
87                         exporterPdfPageSize: 'LETTER',
88                         exporterPdfMaxGridWidth: 500,
89                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
90                         onRegisterApi: function(gridApi){
91                                 $scope.gridApi = gridApi;
92                         }
93         };
94
95         $scope.editBRMSParam = null;
96         $scope.createNewBRMSParamWindow = function(){
97                 $scope.editBRMSParam = null;
98                 var modalInstance = $modal.open({
99                         backdrop: 'static', keyboard: false,
100                         templateUrl : 'add_brmsParam_popup.html',
101                         controller: 'editBRMSParamController',
102                         resolve: {
103                                 message: function () {
104                                         var message = {
105                                                         brmsParamDictionaryDatas: $scope.editBRMSParam
106                                         };
107                                         return message;
108                                 }
109                         }
110                 });
111                 modalInstance.result.then(function(response){
112                         console.log('response', response);
113                         $scope.brmsParamDictionaryDatas=response.brmsParamDictionaryDatas;
114                 });
115         };
116
117         $scope.deleteBRMSParam = function(data) {
118                 var uuu = "searchDictionary";
119                 var postData={data: data, type: "brmsParam"};
120                 var searchString = "\n";
121                 $.ajax({
122                         type : 'POST',
123                         url : uuu,
124                         dataType: 'json',
125                         contentType: 'application/json',
126                         data: JSON.stringify(postData),
127                         success : function(resultList){
128                                 $scope.$apply(function(){
129                                         $scope.list =resultList.result;});
130                                 $scope.searchData = JSON.stringify(resultList.result);
131                                 $scope.searchDatas = JSON.parse($scope.searchData);        
132                                 $scope.success = true;
133                                 var i;
134                                 if($scope.searchDatas.length > 0){
135                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
136                                                 searchString += $scope.searchDatas[i] + "\n";
137                                         }       
138                                 }else{
139                                         searchString += "No Policies is Using this Value"
140                                 }
141
142                                 console.log($scope.list);
143                                 if($scope.success){
144                                         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?",
145                                                         function(){
146                                                 var uuu = "deleteDictionary/brms_dictionary/remove_brmsParam";
147                                                 var postData={data: data};
148                                                 $.ajax({
149                                                         type : 'POST',
150                                                         url : uuu,
151                                                         dataType: 'json',
152                                                         contentType: 'application/json',
153                                                         data: JSON.stringify(postData),
154                                                         success : function(data){
155                                                                 $scope.$apply(function(){$scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;});
156                                                         },
157                                                         error : function(data){
158                                                                 console.log(data);
159                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
160                                                         }
161                                                 });
162
163                                         })}
164                         },
165                         error : function(data){
166                                 alert("Error while Searching.");
167                         }
168                 });
169         };
170
171 });