IOTS-296: Refactoring generic policy unit code

This code is refactored to use the device type specific operation mod functions (payload generation etc.)  in the device type plugins.
This commit is contained in:
Madawa Soysa 2016-12-08 10:29:12 +05:30
parent a0c842c6c6
commit 630a1105a9
3 changed files with 37 additions and 37 deletions

View File

@ -18,7 +18,6 @@
var stepForwardFrom = {}; var stepForwardFrom = {};
var stepBackFrom = {}; var stepBackFrom = {};
var policy = {}; var policy = {};
var configuredOperations = [];
var validateInline = {}; var validateInline = {};
var clearInline = {}; var clearInline = {};
var validateStep = {}; var validateStep = {};
@ -173,7 +172,11 @@ stepForwardFrom["policy-platform"] = function (actionButton) {
* Forward action of policy profile page. Generates policy profile payload. * Forward action of policy profile page. Generates policy profile payload.
*/ */
stepForwardFrom["policy-profile"] = function () { stepForwardFrom["policy-profile"] = function () {
policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations); /*
generatePolicyProfile() function should be implemented in plugin side and should include the logic to build the
policy profile object.
*/
policy["profile"] = generatePolicyProfile();
// updating next-page wizard title with selected platform // updating next-page wizard title with selected platform
$("#policy-criteria-page-wizard-title").text("ADD " + policy["platform"] + " POLICY"); $("#policy-criteria-page-wizard-title").text("ADD " + policy["platform"] + " POLICY");
}; };
@ -182,8 +185,11 @@ stepForwardFrom["policy-profile"] = function () {
* Backward action of policy profile page. Moves back to platform selection step. * Backward action of policy profile page. Moves back to platform selection step.
*/ */
stepBackFrom["policy-profile"] = function () { stepBackFrom["policy-profile"] = function () {
// reinitialize configuredOperations /*
configuredOperations = []; resetPolicyProfile() function should be implemented in plugin side and should include the logic to reset the policy
profile object.
*/
resetPolicyProfile();
}; };
/** /**
@ -359,18 +365,12 @@ stepForwardFrom["policy-naming"] = function () {
}; };
var savePolicy = function (policy, isActive, serviceURL) { var savePolicy = function (policy, isActive, serviceURL) {
var profilePayloads = []; /*
// traverses key by key in policy["profile"] generateProfileFeaturesList() should be implemented in the plugin side and should include logic to build the
var key; profilePayloads array which contains objects, {featureCode:"value", deviceType:"value", content:"value"}.
for (key in policy["profile"]) { policy["profile"] object will be available for the method which returns from the generatePolicyProfile() function.
if (policy["profile"].hasOwnProperty(key)) { */
profilePayloads.push({ var profilePayloads = generateProfileFeaturesList();
"featureCode": key,
"deviceType": policy["platform"],
"content": policy["profile"][key]
});
}
}
$.each(profilePayloads, function (i, item) { $.each(profilePayloads, function (i, item) {
$.each(item.content, function (key, value) { $.each(item.content, function (key, value) {

View File

@ -20,7 +20,6 @@ var validateStep = {};
var skipStep = {}; var skipStep = {};
var stepForwardFrom = {}; var stepForwardFrom = {};
var stepBackFrom = {}; var stepBackFrom = {};
var configuredOperations = [];
var policy = {}; var policy = {};
var currentlyEffected = {}; var currentlyEffected = {};
@ -200,9 +199,11 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
script.type = 'text/javascript'; script.type = 'text/javascript';
script.src = policyOperationsScriptSrc; script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script); $(".wr-advance-operations").prepend(script);
var configuredOperations = operationModule.populateProfile(policy["platform"], /*
policyPayloadObj["profile"]["profileFeaturesList"]); This method should be implemented in the relevant plugin side and should include the logic to
polulateProfileOperations(configuredOperations); populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
} }
}); });
}); });
@ -227,7 +228,11 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
* Forward action of policy profile page. Generates policy profile payload. * Forward action of policy profile page. Generates policy profile payload.
*/ */
stepForwardFrom["policy-profile"] = function () { stepForwardFrom["policy-profile"] = function () {
policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations); /*
generatePolicyProfile() function should be implemented in plugin side and should include the logic to build the
policy profile object.
*/
policy["profile"] = generatePolicyProfile();
// updating next-page wizard title with selected platform // updating next-page wizard title with selected platform
$("#policy-criteria-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]); $("#policy-criteria-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
}; };
@ -415,19 +420,12 @@ var getParameterByName = function (name) {
}; };
var updatePolicy = function (policy, state) { var updatePolicy = function (policy, state) {
var profilePayloads = []; /*
// traverses key by key in policy["profile"] generateProfileFeaturesList() should be implemented in the plugin side and should include logic to build the
var key; profilePayloads array which contains objects, {featureCode:"value", deviceType:"value", content:"value"}.
for (key in policy["profile"]) { policy["profile"] object will be available for the method which returns from the generatePolicyProfile() function.
*/
if (policy["profile"].hasOwnProperty(key)) { var profilePayloads = generateProfileFeaturesList();
profilePayloads.push({
"featureCode": key,
"deviceType": policy["platform"],
"content": policy["profile"][key]
});
}
}
$.each(profilePayloads, function (i, item) { $.each(profilePayloads, function (i, item) {
$.each(item.content, function (key, value) { $.each(item.content, function (key, value) {

View File

@ -86,9 +86,11 @@ var displayPolicy = function (policyPayloadObj) {
script.type = 'text/javascript'; script.type = 'text/javascript';
script.src = policyOperationsScriptSrc; script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script); $(".wr-advance-operations").prepend(script);
var previouslyConfiguredOperations = operationModule.populateProfile(policy["platform"], /*
policyPayloadObj["profile"]["profileFeaturesList"]); This method should be implemented in the relevant plugin side and should include the logic to
polulateProfileOperations(previouslyConfiguredOperations); populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
} }
}); });
}); });