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
revert-70aa11f8
Madawa Soysa 7 years ago committed by Madhawa Perera
parent 0bbdf7a65f
commit e617273c3d

@ -41,8 +41,7 @@ var displayPolicy = function (policyPayloadObj) {
if (!policyPayloadObj.users) { if (!policyPayloadObj.users) {
$("#policy-users").text("NONE"); $("#policy-users").text("NONE");
} } else if (policyPayloadObj.users.length > 0) {
else if (policyPayloadObj.users.length > 0) {
$("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", "));
} else { } else {
$("#users-row").addClass("hidden"); $("#users-row").addClass("hidden");
@ -59,14 +58,11 @@ var displayPolicy = function (policyPayloadObj) {
} }
} }
$("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); $("#policy-groups").text(assignedGroups.toString().split(",").join(", "));
} else {
$("#policy-groups").text("NONE");
} }
if (!policyPayloadObj.roles) { if (!policyPayloadObj.roles) {
$("#policy-roles").text("NONE"); $("#policy-roles").text("NONE");
} } else if (policyPayloadObj.roles.length > 0) {
else if (policyPayloadObj.roles.length > 0) {
$("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", "));
} else { } else {
$("#roles-row").addClass("hidden"); $("#roles-row").addClass("hidden");

@ -41,12 +41,17 @@ var displayPolicy = function (policyPayloadObj) {
$("#policy-status").html(policyStatus); $("#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(", ")); $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", "));
} else { } else {
$("#users-row").addClass("hidden"); $("#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 deviceGroups = policyPayloadObj.deviceGroups;
var assignedGroups = []; var assignedGroups = [];
for (var index in deviceGroups) { for (var index in deviceGroups) {
@ -55,14 +60,12 @@ var displayPolicy = function (policyPayloadObj) {
} }
} }
$("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); $("#policy-groups").text(assignedGroups.toString().split(",").join(", "));
} else {
$("#policy-groups").text("NONE");
} }
if (policyPayloadObj.roles.length > 0) { if (!policyPayloadObj.roles) {
$("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", "));
} else {
$("#roles-row").addClass("hidden"); $("#roles-row").addClass("hidden");
} else if (policyPayloadObj.roles.length > 0) {
$("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", "));
} }
var policyId = policyPayloadObj["id"]; var policyId = policyPayloadObj["id"];

Loading…
Cancel
Save