From e617273c3d26ba9d89a82cd25d41c3b027c16bef Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Sat, 3 Mar 2018 12:09:54 +0530 Subject: [PATCH] Fix policy view interface loading issue (#1206) * Fix policy view interface loading issue When the policy view page is loaded some of the variables of the policyPayloadObj becomes undefined or null. This commit checks for the empty and undefined variables. Relates wso2/product-iots#1681 * Fix formatting issues --- .../public/js/view.js | 8 ++------ .../cdmf.unit.policy.view/public/js/view.js | 17 ++++++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js index c28deb2db5e..a2b2e27b941 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js @@ -41,8 +41,7 @@ var displayPolicy = function (policyPayloadObj) { if (!policyPayloadObj.users) { $("#policy-users").text("NONE"); - } - else if (policyPayloadObj.users.length > 0) { + } else if (policyPayloadObj.users.length > 0) { $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); } else { $("#users-row").addClass("hidden"); @@ -59,14 +58,11 @@ var displayPolicy = function (policyPayloadObj) { } } $("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); - } else { - $("#policy-groups").text("NONE"); } if (!policyPayloadObj.roles) { $("#policy-roles").text("NONE"); - } - else if (policyPayloadObj.roles.length > 0) { + } else if (policyPayloadObj.roles.length > 0) { $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); } else { $("#roles-row").addClass("hidden"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js index 9a5eef0ee32..cf9a711f420 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.view/public/js/view.js @@ -41,12 +41,17 @@ var displayPolicy = function (policyPayloadObj) { $("#policy-status").html(policyStatus); - if (policyPayloadObj.users.length > 0) { + if (!policyPayloadObj.users) { + $("#policy-users").text("NONE"); + } else if (policyPayloadObj.users.length > 0) { $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); } else { $("#users-row").addClass("hidden"); } - if (policyPayloadObj.deviceGroups.length > 0) { + + if (!policyPayloadObj.deviceGroups) { + $("#policy-groups").text("NONE"); + } else if (policyPayloadObj.deviceGroups.length > 0) { var deviceGroups = policyPayloadObj.deviceGroups; var assignedGroups = []; for (var index in deviceGroups) { @@ -55,14 +60,12 @@ var displayPolicy = function (policyPayloadObj) { } } $("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); - } else { - $("#policy-groups").text("NONE"); } - if (policyPayloadObj.roles.length > 0) { - $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); - } else { + if (!policyPayloadObj.roles) { $("#roles-row").addClass("hidden"); + } else if (policyPayloadObj.roles.length > 0) { + $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); } var policyId = policyPayloadObj["id"];