diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index eda434e2f8a..e12b259fbb4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -264,10 +264,14 @@ public class UserManagementServiceImpl implements UserManagementService { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information"); } - List userList, offsetList; + RequestValidationUtil.validatePaginationParameters(offset, limit); + + List userList, offsetList; String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); - int appliedLimit = (limit <= 0) ? -1 : (limit + offset); + // to get whole set of users, appliedLimit is set to -1 + // by default, this whole set is limited to 100 - MaxUserNameListLength of user-mgt.xml + int appliedLimit = -1; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); @@ -285,14 +289,23 @@ public class UserManagementServiceImpl implements UserManagementService { userList.add(user); } - if (offset <= userList.size()) { - offsetList = userList.subList(offset, userList.size()); + int toIndex = offset + limit; + int listSize = userList.size(); + int lastIndex = listSize - 1; + + if (offset <= lastIndex) { + if (toIndex <= listSize) { + offsetList = userList.subList(offset, toIndex); + } else { + offsetList = userList.subList(offset, listSize); + } } else { offsetList = new ArrayList<>(); } + BasicUserInfoList result = new BasicUserInfoList(); result.setList(offsetList); - result.setCount(offsetList.size()); + result.setCount(users.length); return Response.status(Response.Status.OK).entity(result).build(); } catch (UserStoreException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js new file mode 100644 index 00000000000..0dc9a796029 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js @@ -0,0 +1,175 @@ +/* + Copyright (c) 2016, 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 + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +var removeCustomParam = function () { + $(this).parent().parent().remove(); +}; + +/** + * Following function would execute + * when a user clicks on the list item + * initial mode and with out select mode. + */ +function InitiateViewOption() { + $(location).attr('href', $(this).data("url")); +} + +$("#back-to-search").click(function () { + $('#advance-search-result').addClass('hidden'); + $("#advance-search-form").removeClass('hidden'); + $("#view-search-param").addClass('hidden'); + $("#back-to-search").addClass('hidden'); +}); + +$("#view-search-param").click(function () { + $("#advance-search-form").removeClass('hidden'); + $(".title-result").addClass('hidden'); + $("#view-search-param").addClass('hidden'); +}); + +var dynamicForm = '
' + + '
' + + '
' + + '
'; + +$(document).ready(function () { + var isInit = true; + $("#add-custom-param").click(function () { + $("#customSearchParam").prepend(dynamicForm); + $(".close-button-div").unbind("click"); + $(".close-button-div").bind("click", removeCustomParam); + $(".txt-key").select2({tags: true}); + $(".no-tag").select2({tags: false}); + }); + + $("#device-search-btn").click(function () { + var location = $("#location").val(); + var payload_obj = {}; + var conditions = []; + if (location) { + var conditionObject = {}; + conditionObject.key = "LOCATION"; + conditionObject.value = location; + conditionObject.operator = "="; + conditionObject.state = "OR"; + conditions.push(conditionObject) + } + + $("#customSearchParam .dynamic-search-param").each(function () { + var value = $(this).find(".txt-value").val(); + var key = $(this).find(".txt-key").val() + if (value && key) { + var conditionObject = {}; + conditionObject.key = key; + conditionObject.value = value; + conditionObject.operator = $(this).find(".operator").val(); + conditionObject.state = $(this).find(".state").val(); + conditions.push(conditionObject) + } + }); + payload_obj.conditions = conditions; + var deviceSearchAPI = "/api/device-mgt/v1.0/devices/search-devices"; + $("#advance-search-form").addClass(" hidden"); + $("#loading-content").removeClass('hidden'); + var deviceListing = $("#device-listing"); + var deviceListingSrc = deviceListing.attr("src"); + $.template("device-listing", deviceListingSrc, function (template) { + + var successCallback = function (data) { + if (!data) { + $("#loading-content").addClass('hidden'); + $("#advance-search-result").addClass("hidden"); + $("#advance-search-form").removeClass(" hidden"); + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('No Device are available to be displayed.'); + return; + } + data = JSON.parse(data); + if (data.devices.length == 0) { + $("#loading-content").addClass('hidden'); + $("#advance-search-result").addClass("hidden"); + $("#advance-search-form").removeClass(" hidden"); + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('No Device are available to be displayed.'); + return; + } + var viewModel = {}; + var devices = []; + if (data.devices.length > 0) { + for (i = 0; i < data.devices.length; i++) { + var tempDevice = data.devices[i]; + var device = {}; + device.type = tempDevice.type; + device.name = tempDevice.name; + device.deviceIdentifier = tempDevice.deviceIdentifier; + var properties = {} ; + var enrolmentInfo = {}; + properties.VENDOR = tempDevice.deviceInfo.vendor; + properties.DEVICE_MODEL = tempDevice.deviceInfo.deviceModel; + enrolmentInfo.status = "ACTIVE"; + enrolmentInfo.owner = "N/A"; + enrolmentInfo.ownership = "N/A"; + device.enrolmentInfo = enrolmentInfo; + device.properties = properties; + devices.push(device); + } + viewModel.devices = devices; + $('#advance-search-result').removeClass('hidden'); + $("#view-search-param").removeClass('hidden'); + $("#back-to-search").removeClass('hidden'); + $('#device-grid').removeClass('hidden'); + $('#ast-container').removeClass('hidden'); + $('#user-listing-status-msg').text(""); + var content = template(viewModel); + $("#ast-container").html(content); + } else { + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('No Device are available to be displayed.'); + } + $("#loading-content").addClass('hidden'); + if (isInit) { + $('#device-grid').datatables_extended(); + isInit = false; + } + $(".icon .text").res_text(0.2); + }; + invokerUtil.post(deviceSearchAPI, + payload_obj, + successCallback, + function (message) { + $("#loading-content").addClass('hidden'); + $("#advance-search-result").addClass("hidden"); + $("#advance-search-form").removeClass(" hidden"); + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('Server is unable to perform the search please enroll at least one device or check the search query'); + } + ); + }); + }); +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/templates/device-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/templates/device-listing.hbs new file mode 100644 index 00000000000..7bb2b3e3061 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/templates/device-listing.hbs @@ -0,0 +1,44 @@ + + + {{#each devices}} + + + +
+ +
+ + +

Device {{name}}

+ {{#if properties.DEVICE_MODEL}} +
({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})
+ {{/if}} + + {{enrolmentInfo.owner}} + + {{#equal enrolmentInfo.status "ACTIVE"}} Active{{/equal}} + {{#equal enrolmentInfo.status "INACTIVE"}} Inactive{{/equal}} + {{#equal enrolmentInfo.status "BLOCKED"}} Blocked{{/equal}} + {{#equal enrolmentInfo.status "REMOVED"}} Removed{{/equal}} + + {{type}} + {{enrolmentInfo.ownership}} + + + + + {{/each}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs new file mode 100644 index 00000000000..983b61c66ea --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.hbs @@ -0,0 +1,125 @@ + +{{#zone "content"}} + +
+
+ +
+
+ + +
+
+
+
+

Advanced Device Search

+
+ +
+
+ + + +
+
+
+ +
+ + +
+
+ +
+
+ + +
+
+
+
+ +
+
+
+
+ + + + + + + + + +
+
+ +{{/zone}} +{{#zone "bottomJs"}} + {{js "/js/bottomJs.js"}} + +{{/zone}} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.js new file mode 100644 index 00000000000..75c34b8e0e8 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.js @@ -0,0 +1,44 @@ +/* + Copyright (c) 2016, 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 + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +/** + * 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) { + var log = new Log("units/user-create/certificate-create.js"); + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var response = userModule.getRolesByUserStore(); + var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; + if (response["status"] == "success") { + context["roles"] = response["content"]; + } + + context["charLimit"] = mdmProps["usernameLength"]; + context["usernameJSRegEx"] = mdmProps["userValidationConfig"]["usernameJSRegEx"]; + context["usernameHelpText"] = mdmProps["userValidationConfig"]["usernameHelpMsg"]; + context["usernameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["usernameRegExViolationErrorMsg"]; + context["firstnameJSRegEx"] = mdmProps["userValidationConfig"]["firstnameJSRegEx"]; + context["firstnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["firstnameRegExViolationErrorMsg"]; + context["lastnameJSRegEx"] = mdmProps["userValidationConfig"]["lastnameJSRegEx"]; + context["lastnameRegExViolationErrorMsg"] = mdmProps["userValidationConfig"]["lastnameRegExViolationErrorMsg"]; + + return context; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.json new file mode 100644 index 00000000000..c202f579cfa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/search.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/devices/search", + "layout": "cdmf.layout.default" +} \ 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.notification.listing/public/js/notification-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js index f7f7db822f3..6acbcdc68c0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js @@ -1,26 +1,22 @@ /* - * 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 * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ -var responseCodes = { - "CREATED": "Created", - "ACCEPTED": "202", - "INTERNAL_SERVER_ERROR": "Internal Server Error" -}; +var deviceMgtAPIBaseURI = "/api/device-mgt/v1.0"; /** * Following function would execute @@ -31,6 +27,48 @@ function InitiateViewOption() { $(location).attr('href', $(this).data("url")); } +function loadNotifications() { + var deviceListing = $("#notification-listing"); + var deviceListingSrc = deviceListing.attr("src"); + var currentUser = deviceListing.data("currentUser"); + $.template( + "notification-listing", + deviceListingSrc, + function (template) { + invokerUtil.get( + deviceMgtAPIBaseURI + "/notifications", + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + data = JSON.parse(data); + if (data["notifications"] && data["notifications"].length > 0) { + var viewModel = {}; + viewModel["notifications"] = data["notifications"]; + var content = template(viewModel); + $("#ast-container").html(content); + $("#unread-notifications").datatables_extended(); + $("#all-notifications").datatables_extended(); + } + } + }, + // on error + function (jqXHR) { + console.log(jqXHR.status); + } + ); + } + ); +} + +// Start of HTML embedded invoke methods +function showAdvanceOperation(operation, button) { + $(button).addClass('selected'); + $(button).siblings().removeClass('selected'); + var hiddenOperation = ".wr-hidden-operations-content > div"; + $(hiddenOperation + '[data-operation="' + operation + '"]').show(); + $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); +} + $(document).ready(function () { var permissionSet = {}; $.setPermission = function (permission) { @@ -43,76 +81,31 @@ $(document).ready(function () { loadNotifications(); - $("#ast-container").on("click", ".new-notification", function(e){ + $("#ast-container").on("click", ".new-notification", function(e) { var notificationId = $(this).data("id"); - var redirectUrl = $(this).data("url"); - var getNotificationsAPI = "/api/device-mgt/v1.0/notifications/"+notificationId+"/CHECKED"; + // var redirectUrl = $(this).data("url"); + var query = deviceMgtAPIBaseURI + "/notifications" + "/" + notificationId + "/mark-checked"; var errorMsgWrapper = "#error-msg"; var errorMsg = "#error-msg span"; invokerUtil.put( - getNotificationsAPI, + query, null, - function (data) { - data = JSON.parse(data); - if (data.status == responseCodes["ACCEPTED"]) { + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { $("#config-save-form").addClass("hidden"); - location.href = redirectUrl; - } else if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); + // location.href = redirectUrl; } - - $(errorMsgWrapper).removeClass("hidden"); - }, function (data) { - data = data.status; - if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { + }, + // on error + function (jqXHR) { + if (jqXHR.status == 403) { $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); + } else if (jqXHR.status == 500) { + $(errorMsg).text("An unexpected error occurred. Please try refreshing the page in a while."); } $(errorMsgWrapper).removeClass("hidden"); } ); }); - }); - -function loadNotifications(){ - var deviceListing = $("#notification-listing"); - var deviceListingSrc = deviceListing.attr("src"); - var currentUser = deviceListing.data("currentUser"); - $.template("notification-listing", deviceListingSrc, function (template) { - var serviceURL = "/api/device-mgt/v1.0/notifications"; - var successCallback = function (data) { - var viewModel = {}; - data = JSON.parse(data); - viewModel.notifications = data.notifications; - if(data.count > 0){ - var content = template(viewModel); - $("#ast-container").html(content); - $('#unread-notifications').datatables_extended(); - $('#all-notifications').datatables_extended(); - } - - }; - invokerUtil.get(serviceURL, - successCallback, function(message){ - console.log(message.content); - }); - }); -} - - -// Start of HTML embedded invoke methods -var showAdvanceOperation = function (operation, button) { - $(button).addClass('selected'); - $(button).siblings().removeClass('selected'); - var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="' + operation + '"]').show(); - $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); -}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs index 418bef892bb..39d96b17e8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs @@ -19,7 +19,7 @@ {{description}} - +