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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue