Dynamic form working for sensors, only visuals no save logic
Former-commit-id: 7bfd7a5bd685b7527e75e692531a2f9a544733e1
This commit is contained in:
parent
35ac4ba678
commit
26810e9b2c
2 changed files with 39 additions and 9 deletions
|
|
@ -9,23 +9,29 @@ import zutil.db.DBConnection;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
import zutil.ui.Configurator;
|
import zutil.ui.Configurator;
|
||||||
|
import zutil.ui.Configurator.*;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PCConfigureHttpPage extends HalHttpPage {
|
public class PCConfigureHttpPage extends HalHttpPage {
|
||||||
|
private class SensorDataParams{
|
||||||
private Configurator[] sensorConfigurations;
|
public Class clazz;
|
||||||
|
public ConfigurationParam[] params;
|
||||||
|
}
|
||||||
|
private SensorDataParams[] sensorConfigurations;
|
||||||
|
|
||||||
|
|
||||||
public PCConfigureHttpPage() {
|
public PCConfigureHttpPage() {
|
||||||
super("Configuration", "config");
|
super("Configuration", "config");
|
||||||
|
|
||||||
sensorConfigurations = new Configurator[
|
sensorConfigurations = new SensorDataParams[
|
||||||
ControllerManager.getInstance().getAvailableSensors().size()];
|
ControllerManager.getInstance().getAvailableSensors().size()];
|
||||||
int i=0;
|
int i=0;
|
||||||
for(Class c : ControllerManager.getInstance().getAvailableSensors()){
|
for(Class c : ControllerManager.getInstance().getAvailableSensors()){
|
||||||
sensorConfigurations[i++] = new Configurator(c);
|
sensorConfigurations[i] = new SensorDataParams();
|
||||||
|
sensorConfigurations[i].clazz = c;
|
||||||
|
sensorConfigurations[i].params = Configurator.getConfiguration(c);
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,18 @@
|
||||||
|
|
||||||
<!------------- MODALS --------------->
|
<!------------- MODALS --------------->
|
||||||
<script>
|
<script>
|
||||||
|
var sensorDataConf = {};
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
// initialize sensor modal things
|
||||||
|
$("#sensor-data-conf-template div").each(function(){
|
||||||
|
sensorDataConf[$(this).attr("id")] = $(this).html();
|
||||||
|
});
|
||||||
|
$("#sensorModal select[name=type]").change(function(){
|
||||||
|
// Update dynamic inputs
|
||||||
|
$("#sensorModal #sensor-data-conf").html(sensorDataConf[$(this).val()]);
|
||||||
|
});
|
||||||
|
// event
|
||||||
$("#sensorModal").on('show.bs.modal', function (event) {
|
$("#sensorModal").on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget);
|
var button = $(event.relatedTarget);
|
||||||
var modal = $(this);
|
var modal = $(this);
|
||||||
|
|
@ -191,7 +202,7 @@
|
||||||
modal.find("input[name=action]").val("modify_local_sensor");
|
modal.find("input[name=action]").val("modify_local_sensor");
|
||||||
modal.find("input[name=id]").val(button.data("id"));
|
modal.find("input[name=id]").val(button.data("id"));
|
||||||
modal.find("input[name=name]").val(button.data("name"));
|
modal.find("input[name=name]").val(button.data("name"));
|
||||||
modal.find("input[name=type]").val(button.data("type"));
|
modal.find("select[name=type]").val(button.data("type"));
|
||||||
modal.find("input[name=sync]").prop("checked", button.data("sync"));
|
modal.find("input[name=sync]").prop("checked", button.data("sync"));
|
||||||
modal.find("input[name=config]").val(button.data("config"));
|
modal.find("input[name=config]").val(button.data("config"));
|
||||||
}
|
}
|
||||||
|
|
@ -200,6 +211,8 @@
|
||||||
modal.find("input[name=id]").val(-1);
|
modal.find("input[name=id]").val(-1);
|
||||||
modal.find("input[name=sync]").prop("checked", "false");
|
modal.find("input[name=sync]").prop("checked", "false");
|
||||||
}
|
}
|
||||||
|
// Update dynamic inputs
|
||||||
|
modal.find("select[name=type]").change();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -253,9 +266,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="form-group">
|
<div id="sensor-data-conf">
|
||||||
<label class="control-label">Config:</label> <!-- Should be improved, dynamic forms? -->
|
<!-- Dynamic form -->
|
||||||
<input type="text" class="form-control" name="config">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|
@ -266,6 +278,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="sensor-data-conf-template" class="hidden">
|
||||||
|
{{#localSensorConf}}
|
||||||
|
<div id="{{.clazz.getName()}}">
|
||||||
|
{{#.params}}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="control-label">{{.getNiceName()}}:</label>
|
||||||
|
<input type="text" class="form-control" name="{{.getName()}}">
|
||||||
|
</div>
|
||||||
|
{{/.params}}
|
||||||
|
</div>
|
||||||
|
{{/localSensorConf}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="modal fade" id="userModal" tabindex="-1">
|
<div class="modal fade" id="userModal" tabindex="-1">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue