Added relative timestamps

Former-commit-id: 5ea7e7519cbe1059d9595a82229b7c7de3ef17bf
This commit is contained in:
Ziver Koc 2016-01-24 17:37:32 +01:00
parent 73ac1f8208
commit fc41b60386
11 changed files with 3641 additions and 14 deletions

View file

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
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 DETAIL_TEMPLATE = "web-resource/event_detail.tmpl";
@ -52,8 +53,10 @@ public class EventOverviewHttpPage extends HalHttpPage {
Event event = Event.getEvent(db, id);
// 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(2, HISTORY_LIMIT);
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());
Templator tmpl = new Templator(FileUtil.find(DETAIL_TEMPLATE));

View file

@ -18,7 +18,7 @@ import java.util.List;
import java.util.Map;
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 DETAIL_TEMPLATE = "web-resource/sensor_detail.tmpl";
@ -43,7 +43,8 @@ public class SensorOverviewHttpPage extends HalHttpPage {
Sensor sensor = Sensor.getSensor(db, id);
// 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(2, HISTORY_LIMIT);
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());

View file

@ -62,7 +62,7 @@
{{#detectedEvents}}
<tr>
<td>{{.getType()}}</td>
<td>{{.getDeviceData().getTimestamp()}}</td>
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
<td>{{.getDeviceData()}}</td>
<td>
<div class="btn-toolbar pull-right">

View file

@ -36,7 +36,7 @@
</thead>
{{#history}}
<tr>
<td>{{.timestamp}}</a></td>
<td><span class="timestamp">{{.timestamp}}</span></td>
<td>{{.data}}</td>
</tr>
{{/history}}

View file

@ -18,7 +18,7 @@
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
<td>{{.getDeviceData().getData()}}</td>
<td>{{.getDeviceData().getTimestamp()}}</td>
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
<td>
<form method="POST">
<input type="hidden" name="action" value="-">

View file

@ -1,5 +1,13 @@
////////////////////////////////////// Definitions
///////////////////////////////// Autostart
$(function(){
$(".toggle-switch").bootstrapSwitch();
$(".timestamp").relTimestamp();
});
////////////////////////////////////// JQuery functions
// $.attr() # returns all attributes of an element
(function(old) {
$.fn.attr = function() {
if(arguments.length === 0) {
@ -20,8 +28,16 @@
};
})($.fn.attr);
$.fn.relTimestamp = function() {
return this.each(function() {
var timestamp = parseInt($(this).text());
var timestampNow = Date.now();
var timeDiff = timestampNow - timestamp;
///////////////////////////////// Autostart
$(function(){
$(".toggle-switch").bootstrapSwitch();
});
if(timeDiff < 24 * 60 * 60 * 1000) // less than 24 hours
$(this).text(moment(timestamp).fromNow());
else
$(this).text(moment(timestamp).format("YYYY-MM-DD HH:mm"));
return this;
});
};

3606
web-resource/js/moment.js Executable file

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,7 @@
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/bootstrap.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/raphael.min.js"></script>

View file

@ -65,7 +65,7 @@
{{#detectedSensors}}
<tr>
<td>{{.getType()}}</td>
<td>{{.getDeviceData().getTimestamp()}}</td>
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
<td>{{.getDeviceData()}}</td>
<td>
<div class="btn-toolbar pull-right">

View file

@ -70,7 +70,7 @@
</thead>
{{#history}}
<tr>
<td>{{.timestamp}}</a></td>
<td><span class="timestamp">{{.timestamp}}</span></td>
<td>{{.data}}</td>
</tr>
{{/history}}

View file

@ -17,7 +17,7 @@
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
<td>{{.getDeviceData().getClass().getSimpleName()}}</td>
<td>{{.getDeviceData().getData()}}</td>
<td>{{.getDeviceData().getTimestamp()}}</td>
<td><span class="timestamp">{{.getDeviceData().getTimestamp()}}</span></td>
</tr>
{{/sensors}}
</table>