From b5f4bd757af7a6f5d8ff2102c62b261aa9cdc685 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Mon, 19 Feb 2018 17:23:22 +0530 Subject: [PATCH] Fixing devices listing page filters are not showing all the available filtering options Resolves https://github.com/wso2/product-iots/issues/1689 --- .../devicemgt/api/data-tables-invoker-api.jag | 45 ++++++++++++++++++- .../modules/business-controllers/policy.js | 14 +++++- .../app/pages/cdmf.page.devices/devices.hbs | 8 ++-- .../app/pages/cdmf.page.policies/policies.hbs | 8 ++-- .../public/js/dataTables.extended.js | 37 ++++++++++++++- .../dataTables.extended.serversidepaging.js | 36 ++++++++++++++- .../configuration.hbs | 2 + .../configuration.js | 10 +++-- .../public/css/custom-desktop.css | 4 +- .../jaggeryapps/devicemgt/jaggery.conf | 2 +- .../lib/theme-wso2_1.0/less/theme-wso2.less | 2 +- 11 files changed, 147 insertions(+), 21 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag index 5f34c846995..a22707aa808 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag @@ -25,6 +25,11 @@ var uriMatcher = new URIMatcher(String(uri)); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var utility = require("/app/modules/utility.js")["utility"]; +var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; +var EnrolmentInfo = Packages.org.wso2.carbon.device.mgt.common.EnrolmentInfo; + +var DTYPE_CONF_DEVICE_TYPE_KEY = "deviceType"; +var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; function appendQueryParam (url, queryParam , value) { if (url.indexOf("?") > 0) { @@ -33,7 +38,45 @@ function appendQueryParam (url, queryParam , value) { return url + "?" + queryParam + "=" + value; } -if (uriMatcher.match("/{context}/api/data-tables/invoker")) { +if (uriMatcher.match("/{context}/api/data-tables/invoker/filters")) { + var result = {}; + var i; + //Fetching Status types + var status = EnrolmentInfo.Status.values(); + var statusArr = []; + for(i = 0; i < status.length; i++){ + statusArr.push(status[i].name()); + } + result.status = statusArr; + //Fetching Ownership types + var ownership = EnrolmentInfo.OwnerShip.values(); + var ownershipArr = []; + for(i = 0; i < ownership.length; i++){ + ownershipArr.push(ownership[i].name()); + } + result.ownership = ownershipArr; + //Fetching Device Types + result.deviceTypes = []; + var deviceTypesRes = deviceModule.getDeviceTypes(); + if (deviceTypesRes.status === "success") { + var deviceTypes = deviceTypesRes["content"]["deviceTypes"]; + for (i = 0; i < deviceTypes.length; i++) { + var deviceTypeLabel = deviceTypes[i]; + var configs = utility.getDeviceTypeConfig(deviceTypeLabel); + if (configs) { + if (configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY]) { + deviceTypeLabel = configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY]; + } + } + result.deviceTypes.push(deviceTypeLabel); + } + } + //Adding policy compliance + result.compliance = ["MONITOR", "ENFORCE", "WARN", "BLOCK"]; + response["status"] = 200; + response["content"] = result; + response["contentType"] = "application/json"; +} else if (uriMatcher.match("/{context}/api/data-tables/invoker")) { var url = request.getParameter("url"); var targetURL = devicemgtProps["httpsURL"] + request.getParameter("url"); //noinspection JSUnresolvedFunction getAllParameters 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 73f539562cc..de106c6ecb6 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 @@ -51,7 +51,19 @@ policyModule = function () { policyObjectToView["deviceTypeIcon"] = policyObjectToView["platform"]; } //policyObjectToView["icon"] = utility.getDeviceThumb(policyObjectToView["platform"]); - policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"]; + var ownershipType = "None"; + var deviceGroups = policyObjectFromRestEndpoint["deviceGroups"]; + if (deviceGroups) { + for (var j = 0; j < deviceGroups.length; j++) { + var deviceGroup = deviceGroups[j]; + if (deviceGroup.name === "COPE") { + ownershipType = (ownershipType === "BYOD") ? "BYOD & COPE" : "COPE"; + } else if (deviceGroup.name === "BYOD") { + ownershipType = (ownershipType === "COPE") ? "BYOD & COPE" : "BYOD"; + } + } + } + policyObjectToView["ownershipType"] = ownershipType; var assignedRoleCount = policyObjectFromRestEndpoint["roles"].length; var assignedUserCount = policyObjectFromRestEndpoint["users"].length; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 3fe1991ac47..c2ed77579d4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -160,7 +160,7 @@ - By Device Name + By Owner By Status By Platform @@ -169,11 +169,11 @@ - + - + - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs index 0e4a7840e86..6742acaba5a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.hbs @@ -130,12 +130,12 @@ - - + + - - + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index c8164df746e..14cd5f88850 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -56,7 +56,7 @@ $.fn.datatables_extended = function (settings) { search: '' }, initComplete: function () { - + var cachedFilterRes; this.api().columns().every(function () { var column = this; @@ -94,8 +94,41 @@ $.fn.datatables_extended = function (settings) { } }); + if (!cachedFilterRes) { + $.ajax( + { + url: context + "/api/data-tables/invoker/filters", + async:false, + success: function(data) { + cachedFilterRes = data; + } + } + ); + } + $(column).each(function () { - if ($(column.nodes()).attr('data-search')) { + var i; + if (filterColumn.eq(column.index()).hasClass('data-status')) { + for(i = 0; i < cachedFilterRes.status.length; i++){ + var status = cachedFilterRes.status[i]; + select.append('') + } + } else if (filterColumn.eq(column.index()).hasClass('data-ownership')) { + for(i = 0; i < cachedFilterRes.ownership.length; i++){ + var ownership = cachedFilterRes.ownership[i]; + select.append('') + } + } else if (filterColumn.eq(column.index()).hasClass('data-platform')) { + for(i = 0; i < cachedFilterRes.deviceTypes.length; i++){ + var deviceTypes = cachedFilterRes.deviceTypes[i]; + select.append('') + } + } else if (filterColumn.eq(column.index()).hasClass('data-compliance')) { + for(i = 0; i < cachedFilterRes.deviceTypes.length; i++){ + var compliance = cachedFilterRes.compliance[i]; + select.append('') + } + } else if ($(column.nodes()).attr('data-search')) { var values = []; column.nodes().unique().sort().each(function (d, j) { var title = $(d).attr('data-display'); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 32009a3cc19..2bf0713a3e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -117,6 +117,7 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter console.warn('Warning : Dependency missing - Bootstrap Tooltip Library'); } + var cachedFilterRes; this.api().columns().every(function () { var column = this; @@ -169,8 +170,41 @@ $.fn.datatables_extended_serverside_paging = function (settings, url, dataFilter } }); + if(!cachedFilterRes){ + $.ajax( + { + url: context + "/api/data-tables/invoker/filters", + async:false, + success: function(data){ + cachedFilterRes = data; + } + } + ); + } + $(column).each(function () { - if ($(column.nodes()).attr('data-search')) { + var i; + if (filterColumn.eq(column.index()).hasClass('data-status')) { + for(i = 0; i < cachedFilterRes.status.length; i++){ + var status = cachedFilterRes.status[i]; + select.append('') + } + } else if (filterColumn.eq(column.index()).hasClass('data-ownership')) { + for(i = 0; i < cachedFilterRes.ownership.length; i++){ + var ownership = cachedFilterRes.ownership[i]; + select.append('') + } + } else if (filterColumn.eq(column.index()).hasClass('data-platform')) { + for(i = 0; i < cachedFilterRes.deviceTypes.length; i++){ + var deviceTypes = cachedFilterRes.deviceTypes[i]; + select.append('') + } + } else if (filterColumn.eq(column.index()).hasClass('data-compliance')) { + for(i = 0; i < cachedFilterRes.deviceTypes.length; i++){ + var compliance = cachedFilterRes.compliance[i]; + select.append('') + } + } else if ($(column.nodes()).attr('data-search')) { var titles = []; column.nodes().unique().sort().each(function (d, j) { var title = $(d).attr('data-display'); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs index c53f32cce9b..1d42bd01d80 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.hbs @@ -104,6 +104,7 @@ + {{#if geoServicesEnabled}} + {{/if}} {{/unless}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js index 72d6b64c926..759175edffe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js @@ -18,8 +18,9 @@ function onRequest(context) { var utility = require("/app/modules/utility.js").utility; - var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + //get all device types var isAuthorized = false; if (userModule.isAuthorized("/permission/admin/device-mgt/notifications/view")) { @@ -48,9 +49,10 @@ function onRequest(context) { } } } + var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.isEnabled; return { + "geoServicesEnabled": geoServicesEnabled, "deviceTypes": deviceTypesArray, - "isAuthorized": isAuthorized, - "isCloud": mdmProps["isCloud"] + "isAuthorized": isAuthorized }; -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css index b661f08b220..1894b38f37e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css @@ -6152,7 +6152,7 @@ body.inverse .fade-edge:after { .table.list-table.grid-view > thead > tr > td, .table.list-table.grid-view > thead > tr > th { - display: inline-block; + /*display: inline-block;*/ } .table.list-table.grid-view > thead > tr > td:not(:empty):before, @@ -6922,7 +6922,7 @@ select > option:hover { } .table.list-table:not(.grid-view) { - margin: 0px !important; + margin: 6px 0px 0px 0px !important; } .table.list-table:not(.grid-view) > thead, .table.list-table:not(.grid-view) > tbody, .table.list-table:not(.grid-view) > tfoot { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf index 8cedf29ec95..2b567f12991 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf @@ -48,7 +48,7 @@ "path": "/lib/pages.jag" }, { - "url": "/api/data-tables/invoker", + "url": "/api/data-tables/*", "path": "/api/data-tables-invoker-api.jag" }, { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/less/theme-wso2.less b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/less/theme-wso2.less index 80f7cfe4691..61c1527f742 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/less/theme-wso2.less +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/uuf-template-app/app/units/uuf.unit.theme/public/lib/theme-wso2_1.0/less/theme-wso2.less @@ -1766,7 +1766,7 @@ input[type=number].form-control { } & > thead > tr > td, & > thead > tr > th { - display: inline-block; + //display: inline-block; } & > thead > tr > td:not(:empty):before, & > thead > tr > th:not(:empty):before {