diff --git a/docs/definitions.md b/docs/definitions.md index 2d2cdca..3aeca4f 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -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 diff --git a/setup.cfg b/setup.cfg index 24428d7..be49d40 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/trame_simput/__init__.py b/trame_simput/__init__.py index 8cf4890..37bba74 100644 --- a/trame_simput/__init__.py +++ b/trame_simput/__init__.py @@ -2,7 +2,7 @@ from .core import get_simput_manager -__version__ = get_version("trame-simput") +__version__ = get_version("trame_simput") __all__ = [ "__version__", diff --git a/trame_simput/core/proxy.py b/trame_simput/core/proxy.py index c34ddfd..67d975d 100644 --- a/trame_simput/core/proxy.py +++ b/trame_simput/core/proxy.py @@ -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) @@ -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: diff --git a/trame_simput/core/ui/resolvers/vuetify.py b/trame_simput/core/ui/resolvers/vuetify.py index 6678fe0..36f8f9a 100644 --- a/trame_simput/core/ui/resolvers/vuetify.py +++ b/trame_simput/core/ui/resolvers/vuetify.py @@ -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": @@ -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 diff --git a/vue2-components/src/widgets/Proxy/script.js b/vue2-components/src/widgets/Proxy/script.js index 8f821ae..1e8e7c9 100644 --- a/vue2-components/src/widgets/Proxy/script.js +++ b/vue2-components/src/widgets/Proxy/script.js @@ -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'], diff --git a/vue2-components/src/widgets/TextField/script.js b/vue2-components/src/widgets/TextField/script.js index 4825cf9..08d374b 100644 --- a/vue2-components/src/widgets/TextField/script.js +++ b/vue2-components/src/widgets/TextField/script.js @@ -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() @@ -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; + 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); } },