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=========================================================
20 angular.module('abs').controller('actionPolicyController', function ($scope, PolicyAppService, modalService, $modal, Notification) {
23 $scope.savebutton = true;
24 $scope.finalPath = null;
26 PolicyAppService.getData('getDictionary/get_ActionPolicyDictDataByName').then(function (data) {
28 $scope.data = JSON.parse(j.data);
29 console.log($scope.data);
30 $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas);
31 console.log($scope.actionPolicyDictionaryDatas);
33 console.log("failed");
36 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
38 $scope.data = JSON.parse(j.data);
39 console.log($scope.data);
40 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
41 console.log($scope.attributeDictionaryDatas);
43 console.log("failed");
46 PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
48 $scope.data = JSON.parse(j.data);
49 console.log($scope.data);
50 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
51 console.log($scope.functionDefinitionDatas);
53 console.log("failed");
56 function extend(obj, src) {
57 for (var key in src) {
58 if (src.hasOwnProperty(key)) obj[key] = src[key];
63 $scope.saveActionPolicy = function(policy){
65 $scope.savebutton = false;
66 var uuu = "policycreation/save_policy";
67 var postData={policyData: policy};
72 contentType: 'application/json',
73 data: JSON.stringify(postData),
74 success : function(data){
75 $scope.$apply(function(){
76 $scope.data=data.policyData;
77 if($scope.data == 'success'){
78 $scope.temp.policy.readOnly = 'true';
79 Notification.success("Policy Saved Successfully.");
80 }else if ($scope.data == 'PolicyExists'){
81 $scope.savebutton = true;
82 Notification.error("Policy Already Exists with Same Name in Scope.");
85 console.log($scope.data);
87 error : function(data){
88 Notification.error("Error Occured while saving Policy.");
89 $scope.savebutton = true;
94 $scope.validatePolicy = function(policy){
96 document.getElementById("validate").innerHTML = "";
97 var uuu = "policyController/validate_policy.htm";
98 var postData={policyData: policy};
103 contentType: 'application/json',
104 data: JSON.stringify(postData),
105 success : function(data){
106 $scope.$apply(function(){
107 $scope.validateData = data.data.replace(/\"/g, "");
108 $scope.data=data.data;
109 if($scope.data == '"success"'){
110 Notification.success("Validation Success.");
111 $scope.savebutton = false;
113 Notification.error("Validation Failed.");
114 document.getElementById("validate").innerHTML = $scope.validateData;
115 document.getElementById("validate").style.color = "white";
116 document.getElementById("validate").style.backgroundColor = "red";
117 $scope.savebutton = true;
121 console.log($scope.data);
123 error : function(data){
124 Notification.error("Validation Failed.");
125 $scope.savebutton = true;
130 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
131 $scope.temp.policy.attributes = [];
132 $scope.temp.policy.ruleAlgorithmschoices = [];
134 if($scope.temp.policy.attributes.length == 0){
135 $scope.temp.policy.attributes = [];
137 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
138 $scope.temp.policy.ruleAlgorithmschoices = [];
142 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
143 $scope.addNewChoice = function() {
144 var newItemNo = $scope.temp.policy.attributes .length+1;
145 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
147 $scope.removeChoice = function() {
148 var lastItem = $scope.temp.policy.attributes.length-1;
149 $scope.temp.policy.attributes.splice(lastItem);
154 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices}];
156 $scope.addNewRuleAlgorithm = function(){
157 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
158 $scope.ItemNo = newItemNo;
160 var value = newItemNo-1;
161 $scope.attributeDictionaryDatas.push('A'+value);
163 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
167 $scope.removeRuleAlgorithm = function() {
168 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
169 $scope.ItemNo = lastItem;
170 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);