From 0945c8f547720082d038d7e91c24ccf7b4b1f51f Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 11 Aug 2016 18:42:53 +0530 Subject: [PATCH 1/2] Adding user create UI --- .../app/modules/business-controllers/user.js | 6 ++--- .../pages/cdmf.page.user.create/create.hbs | 16 +++++------- .../app/pages/cdmf.page.user.create/create.js | 6 ++--- .../public/js/bottomJs.js | 25 +++++++++---------- .../public/js/invoker-lib.js | 4 ++- .../service-invoker-utility.hbs | 4 +-- 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 8e885cd00b..b3b8ff7e8e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -239,8 +239,7 @@ var userModule = function () { * Get User Roles from user store (Internal roles not included). * @returns {object} a response object with status and content on success. */ - publicMethods.getRolesByUserStore = function () { - var ROLE_LIMIT = devicemgtProps["pageSize"]; + publicMethods.getRolesByUserStore = function (userStore) { var carbonUser = session.get(constants["USER_SESSION_KEY"]); var utility = require("/app/modules/utility.js")["utility"]; if (!carbonUser) { @@ -249,7 +248,8 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles?limit=" + ROLE_LIMIT; + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/roles?user-store=" + userStore + "&limit=100"; var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { response.content = parse(response.content).roles; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs index d9f24cd04f..9fc20f8049 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs @@ -67,25 +67,19 @@
- + - +
- +
- +
@@ -121,6 +115,8 @@

User was added successfully.


An invitation mail will be sent to this user to initiate device enrollment. + Below QR code can also be used to enroll a device. +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js index 4cba6f75c3..a93b1a48cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js @@ -18,18 +18,16 @@ /** * Returns the dynamic state to be populated by add-user page. - * - * @param context Object that gets updated with the dynamic state of this page to be presented * @returns {*} A context object that returns the dynamic state of this page to be presented */ -function onRequest(context) { +function onRequest() { //var log = new Log("/app/pages/cdmf.page.user.create server-side js"); var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var page = {}; - var response = userModule.getRolesByUserStore(); + var response = userModule.getRolesByUserStore("PRIMARY"); if (response["status"] == "success") { page["roles"] = response["content"]; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js index 7280042d59..c254b82cc9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -72,8 +72,8 @@ var disableInlineError = function (inputField, errorMsg, errorSign) { * Validate if provided username is valid against RegEx configures. */ validateInline["user-name"] = function () { - var usernameinput = $("input#username"); - if (inputIsValid(usernameinput.data("regex"), usernameinput.val())) { + var usernameInput = $("input#username"); + if (inputIsValid(usernameInput.data("regex"), usernameInput.val())) { disableInlineError("usernameInputField", "usernameEmpty", "usernameError"); } else { enableInlineError("usernameInputField", "usernameEmpty", "usernameError"); @@ -84,9 +84,9 @@ validateInline["user-name"] = function () { * Validate if provided first name is valid against RegEx configures. */ validateInline["first-name"] = function () { - var firstnameinput = $("input#firstname"); - if (firstnameinput.val()) { - disableInlineError("firstNameField", "fnError"); + var firstnameInput = $("input#firstname"); + if (firstnameInput.val()) { + disableInlineError("firstNameField", "fnError"); } else { enableInlineError("firstNameField", "fnError"); } @@ -96,8 +96,8 @@ validateInline["first-name"] = function () { * Validate if provided last name is valid against RegEx configures. */ validateInline["last-name"] = function () { - var lastnameinput = $("input#lastname"); - if (lastnameinput.val()) { + var lastnameInput = $("input#lastname"); + if (lastnameInput.val()) { disableInlineError("lastNameField", "lnError"); } else { enableInlineError("lastNameField", "lnError"); @@ -165,9 +165,9 @@ $("#userStore").change( function () { var str = ""; $("select option:selected").each(function () { - str += $(this).text() + " "; + str += $(this).text() + ""; }); - var getRolesAPI = deviceMgtAPIsBasePath + "/roles/"+ str; + var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + str + "&limit=100"; invokerUtil.get( getRolesAPI, @@ -188,8 +188,7 @@ $("#userStore").change( } ); - } -).change(); + }).change(); $(document).ready(function () { $("#emailValidationText").hide(); @@ -207,7 +206,7 @@ $(document).ready(function () { var usernameInput = $("input#username"); var firstnameInput = $("input#firstname"); var lastnameInput = $("input#lastname"); - //var charLimit = parseInt($("input#username").attr("limit")); + var charLimit = parseInt($("input#username").attr("limit")); var domain = $("#userStore").val(); var username = usernameInput.val().trim(); var firstname = firstnameInput.val(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index a63dcbd5b0..9410669d5a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -27,8 +27,10 @@ var invokerUtil = function () { restAPIRequestDetails["requestURL"] = requestURL; restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload); + var appContext = $("#app-context").data("app-context"); + var request = { - url: context + "/api/invoker/execute/", + url: appContext + "/api/invoker/execute/", type: "POST", contentType: "application/json", data: JSON.stringify(restAPIRequestDetails), diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs index af0fa53631..8975481921 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs @@ -31,11 +31,9 @@
+ {{/zone}} {{#zone "bottomJs"}} - {{js "js/js.cookie.js"}} {{js "js/invoker-lib.js"}} {{/zone}} From 120fe530ac546cdc5f9a7890039a03aff552ffe3 Mon Sep 17 00:00:00 2001 From: kamidu Date: Thu, 11 Aug 2016 19:05:03 +0530 Subject: [PATCH 2/2] Fix the device view related issues --- .../modules/business-controllers/device.js | 39 ++++++++++--------- .../service-invoker-utility.hbs | 4 +- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 4510106bad..c12327a912 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -22,7 +22,7 @@ deviceModule = function () { var utility = require('/app/modules/utility.js').utility; var constants = require('/app/modules/constants.js'); - var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; // var ArrayList = Packages.java.util.ArrayList; @@ -33,6 +33,8 @@ deviceModule = function () { // var ConfigOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation; // var CommandOperation = Packages.org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; + var deviceManagementService = utility.getDeviceManagementService(); + var publicMethods = {}; var privateMethods = {}; @@ -215,18 +217,20 @@ deviceModule = function () { var utility = require('/app/modules/utility.js')["utility"]; try { utility.startTenantFlow(carbonUser); - - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId; + //var url = mdmProps["httpsURL"] + "/mdm-admin/devices/view?type=" + deviceType + "&id=" + deviceId; + var url = mdmProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId; return serviceInvokers.XMLHttp.get( - url, function (responsePayload) { - var device = responsePayload.responseContent; - if (device) { + url, + function (backendResponse) { + var response = {}; + if (backendResponse.status == 200 && backendResponse.responseText) { + response["status"] = "success"; + var device = parse(backendResponse.responseText); var propertiesList = device["properties"]; var properties = {}; - if (propertiesList){ - for (var i = 0; i < propertiesList.length; i++) { - properties[propertiesList[i]["name"]] = propertiesList[i]["value"]; - } + for (var i = 0; i < propertiesList.length; i++) { + properties[propertiesList[i]["name"]] = + propertiesList[i]["value"]; } var deviceObject = {}; deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"]; @@ -241,13 +245,12 @@ deviceModule = function () { properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"]; } deviceObject[constants["DEVICE_PROPERTIES"]] = properties; - return deviceObject; + response["content"] = deviceObject; + return response; + } else { + response["status"] = "error"; + return response; } - }, - function (responsePayload) { - var response = {}; - response["status"] = "error"; - return response; } ); } catch (e) { @@ -310,9 +313,9 @@ deviceModule = function () { var url; var license; if (deviceType == "windows") { - url = devicemgtProps["httpURL"] + "/mdm-windows-agent/services/device/license"; + url = mdmProps["httpURL"] + "/mdm-windows-agent/services/device/license"; } else if (deviceType == "ios") { - url = devicemgtProps["httpsURL"] + "/ios-enrollment/license/"; + url = mdmProps["httpsURL"] + "/ios-enrollment/license/"; } if (url != null && url != undefined) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs index af0fa53631..cae63722ba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs @@ -32,10 +32,12 @@ {{/zone}} -{{#zone "bottomJs"}} +{{#zone "topJs"}} +{{/zone}} +{{#zone "bottomJs"}} {{js "js/js.cookie.js"}} {{js "js/invoker-lib.js"}} {{/zone}}