Refactoring policy view and edit units

Refactored the units policy.view and policy.edit to be consistant with policy.create unit. Related to IOTS-296
revert-70aa11f8
Madawa Soysa 8 years ago
parent bb7286c2d5
commit a28458cf13

@ -2,6 +2,8 @@
{{#if isAuthorized }} {{#if isAuthorized }}
<span id="logged-in-user" class="hidden" data-username="{{user.username}}" data-domain="{{user.domain}}" <span id="logged-in-user" class="hidden" data-username="{{user.username}}" data-domain="{{user.domain}}"
data-tenant-id="{{user.tenantId}}"></span> data-tenant-id="{{user.tenantId}}"></span>
<span id="policy-operations" class="hidden" data-template="{{policyOperations.template}}"
data-script="{{policyOperations.script}}" data-style="{{policyOperations.style}}"></span>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">

@ -17,8 +17,8 @@
*/ */
function onRequest(context) { function onRequest(context) {
var log = new Log("policy-view-edit-unit backend js"); var deviceType = request.getParameter("deviceType");
var utility = require("/app/modules/utility.js").utility;
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
@ -31,12 +31,30 @@ function onRequest(context) {
if (usersResult.status == "success") { if (usersResult.status == "success") {
context.users = usersResult.content; context.users = usersResult.content;
} }
context["groups"] = groupModule.getGroups(); context["groups"] = groupModule.getGroups();
var user = userModule.getCarbonUser(); var user = userModule.getCarbonUser();
context["user"] = {username: user.username, domain: user.domain, tenantId: user.tenantId}; context["user"] = {username: user.username, domain: user.domain, tenantId: user.tenantId};
context["policyOperations"] = {};
var policyEditSrc = "/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-edit");
if (new File(policyEditSrc).isExists()) {
var policyOperationsTemplateSrc = policyEditSrc + "/public/templates/" + deviceType + "-policy-edit.hbs";
if (new File(policyOperationsTemplateSrc).isExists()) {
context["policyOperations"].template = "/public/cdmf.unit.device.type." + deviceType +
".policy-edit/templates/" + deviceType + "-policy-edit.hbs";
}
var policyOperationsScriptSrc = policyEditSrc + "/public/js/" + deviceType + "-policy-edit.js";
if (new File(policyOperationsScriptSrc).isExists()) {
context["policyOperations"].script = "/public/cdmf.unit.device.type." + deviceType + ".policy-edit/js/" +
deviceType + "-policy-edit.js";
}
var policyOperationsStylesSrc = policyEditSrc + "/public/css/" + deviceType + "-policy-edit.css";
if (new File(policyOperationsStylesSrc).isExists()) {
context["policyOperations"].style = "/public/cdmf.unit.device.type." + deviceType + ".policy-edit/css/" +
deviceType + "-policy-edit.css";
}
}
context.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/manage"); context.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/manage");
context.isAuthorizedViewUsers = userModule.isAuthorized("/permission/admin/device-mgt/roles/view"); context.isAuthorizedViewUsers = userModule.isAuthorized("/permission/admin/device-mgt/roles/view");
context.isAuthorizedViewRoles = userModule.isAuthorized("/permission/admin/device-mgt/users/view"); context.isAuthorizedViewRoles = userModule.isAuthorized("/permission/admin/device-mgt/users/view");

@ -179,52 +179,47 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
$("#policy-profile-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]); $("#policy-profile-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
var deviceType = policy["platform"]; var deviceType = policy["platform"];
var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType + var policyOperations = $("#policy-operations");
'.policy-edit/templates/' + deviceType + '-policy-edit.hbs'; var policyEditTemplateSrc = $(policyOperations).data("template");
var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType + var policyEditScriptSrc = $(policyOperations).data("script");
'.policy-edit/js/' + deviceType + '-policy-edit.js'; var policyEditStylesSrc = $(policyOperations).data("style");
var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType + var policyEditTemplateCacheKey = deviceType + '-policy-edit';
'.policy-edit/css/' + deviceType + '-policy-edit.css';
var policyOperationsTemplateCacheKey = deviceType + '-policy-operations'; if (policyEditTemplateSrc) {
if (policyEditScriptSrc) {
$.isResourceExists(policyOperationsTemplateSrc, function (status) { var script = document.createElement('script');
if (status) { script.type = 'text/javascript';
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) { script.src = context + policyEditScriptSrc;
var content = template(); $(".wr-advance-operations").prepend(script);
$("#device-type-policy-operations").html(content).removeClass("hidden"); hasPolicyProfileScript = true;
$(".policy-platform").addClass("hidden");
$.isResourceExists(policyOperationsScriptSrc, function (status) {
if (status) {
hasPolicyProfileScript = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script);
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
});
$.isResourceExists(policyOperationsStylesSrc, function (status) {
if (status) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = policyOperationsStylesSrc;
$(".wr-advance-operations").prepend(style);
}
});
} else { } else {
$("#generic-policy-operations").removeClass("hidden"); hasPolicyProfileScript = false;
} }
$(".wr-advance-operations-init").addClass("hidden"); $.template(policyEditTemplateCacheKey, context + policyEditTemplateSrc, function (template) {
}); var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden");
if (hasPolicyProfileScript) {
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
} else {
$("#generic-policy-operations").removeClass("hidden");
}
if (policyEditStylesSrc) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = context + policyEditStylesSrc;
$(".wr-advance-operations").prepend(style);
}
$(".wr-advance-operations-init").addClass("hidden");
if(!hasPolicyProfileScript) { if (!hasPolicyProfileScript) {
populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
} }
}; };

@ -67,52 +67,47 @@ var displayPolicy = function (policyPayloadObj) {
} }
var deviceType = policy["platform"]; var deviceType = policy["platform"];
var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType + var policyOperations = $("#policy-operations");
'.policy-view/templates/' + deviceType + '-policy-view.hbs'; var policyViewTemplateSrc = $(policyOperations).data("template");
var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType + var policyViewScriptSrc = $(policyOperations).data("script");
'.policy-view/js/' + deviceType + '-policy-view.js'; var policyViewStylesSrc = $(policyOperations).data("style");
var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType + var policyViewTemplateCacheKey = deviceType + '-policy-view';
'.policy-view/css/' + deviceType + '-policy-view.css';
var policyOperationsTemplateCacheKey = deviceType + '-policy-operations';
$.isResourceExists(policyOperationsTemplateSrc, function (status) { if (policyViewTemplateSrc) {
if (status) { if (policyViewScriptSrc) {
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) { var script = document.createElement('script');
var content = template(); script.type = 'text/javascript';
$("#device-type-policy-operations").html(content).removeClass("hidden"); script.src = context + policyViewScriptSrc;
$(".policy-platform").addClass("hidden"); $(".wr-advance-operations").prepend(script);
$.isResourceExists(policyOperationsScriptSrc, function (status) { hasPolicyProfileScript = true;
if (status) {
hasPolicyProfileScript = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script);
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
});
$.isResourceExists(policyOperationsStylesSrc, function (status) {
if (status) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = policyOperationsStylesSrc;
$(".wr-advance-operations").prepend(style);
}
});
} else { } else {
$("#generic-policy-operations").removeClass("hidden"); hasPolicyProfileScript = false;
} }
$(".wr-advance-operations-init").addClass("hidden"); $.template(policyViewTemplateCacheKey, context + policyViewTemplateSrc, function (template) {
}); var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden");
if (hasPolicyProfileScript) {
/*
This method should be implemented in the relevant plugin side and should include the logic to
populate the policy profile in the plugin specific UI.
*/
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
}
});
} else {
$("#generic-policy-operations").removeClass("hidden");
}
if (policyViewStylesSrc) {
var style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = context + policyViewStylesSrc;
$(".wr-advance-operations").prepend(style);
}
$(".wr-advance-operations-init").addClass("hidden");
if(!hasPolicyProfileScript) { if (!hasPolicyProfileScript) {
populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
} }
}; };

