🐛 Fix conditionalgroup handling
This commit is contained in:
1 parent
c78c2641dd
commit
995d3572fc
5 files changed
+65
-6
No files matched your search
@@ -331,19 +331,20 @@ class SerialTransport(Transport):
|
||||
focus = kwargs["connect_via"]
|
||||
|
||||
if focus == "port":
|
||||
return cls._create_serial_for_port_and_baudrate(
|
||||
kwargs.get("port"), kwargs.get("baudrate")
|
||||
)
|
||||
port = kwargs.pop("port")
|
||||
baudrate = kwargs.pop("baudrate")
|
||||
return cls._create_serial_for_port_and_baudrate(port, baudrate, **kwargs)
|
||||
|
||||
elif focus == "usbid":
|
||||
from serial.tools.list_ports import comports
|
||||
|
||||
usbid = kwargs.get("usbid")
|
||||
usbid = kwargs.pop("usbid")
|
||||
baudrate = kwargs.pop("baudrate")
|
||||
vid, pid = usbid.split(":")
|
||||
for port in comports():
|
||||
if f"{port.vid:04x}" == vid and f"{port.pid:04x}" == pid:
|
||||
return cls._create_serial_for_port_and_baudrate(
|
||||
port.device, kwargs.get("baudrate")
|
||||
port.device, baudrate, **kwargs
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Can't find USB ID to connect to: {usbid}")
|
||||
|
||||
@@ -39,7 +39,10 @@ def get_param_dict(data, options):
|
||||
if key not in options_by_name:
|
||||
continue
|
||||
option = options_by_name[key]
|
||||
|
||||
result[key] = option.convert(value)
|
||||
if option.type == "conditionalgroup":
|
||||
result.update(get_param_dict(data, option.groups[value]))
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -69,6 +69,17 @@ $(function () {
|
||||
override ? override[p.name] : undefined
|
||||
);
|
||||
});
|
||||
} else if (option.type === "conditionalgroup") {
|
||||
value = convertValue(value, option);
|
||||
option.expertParameters = {};
|
||||
_.each(option.groups, function (group, key) {
|
||||
_.each(group, function (o) {
|
||||
extendOption(o);
|
||||
});
|
||||
option.expertParameters[key] = _.any(group, function (p) {
|
||||
return p.expert;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
value = convertValue(value, option, override);
|
||||
}
|
||||
@@ -461,6 +472,12 @@ $(function () {
|
||||
result[parameter.group.name] = toOptions(
|
||||
parameter.group.params
|
||||
);
|
||||
} else if (parameter.type === "conditionalgroup") {
|
||||
result[parameter.name] = parameter.value();
|
||||
_.extend(
|
||||
result,
|
||||
toOptions(parameter.groups[parameter.value()])
|
||||
);
|
||||
} else if (
|
||||
parameter.type === "list" ||
|
||||
parameter.type === "smalllist"
|
||||
|
||||
@@ -68,6 +68,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/html" id="connection_dialog_template_url">
|
||||
<div class="control-group" data-bind="css: { 'control-changed': $data.modified }">
|
||||
<a href="javascript:void(0)" class="fa fa-undo control-undo" title="Reset to default" data-bind="click: reset, visible: $data.modified() && $root.isErrorOrClosed()"></a>
|
||||
<label class="control-label" data-bind="markdownInline: $data.title, css: { 'control-changed': $data.modified }"></label>
|
||||
<div class="controls">
|
||||
<input class="input-block-level" type="text" data-bind="value: $data.value, attr: {placeholder: $data.default}, css: {disabled: !$root.isErrorOrClosed()}, enable: $root.isErrorOrClosed()">
|
||||
<span class="help-block" data-bind="visible: $data.help, markdownInline: $data.help"></span>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/html" id="connection_dialog_template_integer">
|
||||
<div class="control-group" data-bind="css: { 'control-changed': $data.modified }">
|
||||
<a href="javascript:void(0)" class="fa fa-undo control-undo" title="Reset to default" data-bind="click: reset, visible: $data.modified() && $root.isErrorOrClosed()"></a>
|
||||
@@ -202,3 +212,30 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
</script>
|
||||
<script type="text/html" id="connection_dialog_template_conditionalgroup">
|
||||
<div class="control-group" data-bind="css: { 'control-changed': $data.modified }">
|
||||
<a href="javascript:void(0)" class="fa fa-undo control-undo" title="Reset to default" data-bind="click: reset, visible: $data.modified() && $root.isErrorOrClosed()"></a>
|
||||
<label class="control-label" data-bind="markdownInline: $data.title, css: { 'control-changed': $data.modified }"></label>
|
||||
<div class="controls">
|
||||
<select class="input-block-level" data-bind="options: $data.choices, optionsText: 'title', optionsValue: 'value', value: $data.value, css: {disabled: !$root.isErrorOrClosed()}, enable: $root.isErrorOrClosed()"></select>
|
||||
<span class="help-block" data-bind="visible: $data.help, markdownInline: $data.help"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ko foreach: $data.groups[$data.value()] -->
|
||||
<!-- ko if: !expert -->
|
||||
<!-- ko template: { name: 'connection_dialog_template_' + $data.type, data: $data } --><!-- /ko -->
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
|
||||
<div class="advanced_options" data-bind="visible: $data.expertParameters[$data.value]">
|
||||
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', parent: '.advanced_options', container: '.hide' }"><i class="fa fa-caret-right"></i> {{ _('Expert options') }}</a></small></div>
|
||||
<div class="hide">
|
||||
<!-- ko foreach: $data.groups[$data.value()] -->
|
||||
<!-- ko if: expert -->
|
||||
<!-- ko template: { name: 'connection_dialog_template_' + $data.type, data: $data } --><!-- /ko -->
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
@@ -127,7 +127,8 @@
|
||||
<script type="text/html" id="connection_template_conditionalgroup">
|
||||
<label data-bind="text: $data.title, css: {disabled: !$root.isErrorOrClosed()}, enable: $root.isErrorOrClosed()"></label>
|
||||
<select class="input-block-level" data-bind="options: $data.choices, optionsText: 'title', optionsValue: 'value', value: $data.value, css: {disabled: !$root.isErrorOrClosed()}, enable: $root.isErrorOrClosed()"></select>
|
||||
<!-- ko foreach: $data.groups[$data.value] -->
|
||||
|
||||
<!-- ko foreach: $data.groups[$data.value()] -->
|
||||
<!-- ko if: !advanced -->
|
||||
<!-- ko template: { name: 'connection_template_' + $data.type, data: $data } --><!-- /ko -->
|
||||
<!-- /ko -->
|
||||
|
||||
Reference in new issue
Block a user