Added relative timestamps
Former-commit-id: 5ea7e7519cbe1059d9595a82229b7c7de3ef17bf
This commit is contained in:
parent
73ac1f8208
commit
fc41b60386
11 changed files with 3641 additions and 14 deletions
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class EventOverviewHttpPage extends HalHttpPage {
|
public class EventOverviewHttpPage extends HalHttpPage {
|
||||||
|
private static final int HISTORY_LIMIT = 200;
|
||||||
private static final String OVERVIEW_TEMPLATE = "web-resource/event_overview.tmpl";
|
private static final String OVERVIEW_TEMPLATE = "web-resource/event_overview.tmpl";
|
||||||
private static final String DETAIL_TEMPLATE = "web-resource/event_detail.tmpl";
|
private static final String DETAIL_TEMPLATE = "web-resource/event_detail.tmpl";
|
||||||
|
|
||||||
|
|
@ -52,8 +53,10 @@ public class EventOverviewHttpPage extends HalHttpPage {
|
||||||
Event event = Event.getEvent(db, id);
|
Event event = Event.getEvent(db, id);
|
||||||
|
|
||||||
// get history data
|
// get history data
|
||||||
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC");
|
PreparedStatement stmt = db.getPreparedStatement(
|
||||||
|
"SELECT * FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT ?");
|
||||||
stmt.setLong(1, event.getId());
|
stmt.setLong(1, event.getId());
|
||||||
|
stmt.setLong(2, HISTORY_LIMIT);
|
||||||
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());
|
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());
|
||||||
|
|
||||||
Templator tmpl = new Templator(FileUtil.find(DETAIL_TEMPLATE));
|
Templator tmpl = new Templator(FileUtil.find(DETAIL_TEMPLATE));
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SensorOverviewHttpPage extends HalHttpPage {
|
public class SensorOverviewHttpPage extends HalHttpPage {
|
||||||
private static final int HISTORY_LIMIT = 1000;
|
private static final int HISTORY_LIMIT = 200;
|
||||||
private static final String OVERVIEW_TEMPLATE = "web-resource/sensor_overview.tmpl";
|
private static final String OVERVIEW_TEMPLATE = "web-resource/sensor_overview.tmpl";
|
||||||
private static final String DETAIL_TEMPLATE = "web-resource/sensor_detail.tmpl";
|
private static final String DETAIL_TEMPLATE = "web-resource/sensor_detail.tmpl";
|
||||||
|
|
||||||
|
|
@ -43,7 +43,8 @@ public class SensorOverviewHttpPage extends HalHttpPage {
|
||||||
Sensor sensor = Sensor.getSensor(db, id);
|
Sensor sensor = Sensor.getSensor(db, id);
|
||||||
|
|
||||||
// get history data
|
// get history data
|
||||||
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT ?");
|
PreparedStatement stmt = db.getPreparedStatement(
|
||||||
|
"SELECT * FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT ?");
|
||||||
stmt.setLong(1, sensor.getId());
|
stmt.setLong(1, sensor.getId());
|
||||||
stmt.setLong(2, HISTORY_LIMIT);
|
stmt.setLong(2, HISTORY_LIMIT);
|
||||||
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());
|
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
{{#detectedEvents}}
|
{{#detectedEvents}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.getType()}}</td>
|
<td>{{.getType()}}</td>
|
||||||
<td>{{.getDeviceData().getTimestamp()}}</td>
|
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||||
<td>{{.getDeviceData()}}</td>
|
<td>{{.getDeviceData()}}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-toolbar pull-right">
|
<div class="btn-toolbar pull-right">
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
{{#history}}
|
{{#history}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.timestamp}}</a></td>
|
<td><span class="timestamp">{{.timestamp}}</span></td>
|
||||||
<td>{{.data}}</td>
|
<td>{{.data}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/history}}
|
{{/history}}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||||
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
||||||
<td>{{.getDeviceData().getData()}}</td>
|
<td>{{.getDeviceData().getData()}}</td>
|
||||||
<td>{{.getDeviceData().getTimestamp()}}</td>
|
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||||
<td>
|
<td>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<input type="hidden" name="action" value="-">
|
<input type="hidden" name="action" value="-">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
////////////////////////////////////// Definitions
|
///////////////////////////////// Autostart
|
||||||
|
$(function(){
|
||||||
|
$(".toggle-switch").bootstrapSwitch();
|
||||||
|
|
||||||
|
$(".timestamp").relTimestamp();
|
||||||
|
});
|
||||||
|
|
||||||
|
////////////////////////////////////// JQuery functions
|
||||||
|
|
||||||
|
// $.attr() # returns all attributes of an element
|
||||||
(function(old) {
|
(function(old) {
|
||||||
$.fn.attr = function() {
|
$.fn.attr = function() {
|
||||||
if(arguments.length === 0) {
|
if(arguments.length === 0) {
|
||||||
|
|
@ -20,8 +28,16 @@
|
||||||
};
|
};
|
||||||
})($.fn.attr);
|
})($.fn.attr);
|
||||||
|
|
||||||
|
$.fn.relTimestamp = function() {
|
||||||
|
return this.each(function() {
|
||||||
|
var timestamp = parseInt($(this).text());
|
||||||
|
var timestampNow = Date.now();
|
||||||
|
var timeDiff = timestampNow - timestamp;
|
||||||
|
|
||||||
///////////////////////////////// Autostart
|
if(timeDiff < 24 * 60 * 60 * 1000) // less than 24 hours
|
||||||
$(function(){
|
$(this).text(moment(timestamp).fromNow());
|
||||||
$(".toggle-switch").bootstrapSwitch();
|
else
|
||||||
});
|
$(this).text(moment(timestamp).format("YYYY-MM-DD HH:mm"));
|
||||||
|
return this;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
||||||
3606
web-resource/js/moment.js
Executable file
3606
web-resource/js/moment.js
Executable file
File diff suppressed because it is too large
Load diff
|
|
@ -17,6 +17,7 @@
|
||||||
<script src="js/jquery-1.11.3.min.js"></script>
|
<script src="js/jquery-1.11.3.min.js"></script>
|
||||||
<script src="js/bootstrap.min.js"></script>
|
<script src="js/bootstrap.min.js"></script>
|
||||||
<script src="js/bootstrap-switch.min.js"></script>
|
<script src="js/bootstrap-switch.min.js"></script>
|
||||||
|
<script src="js/moment.js"></script>
|
||||||
<script src="js/hal.js"></script>
|
<script src="js/hal.js"></script>
|
||||||
|
|
||||||
<script src="js/raphael.min.js"></script>
|
<script src="js/raphael.min.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
{{#detectedSensors}}
|
{{#detectedSensors}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.getType()}}</td>
|
<td>{{.getType()}}</td>
|
||||||
<td>{{.getDeviceData().getTimestamp()}}</td>
|
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||||
<td>{{.getDeviceData()}}</td>
|
<td>{{.getDeviceData()}}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-toolbar pull-right">
|
<div class="btn-toolbar pull-right">
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
{{#history}}
|
{{#history}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.timestamp}}</a></td>
|
<td><span class="timestamp">{{.timestamp}}</span></td>
|
||||||
<td>{{.data}}</td>
|
<td>{{.data}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/history}}
|
{{/history}}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||||
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
|
||||||
<td>{{.getDeviceData().getData()}}</td>
|
<td>{{.getDeviceData().getData()}}</td>
|
||||||
<td>{{.getDeviceData().getTimestamp()}}</td>
|
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/sensors}}
|
{{/sensors}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue