Fixed SonarIssues Alerts to Bootstrap Notification
[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, 2019 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, Notification){
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: 'rule', visible : false},
63                         {field: 'userCreatedBy.userName', displayName : 'Created By'},
64                         {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
65                         ],
66                         exporterMenuPdf: false,
67                         exporterPdfDefaultStyle: {fontSize: 9},
68                         exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
69                         exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
70                         exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
71                         exporterPdfFooter: function ( currentPage, pageCount ) {
72                                 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
73                         },
74                         exporterPdfCustomFormatter: function ( docDefinition ) {
75                                 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
76                                 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
77                                 return docDefinition;
78                         },
79                         exporterFieldCallback: function(grid, row, col, input) {
80                                 if( col.name == 'createdDate' || col.name == 'modifiedDate') {
81                                         var date = new Date(input);
82                                         return date.toString("yyyy-MM-dd HH:MM:ss a");
83                                 } else {
84                                         return input;
85                                 }
86                         },
87                         exporterPdfOrientation: 'portrait',
88                         exporterPdfPageSize: 'LETTER',
89                         exporterPdfMaxGridWidth: 500,
90                         exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
91                         onRegisterApi: function(gridApi){
92                                 $scope.gridApi = gridApi;
93                         }
94         };
95
96         $scope.editBRMSParam = null;
97         $scope.createNewBRMSParamWindow = function(){
98                 $scope.editBRMSParam = null;
99                 var modalInstance = $modal.open({
100                         backdrop: 'static', keyboard: false,
101                         templateUrl : 'add_brmsParam_popup.html',
102                         controller: 'editBRMSParamController',
103                         resolve: {
104                                 message: function () {
105                                         var message = {
106                                                         brmsParamDictionaryDatas: $scope.editBRMSParam
107                                         };
108                                         return message;
109                                 }
110                         }
111                 });
112                 modalInstance.result.then(function(response){
113                         console.log('response', response);
114                         $scope.brmsParamDictionaryDatas=response.brmsParamDictionaryDatas;
115                 });
116         };
117
118         $scope.deleteBRMSParam = function(data) {
119                 var uuu = "searchDictionary";
120                 var postData={data: data, type: "brmsParam"};
121                 var searchString = "\n";
122                 $.ajax({
123                         type : 'POST',
124                         url : uuu,
125                         dataType: 'json',
126                         contentType: 'application/json',
127                         data: JSON.stringify(postData),
128                         success : function(resultList){
129                                 $scope.$apply(function(){
130                                         $scope.list =resultList.result;});
131                                 $scope.searchData = JSON.stringify(resultList.result);
132                                 $scope.searchDatas = JSON.parse($scope.searchData);        
133                                 $scope.success = true;
134                                 var i;
135                                 if($scope.searchDatas.length > 0){
136                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
137                                                 searchString += $scope.searchDatas[i] + "\n";
138                                         }       
139                                 }else{
140                                         searchString += "No Policies is Using this Value"
141                                 }
142
143                                 console.log($scope.list);
144                                 if($scope.success){
145                                         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?",
146                                                         function(){
147                                                 var uuu = "deleteDictionary/brms_dictionary/remove_brmsParam";
148                                                 var postData={data: data};
149                                                 $.ajax({
150                                                         type : 'POST',
151                                                         url : uuu,
152                                                         dataType: 'json',
153                                                         contentType: 'application/json',
154                                                         data: JSON.stringify(postData),
155                                                         success : function(data){
156                                                                 $scope.$apply(function(){$scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;});
157                                                         },
158                                                         error : function(data){
159                                                                 console.log(data);
160                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
161                                                         }
162                                                 });
163
164                                         })}
165                         },
166                         error : function(data){
167                                 Notification.error("Error while Searching.");
168                         }
169                 });
170         };
171
172 });