From ca2a1b85c30c0a7a6536c14414a1e12d5cc31375 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Thu, 17 Oct 2019 19:20:12 +0530 Subject: [PATCH] Add UI controller method to retrieve all policies by policy type --- .../modules/business-controllers/policy.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js index 147b664ba63..8c881ef3df8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js @@ -62,6 +62,8 @@ policyModule = function () { policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"]; policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]; + policyObjectFromRestEndpoint["policyType"] = policyListFromRestEndpoint["policyType"]; + policyObjectFromRestEndpoint["correctiveActions"] = policyListFromRestEndpoint["correctiveActions"]; if (policyObjectToView["platform"] == "ios") { policyObjectToView["deviceTypeIcon"] = "apple"; } else { @@ -168,6 +170,27 @@ policyModule = function () { } }; + /** + * Retrieve all policies based on policy type + */ + publicMethods.getAllPoliciesByType = function (policyType) { + var carbonUser = session.get(constants["USER_SESSION_KEY"]); + if (!carbonUser) { + log.error("User object was not found in the session"); + userModule.logout(function () { + response.sendRedirect(devicemgtProps["appContext"] + "login"); + }); + } + try { + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/policies/type/" + policyType + "?offset=0&limit=100"; + return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse); + } catch (e) { + log.error("Error occurred while retrieving policies by policy type " + policyType); + throw e; + } + }; + /* Get policies count from backend services. */