Fixed Sonar issues for Console Logs
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / AutoPushController.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('policyPushController', 
21     function ($scope, PolicyAppService, modalService, $modal, Notification,$filter){
22     $( "#dialog" ).hide();
23
24    $scope.isDisabled = true;
25    $scope.loading = true;
26
27    PolicyAppService.getData('get_LockDownData').then(function(data){
28         var j = data;
29         $scope.data = JSON.parse(j.data);
30         $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
31         if($scope.lockdowndata[0].lockdown == true){
32             $scope.isDisabled = true;
33         }else{
34             $scope.isDisabled = false;
35         }
36     });
37
38     $scope.pdpdata;
39     PolicyAppService.getData('get_PDPGroupData').then(function (data) {
40         var j = data;
41         $scope.pdpdata = JSON.parse(j.data);
42         $scope.pushTabPDPGrid.data = $scope.pdpdata;
43     });
44
45     $scope.getPDPData = function(){
46          $scope.pushTabPDPGrid.data = $scope.pdpdata;
47     };
48     $scope.filterPdpGroup;
49     $scope.filterPDPGroupData = function() {
50         $scope.pushTabPDPGrid.data = $filter('filter')($scope.pdpdata, $scope.filterPdpGroup, undefined);
51     };
52     
53     $scope.pushTabPDPGrid = {    
54         onRegisterApi: function(gridApi) {
55             $scope.gridApi = gridApi;
56         },
57         enableFiltering: true,
58         columnDefs: [
59             { field: 'default',displayName : '', enableFiltering : false, enableSorting : false,
60                 cellTemplate: '<button  type="button"  ng-click="grid.appScope.editPDPGroupWindow(row.entity)"><a class="fa fa-pencil-square-o"></a></i></button> ',
61                 width: '5%'
62             },
63             { field: 'id', displayName : 'ID'},
64             { field: 'name', displayName : 'Name' },
65             { field: 'description' }
66         ]
67     };
68
69
70     $scope.editPDPGroupWindow = function (selectedPdpGroupData) {
71         $scope.removePDPGroupPolicies = selectedPdpGroupData;
72         if($scope.isDisabled){
73             Notification.error("Policy Application has been LockDown.");
74         }else{
75             var modalInstance = $modal.open({
76                 backdrop: 'static', keyboard: false,
77                 templateUrl: 'remove_PDPGroupPolicies_popup.html',
78                 controller: 'removeGroupPoliciesController',
79                 resolve: {
80                     message: function () {
81                         var message = {
82                             selectedPdpGroupData: $scope.removePDPGroupPolicies
83                         };
84                         return message;
85                     }
86                 }
87             });
88             modalInstance.result.then(function (response) {
89                 $scope.pdpdata = JSON.parse(response.data);
90                 $scope.pushTabPDPGrid.data =  $scope.pdpdata;
91             });
92         }
93     };
94
95     $scope.gridOptions = {
96         data : 'policydatas',
97          onRegisterApi: function(gridApi) {
98              $scope.gridPolicyApi = gridApi;
99                },
100         enableSorting: true,
101         enableFiltering: true,
102         showTreeExpandNoChildren: true,
103         paginationPageSizes: [10, 20, 50, 100],
104         paginationPageSize: 20,
105         columnDefs: [{name: 'policyName', displayName : 'Policy Name', sort: { direction: 'asc', priority: 0 }}, 
106                      {name: 'activeVersion', displayName : 'Version'}, 
107                      {name: 'modifiedDate', displayName : 'Last Modified',type: 'date', cellFilter: 'date:\'yyyy-MM-dd HH:MM:ss a\'' }]
108     };
109     
110    
111     PolicyAppService.getData('get_AutoPushPoliciesContainerData').then(function (data) {
112         $scope.loading = false;
113         var j = data;
114     $scope.data = JSON.parse(j.data);
115     $scope.policydatas =JSON.parse($scope.data.policydatas);
116        });
117    
118     $scope.pushPoliciesButton = function(){
119         var policySelection = $scope.gridPolicyApi.selection.getSelectedRows();
120         var currentSelection = $scope.gridApi.selection.getSelectedRows();
121         if(policySelection.length == 0 && currentSelection.length == 0){
122         Notification.error("Please Select Policy and PDP Group to Push");
123         }
124         if(policySelection.length == 0 && currentSelection.length != 0){
125         Notification.error("Please Select Policy to Push");
126         }
127         if(policySelection.length != 0 && currentSelection.length == 0){
128         Notification.error("Please Select PDP Group to Push");
129         }
130         if(policySelection.length != 0 && currentSelection.length != 0){
131         var finalData = {
132             "pdpDatas": currentSelection,
133             "policyDatas": policySelection
134         };
135         var uuu = "auto_Push/PushPolicyToPDP.htm";
136         var postData={pushTabData: finalData};
137         $.ajax({
138             type : 'POST',
139             url : uuu,
140             dataType: 'json',
141             contentType: 'application/json',
142             data: JSON.stringify(postData),
143             success : function(data){
144             $scope.$apply(function(){
145                 $scope.data=data.data;
146                 $scope.pdpdata = JSON.parse(data.data);
147                 $scope.pushTabPDPGrid.data =  $scope.pdpdata;
148                 Notification.success("Policy Pushed Successfully");
149             });
150             },
151             error : function(data){
152             Notification.error("Error Occured while Pushing Policy.");
153             }
154         });
155
156         }
157     };
158 });