aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js')
-rw-r--r--src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js156
1 files changed, 135 insertions, 21 deletions
diff --git a/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js b/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js
index 5a1ac538..4e8855eb 100644
--- a/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js
+++ b/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js
@@ -37,7 +37,8 @@ app
var allPolicies = {};
$scope.guardType = "GUARD_MIN_MAX";
$scope.number = 0;
- $scope.clname="";
+ $scope.clname = "";
+ $scope.guard_ids = [];
function getAllFormId() {
return Array.from(document.getElementsByClassName("formId"));
@@ -54,17 +55,7 @@ app
}
console.log("No active formId found !");
}
- function initTargetResourceId() {
- if (vf_Services !== null && vf_Services !== undefined) {
- // Set all the Resource Invariant UUID in the target resource ID
- // list (+Empty and other)
- Object.keys(vf_Services["shared"]["byVf"]).forEach(function(key) {
-
- $("#targetResourceId").append($('<option></option>').val(key).html(key));
- });
- }
- }
function add_one_more() {
console.log("add one more");
@@ -102,6 +93,7 @@ app
$(".formId").not($("#formId" + count)).css("display", "none");
addCustListen(count);
$("#formId" + count + " #id").val("new");
+ $("#formId" + count + " #clname").val($scope.clname);
return count;
}
function addCustListen(count) {
@@ -150,10 +142,11 @@ app
}
function savePolicyLocally() {
- var polForm = {}
- polForm = serializeElement($("#operationalPolicyHeaderForm"));
+ var polForm = {};
+ var clPolForm = {};
+ clPolForm = serializeElement($("#operationalPolicyHeaderForm"));
+ allPolicies['guard_policies'] = {};
var policiesArray = []
- allPolicies['guard_policies'] = [];
$.each($(".formId"), function() {
var policyProperties = serializeElement($("#" + this.id + " .policyProperties"));
@@ -161,9 +154,15 @@ app
policiesArray.push(policyProperties);
// Now get the Guard
if ($("#" + this.id + " #enableGuardPolicy").is(':checked')) {
- allPolicies['guard_policies'].push(serializeElement($("#" + this.id + " .guardProperties")));
+ var guardPolicyBody = serializeElement($("#" + this.id + " .guardProperties"));
+ var guardPolicyId = guardPolicyBody['id'];
+ delete guardPolicyBody['id'];
+
+ allPolicies['guard_policies'][guardPolicyId] = guardPolicyBody;
+ $scope.guard_ids.push(guardPolicyId);
}
});
+ polForm['controlLoop'] = clPolForm;
polForm['policies'] = policiesArray;
allPolicies['operational_policy'] = polForm;
}
@@ -183,7 +182,7 @@ app
// Set the header
$.each($('#operationalPolicyHeaderForm').find('.form-control'), function() {
- $(this).val(allPolicies['operational_policy'][this.id]);
+ $(this).val(allPolicies['operational_policy']['controlLoop'][this.id]);
});
// Set the sub-policies
$.each(allPolicies['operational_policy']['policies'], function(opPolicyElemIndex, opPolicyElemValue) {
@@ -198,13 +197,14 @@ app
$("#go_properties_tab" + formNum).text(
allPolicies['operational_policy']['policies'][opPolicyElemIndex]['id']);
// Check if there is a guard set for it
- $.each(allPolicies['guard_policies'], function(guardElemIndex, guardElemValue) {
+ $.each(allPolicies['guard_policies'], function(guardElemId, guardElemValue) {
if (guardElemValue.recipe === $($("#formId" + formNum + " #recipe")[0]).val()) {
// Found one, set all guard prop
$.each($('.guardProperties').find('.form-control'), function(guardPropElemIndex,guardPropElemValue) {
+ guardElemValue['id'] = guardElemId;
$("#formId"+formNum+" .guardProperties").find("#"+guardPropElemValue.id).val(
- allPolicies['guard_policies'][guardElemIndex][guardPropElemValue.id]);
+ guardElemValue[guardPropElemValue.id]);
});
// And finally enable the flag
$("#formId" + formNum + " #enableGuardPolicy").prop("checked", true);
@@ -212,6 +212,107 @@ app
});
});
}
+
+ $scope.initTargetResourceId = function() {
+
+ var recipe = $(event.target).val();
+
+ var type = $(event.target).val();
+
+ $("#modelName").val("");
+ $("#modelInvariantId").val("");
+ $("#modelVersionId").val("");
+ $("#modelVersion").val("");
+ $("#modelCustomizationId").val("");
+ $('#resourceId').empty();
+ $("#resourceId")
+ .append(
+ $('<option></option>').val("")
+ .html(""));
+ $("#resourceId").append(
+ $('<option></option>').val("Other:")
+ .html("Other:"));
+ if (type == "VM" || type == "" || type == "VNF" ) {
+ $("#metadata *").prop('disabled',true);
+ }
+
+ var resourceVnf = getResourceDetailsProperty();
+ if (type == "VNF"
+ && (null !== resourceVnf || undefined !== resourceVnf)) {
+ for ( var prop in resourceVnf) {
+ var name = resourceVnf[prop]["name"];
+ $("#resourceId").append(
+ $('<option></option>')
+ .val(name).html(name));
+ }
+
+ }
+ var resourceVfc = getResourceDetailsVfcProperty();
+ if (type == "VFC"
+ && (null !== resourceVfc || undefined !== resourceVfc)) {
+ if (recipe == 'VF Module Create'
+ || recipe == 'VF Module Delete') {
+ for ( var prop in resourceVfc) {
+ if (resourceVfc[prop]["isBase"] == false) {
+ var name = resourceVfc[prop]["name"];
+ $("#resourceId").append(
+ $('<option></option>')
+ .val(name)
+ .html(name));
+ }
+ }
+ }
+ else
+ {
+ for ( var prop in resourceVfc) {
+ var name = resourceVfc[prop]["name"];
+ $("#resourceId").append(
+ $('<option></option>')
+ .val(name).html(name));
+ }
+ }
+ }
+ }
+
+ $scope.changeTargetResourceId = function() {
+ $("#modelName").val("");
+ $("#modelInvariantId").val("");
+ $("#modelVersionId").val("");
+ $("#modelVersion").val("");
+ $("#modelCustomizationId").val("");
+ var resourceVfc = getResourceDetailsVfcProperty();
+ var type = $("#type").val();
+ var recipe = $("#recipe").val();
+ vfBaseName = $(event.target).val();
+ if (type == "VFC"
+ && (null !== resourceVfc || undefined !== resourceVfc)
+ && (recipe == 'VF Module Create' || recipe == 'VF Module Delete')) {
+ for ( var prop in resourceVfc) {
+ var name = resourceVfc[prop]["name"];
+ if (name == vfBaseName) {
+ var vfModuleModelName = resourceVfc[prop]["name"];
+ $("#modelName").val(
+ vfModuleModelName);
+ var vfModuleModelInvariantUUID = resourceVfc[prop]["invariantUUID"];
+ $("#modelInvariantId").val(
+ vfModuleModelInvariantUUID);
+ var vfModuleModelUUID = resourceVfc[prop]["UUID"];
+ $("#modelVersionId").val(
+ vfModuleModelUUID);
+ var vfModuleModelVersion = resourceVfc[prop]["version"];
+ $("#modelVersion").val(
+ vfModuleModelVersion);
+ var vfModuleModelCustomizationUUID = resourceVfc[prop]["customizationUUID"];
+ $("#modelCustomizationId")
+ .val(
+ vfModuleModelCustomizationUUID);
+ }
+ }
+ }
+ else {
+ $("#metadata *").prop('disabled',true);
+ }
+ }
$scope.changeGuardPolicyType = function() {
@@ -258,13 +359,20 @@ app
add_new_policy();
}
$("#savePropsBtn").click(function(event) {
-
console.log("save properties triggered");
savePolicyLocally();
+ for(var i = 0; i <= $scope.guard_ids.length; i++) {
+ for(var j = i; j <= $scope.guard_ids.length; j++) {
+ if(i != j && $scope.guard_ids[i] == $scope.guard_ids[j]) {
+ // duplacated guard policy id exist
+ alert("The guard policy ID should be unique.");
+ return;
+ }
+ }
+ }
angular.element(document.getElementById('formSpan')).scope().submitForm(allPolicies);
$("#close_button").click();
});
- initTargetResourceId();
});
}
$scope.init();
@@ -274,6 +382,12 @@ app
// Get the second recipe (guard one) and update it
$($("#formId" + formNum + " #recipe")[1]).val($(event.target).val());
}
+ $scope.updateGuardActor = function(event) {
+
+ var formNum = $(event.target).closest('.formId').attr('id').substring(6);
+ // Get the second actor (guard one) and update it
+ $($("#formId" + formNum + " #actor")[1]).val($(event.target).val());
+ }
// When we change the name of a policy
$scope.updateTabLabel = function(event) {
@@ -302,4 +416,4 @@ app
});
};
- } ]); \ No newline at end of file
+ } ]);