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 0000000000..0dc9a79602 --- /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 0000000000..7bb2b3e306 --- /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 0000000000..983b61c66e --- /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 0000000000..75c34b8e0e --- /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 0000000000..c202f579cf --- /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