Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix proxy list #24

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The __YAML__ structure follow the given hierarchy:
1. type: Name of the domain class
2. name: (optional) identifier when we don't want to use its `type` as identifier.
3. **: additional parameters specific to domain type expectation.
2. proxyType: Name of proxy used in proxy lists

# Domain definitions

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
name = trame-simput
name = trame_simput
version = 2.5.0
description = Simput implementation for trame
long_description = file: README.rst
Expand Down
2 changes: 1 addition & 1 deletion trame_simput/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .core import get_simput_manager

__version__ = get_version("trame-simput")
__version__ = get_version("trame_simput")

__all__ = [
"__version__",
Expand Down
10 changes: 10 additions & 0 deletions trame_simput/core/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,20 @@ def __init__(
if _prop_name.startswith("_"):
continue

_size = _prop_def.get("size", None)
_positive_size = _size is not None and isinstance(_size, int) and _size > 0
_init_def = _prop_def.get("initial", None)
_is_proxy = _prop_def.get("type", None) == "proxy"
_proxy_type = _prop_def.get("proxyType", None)
if _prop_name in kwargs:
self.set_property(_prop_name, kwargs[_prop_name])
elif isinstance(_init_def, dict):
logger.error("Don't know how to deal with domain yet: %s", _init_def)
elif _positive_size and _is_proxy and _proxy_type is not None:
_init_def = [
self._proxy_manager.create(_proxy_type).id for _ in range(_size)
]
self.set_property(_prop_name, _init_def)
else:
self.set_property(_prop_name, _init_def)

Expand Down Expand Up @@ -705,6 +714,7 @@ def delete(self, proxy_id, trigger_modified=True):
before_delete = set(self._id_map.keys())
# Delete ourself
proxy_to_delete: Proxy = self._id_map[proxy_id]
self.clean_proxy_domains(proxy_to_delete.id)
del self._id_map[proxy_id]

for tag in proxy_to_delete.tags:
Expand Down
6 changes: 5 additions & 1 deletion trame_simput/core/ui/resolvers/vuetify.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self):

def get_widget(self, elem):
model = self._model.get(elem.get("name"), {})
attributes = {key: model[key] for key in model if not key.startswith("_")}
attributes = {}
if elem.tag in VUETIFY_MAP:
return VUETIFY_MAP[elem.tag], attributes
elif elem.tag == "input":
Expand Down Expand Up @@ -80,6 +80,10 @@ def get_widget(self, elem):
if self._model.get(elem.get("name"), {}).get("type", "string") == "bool":
widget = "sw-switch"

proxy_type = model.get("proxyType", None)
if proxy_type is not None:
attributes["proxyType"] = proxy_type

return widget, attributes
elif elem.tag == "proxy":
return "sw-proxy", attributes
Expand Down
6 changes: 4 additions & 2 deletions vue2-components/src/widgets/Proxy/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ export default {
return getComponentProps(this.computedLayout, index);
},
deleteEntry(index) {
this.model.splice(index, 1);
this.dirty(this.name);
if (this.computedSize > Number(this.size)) {
this.model.splice(index, 1);
this.dirty(this.name);
}
},
},
inject: ['data', 'properties', 'domains', 'dirty'],
Expand Down
13 changes: 7 additions & 6 deletions vue2-components/src/widgets/TextField/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ export default {
if (!this.model) {
this.model = [];
}
this.dynamicSize = this.model.length + 1;
this.model.length = this.dynamicSize;
if (this.type == 'proxy') {
this.getSimput()
.wsClient.getConnection()
Expand All @@ -158,16 +156,19 @@ export default {
])
.then((proxy_id) => {
if (proxy_id != undefined) {
this.model[this.dynamicSize - 1] = proxy_id;
this.validate(this.dynamicSize);
this.model.push(proxy_id);
this.dirty(this.name);
}
this.dynamicSize = this.model.length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you know what dynamicSize is, you might want to "document" it somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is simply a reactive Vue property. It is defined differently in Vue2 and Vue3 but in both cases the point is that updating it updates the component.
It is defined for multiple files, should it be ducomented in all of these places ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be ducomented in all of these places ?

not necessarily. Wherever it makes most sense, but it can simply be in the file you modified in your commit.

this.validate(this.dynamicSize);
});
} else {
if (this.newValue === 'null') {
this.model[this.dynamicSize - 1] = null;
this.model.push(null);
} else if (this.newValue === 'same') {
this.model[this.dynamicSize - 1] = this.model[this.dynamicSize - 2];
this.model.push(this.model[this.model.length - 2]);
}
this.dynamicSize = this.model.length;
this.validate(this.dynamicSize);
}
},
Expand Down
Loading