$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();
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;
$scope.choices = [];
$scope.attributeDatas = [{"attributes" : $scope.choices}];
-
+ $scope.isInitEditTemplate = true; //just initially create the edit template, didn't click add button yet.
$scope.addNewChoice = function(value) {
console.log(value);
if(value != undefined){
var div = document.getElementById(value+"@0");
if(div != null){
var clone = div.cloneNode(true);
- var addElement = parentElement.childElementCount + 1;
+ var addElement = parentElement.childElementCount;
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);
+ 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]){
+ clone.value = $scope.temp.policy.ruleData[clone.id];
+ }
+ clone.className += ' child_single'; //here cloned is single element
+ document.getElementById("div."+value).appendChild(clone);
+ plainAttributeKeys.push(''+value+'@'+addElement);
+ }
+ }else{ //not view or edit
+ 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");
$scope.removeChoice = function(value) {
console.log(value);
if(value != undefined){
+ var c = document.getElementById("div."+value).childElementCount;
+
+ if(c == 1){
+ Notification.error("The original one is not removable.");
+ return;
+ }
document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
}
};
var plainAttributeKeys = [];
$scope.dcaeModelData = data[0].dcaeModelData;
$scope.dcaeJsonDate = data[0].jsonValue;
+ if(data[0].allManyTrueKeys){
+ console.log("$scope.allManyTrueKeys: " + $scope.allManyTrueKeys);
+ }
console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate);
var attributes = $scope.dcaeModelData.attributes;
var refAttributes = $scope.dcaeModelData.ref_attributes;
var subAttributes = $scope.dcaeModelData.sub_attributes;
console.log("subAttributes: " + subAttributes);
-
+ console.log("refAttributes: " + refAttributes);
var enumAttributes = $scope.dcaeModelData.enumValues;
var annotation = $scope.dcaeModelData.annotation;
var dictionary = $scope.microServiceAttributeDictionaryDatas;
$scope.jsonLayout($scope.dcaeJsonDate);
});
- if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
+
+ if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ // If it's veiw or edit
+
+ if($scope.temp.policy.editPolicy){
+ $scope.isInitEditTemplate = true;
+ }
+
var checkData = [];
var data = [];
- if($scope.temp.policy.ruleData != null){
- var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
- propNames.forEach(function(name) {
- data.push(name);
- });
- for(a = 0; a < data.length; a++){
- var splitPlainAttributeKey1 = data[a].split(".");
- if(splitPlainAttributeKey1[0].indexOf("@") != -1){
- var key = splitPlainAttributeKey1[0];
- checkData.push(key);
- }
- }
- var unique = checkData.filter(onlyUnique);
- for(i =0; i < unique.length; i++){
- if(unique[i].indexOf("@0") == -1){
- var finalkey = unique[i].split("@")[0];
- $scope.addNewChoice(finalkey);
- }
- }
- }
+ // If ruleData contains extra elements created by clicked add button
+ if($scope.temp.policy.ruleData != null){
+ var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
+ propNames.forEach(function(name) {
+ data.push(name);
+ });
+
+ var extraElements = data;
+
+ if(plainAttributeKeys != null){
+ for(b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array
+ var newValue = plainAttributeKeys[b].split("*");
+ for(a = 0; a < data.length; a++){
+ if(data[a] === newValue[0] || data[a] === (newValue[0]+"@0")){
+ extraElements.splice(a, 1);
+ }
+ }
+ }
+
+ //--- Populate these extra elements created by clicked add button
+ for(a = 0; a < extraElements.length; a++){
+ if(extraElements[a].includes("@")){
+ var n = extraElements[a].lastIndexOf("@");
+ if(n > 0){
+ var key = extraElements[a].substring(0, n+2); //include @x in key also by n+2 since x can be 1, or 2, or 3
+ checkData.push(key);
+ }
+ }
+ }
+ var unique = checkData.filter(onlyUnique);
+ for(i =0; i < unique.length; i++){
+ //remove @x and let addNewChoice add @1 or @2...
+ var newKey = unique[i].substring(0, unique[i].length-2);
+ console.log("newKey: " + newKey);
+ $scope.addNewChoice(newKey);
+ }
+ }
+ }
+ //After initially create the edit template, reset it to false.
+ $scope.isInitEditTemplate = false;
}
var ele = angular.element(document.getElementById("DynamicTemplate"));
$compile(ele.contents())($scope);
var stringValue = "java.lang.String";
var string = "string";
var intValue = "int";
+ var integerValue = "integer";
var double = "double";
var boolean = "boolean";
var baseLevel = level;
if (lableList.length > 0){
array = true;
}
- if ( key=="0"){
+ if ( key==="0"){
var newKey = lableList.pop();
$scope.labelLayout(baseLevel, newKey, array );
if (array){
switch (dataTest[key].split(splitcolon)[0]){
case stringValue:
- $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
+ $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
break;
case string:
- $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
+ $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
break;
case intValue:
- $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
+ $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
break;
+ case integerValue:
+ $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
+ break;
case double:
- $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
+ $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
break;
case boolean:
$scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
if (dataTest[key].includes('dictionary-')){
var list = getDictionary(dataTest[key].split('dictionary-')[1]);
}else{
+ //--- get dropdown values from enumValues
var list = getList(dataTest[key]);
}
- if (list.length===0){
- $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
+ if (list.length===0){ //not dropdown element
+ $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
}else{
- $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
+ $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list, isRequired);
}
break;
}
}
- $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
+ $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType ){
$scope.temp.policy.ruleGridData.push(attibuteKey);
var br = document.createElement("BR");
var labeltext = null;
var requiredLabName = "";
if (matching.includes(attibuteKey)){
- labeltext = document.createTextNode(attibuteKey + "*!");
+ labeltext = document.createTextNode(attibuteKey + "*!");
+ isRequired = true; //set required as true for matching element
}else {
- //var labeltext = document.createTextNode(refattributeLabel);
if(isRequired){
requiredLabName = attibuteKey + " *";
labeltext = document.createTextNode(requiredLabName);
var textField = document.createElement("INPUT");
textField.setAttribute("class" , "form-control");
- textField.setAttribute("type" , "text");
+ if(dataType){
+ if(dataType == "double"){
+ textField.setAttribute("type" , "number");
+ textField.setAttribute("step" , "any");
+ }else{
+ textField.setAttribute("type" , dataType);
+ }
+ }
textField.setAttribute("style" , "width:300px;");
textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
var checkKey;
if(attributeManyKey){
checkKey = labelValue + attibuteKey+'@0';
- textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
+ textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
var divTag = document.createElement("div");
divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
var addButton = document.createElement("BUTTON");
removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
document.getElementById(divID).appendChild(addButton);
document.getElementById(divID).appendChild(removeButton);
- document.getElementById(divID).appendChild(label);
- document.getElementById(divID).appendChild(textField);
- document.getElementById(divID).appendChild(br);
+ document.getElementById(divID).appendChild(label);
+ var id = "div."+labelValue+attibuteKey;
+ var divTag = document.createElement("div");
+ divTag.setAttribute("id", id);
+ document.getElementById(divID).appendChild(divTag);
+ textField.className += ' first_child';
+ if(isRequired){
+ textField.setAttribute("required", "true");
+ }
+ divTag.appendChild(textField);
document.getElementById(divID).appendChild(divTag);
}else{
if (attributeManyKey){
var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
- var i =1 ;
- while(true){
- var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
- if(newValue==null){
- break;
- }else{
- $scope.addNewChoice(newCheckKey);
- document.getElementById(newCheckKey+'@'+i).value = newValue;
- i = i+1;
- }
- }
-
}else{
document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
}
document.getElementById(divID).appendChild(divTag);
var divTag = document.createElement("div");
- divTag.setAttribute("id", id +'@0');
+ divTag.setAttribute("id", id +'@0');
divTag.className += ' children_group'; //here is div with a group of children.
}
};
- $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
+ $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues, isRequired){
var br = document.createElement("BR");
if (labelLevel.length < 1){
var label = document.createElement("Label")
+
+ var refAttributes = $scope.dcaeModelData.ref_attributes;
+ if(isRequired != true && refAttributes){ //check refAttributes also
+ var refAttributesList = refAttributes.split(splitComma);
+ for (k = 0; k < refAttributesList.length; k++){
+ var refAttribute = refAttributesList[k].split(splitEqual);
+ if (attributeName == refAttribute[0].trim() && refAttribute[1].includes("required-true")){
+ isRequired = true;
+ }
+ }
+ }
+
if (matching.includes(attributeName)){
var labeltext = document.createTextNode(attributeName + "*!");
+ label.appendChild(labeltext);
+ isRequired = true; //set required as true for matching element
}else {
- var labeltext = document.createTextNode(attributeName);
+ var labeltext = document.createTextNode(attributeName);
+ if(isRequired){
+ requiredLabName = attributeName+ " *";
+ labeltext = document.createTextNode(requiredLabName);
+ }else{
+ labeltext = document.createTextNode(attributeName);
+ }
+
+ label.appendChild(labeltext);
}
label.appendChild(labeltext);
listField.setAttribute("style" , "width:300px;");
listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
+ if(isRequired){
+ 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);
+ }
+
for (i=0; i < listemunerateValues.length; i += 1) {
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 + '');
if(plainAttributeKeys != null){
for(a = 0; a < plainAttributeKeys.length; a++){
var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
- console.log(splitPlainAttributeKey[1]);
+ console.log("splitPlainAttributeKey: " + splitPlainAttributeKey);
var searchElement = document.getElementById(splitPlainAttributeKey[0]);
var key = splitPlainAttributeKey[0];
if(searchElement == null){
if (elumentLocation > 1){
enumKey = keySplit[keySplit.length - 1];
}
- if (enumKeyList.indexOf(enumKey) != -1){
- if (splitPlainAttributeKey[1].indexOf("true") !== -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++) {
multiSlect.push(searchElement.selectedOptions[i].value);
}else{
jsonPolicy[key]= searchElement.value;
}
+ if(searchElement.getAttribute("required")){
+ if(!searchElement.value){
+ return;
+ }
+ }
} else {
if(searchElement.value != null){
jsonPolicy[key]= searchElement.value;
}
}
var uuu = "policyController/validate_policy.htm";
+
+ console.log("$scope.isCheck:" + $scope.isCheck);
+
+ if($scope.isCheck == true){
+ if(("configName" in policy) == false){
+ Notification.error("Validation Failed: configName is required");
+ $scope.savebutton = true;
+ return;
+ }
+ if(("location" in policy) == false){
+ Notification.error("Validation Failed: location is required");
+ $scope.savebutton = true;
+ return;
+ }
+ if(("uuid" in policy) == false){
+ Notification.error("Validation Failed: uuid is required");
+ $scope.savebutton = true;
+ return;
+ }
+ if(("policyScope" in policy) == false){
+ Notification.error("Validation Failed: policyScope is required");
+ $scope.savebutton = true;
+ return;
+ }
+ }
+
var postData={policyData: policy, policyJSON : jsonPolicy};
$.ajax({
type : 'POST',