X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fwebapp%2Fapp%2FpolicyApp%2Fpolicy-models%2FEditor%2FPolicyTemplateController%2FDCAEMicroServicePolicyController.js;h=cffa46f53ce68c1f7abb33da8e7b99b6c480db29;hb=06e02108525c3e5e8c85de233aef3bb332173c00;hp=1b4337033fe27079415bee2c4bb930d3a15b844e;hpb=def1c29d8a8c4372e006b1388a456bca92d57500;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js index 1b4337033..cffa46f53 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) { $("#dialog").hide(); @@ -99,9 +100,9 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind var j = data; $scope.data = JSON.parse(j.data); console.log($scope.data); - console.log("$scope.data.microServiceCongigNameDictionaryDatas : " + $scope.data.microServiceCongigNameDictionaryDatas); - if($scope.data.microServiceCongigNameDictionaryDatas){ - $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas); + console.log("$scope.data.microServiceConfigNameDictionaryDatas : " + $scope.data.microServiceConfigNameDictionaryDatas); + if($scope.data.microServiceConfigNameDictionaryDatas){ + $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceConfigNameDictionaryDatas); } console.log($scope.microServiceCongigNameDictionaryDatas); }, function (error) { @@ -170,9 +171,9 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind $scope.choices = []; $scope.attributeDatas = [{"attributes" : $scope.choices}]; - $scope.isInitEditTemplate = true; //just initially create the edit template, didn't click add button yet. addNewChoice = function(value) { - console.log("input value : " + value); + console.log("input key : " + value); + var isFoundInRuleData = false; if(value != undefined){ if (value.startsWith('div.')){ value = value.replace('div.',''); @@ -188,9 +189,15 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind clone.id = ''+value+'@'+addElement; clone.value = ''; if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ //if it's view or edit - if($scope.temp.policy.ruleData[clone.id] || ($scope.temp.policy.editPolicy && !$scope.isInitEditTemplate)){ // Only append child if its value found in ruleData or edit mode + if($scope.temp.policy.ruleData[clone.id] || $scope.temp.policy.editPolicy){ // Only append child if its value found in ruleData or edit mode if($scope.temp.policy.ruleData[clone.id]){ clone.value = $scope.temp.policy.ruleData[clone.id]; + isFoundInRuleData = true; + } + console.log(" clone.value :" + clone.value); + console.log(" clone.id :" + clone.id); + if(!isFoundInRuleData && isInitViewEdit){ + return; } if(!clone.className.includes("child_single")){ clone.className += ' child_single'; //here cloned is single element @@ -246,6 +253,8 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind for(var i=0; i 0){ + if(dataType != "boolean" && defaultValue.length > 0){ if(defaultValue.includes(":")){ defaultValue = defaultValue.split(":")[0]; if(defaultValue === "NA") { @@ -1089,7 +1200,12 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind } } } - plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey); + + if (dataType != "boolean"){ + plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey); + }else{ + plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean"); + } }; $scope.labelManyKeys = []; @@ -1192,7 +1308,7 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind } }; - $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues, isRequired){ + $scope.dropBoxLayout = function(labelLevel, attributeName, many , defaultValue, listemunerateValues, isRequired, description){ var br = document.createElement("BR"); if (labelLevel.length < 1){ @@ -1243,118 +1359,197 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind requiredNodeToolTip.textContent = "Conditional Required"; requiredNode.appendChild(requiredNodeToolTip); + } + + var listField = document.createElement("SELECT"); + listField.setAttribute("class" , "form-control"); + listField.setAttribute("style" , "width:300px;"); + listField.setAttribute("ng-disabled" , "temp.policy.readOnly"); + + if(description && description != "null"){ + listField.setAttribute("title", description); + } + + if(isRequired){ + if(document.getElementById(divID).hasAttribute('data-conditional')){ + listField.setAttribute("data-conditional", divID); + listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')"); + }else{ + listField.setAttribute("required", true); } - - var listField = document.createElement("SELECT"); - listField.setAttribute("class" , "form-control"); - listField.setAttribute("style" , "width:300px;"); - listField.setAttribute("ng-disabled" , "temp.policy.readOnly"); - - if(isRequired){ - if(document.getElementById(divID).hasAttribute('data-conditional')){ - listField.setAttribute("data-conditional", divID); - listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')"); - }else{ - listField.setAttribute("required", true); - } - } - if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element - var optionFirst = document.createElement('option'); - optionFirst.setAttribute('value', ""); - listField.appendChild(optionFirst); + } + if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element + var optionFirst = document.createElement('option'); + var optionValue = ""; + if($scope.temp.policy.ruleData != null){ + if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){ + optionValue = $scope.temp.policy.ruleData[labelLevel + attributeName]; + } + } + optionFirst.setAttribute('value', optionValue); + optionFirst.appendChild(document.createTextNode(optionValue)); + listField.appendChild(optionFirst); + } + var ruleFormationCheck = false; + if(listemunerateValues.length !== 0 && typeof listemunerateValues[0] == "string" && listemunerateValues[0].includes("dictionary:")) { + var ruleCheck = listemunerateValues[0].split("&"); + var dictParams = ruleCheck[0].split(":"); + var dictParamsSplit = dictParams[1].split("@"); + if (ruleCheck[1] != undefined && ruleCheck[1] == 'Rule') { + ruleFormationCheck = true; } - + PolicyAppService.getData(dictParamsSplit[0]).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.listDictionarys = JSON.parse($scope.data[dictParamsSplit[1]]); + for (i=0; i < $scope.listDictionarys.length; i += 1) { + option = document.createElement('option'); + option.setAttribute('value', $scope.listDictionarys[i]); + option.appendChild(document.createTextNode($scope.listDictionarys[i])); + listField.appendChild(option); + } + }, function (error) { + console.log("failed"); + }); + + } + else{ for (i=0; i < listemunerateValues.length; i += 1) { - if(listemunerateValues[i].includes("equal-sign")){ + if(typeof listemunerateValues[i] == "string" && listemunerateValues[i].includes("equal-sign")){ listemunerateValues[i] = listemunerateValues[i].replace('equal-sign','='); } + option = document.createElement('option'); option.setAttribute('value', listemunerateValues[i]); option.appendChild(document.createTextNode(listemunerateValues[i])); option.setAttribute('value', listemunerateValues[i]); listField.appendChild(option); } - listField.setAttribute("id" , ''+ labelLevel + attributeName + ''); - - enumKeyList.push(attributeName); - - document.getElementById(divID).appendChild(label); - document.getElementById(divID).appendChild(br); - - if(many == true){ - document.getElementById(divID).appendChild(listField).multiple = true; - plainAttributeKeys.push(labelLevel + attributeName+'*'+true); - }else { - document.getElementById(divID).appendChild(listField).multiple = false; - plainAttributeKeys.push(labelLevel + attributeName+'*'+false); + } + listField.setAttribute("id" , ''+ labelLevel + attributeName + ''); + + enumKeyList.push(attributeName); + + document.getElementById(divID).appendChild(label); + document.getElementById(divID).appendChild(br); + + if(many == true){ + document.getElementById(divID).appendChild(listField).multiple = true; + plainAttributeKeys.push(labelLevel + attributeName+'*'+true); + }else { + document.getElementById(divID).appendChild(listField).multiple = false; + plainAttributeKeys.push(labelLevel + attributeName+'*'+false); + + if (defaultValue){ + if(defaultValue.includes(':')){ + defaultValue = defaultValue.split(':')[0]; + } + var location = listemunerateValues.indexOf(defaultValue); + document.getElementById(labelLevel +attributeName).options[location+1].selected = true; } - - if($scope.temp.policy.ruleData != null){ - if (many == true){ - document.getElementById(labelLevel +attributeName).options[0].selected = false; - for (i=0; i < listemunerateValues.length; i += 1) { - var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i]; - if (testValue === undefined){ - testValue = $scope.temp.policy.ruleData[labelLevel +attributeName]; - } - var location = listemunerateValues.indexOf(testValue); - if (location!=-1){ - document.getElementById(labelLevel +attributeName).options[location].selected = true; - } - } - }else { - if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){ - document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName]; - } + } + + if (ruleFormationCheck) { + var optionInput = document.createElement("INPUT"); + optionInput.setAttribute("type" , "text"); + optionInput.setAttribute("id" , ''+ labelLevel + attributeName + '.input'); + optionInput.setAttribute("name" , "ruleName"); + optionInput.setAttribute("value" , " "); + optionInput.setAttribute("style" , "width:300px;"); + optionInput.setAttribute("ng-disabled" , "temp.policy.readOnly"); + optionInput.removeAttribute("required"); + + document.getElementById(divID).appendChild(optionInput); + + var optionButton = document.createElement("BUTTON"); + optionButton.setAttribute("ng-disabled" , "temp.policy.readOnly"); + var buttonLabel = document.createTextNode("+"); + optionButton.appendChild(buttonLabel); + optionButton.setAttribute("class", "btn btn-add-remove"); + optionButton.setAttribute("onclick" , 'addDynamicOptions("'+ labelLevel + attributeName + '");'); + optionButton.removeAttribute("required"); + + + document.getElementById(divID).appendChild(optionButton); + document.getElementById(divID).appendChild(br); + } + + if($scope.temp.policy.ruleData != null){ + if (many == true){ + document.getElementById(labelLevel +attributeName).options[0].selected = false; + for (i=0; i < listemunerateValues.length; i += 1) { + var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i]; + if (testValue === undefined){ + testValue = $scope.temp.policy.ruleData[labelLevel +attributeName]; + } + var location = listemunerateValues.indexOf(testValue); + if (location!=-1){ + document.getElementById(labelLevel +attributeName).options[location].selected = true; } + } + }else { + if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){ + document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName]; } - }; - - function onlyUnique(value, index, self) { - return self.indexOf(value) === index; - }; - - - function checkDictionary(value){ - for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) { - if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){ - return true; - } - } - - } - $scope.savePolicy = function(policy){ - if(policy.itemContent != undefined){ - $scope.refreshCheck = true; - $scope.policyNavigator = policy.itemContent; - policy.itemContent = ""; - } - $scope.savebutton = false; - var splitAt = '*'; - var dot ='.'; - var jsonPolicy = {}; - if(plainAttributeKeys != null){ - for(a = 0; a < plainAttributeKeys.length; a++){ - var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt); - console.log("splitPlainAttributeKey: " + splitPlainAttributeKey); - var searchElement = document.getElementById(splitPlainAttributeKey[0]); - var key = splitPlainAttributeKey[0]; - if(searchElement == null){ - searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0'); - key = splitPlainAttributeKey[0]+'@0'; - }else if (searchElement.nodeName == 'BUTTON'){ - searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0'); - key = splitPlainAttributeKey[0]+'@0'; - } - if(searchElement != null){ - var keySplit = key.split(dot); - var elumentLocation = keySplit.length; - var enumKey = key; - if (elumentLocation > 1){ - enumKey = keySplit[keySplit.length - 1]; - } - //check it is undefined or not - if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){ + } + } + }; + + addDynamicOptions = function(id) { + var option = document.createElement("option"); + var value = document.getElementById(id+".input").value; + option.setAttribute('value', value); + option.appendChild(document.createTextNode(value)); + document.getElementById(id).options.add(option); + document.getElementById(id+".input").value = ""; + }; + + function onlyUnique(value, index, self) { + return self.indexOf(value) === index; + }; + + + function checkDictionary(value){ + for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) { + if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){ + return true; + } + } + + } + $scope.savePolicy = function(policy){ + if(policy.itemContent != undefined){ + $scope.refreshCheck = true; + $scope.policyNavigator = policy.itemContent; + policy.itemContent = ""; + } + $scope.savebutton = false; + var splitAt = '*'; + var dot ='.'; + var jsonPolicy = {}; + if(plainAttributeKeys != null){ + for(a = 0; a < plainAttributeKeys.length; a++){ + var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt); + console.log("splitPlainAttributeKey: " + splitPlainAttributeKey); + var searchElement = document.getElementById(splitPlainAttributeKey[0]); + var key = splitPlainAttributeKey[0]; + if(searchElement == null){ + searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0'); + key = splitPlainAttributeKey[0]+'@0'; + }else if (searchElement.nodeName == 'BUTTON'){ + searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0'); + key = splitPlainAttributeKey[0]+'@0'; + } + if(searchElement != null){ + var keySplit = key.split(dot); + var elumentLocation = keySplit.length; + var enumKey = key; + if (elumentLocation > 1){ + enumKey = keySplit[keySplit.length - 1]; + } + //check it is undefined or not + if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){ if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){ var multiSlect = []; for ( var i = 0; i < searchElement.selectedOptions.length; i++) { @@ -1363,12 +1558,30 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind jsonPolicy[key]= multiSlect; }else{ console.log(" searchElement.value = > " + searchElement.value); - jsonPolicy[key]= searchElement.value; + if(splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1] == "boolean"){ + jsonPolicy[key]= false; + for(var i=0; i " + searchElement.value); - jsonPolicy[key]= searchElement.value; + if(splitPlainAttributeKey[1] == "boolean"){ + jsonPolicy[key]= false; + for(var i=0; i