Fixed config page bugs

Former-commit-id: cd32facd6e679eb9a66b294d4011da8eb801fd00
This commit is contained in:
Ziver Koc 2016-01-22 20:48:29 +01:00
parent 09d59635c3
commit 5a4107f60f
4 changed files with 32 additions and 28 deletions

View file

@ -117,11 +117,12 @@ public class ControllerManager implements HalSensorReportListener,
}
else { // unknown sensor
logger.finest("Received report from unregistered sensor: "+ sensorData);
if(!detectedSensors.contains(sensorData)) {
Sensor detectedSensor = new Sensor();
detectedSensor.setDeviceData(sensorData);
Sensor detectedSensor = findSensor(sensorData, detectedSensors);
if(detectedSensor == null) {
detectedSensor = new Sensor();
detectedSensors.add(detectedSensor);
}
detectedSensor.setDeviceData(sensorData);
}
}catch (SQLException e){
logger.log(Level.WARNING, "Unable to store sensor report", e);
@ -202,11 +203,12 @@ public class ControllerManager implements HalSensorReportListener,
}
else { // unknown sensor
logger.info("Received report from unregistered event: "+ eventData);
if(!detectedEvents.contains(eventData)) {
Event detectedEvent = new Event();
detectedEvent.setDeviceData(eventData);
Event detectedEvent = findEvent(eventData, detectedEvents);
if(detectedEvent == null) {
detectedEvent = new Event();
detectedEvents.add(detectedEvent);
}
detectedEvent.setDeviceData(eventData);
}
}catch (SQLException e){
logger.log(Level.WARNING, "Unable to store event report", e);

View file

@ -60,6 +60,8 @@ public abstract class AbstractDevice<T> extends DBBean {
}
public void setDeviceData(T data) {
this.deviceData = data;
if(data != null)
type = data.getClass().getName();
updateConfigString();
}
public void save(DBConnection db) throws SQLException {

View file

@ -63,7 +63,7 @@
<tr>
<td>{{.getType()}}</td>
<td>{{.getDeviceData().getTimestamp()}}</td>
<td>{{.}}</td>
<td>{{.getDeviceData()}}</td>
<td>
<div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
@ -104,22 +104,22 @@
var modal = $(this);
modal.find("input[type=text]").val(""); // Reset all inputs
if(button.data("id") >= 0){ // edit
modal.find("select[name=type]").val(button.data("type"));
modal.find("select[name=type]").change(); // Update dynamic inputs
$.each(button.attr(), function(name, value) {
if(name.startsWith("data-")) {
name = name.substring(5);
console.log(name, value);
modal.find("input[name="+name+"]").val(value);
}
});
modal.find("input[name=action]").val("modify_local_event");
}
else{ // create
modal.find("input[name=action]").val("create_local_event");
modal.find("input[name=id]").val(-1);
modal.find("select[name=type]").change(); // Update dynamic inputs
}
// Set dynamic data
modal.find("select[name=type]").val(button.data("type"));
modal.find("select[name=type]").change(); // Update dynamic inputs
$.each(button.attr(), function(name, value) {
if(name.startsWith("data-")) {
name = name.substring(5);
console.log(name, value);
modal.find("input[name="+name+"]").val(value);
}
});
});
});
</script>

View file

@ -66,7 +66,7 @@
<tr>
<td>{{.getType()}}</td>
<td>{{.getDeviceData().getTimestamp()}}</td>
<td>{{.}}</td>
<td>{{.getDeviceData()}}</td>
<td>
<div class="btn-toolbar pull-right">
<button type="button" class="btn btn-default btn-xs" data-toggle="modal"
@ -204,15 +204,6 @@
var modal = $(this);
modal.find("input[type=text]").val(""); // Reset all inputs
if(button.data("id") >= 0){ // edit
modal.find("select[name=type]").val(button.data("type"));
modal.find("select[name=type]").change(); // Update dynamic inputs
$.each(button.attr(), function(name, value) {
if(name.startsWith("data-")) {
name = name.substring(5);
console.log(name, value);
modal.find("input[name="+name+"]").val(value);
}
});
modal.find("input[name=action]").val("modify_local_sensor");
modal.find("input[name=sync]").prop("checked", button.data("sync"));
}
@ -220,8 +211,17 @@
modal.find("input[name=action]").val("create_local_sensor");
modal.find("input[name=id]").val(-1);
modal.find("input[name=sync]").prop("checked", "false");
modal.find("select[name=type]").change(); // Update dynamic inputs
}
// set dynamic form data
modal.find("select[name=type]").val(button.data("type"));
modal.find("select[name=type]").change(); // Update dynamic inputs
$.each(button.attr(), function(name, value) {
if(name.startsWith("data-")) {
name = name.substring(5);
console.log(name, value);
modal.find("input[name="+name+"]").val(value);
}
});
});