Moved user profile to a new page
Former-commit-id: f28819825c92b749ac250e844db9dec292132b8c
This commit is contained in:
parent
4428824061
commit
2c98cd897d
7 changed files with 91 additions and 41 deletions
|
|
@ -10,6 +10,7 @@ import se.hal.intf.HalHttpPage;
|
|||
import se.hal.page.SensorConfigHttpPage;
|
||||
import se.hal.page.PCHeatMapHttpPage;
|
||||
import se.hal.page.PCOverviewHttpPage;
|
||||
import se.hal.page.UserConfigHttpPage;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.Sensor;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
@ -74,7 +75,8 @@ public class HalServer {
|
|||
pages = new HalHttpPage[]{
|
||||
new PCOverviewHttpPage(),
|
||||
new PCHeatMapHttpPage(),
|
||||
new SensorConfigHttpPage()
|
||||
new SensorConfigHttpPage(),
|
||||
new UserConfigHttpPage(),
|
||||
};
|
||||
HttpServer http = new HttpServer(HalContext.getIntegerProperty("http_port"));
|
||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/")));
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public class PCHeatMapHttpPage extends HalHttpPage {
|
|||
|
||||
|
||||
public PCHeatMapHttpPage() {
|
||||
super("Heatmap", "map");
|
||||
super("Heatmap", "pc_heatmap");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class PCOverviewHttpPage extends HalHttpPage {
|
|||
private static final String TEMPLATE = "web-resource/pc_overview.tmpl";
|
||||
|
||||
public PCOverviewHttpPage() {
|
||||
super("Power;Challenge", "powerChallenge");
|
||||
super("Power;Challenge", "pc_overview");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class SensorConfigHttpPage extends HalHttpPage {
|
|||
|
||||
|
||||
public SensorConfigHttpPage() {
|
||||
super("Configuration", "config");
|
||||
super("Configuration", "sensor_config");
|
||||
|
||||
sensorConfigurations = new SensorDataParams[
|
||||
ControllerManager.getInstance().getAvailableSensors().size()];
|
||||
|
|
@ -49,18 +49,10 @@ public class SensorConfigHttpPage extends HalHttpPage {
|
|||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
String action = request.get("action");
|
||||
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
||||
Sensor sensor;
|
||||
User user;
|
||||
switch(action) {
|
||||
// Local User
|
||||
case "modify_local_user":
|
||||
localUser.setUserName(request.get("username"));
|
||||
localUser.setAddress(request.get("address"));
|
||||
localUser.save(db);
|
||||
break;
|
||||
|
||||
switch(request.get("action")) {
|
||||
// Local Sensors
|
||||
case "create_local_sensor":
|
||||
sensor = new Sensor();
|
||||
|
|
|
|||
55
src/se/hal/page/UserConfigHttpPage.java
Executable file
55
src/se/hal/page/UserConfigHttpPage.java
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalHttpPage;
|
||||
import se.hal.struct.Sensor;
|
||||
import se.hal.struct.User;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.ConfigurationParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UserConfigHttpPage extends HalHttpPage {
|
||||
private static final String TEMPLATE = "web-resource/user_config.tmpl";
|
||||
|
||||
|
||||
public UserConfigHttpPage() {
|
||||
super("Profile", "user_profile");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Templator httpRespond(
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request)
|
||||
throws Exception{
|
||||
|
||||
DBConnection db = HalContext.getDB();
|
||||
User localUser = User.getLocalUser(db);
|
||||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
User user;
|
||||
switch(request.get("action")) {
|
||||
// Local User
|
||||
case "modify_local_user":
|
||||
localUser.setUserName(request.get("username"));
|
||||
localUser.setAddress(request.get("address"));
|
||||
localUser.save(db);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||
tmpl.set("user", localUser);
|
||||
|
||||
return tmpl;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +1,5 @@
|
|||
<h1 class="page-header">Configuration</h1>
|
||||
|
||||
<div class="col-md-8">
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">Profile Information</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal" method="POST">
|
||||
<input type="hidden" name="action" value="modify_local_user">
|
||||
<div class="form-group">
|
||||
<label for="username" class="col-sm-2 control-label">Username:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="username" name="username" value="{{user.username}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="address" class="col-sm-2 control-label">Address:</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea class="form-control" id="address" name="address">{{user.address}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">Local Sensors</div>
|
||||
|
|
|
|||
29
web-resource/user_config.tmpl
Executable file
29
web-resource/user_config.tmpl
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
<h1 class="page-header">Profile</h1>
|
||||
|
||||
<div class="col-md-8">
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">Profile Information</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal" method="POST">
|
||||
<input type="hidden" name="action" value="modify_local_user">
|
||||
<div class="form-group">
|
||||
<label for="username" class="col-sm-2 control-label">Username:</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="username" name="username" value="{{user.username}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="address" class="col-sm-2 control-label">Address:</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea class="form-control" id="address" name="address">{{user.address}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue