did some UI changes

application-manager-new
GPrathap 9 years ago
parent f92f3f9692
commit 7ab6046d31

@ -5,7 +5,7 @@
data-appcontext="{{@app.context}}"></span> data-appcontext="{{@app.context}}"></span>
<div id="div-chart"> <div id="div-chart">
<div class="chartWrapper" id="chartWrapper"> <div class="chartWrapper" id="chartWrapper">
<span id="span-title">Temperature</span> <span id="span-title">${nameOfTheSensor}</span>
<div id="y_axis" class="custom_y_axis"></div> <div id="y_axis" class="custom_y_axis"></div>
<div class="legend_container"> <div class="legend_container">
<div id="smoother" title="Smoothing"></div> <div id="smoother" title="Smoothing"></div>

@ -17,14 +17,23 @@
*/ */
function onRequest(context) { function onRequest(context) {
var devices = context.unit.params.devices;
var deviceType = context.uriParams.deviceType; var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("deviceId"); var deviceId = request.getParameter("deviceId");
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { if (devices) {
return {
"devices": stringify(devices),
"backendApiUri": devicemgtProps["httpsURL"] + "/"+deviceType+"/device/stats/"
};
} else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
var device = deviceModule.viewDevice(deviceType, deviceId); var device = deviceModule.viewDevice(deviceType, deviceId);
if (device && device.status != "error") { if (device && device.status != "error") {
return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/"+deviceType+"/device/stats/" + deviceId}; return {
"device": device,
"backendApiUri": devicemgtProps["httpsURL"] + "/"+deviceType+"/device/stats/" + deviceId
};
} else { } else {
response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!");
exit(); exit();

@ -18,27 +18,20 @@
var palette = new Rickshaw.Color.Palette({scheme: "classic9"}); var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
function drawGraph(from, to) { function drawGraph_${deviceType}(from, to) {
var backendApiUrl = $("#chart").data("backend-api-url") + "?from=" + from + "&to=" + to; $("#y_axis").html("");
$("#smoother").html("");
$("#legend").html("");
$("#chart").html("");
$("#x_axis").html("");
$("#slider").html("");
var successCallback = function (data) { var devices = $("#details").data("devices");
if (data) {
drawLineGraph(JSON.parse(data)); var tzOffset = new Date().getTimezoneOffset() * 60;
}
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
});
}
function drawLineGraph(data) {
var chartWrapperElmId = "#div-chart"; var chartWrapperElmId = "#div-chart";
var graphWidth = $(chartWrapperElmId).width() - 50; var graphWidth = $(chartWrapperElmId).width() - 50;
if (data.length == 0 || data.length == undefined) {
$("#chart").html("<br/>No data available...");
return;
}
$("#chart").empty();
var graphConfig = { var graphConfig = {
element: document.getElementById("chart"), element: document.getElementById("chart"),
width: graphWidth, width: graphWidth,
@ -53,47 +46,28 @@ function drawLineGraph(data) {
series: [] series: []
}; };
var tzOffset = new Date().getTimezoneOffset() * 60; if (devices) {
for (var i = 0; i < devices.length; i++) {
var min = Number.MAX_VALUE; graphConfig['series'].push(
var max = Number.MIN_VALUE;
var range_min = 99999, range_max = 0;
var max_val = parseInt(data[0].values.temperature);
var min_val = max_val;
var chartData = [];
for (var i = 0; i < data.length; i++) {
var y_val = parseInt(data[i].values.temperature);
if (y_val > max_val) {
max_val = y_val;
} else if (y_val < min_val) {
min_val = y_val;
}
chartData.push(
{ {
x: parseInt(data[i].values.time) - tzOffset, 'color': palette.color(),
y: y_val 'data': [{
} x: parseInt(new Date().getTime() / 1000),
); y: 0
} }],
if (range_max < max_val) { 'name': devices[i].name
range_max = max_val; });
}
if (range_min > min_val) {
range_min = min_val;
} }
} else {
graphConfig['series'].push( graphConfig['series'].push(
{ {
'color': palette.color(), 'color': palette.color(),
'data': chartData, 'data': [{
'name': $("#details").data("devicename"), x: parseInt(new Date().getTime() / 1000),
'scale': d3.scale.linear().domain([Math.min(min, min_val), Math.max(max, max_val)]) y: 0
.nice() }],
} 'name': $("#details").data("devicename")
); });
if (graphConfig['series'].length == 0) {
$(chartWrapperElmId).html("No data available...");
return;
} }
var graph = new Rickshaw.Graph(graphConfig); var graph = new Rickshaw.Graph(graphConfig);
@ -106,13 +80,12 @@ function drawLineGraph(data) {
xAxis.render(); xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y.Scaled({ var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph, graph: graph,
orientation: 'left', orientation: 'left',
element: document.getElementById("y_axis"), element: document.getElementById("y_axis"),
width: 40, width: 40,
height: 410, height: 410
'scale': d3.scale.linear().domain([Math.min(min, range_min), Math.max(max, range_max)]).nice()
}); });
yAxis.render(); yAxis.render();
@ -131,7 +104,7 @@ function drawLineGraph(data) {
graph: graph, graph: graph,
formatter: function (series, x, y) { formatter: function (series, x, y) {
var date = '<span class="date">' + var date = '<span class="date">' +
moment((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>'; moment.unix((x + tzOffset) * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
var swatch = '<span class="detail_swatch" style="background-color: ' + var swatch = '<span class="detail_swatch" style="background-color: ' +
series.color + '"></span>'; series.color + '"></span>';
return swatch + series.name + ": " + parseInt(y) + '<br>' + date; return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
@ -152,4 +125,59 @@ function drawLineGraph(data) {
graph: graph, graph: graph,
legend: legend legend: legend
}); });
var deviceIndex = 0;
if (devices) {
getData();
} else {
var backendApiUrl = $("#chart").data("backend-api-url") + "?from=" + from + "&to=" + to;
var successCallback = function (data) {
if (data) {
drawLineGraph(JSON.parse(data));
}
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
});
}
function getData() {
if (deviceIndex >= devices.length) {
return;
}
var backendApiUrl = $("#chart").data("backend-api-url") + devices[deviceIndex].deviceIdentifier
+ "?from=" + from + "&to=" + to;
var successCallback = function (data) {
if (data) {
drawLineGraph(JSON.parse(data));
}
deviceIndex++;
getData();
};
invokerUtil.get(backendApiUrl, successCallback, function (message) {
console.log(message);
deviceIndex++;
getData();
});
}
function drawLineGraph(data) {
if (data.length === 0 || data.length === undefined) {
return;
}
var chartData = [];
for (var i = 0; i < data.length; i++) {
chartData.push(
{
x: parseInt(data[i].values.time) - tzOffset,
y: parseInt(data[i].values.${nameOfTheSensor})
}
);
}
graphConfig.series[deviceIndex].data = chartData;
graph.update();
}
} }

@ -3,7 +3,7 @@
{{/zone}} {{/zone}}
<div id="div-chart" data-websocketurl="{{websocketEndpoint}}"> <div id="div-chart" data-websocketurl="{{websocketEndpoint}}">
<div class="chartWrapper" id="chartWrapper"> <div class="chartWrapper" id="chartWrapper">
<div id="y_axis" class="custom_y_axis">Temperature</div> <div id="y_axis" class="custom_y_axis">${nameOfTheSensor}</div>
<div class="legend_container"> <div class="legend_container">
<div id="smoother" title="Smoothing"></div> <div id="smoother" title="Smoothing"></div>
<div id="legend"></div> <div id="legend"></div>

@ -27,7 +27,7 @@ function onRequest(context) {
if (tokenPair) { if (tokenPair) {
token = tokenPair.accessToken; token = tokenPair.accessToken;
} }
websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.devices.temperature/1.0.0?" + websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.devices.${nameOfTheSensor}/1.0.0?" +
"token="+ token +"&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; "token="+ token +"&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type;
return {"device": device, "websocketEndpoint" : websocketEndpoint}; return {"device": device, "websocketEndpoint" : websocketEndpoint};
} }

@ -63,7 +63,7 @@ $(window).load(function () {
new Rickshaw.Graph.HoverDetail({ new Rickshaw.Graph.HoverDetail({
graph: graph, graph: graph,
formatter: function (series, x, y) { formatter: function (series, x, y) {
var date = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>'; var date = '<span class="date">' + moment.unix(x*1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>'; var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
return swatch + series.name + ": " + parseInt(y) + '<br>' + date; return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
} }

Loading…
Cancel
Save