2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 app.controller('policyPushController', function ($scope, PDPService, AdminTabService, AutoPushService, modalService, $modal, Notification,$filter){
22 $( "#dialog" ).hide();
24 $scope.isDisabled = true;
25 $scope.loading = true;
27 AdminTabService.getData().then(function(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;
34 $scope.isDisabled = false;
36 console.log($scope.data);
38 console.log("failed");
42 PDPService.getPDPData().then(function (data) {
44 $scope.pdpdata = JSON.parse(j.data);
45 console.log($scope.pdpdata);
46 $scope.pushTabPDPGrid.data = $scope.pdpdata;
48 console.log("failed");
51 $scope.getPDPData = function(){
52 $scope.pushTabPDPGrid.data = $scope.pdpdata;
54 $scope.filterPdpGroup;
55 $scope.filterPDPGroupData = function() {
56 $scope.pushTabPDPGrid.data = $filter('filter')($scope.pdpdata, $scope.filterPdpGroup, undefined);
59 $scope.pushTabPDPGrid = {
60 onRegisterApi: function(gridApi) {
61 $scope.gridApi = gridApi;
63 enableFiltering: true,
65 { field: 'default',displayName : '', enableFiltering : false, enableSorting : false,
66 cellTemplate: '<button type="button" class="btn btn-primary" ng-click="grid.appScope.editPDPGroupWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ',
69 { field: 'id', displayName : 'ID'},
70 { field: 'name', displayName : 'Name' },
71 { field: 'description' }
76 $scope.editPDPGroupWindow = function (selectedPdpGroupData) {
77 $scope.removePDPGroupPolicies = selectedPdpGroupData;
78 if($scope.isDisabled){
79 Notification.error("Policy Application has been LockDown.");
81 var modalInstance = $modal.open({
82 backdrop: 'static', keyboard: false,
83 templateUrl: 'remove_PDPGroupPolicies_popup.html',
84 controller: 'removeGroupPoliciesController',
86 message: function () {
88 selectedPdpGroupData: $scope.removePDPGroupPolicies
94 modalInstance.result.then(function (response) {
95 console.log('response', response);
96 $scope.pdpdata = JSON.parse(response.data);
97 $scope.pushTabPDPGrid.data = $scope.pdpdata;
102 $scope.gridOptions = {
103 onRegisterApi: function(gridApi) {
104 $scope.gridPolicyApi = gridApi;
107 enableFiltering: true,
108 showTreeExpandNoChildren: true,
109 paginationPageSizes: [10, 20, 50, 100],
110 paginationPageSize: 20,
111 columnDefs: [{name: 'name'}, {name: 'version'}, {name: 'dateModified'}]
117 $scope.filterPolicyData = function() {
118 $scope.gridOptions.data = $filter('filter')($scope.files, $scope.filterPolicy, undefined);
121 AutoPushService.getAutoPushPoliciesData().then(function (data1) {
122 $scope.loading = false;
123 $scope.files = data1.data;
124 var data = data1.data;
127 var writeoutNode = function(childArray, currentLevel, dataArray){
128 childArray.forEach( function(childNode){
129 if (childNode.files.length > 0){
130 childNode.$$treeLevel = currentLevel;
131 id=childNode.categoryId;
132 if(childNode.categoryId == childNode.parentCategoryId){
136 if((id!=childNode.parentCategoryId) || (childNode.categoryId == childNode.parentCategoryId)){
137 if(childNode.categoryId == childNode.parentCategoryId){
140 childNode.$$treeLevel = currentLevel;
143 dataArray.push( childNode );
144 writeoutNode( childNode.files, currentLevel + 1, dataArray );
148 $scope.gridOptions.data = [];
149 writeoutNode(data, 0, $scope.gridOptions.data);
150 }, function (error) {
151 console.log("failed");
156 $scope.pushPoliciesButton = function(){
157 var policySelection = $scope.gridPolicyApi.selection.getSelectedRows();
158 console.log(policySelection);
159 var currentSelection = $scope.gridApi.selection.getSelectedRows();
160 if(policySelection.length == 0 && currentSelection.length == 0){
161 Notification.error("Please Select Policy and PDP Group to Push");
163 if(policySelection.length == 0 && currentSelection.length != 0){
164 Notification.error("Please Select Policy to Push");
166 if(policySelection.length != 0 && currentSelection.length == 0){
167 Notification.error("Please Select PDP Group to Push");
169 if(policySelection.length != 0 && currentSelection.length != 0){
171 "pdpDatas": currentSelection,
172 "policyDatas": policySelection
174 console.log(finalData);
175 var uuu = "auto_Push/PushPolicyToPDP.htm";
176 var postData={pushTabData: finalData};
181 contentType: 'application/json',
182 data: JSON.stringify(postData),
183 success : function(data){
184 $scope.$apply(function(){
185 $scope.data=data.data;
186 $scope.pdpdata = JSON.parse(data.data);
187 $scope.pushTabPDPGrid.data = $scope.pdpdata;
188 Notification.success("Policy Pushed Successfully");
190 console.log($scope.data);
192 error : function(data){
193 Notification.error("Error Occured while Pushing Policy.");