Added Event overview page. issue 5
Former-commit-id: 6ee75491189dc68b53b928436ef5d06a81b81568
This commit is contained in:
parent
4602d0bfc7
commit
87913dfd28
4 changed files with 146 additions and 0 deletions
|
|
@ -82,6 +82,8 @@ public class HalServer {
|
|||
new PCOverviewHttpPage(),
|
||||
new PCHeatMapHttpPage(),
|
||||
new SensorConfigHttpPage(),
|
||||
|
||||
new EventOverviewHttpPage(),
|
||||
new EventConfigHttpPage(),
|
||||
new UserConfigHttpPage(),
|
||||
};
|
||||
|
|
|
|||
85
src/se/hal/page/EventOverviewHttpPage.java
Executable file
85
src/se/hal/page/EventOverviewHttpPage.java
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.intf.HalHttpPage;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.User;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.SQLResultHandler;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.ConfigurationParam;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EventOverviewHttpPage extends HalHttpPage {
|
||||
private static final String OVERVIEW_TEMPLATE = "web-resource/event_overview.tmpl";
|
||||
private static final String DETAIL_TEMPLATE = "web-resource/event_detail.tmpl";
|
||||
|
||||
|
||||
public EventOverviewHttpPage(){
|
||||
super("Overview", "event_overview");
|
||||
super.getRootNav().getSubNav("events").addSubNav(super.getNav());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Templator httpRespond(
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request)
|
||||
throws Exception{
|
||||
|
||||
DBConnection db = HalContext.getDB();
|
||||
|
||||
// Save new input
|
||||
if(request.containsKey("id")){
|
||||
int id = Integer.parseInt(request.get("id"));
|
||||
Event event = Event.getEvent(db, id);
|
||||
|
||||
// get history data
|
||||
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM event_data_raw WHERE event_id == ?");
|
||||
stmt.setLong(1, event.getId());
|
||||
List<HistoryData> history = DBConnection.exec(stmt, new HistoryDataListSqlResult());
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find(DETAIL_TEMPLATE));
|
||||
tmpl.set("event", event);
|
||||
tmpl.set("history", history);
|
||||
return tmpl;
|
||||
}
|
||||
else {
|
||||
Templator tmpl = new Templator(FileUtil.find(OVERVIEW_TEMPLATE));
|
||||
tmpl.set("events", Event.getLocalEvents(db));
|
||||
return tmpl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static class HistoryData{
|
||||
public long timestamp;
|
||||
public double data;
|
||||
}
|
||||
|
||||
protected class HistoryDataListSqlResult implements SQLResultHandler<List<HistoryData>> {
|
||||
@Override
|
||||
public List<HistoryData> handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||
ArrayList<HistoryData> list = new ArrayList<HistoryData>();
|
||||
while(result.next()){
|
||||
HistoryData data = new HistoryData();
|
||||
data.timestamp = result.getLong("timestamp");
|
||||
data.data = result.getLong("data");
|
||||
list.add(data);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
web-resource/event_detail.tmpl
Executable file
22
web-resource/event_detail.tmpl
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
<h1 class="page-header">Details for <a href="#">{{event.getName()}}</a></h1>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">History data</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<table class="table table-hover table-condensed">
|
||||
<thead>
|
||||
<th class="col-md-6">Timestamp</th>
|
||||
<th class="col-md-2">Data</th>
|
||||
</thead>
|
||||
{{#history}}
|
||||
<tr>
|
||||
<td>{{.timestamp}}</a></td>
|
||||
<td>{{.data()}}</td>
|
||||
</tr>
|
||||
{{/history}}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
37
web-resource/event_overview.tmpl
Executable file
37
web-resource/event_overview.tmpl
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
<h1 class="page-header">Event Overview</h1>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">Local Events</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<table class="table table-hover table-condensed">
|
||||
<thead>
|
||||
<th class="col-md-5">Name</th>
|
||||
<th class="col-md-3">Data</th>
|
||||
<th class="col-md-3">Last Update</th>
|
||||
<th class="col-md-1">Actions</th>
|
||||
</thead>
|
||||
{{#events}}
|
||||
<tr>
|
||||
<td><a href="?id={{.getId()}}">{{.getName()}}</a></td>
|
||||
<td>{{.getData()}}</td>
|
||||
<td>updated 1 min ago</td>
|
||||
<td>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="-">
|
||||
<input type="hidden" name="id" value="{{.getId()}}">
|
||||
|
||||
<div class="btn-toolbar pull-right">
|
||||
<button type="submit" class="btn btn-danger btn-xs">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{/events}}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue