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=663d8844bb5f030cecacd8b35fb080b2ccd5140f;hb=09e5ff42a2994650584b87ced8a1549e816408f7;hp=fb966430cb4fd86ff9af1d4aa0bc18c4d6ba94de;hpb=fc5c07705edc4dcb7083b39116a43844bb6a1490;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 fb966430c..663d8844b 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ECOMP Policy Engine + * ONAP Policy Engine * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -25,6 +25,13 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "Micro Service" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); @@ -37,6 +44,15 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind return $('#' + id).modal(hide ? 'hide' : 'show'); }; + $('#ttlDate').datepicker({ + dateFormat: 'dd/mm/yy', + changeMonth: true, + changeYear: true, + onSelect: function(date) { + angular.element($('#ttlDate')).triggerHandler('input'); + } + }); + if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){ if ($scope.temp.policy.configName == undefined){ $scope.isCheck = false; @@ -47,12 +63,12 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind $scope.isCheck = false; } - PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) { + PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) { var j = data; $scope.data = JSON.parse(j.data); console.log($scope.data); - $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas); - console.log($scope.ecompNameDictionaryDatas); + $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas); + console.log($scope.onapNameDictionaryDatas); }, function (error) { console.log("failed"); }); @@ -163,10 +179,14 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind var addElement = parentElement.childElementCount + 1; clone.id = ''+value+'@'+addElement; clone.value = ''; + clone.className += ' child_single'; //here cloned is single element document.getElementById("div."+value).appendChild(clone); plainAttributeKeys.push(''+value+'@'+addElement); }else{ div = document.getElementById("div."+value+"@0"); + + div.className += ' children_group'; //here is div with a group of children. + var childElement = parentElement.firstElementChild; var countParent = parentElement.childElementCount; var childElementString = childElement.innerHTML; @@ -295,9 +315,12 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind var plainAttributeKeys = []; $scope.dcaeModelData = data[0].dcaeModelData; $scope.dcaeJsonDate = data[0].jsonValue; + console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate); var attributes = $scope.dcaeModelData.attributes; var refAttributes = $scope.dcaeModelData.ref_attributes; - var subAttributes = $scope.dcaeModelData.sub_attributes; + var subAttributes = $scope.dcaeModelData.sub_attributes; + console.log("subAttributes: " + subAttributes); + var enumAttributes = $scope.dcaeModelData.enumValues; var annotation = $scope.dcaeModelData.annotation; var dictionary = $scope.microServiceAttributeDictionaryDatas; @@ -316,25 +339,23 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind } - if (dictionary!= null || dictionary>1){ - if (dictionary!= null || dictionary.length>1){ - for (m=0; m < dictionary.length; m += 1){ - var keyCompare = dictionary[m].name; - var valueCompare = dictionary[m].value; - var valueModel = dictionary[m].modelName; - var conpairService = serviceName; - if (valueModel.includes('-v')){ - conpairService = service; - } - if(valueModel.localeCompare(conpairService) == 0){ - console.log(valueCompare); - dictionaryList.push(dictionary[m]); - if (!dictionaryNameList.includes(dictionary[m].name)){ - dictionaryNameList.push(dictionary[m].name) - } - } - } - } + if (dictionary!= null && dictionary.length>1){ + for (m=0; m < dictionary.length; m += 1){ + var keyCompare = dictionary[m].name; + var valueCompare = dictionary[m].value; + var valueModel = dictionary[m].modelName; + var conpairService = serviceName; + if (valueModel.includes('-v')){ + conpairService = service; + } + if(valueModel.localeCompare(conpairService) == 0){ + console.log(valueCompare); + dictionaryList.push(dictionary[m]); + if (!dictionaryNameList.includes(dictionary[m].name)){ + dictionaryNameList.push(dictionary[m].name) + } + } + } } $scope.temp.policy.ruleGridData = []; @@ -442,11 +463,11 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind return Object.prototype.toString.call(arrayTest) === '[object Array]'; } var lableList = []; - function deconstructJSON(dataTest, level , name) { var array = false; var label = level; var stringValue = "java.lang.String"; + var string = "string"; var intValue = "int"; var double = "double"; var boolean = "boolean"; @@ -459,6 +480,7 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind for (key in dataTest) { array = isArray(dataTest[key]); console.log(key , dataTest[key]); + if (!!dataTest[key] && typeof(dataTest[key])=="object") { if (array==false && key!=="0"){ $scope.labelLayout(label, key, array ); @@ -500,11 +522,35 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind if (dataTest[key].includes('required-true')){ isRequired = true; } - console.log("attirbuteLabel = " + attirbuteLabel); + + var subAttributes = $scope.dcaeModelData.sub_attributes; + + if(subAttributes){ + var jsonObject = JSON.parse(subAttributes); + var allkeys = Object.keys(jsonObject); + if(allkeys){ + for (var k = 0; k < allkeys.length; k++) { + var keyValue = allkeys[k]; + console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]); + if(jsonObject[keyValue]){ + var tempObject = jsonObject[keyValue]; + if(tempObject && tempObject[key]){ + if (tempObject[key].includes('required-true')){ + isRequired = true; + } + } + } + } + } + } + switch (dataTest[key].split(splitcolon)[0]){ case stringValue: $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired); break; + case string: + $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired); + break; case intValue: $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired); break; @@ -582,13 +628,13 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind var buttonaddLabel = document.createTextNode("+"); addButton.appendChild(buttonaddLabel); addButton.setAttribute("id", labelValue + attibuteKey); - addButton.setAttribute("class", "btn btn-default"); + addButton.setAttribute("class", "btn btn-add-remove"); addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");'); addButton.setAttribute("ng-disabled" , "temp.policy.readOnly"); var removeButton = document.createElement("BUTTON"); var buttonremoveLabel = document.createTextNode("-"); removeButton.appendChild(buttonremoveLabel); - removeButton.setAttribute("class", "btn btn-default"); + removeButton.setAttribute("class", "btn btn-add-remove"); removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");'); removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly"); document.getElementById(divID).appendChild(addButton); @@ -597,6 +643,7 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind document.getElementById(divID).appendChild(textField); document.getElementById(divID).appendChild(br); document.getElementById(divID).appendChild(divTag); + }else{ checkKey = labelValue + attibuteKey; textField.setAttribute("id" , ''+labelValue +attibuteKey+''); @@ -609,6 +656,16 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind } + if(divID.includes("@0") && divID.includes("div.")){ + var firstChild_Id = divID.split("@0")[0]; + var firstChild_element = document.getElementById(firstChild_Id); + if(firstChild_element){ + firstChild_element.className += ' children_group'; //here is a div with a group of children. + } + } + console.log('firstChild_Id: ' + firstChild_Id); + console.log('divID: ' + divID); + if (defaultValue.length > 0){ if(defaultValue.includes(":")){ defaultValue = defaultValue.split(":")[0]; @@ -661,18 +718,20 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind var labeltext = document.createTextNode(lableName); label.appendChild(labeltext); + + var subAttributes = $scope.dcaeModelData.sub_attributes; if(labelManyKey){ var addButton = document.createElement("BUTTON"); var buttonLabel = document.createTextNode("+"); addButton.appendChild(buttonLabel); - addButton.setAttribute("class", "btn btn-default"); + addButton.setAttribute("class", "btn btn-add-remove"); addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");'); addButton.setAttribute("ng-disabled" , "temp.policy.readOnly"); var removeButton = document.createElement("BUTTON"); var buttonremoveLabel = document.createTextNode("-"); removeButton.appendChild(buttonremoveLabel); - removeButton.setAttribute("class", "btn btn-default"); + removeButton.setAttribute("class", "btn btn-add-remove"); removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");'); removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly"); document.getElementById(divID).appendChild(addButton); @@ -685,12 +744,16 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind var divTag = document.createElement("div"); divTag.setAttribute("id", id +'@0'); + + divTag.className += ' children_group'; //here is div with a group of children. + document.getElementById(id).appendChild(divTag); }else{ var divTag = document.createElement("div"); divTag.setAttribute("id", "div."+labelValue+lableName); + divTag.className += ' children_group'; //here is div with a group of children. document.getElementById(divID).appendChild(label); - document.getElementById(divID).appendChild(divTag); + document.getElementById(divID).appendChild(divTag); } }; @@ -801,7 +864,6 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind if (elumentLocation > 1){ enumKey = keySplit[keySplit.length - 1]; } - var aWhiteSpace = " "; if (enumKeyList.indexOf(enumKey) != -1){ if (splitPlainAttributeKey[1].indexOf("true") !== -1){ var multiSlect = []; @@ -810,19 +872,11 @@ angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$wind } jsonPolicy[key]= multiSlect; }else{ - //set a space due to empty value caused JSON format error in PolicyRestAdapter and remove it in back-end. - if(searchElement.value == ""){ - searchElement.value = aWhiteSpace; - } console.log(" searchElement.value = > " + searchElement.value); jsonPolicy[key]= searchElement.value; } } else { if(searchElement.value != null){ - //set a default value due to empty value caused JSON format error in PolicyRestAdapter - if(searchElement.value == ""){ - searchElement.value = aWhiteSpace; - } console.log(" searchElement.value = > " + searchElement.value); jsonPolicy[key]= searchElement.value; }