mirror of
https://repository.entgra.net/community/product-iots.git
synced 2025-09-16 23:32:19 +00:00
fixing hanging on list all devices
This commit is contained in:
parent
1b5e29a5a5
commit
2b2ce0f35b
@ -24,8 +24,10 @@ var log = new Log("api/device-api.jag");
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var dcProps = require('/config/dc-props.js').config();
|
||||
var downloadModule = require("/modules/download.js").downloadModule;
|
||||
var utility = require("/modules/utility.js").utility;
|
||||
|
||||
var carbon = require('carbon');
|
||||
var carbonHttpServletTransport = carbon.server.address('http');
|
||||
var carbonHttpsServletTransport = carbon.server.address('https');
|
||||
|
||||
var result;
|
||||
|
||||
@ -39,12 +41,33 @@ if (uriMatcher.match("/{context}/api/device/sketch/")) {
|
||||
exit();
|
||||
}
|
||||
|
||||
fireAlarmManagerService = "http://localhost:9763/iotdevices/FireAlarmManager";
|
||||
fireAlarmManagerService = carbonHttpsServletTransport + "/iotdevices/FireAlarmManager";
|
||||
sketchDownloadEndPoint = fireAlarmManagerService + "/downloadSketch";
|
||||
response.sendRedirect(sketchDownloadEndPoint + "?type="+sketchType+"&owner="+user.username);
|
||||
exit();
|
||||
}
|
||||
|
||||
if (uriMatcher.match("/{context}/api/devices/")) {
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
if(!user){
|
||||
response.sendRedirect(dcProps.appContext + "login?#login-required");
|
||||
exit();
|
||||
}
|
||||
|
||||
devicesManagerService = carbonHttpsServletTransport + "/iotdevices/DevicesManager";
|
||||
listAllDevicesEndPoint = devicesManagerService + "/getDevices";
|
||||
|
||||
var data = {};
|
||||
//XMLHTTPRequest's GET
|
||||
result = get(listAllDevicesEndPoint+"?username="+user.username, data ,"json");
|
||||
|
||||
//response.sendRedirect(listAllDevicesEndPoint + "?username="+user.username);
|
||||
//exit();
|
||||
}
|
||||
|
||||
// returning the result.
|
||||
if (result) {
|
||||
print(result);
|
||||
|
||||
@ -80,11 +80,14 @@ function getBulbStatusData(user, deviceId, from, to) {
|
||||
|
||||
var bulbStatusData = [];
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
bulbStatusData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
value: fetchedData.get(i).getValue()
|
||||
});
|
||||
if(fetchedData != null) {
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
bulbStatusData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
value: fetchedData.get(i).getValue()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return bulbStatusData;
|
||||
@ -97,11 +100,15 @@ function getFanStatusData(user, deviceId, from, to) {
|
||||
|
||||
var fanStatusData = [];
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
fanStatusData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
value: fetchedData.get(i).getValue()
|
||||
});
|
||||
if(fetchedData != null) {
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
fanStatusData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
value: fetchedData.get(i).getValue()
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return fanStatusData;
|
||||
@ -113,13 +120,16 @@ function getTemperatureData(user, deviceId, from, to) {
|
||||
|
||||
var temperatureData = [];
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
temperatureData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
value: fetchedData.get(i).getValue()
|
||||
});
|
||||
}
|
||||
if(fetchedData != null) {
|
||||
|
||||
for (var i = 0; i < fetchedData.size(); i++) {
|
||||
temperatureData.push({
|
||||
time: fetchedData.get(i).getTime(),
|
||||
value: fetchedData.get(i).getValue()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return temperatureData;
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,10 @@
|
||||
"url": "/api/device/*",
|
||||
"path": "/api/device-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/devices/*",
|
||||
"path": "/api/device-api.jag"
|
||||
},
|
||||
{
|
||||
"url": "/api/user/*",
|
||||
"path": "/api/user-api.jag"
|
||||
|
||||
@ -10,7 +10,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row margin-double padding-double">
|
||||
<table class="table table-hover border">
|
||||
<form method="GET" action="{{myDevicePath}}">
|
||||
<table class="table table-hover border" id="devicesTable">
|
||||
<thead>
|
||||
<tr class="grey-bg">
|
||||
<th class="uppercase">Device ID</th>
|
||||
@ -19,37 +20,19 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<form method="GET" action="{{myDevicePath}}">
|
||||
{{#if devices.device}}
|
||||
{{#each devices.device}}
|
||||
<tr class="border-top">
|
||||
<th scope="row">{{deviceIdentifier}}</th>
|
||||
<td>{{name}}</td>
|
||||
<td class="float-right border-top ">
|
||||
<button class="btn-black-action" name="deviceId"
|
||||
value="{{deviceIdentifier}}">
|
||||
<i class="fw fw-view padding-right"></i>View
|
||||
</button>
|
||||
<button class="btn-black-action" name="deviceId" value="{{deviceIdentifier}}">
|
||||
<i class="fw fw-edit padding-right"></i>Edit
|
||||
</button>
|
||||
<button class="btn-black-action" name="deviceId" value="{{deviceIdentifier}}">
|
||||
<i class="fw fw-delete padding-right"></i>Remove
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
{{else}}
|
||||
<tr class="border-top">
|
||||
<th scope="row"></th>
|
||||
<td colspan="2">
|
||||
No Devices available.
|
||||
</td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
</form>
|
||||
{{! All devices will be listed here @see: alldevices_util.js}}
|
||||
<tr class="border-top">
|
||||
<th scope="row"></th>
|
||||
<td colspan="2">
|
||||
No Devices available.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{/zone}}
|
||||
{{#zone "bottomJs"}}
|
||||
<script src="{{self.publicURL}}/js/alldevices_util.js"></script>
|
||||
{{/zone}}
|
||||
@ -1,16 +1,5 @@
|
||||
function onRequest(context) {
|
||||
context.myDevicePath = "/iot/mydevice";
|
||||
|
||||
var constants = require("/modules/constants.js");
|
||||
var httpReq = new XMLHttpRequest();
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
var endPoint = "http://localhost:9763/iotdevices/DevicesManager/getDevices?username=" + user.username;
|
||||
//
|
||||
httpReq.open("GET", endPoint, false);
|
||||
httpReq.setRequestHeader("Content-type","application/json");
|
||||
httpReq.send();
|
||||
//
|
||||
context.devices = JSON.parse(httpReq.responseText);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
function getAllDevices(){
|
||||
var getDevicesRequest = $.ajax({
|
||||
url: "api/devices",
|
||||
method: "GET",
|
||||
contentType: "application/json"
|
||||
});
|
||||
|
||||
getDevicesRequest.done(function (data) {
|
||||
updateDevicesTable(JSON.parse(data));
|
||||
});
|
||||
|
||||
getDevicesRequest.fail(function (jqXHR, textStatus) {
|
||||
var err = jqXHR;
|
||||
alert("Request failed: " + textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function updateDevicesTable(data) {
|
||||
devices = data.data.device;
|
||||
if (devices) {
|
||||
$('#devicesTable tbody > tr').remove();
|
||||
for (var i = 0; i < devices.length; i++) {
|
||||
var deviceIdentifier = devices[i].deviceIdentifier;
|
||||
var deviceName = devices[i].name;
|
||||
$('#devicesTable tbody').append(
|
||||
"<tr class='border-top'><th scope='row'>"+deviceIdentifier+"</th>"+
|
||||
"<td>"+deviceName+"</td>"+
|
||||
"<td class='float-right border-top '>"+
|
||||
"<button class='btn-black-action' name='deviceId' value='"+deviceIdentifier+"'>"+
|
||||
"<i class='fw fw-view padding-right'></i>View</button>"+
|
||||
"<button class='btn-black-action' name='deviceId' value='"+deviceIdentifier+"'>"+
|
||||
"<i class='fw fw-edit padding-right'></i>Edit</button>"+
|
||||
"<button class='btn-black-action' name='deviceId' value='"+deviceIdentifier+"'>"+
|
||||
"<i class='fw fw-delete padding-right'></i>Remove</button>"+
|
||||
"</td></tr>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearTable(tableId){
|
||||
$('#'+tableId+' tbody > tr').remove();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
console.log("getAllDevices()");
|
||||
getAllDevices();
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user