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=========================================================
24 angular.module('abs').controller('actionPolicyController', function ($scope, PapUrlService, PolicyDictionaryService,modalService, $modal, Notification) {
28 PapUrlService.getPapUrl().then(function(data) {
30 papUrl = config.PAP_URL;
33 PolicyDictionaryService.getActionPolicyDictionaryData(papUrl).then(function (data) {
35 $scope.data = JSON.parse(j.data);
36 console.log($scope.data);
37 $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas);
38 console.log($scope.actionPolicyDictionaryDatas);
40 console.log("failed");
43 PolicyDictionaryService.getAttributeDictionaryData(papUrl).then(function (data) {
45 $scope.data = JSON.parse(j.data);
46 console.log($scope.data);
47 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
48 console.log($scope.attributeDictionaryDatas);
50 console.log("failed");
55 PolicyDictionaryService.getFunctionDefinitionData().then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
60 console.log($scope.functionDefinitionDatas);
62 console.log("failed");
65 function extend(obj, src) {
66 for (var key in src) {
67 if (src.hasOwnProperty(key)) obj[key] = src[key];
72 $scope.saveActionPolicy = function(policy){
74 /*var attributeData = extend(policy, $scope.attributeDatas[0]);*/
75 // var finalData = extend(policy, $scope.ruleAlgorithmDatas[0]);
76 //console.log(finalData);
77 var uuu = "policyController/save_Actionpolicy.htm";
78 var postData={policyData: policy};
83 contentType: 'application/json',
84 data: JSON.stringify(postData),
85 success : function(data){
86 $scope.$apply(function(){
87 $scope.data=data.data;
88 $scope.temp.policy.readOnly = 'true';
89 Notification.success("Policy Saved Successfully.");
91 console.log($scope.data);
92 $modalInstance.close();
95 error : function(data){
96 Notification.error("Error Occured while saving Policy.");
101 $scope.validatePolicy = function(policy){
103 var uuu = "policyController/validate_policy.htm";
104 var postData={policyData: policy};
109 contentType: 'application/json',
110 data: JSON.stringify(postData),
111 success : function(data){
112 $scope.$apply(function(){
113 $scope.data=data.data;
114 if($scope.data == '"success"'){
115 Notification.success("Validation Success.");
117 Notification.error("Validation Failed.");
121 console.log($scope.data);
122 /*$modalInstance.close();*/
125 error : function(data){
126 Notification.error("Validation Failed.");
131 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
132 $scope.temp.policy.attributes = [];
133 $scope.temp.policy.ruleAlgorithmschoices = [];
135 if($scope.temp.policy.attributes.length == 0){
136 $scope.temp.policy.attributes = [];
138 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
139 $scope.temp.policy.ruleAlgorithmschoices = [];
143 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
144 $scope.addNewChoice = function() {
145 var newItemNo = $scope.temp.policy.attributes .length+1;
146 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
148 $scope.removeChoice = function() {
149 var lastItem = $scope.temp.policy.attributes.length-1;
150 $scope.temp.policy.attributes.splice(lastItem);
155 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices}];
157 $scope.addNewRuleAlgorithm = function(){
158 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
159 $scope.ItemNo = newItemNo;
161 var value = newItemNo-1;
162 $scope.attributeDictionaryDatas.push('A'+value);
165 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
169 $scope.removeRuleAlgorithm = function() {
170 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
171 $scope.ItemNo = lastItem;
172 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);