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', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23 $scope.policyNavigator;
24 $scope.savebutton = true;
25 $scope.refreshCheck = false;
27 $scope.refresh = function(){
28 if($scope.refreshCheck){
29 $scope.policyNavigator.refresh();
31 $scope.modal('createNewPolicy', true);
34 $scope.modal = function(id, hide) {
35 return $('#' + id).modal(hide ? 'hide' : 'show');
38 if($scope.temp.policy.ruleProvider==undefined){
39 $scope.temp.policy.ruleProvider="Custom";
42 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
44 $scope.data = JSON.parse(j.data);
45 console.log($scope.data);
46 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
47 console.log($scope.ecompNameDictionaryDatas);
49 console.log("failed");
52 PolicyAppService.getData('getDictionary/get_SettingsDictionaryDataByName').then(function (data) {
54 $scope.data = JSON.parse(j.data);
55 console.log($scope.data);
56 $scope.settingsDictionaryDatas = JSON.parse($scope.data.settingsDictionaryDatas);
57 console.log($scope.settingsDictionaryDatas);
59 console.log("failed");
62 PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
64 $scope.data = JSON.parse(j.data);
65 console.log($scope.data);
66 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
67 console.log($scope.functionDefinitionDatas);
69 console.log("failed");
72 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
74 $scope.data = JSON.parse(j.data);
75 console.log($scope.data);
76 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
77 console.log($scope.attributeDictionaryDatas);
79 console.log("failed");
84 function extend(obj, src) {
85 for (var key in src) {
86 if (src.hasOwnProperty(key)) obj[key] = src[key];
91 $scope.saveDecisionPolicy = function(policy){
92 if(policy.itemContent != undefined){
93 $scope.refreshCheck = true;
94 $scope.policyNavigator = policy.itemContent;
95 policy.itemContent = "";
97 $scope.savebutton = false;
99 var uuu = "policycreation/save_policy";
100 var postData={policyData: policy};
105 contentType: 'application/json',
106 data: JSON.stringify(postData),
107 success : function(data){
108 $scope.$apply(function(){
109 $scope.data=data.policyData;
110 if($scope.data == 'success'){
111 $scope.temp.policy.readOnly = 'true';
112 Notification.success("Policy Saved Successfully.");
113 }else if ($scope.data == 'PolicyExists'){
114 $scope.savebutton = true;
115 Notification.error("Policy Already Exists with Same Name in Scope.");
118 console.log($scope.data);
121 error : function(data){
122 Notification.error("Error Occured while saving Policy.");
127 $scope.validatePolicy = function(policy){
129 document.getElementById("validate").innerHTML = "";
130 var uuu = "policyController/validate_policy.htm";
131 var postData={policyData: policy};
136 contentType: 'application/json',
137 data: JSON.stringify(postData),
138 success : function(data){
139 $scope.$apply(function(){
140 $scope.validateData = data.data.replace(/\"/g, "");
141 $scope.data=data.data;
142 if($scope.data == '"success"'){
143 Notification.success("Validation Success.");
144 $scope.savebutton = false;
146 Notification.error("Validation Failed.");
147 document.getElementById("validate").innerHTML = $scope.validateData;
148 document.getElementById("validate").style.color = "white";
149 document.getElementById("validate").style.backgroundColor = "red";
150 $scope.savebutton = true;
154 console.log($scope.data);
156 error : function(data){
157 Notification.error("Validation Failed.");
158 $scope.savebutton = true;
163 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
164 $scope.temp.policy.attributes = [];
165 $scope.temp.policy.settings = [];
166 $scope.temp.policy.ruleAlgorithmschoices = [];
167 }else if($scope.temp.policy.ruleProvider=="Custom"){
168 if($scope.temp.policy.attributes.length == 0){
169 $scope.temp.policy.attributes = [];
171 if($scope.temp.policy.settings.length == 0){
172 $scope.temp.policy.settings = [];
174 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
175 $scope.temp.policy.ruleAlgorithmschoices = [];
178 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
179 $scope.addNewChoice = function() {
180 var newItemNo = $scope.temp.policy.attributes.length+1;
181 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
183 $scope.removeChoice = function() {
184 var lastItem = $scope.temp.policy.attributes.length-1;
185 $scope.temp.policy.attributes.splice(lastItem);
189 $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
190 $scope.addNewSettingsChoice = function() {
191 var newItemNo = $scope.temp.policy.settings.length+1;
192 $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
194 $scope.removeSettingsChoice = function() {
195 var lastItem = $scope.temp.policy.settings.length-1;
196 $scope.temp.policy.settings.splice(lastItem);
200 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
202 $scope.addNewRuleAlgorithm = function() {
203 if($scope.temp.policy.ruleAlgorithmschoices != null){
204 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
209 var value = newItemNo-1;
210 $scope.attributeDictionaryDatas.push('A'+value);
212 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
215 $scope.removeRuleAlgorithm = function() {
216 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
217 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
220 $scope.providerListener = function(ruleProvider) {
221 if (ruleProvider!="Custom"){
222 $scope.temp.policy.ruleAlgorithmschoices = [];
223 $scope.temp.policy.settings = [];
224 $scope.temp.policy.attributes = [];