Merge pull request #540 from madawas/release-2.0.x

Refactoring policy view and edit units
This commit is contained in:
Rasika Perera 2017-01-11 22:39:53 +05:30 committed by GitHub
commit e05600607a
6 changed files with 123 additions and 95 deletions

View File

@ -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">

View File

@ -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");

View File

@ -179,27 +179,27 @@ 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';
$.isResourceExists(policyOperationsTemplateSrc, function (status) { if (policyEditTemplateSrc) {
if (status) { if (policyEditScriptSrc) {
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) { var script = document.createElement('script');
script.type = 'text/javascript';
script.src = context + policyEditScriptSrc;
$(".wr-advance-operations").prepend(script);
hasPolicyProfileScript = true;
} else {
hasPolicyProfileScript = false;
}
$.template(policyEditTemplateCacheKey, context + policyEditTemplateSrc, function (template) {
var content = template(); var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden"); $("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden"); $(".policy-platform").addClass("hidden");
$.isResourceExists(policyOperationsScriptSrc, function (status) { if (hasPolicyProfileScript) {
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 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. populate the policy profile in the plugin specific UI.
@ -207,22 +207,17 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); 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"); $("#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"); $(".wr-advance-operations-init").addClass("hidden");
});
if (!hasPolicyProfileScript) { if (!hasPolicyProfileScript) {
populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);

View File

@ -67,27 +67,27 @@ 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');
script.type = 'text/javascript';
script.src = context + policyViewScriptSrc;
$(".wr-advance-operations").prepend(script);
hasPolicyProfileScript = true;
} else {
hasPolicyProfileScript = false;
}
$.template(policyViewTemplateCacheKey, context + policyViewTemplateSrc, function (template) {
var content = template(); var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden"); $("#device-type-policy-operations").html(content).removeClass("hidden");
$(".policy-platform").addClass("hidden"); $(".policy-platform").addClass("hidden");
$.isResourceExists(policyOperationsScriptSrc, function (status) { if (hasPolicyProfileScript) {
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 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. populate the policy profile in the plugin specific UI.
@ -95,22 +95,17 @@ var displayPolicy = function (policyPayloadObj) {
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); 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"); $("#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"); $(".wr-advance-operations-init").addClass("hidden");
});
if (!hasPolicyProfileScript) { if (!hasPolicyProfileScript) {
populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); populateGenericProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);

View File

@ -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;">

View File

@ -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;
} }