@ -8,7 +8,8 @@
</div> </div>
</div> </div>
{{/defineZone}} {{/defineZone}}
<span id="policy-operations" class="hidden" data-template="{{template}}" data-script="{{script}}"
data-style="{{style}}"></span>
<!-- #page-content-wrapper --> <!-- #page-content-wrapper -->
<div class="page-content-wrapper"> <div class="page-content-wrapper">
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;"> <div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">

@ -17,10 +17,27 @@
*/ */
function onRequest(context) { function onRequest(context) {
// var log = new Log("policy-view-edit-unit backend js"); var utility = require("/app/modules/utility.js").utility;
var page = {};
// var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceType = request.getParameter("deviceType");
// context.roles = userModule.getRoles(); var policyViewSrc = "/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-view");
context.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/view"); if (new File(policyViewSrc).isExists()) {
return context; var policyOperationsTemplateSrc = policyViewSrc + "/public/templates/" + deviceType + "-policy-view.hbs";
if (new File(policyOperationsTemplateSrc).isExists()) {
page.template = "/public/cdmf.unit.device.type." + deviceType + ".policy-view/templates/" + deviceType +
"-policy-view.hbs";
}
var policyOperationsScriptSrc = policyViewSrc + "/public/js/" + deviceType + "-policy-view.js";
if (new File(policyOperationsScriptSrc).isExists()) {
page.script = "/public/cdmf.unit.device.type." + deviceType + ".policy-view/js/" + deviceType +
"-policy-view.js";
}
var policyOperationsStylesSrc = policyViewSrc + "/public/css/" + deviceType + "-policy-view.css";
if (new File(policyOperationsStylesSrc).isExists()) {
page.style = "/public/cdmf.unit.device.type." + deviceType + ".policy-view/css/" + deviceType +
"-policy-view.css";
}
}
page.isAuthorized = userModule.isAuthorized("/permission/admin/device-mgt/policies/view");
return page;
} }
Loading…
Cancel
Save