forked from community/device-mgt-core
parent
6a580994fb
commit
28760d2bee
@ -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 = '<div class="dynamic-search-param row"><div class="row"><a class="close-button-div icon fw fw-error">' +
|
||||
'</a></div><div class="form-group wr-input-control col-md-2"><label class="wr-input-label ">State</label>' +
|
||||
'<select class="state no-tag form-control select2-custom"><option>AND</option><option>OR</option></select></div><div ' +
|
||||
'class="form-group wr-input-control col-md-4"><label class="wr-input-label ">Key</label><select class=' +
|
||||
'"txt-key form-control select2-custom"><option>deviceModel</option><option>vendor</option><option>osVersion' +
|
||||
'</option><option>batteryLevel</option><option>internalTotalMemory</option> <option>' +
|
||||
'internalAvailableMemory</option> <option>externalTotalMemory</option> <option>externalAvailableMemory' +
|
||||
'</option> <option>connectionType</option> <option>ssid</option> <option>cpuUsage</option> <option>' +
|
||||
'totalRAMMemory</option> <option>availableRAMMemory</option> <option>pluggedIn</option></select></div>' +
|
||||
'<div class="form-group wr-input-control col-md-2">' +
|
||||
'<label class="wr-input-label ">Operator</label><select class="form-control select2-custom no-tag operator">' +
|
||||
'<option>=</option><option> !=</option><option> <</option>' +
|
||||
'<option> =<</option><option> ></option><option> >=</option></select></div><div class="form-group ' +
|
||||
'wr-input-control col-md-4"><label class="wr-input-label' +
|
||||
' ">Value</label><input type="text" class="form-control txt-value"/></div></div>';
|
||||
|
||||
$(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');
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,44 @@
|
||||
|
||||
|
||||
{{#each devices}}
|
||||
|
||||
<tr data-type="selectable" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}">
|
||||
<td class="remove-padding icon-only content-fill viewEnabledIcon"
|
||||
{{#unequal enrolmentInfo.status "REMOVED"}}
|
||||
data-url="view?type={{type}}&id={{deviceIdentifier}}"
|
||||
{{/unequal}}
|
||||
>
|
||||
<div class="thumbnail icon">
|
||||
<i class="square-element text fw fw-mobile"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td class="fade-edge" data-search="{{properties.DEVICE_MODEL}},{{properties.VENDOR}}" data-display="{{properties.DEVICE_MODEL}}">
|
||||
<h4>Device {{name}}</h4>
|
||||
{{#if properties.DEVICE_MODEL}}
|
||||
<div>({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})</div>
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.owner}}" data-display="{{enrolmentInfo.owner}}" data-grid-label="Owner">{{enrolmentInfo.owner}}</td>
|
||||
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.status}}" data-display="{{enrolmentInfo.status}}" data-grid-label="Status">
|
||||
{{#equal enrolmentInfo.status "ACTIVE"}}<span><i class="fw fw-ok icon-success"></i> Active</span>{{/equal}}
|
||||
{{#equal enrolmentInfo.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
|
||||
{{#equal enrolmentInfo.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
|
||||
{{#equal enrolmentInfo.status "REMOVED"}}<span><i class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
|
||||
</td>
|
||||
<td class="fade-edge remove-padding-top" data-search="{{type}}" data-display="{{type}}" data-grid-label="Type">{{type}}</td>
|
||||
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}" data-display="{{enrolmentInfo.ownership}}" data-grid-label="Ownership">{{enrolmentInfo.ownership}}</td>
|
||||
<td class="text-right content-fill text-left-on-grid-view no-wrap">
|
||||
<!--{{#equal type "TemperatureController"}}
|
||||
{{#equal status "INACTIVE"}}
|
||||
<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view claim-btn" data-deviceid="{{deviceIdentifier}}">
|
||||
<span class="fw-stack">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-edit fw-stack-1x"></i>
|
||||
</span>
|
||||
<span class="hidden-xs hidden-on-grid-view">Claim</span>
|
||||
</a>
|
||||
{{/equal}}
|
||||
{{/equal}}-->
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
@ -0,0 +1,125 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
{{#zone "content"}}
|
||||
<!-- content/body -->
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<!-- content -->
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-centered">
|
||||
<button id="back-to-search" class="wr-btn col-fixed-right hidden">Back to Search Query</button>
|
||||
<button id="view-search-param" class="wr-btn col-fixed-right hidden">View Search Query</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="advance-search-form" class="container col-centered wr-content">
|
||||
<div class="wr-form">
|
||||
<p class="page-sub-title">Advanced Device Search</p>
|
||||
<hr/>
|
||||
<div id="device-listing-status" class="raw hidden">
|
||||
<div class="col-lg-12 col-md-12">
|
||||
<ul style="list-style-type: none;">
|
||||
<li class="message message-info">
|
||||
<h4>
|
||||
<i class="icon fw fw-info"></i>
|
||||
<a id="device-listing-status-msg"></a>
|
||||
</h4>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12">
|
||||
<div id="device-search-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
|
||||
<label class="wr-input-label ">
|
||||
Location
|
||||
</label>
|
||||
<br>
|
||||
<div class="row" >
|
||||
<div id="locationInputField" class=" col-md-10 form-group wr-input-control">
|
||||
<input type="text" id="location" class="form-control"/>
|
||||
<br>
|
||||
<span class=" locationError hidden glyphicon glyphicon-remove form-control-feedback"></span>
|
||||
<label class="error usernameEmpty hidden" for="summary">This field is required.</label>
|
||||
</div>
|
||||
<div class= "col-md-2 form-group wr-input-control col-fixed-right">
|
||||
<button id="device-search-btn" class="wr-btn-search ">Search</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="add-custom-param" class="wr-btn">Add a custom search parameter</button>
|
||||
<br>
|
||||
</div>
|
||||
<br>
|
||||
<div id="customSearchParam" class="col-lg-10 col-md-10">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content -->
|
||||
<!-- loading -->
|
||||
<div id="loading-content" class="col-centered hidden">
|
||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||
|
||||
Searching for Devices . . .
|
||||
<br>
|
||||
</div>
|
||||
<!--/loading-->
|
||||
|
||||
<!-- result content -->
|
||||
<div id="advance-search-result" class="col-centered hidden">
|
||||
<div class="wr-form">
|
||||
<b class="page-sub-title title-result">Advanced Search Results</b>
|
||||
<hr/>
|
||||
<div id="device-table">
|
||||
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
|
||||
id="device-grid">
|
||||
<thead class="hidden">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ast-container">
|
||||
|
||||
<br class="c-both"/>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- / result content -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- /content/body -->
|
||||
{{/zone}}
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "/js/bottomJs.js"}}
|
||||
<script id="device-listing" src="{{@page.publicUri}}/templates/device-listing.hbs"
|
||||
type="text/x-handlebars-template"></script>
|
||||
{{/zone}}
|
||||
|
@ -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;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"uri": "/devices/search",
|
||||
"layout": "cdmf.layout.default"
|
||||
}
|
Loading…
Reference in new issue