Included Policy GUI Enhancements and validations
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / pdpGroupPopUpController.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('editPDPGrouppopupController' ,  function ($scope, $modalInstance, message, modalService, $modal, Notification){
21         if(message.pdpGroupData==null){
22                 $scope.label='Add New PDP Group'
23         }else{
24                 $scope.label='Edit PDP Group'
25                         $scope.disableCd=true;
26                 $scope.policies = message.pdpGroupData.policies;
27                 $scope.pdps = message.pdpGroupData.pdps;
28                 $scope.selectedPdp = message.pdpGroupData;
29         }
30         
31         $scope.editPDPGroup = message.pdpGroupData;
32
33         $scope.policiesGrid = {
34                 data : 'policies',
35                 enableFiltering: true,
36                 columnDefs: [
37                         { field: 'root', displayName : 'Root', width : '10%'},
38                         { field: 'name', displayName : 'Name' },
39                         { field: 'version' , width : '10%'},
40                         { field: 'id' }
41                 ]
42         };
43
44         $scope.pdpsGrid = {
45                 data : 'pdps',
46                 enableFiltering: true,
47                 columnDefs: [{
48                         field: 'id', enableFiltering: false, headerCellTemplate: '' +
49                         '<button id=\'New\' ng-click="grid.appScope.createNewPDPInGroup()" class="btn btn-success">' + 'Create PDP</button>',
50                         cellTemplate:
51                         '<button  type="button"  class="btn btn-primary" ng-click="grid.appScope.editPDPInGroup(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
52                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deletePDPFromGroup(row.entity)" ><i class="fa fa-trash-o"></i></button> '+
53                         '<button  type="button"  class="btn btn-success" ng-click="grid.appScope.statusOfPDP(row.entity.status)" >Status</button>',  width: '25%'
54                 },
55                         { field: 'id', displayName : 'PDP URL'},
56                         { field: 'jmxPort', displayName : 'JMX Port' , width : '10%' },
57                         { field: 'name' , displayName : 'PDP Name'},
58                         { field: 'description' }
59                 ]
60         };
61
62         $scope.createNewPDPInGroup = function(pdpInGroup) {
63                 $scope.pdpInGroup = null;
64                 var modalInstance = $modal.open({
65                         backdrop: 'static', keyboard: false,
66                         templateUrl : 'create_newPDP_InGroup.html',
67                         controller: 'pdpInGroupController',
68                         resolve: {
69                                 message: function () {
70                                         var message = {
71                                                 data: $scope.pdpInGroup,
72                                                 activePDP : $scope.selectedPdp
73                                         };
74                                         return message;
75                                 }
76                         }
77                 });
78                 modalInstance.result.then(function(response){
79                         console.log('response', response);
80                         refreshPDPGroupDatas(response);
81                 });
82         };
83
84         $scope.editPDPInGroup = function(pdpInGroup) {
85                 $scope.editPDPInGroupData = pdpInGroup;
86                 var modalInstance = $modal.open({
87                         backdrop: 'static', keyboard: false,
88                         templateUrl: 'create_newPDP_InGroup.html',
89                         controller: 'pdpInGroupController',
90                         resolve: {
91                                 message: function () {
92                                         var message = {
93                                                 pdpInGroup : $scope.editPDPInGroupData,
94                                                 activePDP : $scope.selectedPdp
95                                         };
96                                         return message;
97                                 }
98                         }
99                 });
100                 modalInstance.result.then(function(response){
101                         console.log('response', response);
102                         refreshPDPGroupDatas(response);
103                 });
104         };
105
106         $scope.deletePDPFromGroup = function(data){
107                 modalService.popupConfirmWin("Confirm","You are about to delete the PDP Group :  "+data.name+". Do you want to continue?",
108                                 function(){
109                         var uuu = "pdp_Group/remove_pdpFromGroup.htm";
110                         var postData={data: data,
111                                         activePDP : $scope.selectedPdp};
112                         $.ajax({
113                                 type : 'POST',
114                                 url : uuu,
115                                 dataType: 'json',
116                                 contentType: 'application/json',
117                                 data: JSON.stringify(postData),
118                                 success : function(data){
119                                         $scope.$apply(function(){
120                                                 refreshPDPGroupDatas(data);
121                                         });
122                                         Notification.success("PDP Group Deleted Successfully");
123                                 },
124                                 error : function(data){
125                                         console.log(data);
126                                         Notification.error("Error Occured While Deleting a PDP Group");
127                                 }
128                         });
129                 })
130         };
131
132         $scope.statusOfPDP = function(status){
133                 $scope.pdpStatus = status;
134                 console.log($scope.pdpStatus);
135                 var modalInstance = $modal.open({
136                         backdrop: 'static', keyboard: false,
137                         templateUrl: 'pdpGroupStatusWindow.html',
138                         controller: 'pdpGroupStatusController',
139                         resolve: {
140                                 message: function () {
141                                         var message = {
142                                                 status : $scope.pdpStatus,
143                                                 policies : $scope.policies
144                                         };
145                                         return message;
146                                 }
147                         }
148                 });
149                 modalInstance.result.then(function(response){
150                         console.log('response', response);
151                         $scope.data=response.data;
152                 });
153         };
154
155         $scope.savePDPGroup = function(pdpGroupData) {
156                 var uuu = "pdp_Group/save_pdp_group.htm";
157                 var postData={pdpGroupData: pdpGroupData};
158                 $.ajax({
159                         type : 'POST',
160                         url : uuu,
161                         dataType: 'json',
162                         contentType: 'application/json',
163                         data: JSON.stringify(postData),
164                         success : function(data){
165                                 $scope.$apply(function(){
166                                 $scope.data=data.data;});
167                                 console.log($scope.data);
168                                 $modalInstance.close({data:$scope.data});
169                         },
170                         error : function(data){
171                                 Notification.error("Error while saving PDP Group.");
172                         }
173                 });
174         };
175         
176         function refreshPDPGroupDatas(response){
177                 $scope.selectedPDPName = $scope.selectedPdp.id;
178                 if(response != undefined){
179                         $scope.data = JSON.parse(response.data);
180                         for(var i=0; i< $scope.data.length; i++){
181                                 if($scope.data[i].id === $scope.selectedPDPName){
182                                         $scope.policies = $scope.data[i].policies;
183                                 $scope.pdps = $scope.data[i].pdps;
184                                 }
185                         }
186                 }
187         };
188
189         $scope.close = function() {
190                 $modalInstance.close();
191         };
192 });