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('decisionPolicyController', function ($scope, PolicyAppService, modalService, $modal, Notification) {
22 $scope.savebutton = true;
23 $scope.finalPath = null;
25 if($scope.temp.policy.ruleProvider==undefined){
26 $scope.temp.policy.ruleProvider="Custom";
29 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
31 $scope.data = JSON.parse(j.data);
32 console.log($scope.data);
33 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
34 console.log($scope.ecompNameDictionaryDatas);
36 console.log("failed");
39 PolicyAppService.getData('getDictionary/get_SettingsDictionaryDataByName').then(function (data) {
41 $scope.data = JSON.parse(j.data);
42 console.log($scope.data);
43 $scope.settingsDictionaryDatas = JSON.parse($scope.data.settingsDictionaryDatas);
44 console.log($scope.settingsDictionaryDatas);
46 console.log("failed");
49 PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
54 console.log($scope.functionDefinitionDatas);
56 console.log("failed");
59 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
64 console.log($scope.attributeDictionaryDatas);
66 console.log("failed");
71 function extend(obj, src) {
72 for (var key in src) {
73 if (src.hasOwnProperty(key)) obj[key] = src[key];
78 $scope.saveDecisionPolicy = function(policy){
79 $scope.savebutton = false;
81 var uuu = "policycreation/save_policy";
82 var postData={policyData: policy};
87 contentType: 'application/json',
88 data: JSON.stringify(postData),
89 success : function(data){
90 $scope.$apply(function(){
91 $scope.data=data.policyData;
92 if($scope.data == 'success'){
93 $scope.temp.policy.readOnly = 'true';
94 Notification.success("Policy Saved Successfully.");
95 }else if ($scope.data == 'PolicyExists'){
96 $scope.savebutton = true;
97 Notification.error("Policy Already Exists with Same Name in Scope.");
100 console.log($scope.data);
103 error : function(data){
104 Notification.error("Error Occured while saving Policy.");
109 $scope.validatePolicy = function(policy){
111 document.getElementById("validate").innerHTML = "";
112 var uuu = "policyController/validate_policy.htm";
113 var postData={policyData: policy};
118 contentType: 'application/json',
119 data: JSON.stringify(postData),
120 success : function(data){
121 $scope.$apply(function(){
122 $scope.validateData = data.data.replace(/\"/g, "");
123 $scope.data=data.data;
124 if($scope.data == '"success"'){
125 Notification.success("Validation Success.");
126 $scope.savebutton = false;
128 Notification.error("Validation Failed.");
129 document.getElementById("validate").innerHTML = $scope.validateData;
130 document.getElementById("validate").style.color = "white";
131 document.getElementById("validate").style.backgroundColor = "red";
132 $scope.savebutton = true;
136 console.log($scope.data);
138 error : function(data){
139 Notification.error("Validation Failed.");
140 $scope.savebutton = true;
145 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
146 $scope.temp.policy.attributes = [];
147 $scope.temp.policy.settings = [];
148 $scope.temp.policy.ruleAlgorithmschoices = [];
150 if($scope.temp.policy.attributes.length == 0){
151 $scope.temp.policy.attributes = [];
153 if($scope.temp.policy.settings.length == 0){
154 $scope.temp.policy.settings = [];
156 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
157 $scope.temp.policy.ruleAlgorithmschoices = [];
160 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
161 $scope.addNewChoice = function() {
162 var newItemNo = $scope.temp.policy.attributes.length+1;
163 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
165 $scope.removeChoice = function() {
166 var lastItem = $scope.temp.policy.attributes.length-1;
167 $scope.temp.policy.attributes.splice(lastItem);
171 $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
172 $scope.addNewSettingsChoice = function() {
173 var newItemNo = $scope.temp.policy.settings.length+1;
174 $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
176 $scope.removeSettingsChoice = function() {
177 var lastItem = $scope.temp.policy.settings.length-1;
178 $scope.temp.policy.settings.splice(lastItem);
182 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
184 $scope.addNewRuleAlgorithm = function() {
185 if($scope.temp.policy.ruleAlgorithmschoices != null){
186 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
191 var value = newItemNo-1;
192 $scope.attributeDictionaryDatas.push('A'+value);
194 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
197 $scope.removeRuleAlgorithm = function() {
198 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
199 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
202 $scope.providerListener = function(ruleProvider) {
203 if (ruleProvider!="Custom"){
204 $scope.temp.policy.ruleAlgorithmschoices = [];
205 $scope.temp.policy.settings = [];
206 $scope.temp.policy.attributes = [];