Commit 34d0be39 authored by Duggan, John's avatar Duggan, John
Browse files

Merge branch '80-allow-restricting-datafiles-to-a-given-list-of-extensions' into 'main'

Allow restricting datafiles to a given list of extensions

Closes #80

See merge request ndip/public-packages/nova-trame!62
parents c83e41c1 5b5a7706
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
### nova-trame, 0.19.1

* DataSelector now has an additional parameter `extensions` for restricting the selectable datafiles to a list of file extensions (thanks to John Duggan).

### nova-trame, 0.19.0

* You can now use `nova.trame.view.components.DataSelector` to allow the user to select a list of data files from the analysis cluster (thanks to John Duggan).

### nova-trame, 0.18.2

* Passing a string to the style parameter to GridLayout, HBoxLayout, and VBoxLayout will no longer cause Trame to crash (thanks to John Duggan).
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Changelog = "https://code.ornl.gov/ndip/public-packages/nova-trame/blob/main/CHA

[tool.poetry]
name = "nova-trame"
version = "0.19.0"
version = "0.19.1"
description = "A Python Package for injecting curated themes and custom components into Trame applications"
authors = ["Duggan, John <dugganjw@ornl.gov>"]
readme = "README.md"
+9 −2
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ class DataSelectorState(BaseModel, validate_assignment=True):
    instrument: str = Field(default="", title="Instrument")
    experiment: str = Field(default="", title="Experiment")
    directory: str = Field(default="")
    extensions: List[str] = Field(default=[])
    prefix: str = Field(default="")

    @field_validator("experiment", mode="after")
@@ -101,10 +102,11 @@ class DataSelectorState(BaseModel, validate_assignment=True):
class DataSelectorModel:
    """Manages file system interactions for the DataSelector widget."""

    def __init__(self, facility: str, instrument: str, prefix: str) -> None:
    def __init__(self, facility: str, instrument: str, extensions: List[str], prefix: str) -> None:
        self.state = DataSelectorState()
        self.state.facility = facility
        self.state.instrument = instrument
        self.state.extensions = extensions
        self.state.prefix = prefix

    def get_facilities(self) -> List[str]:
@@ -192,6 +194,11 @@ class DataSelectorModel:

            for entry in os.scandir(datafile_path):
                if entry.is_file():
                    if self.state.extensions:
                        for extension in self.state.extensions:
                            if entry.path.lower().endswith(extension):
                                datafiles.append(entry.path)
                    else:
                        datafiles.append(entry.path)
        except OSError:
            pass
+6 −2
Original line number Diff line number Diff line
"""View Implementation for DataSelector."""

from typing import Any, Optional, cast
from typing import Any, List, Optional, cast

from trame.app import get_server
from trame.widgets import client, html
@@ -24,6 +24,7 @@ class DataSelector(vuetify.VDataTableVirtual):
        v_model: str,
        facility: str = "",
        instrument: str = "",
        extensions: Optional[List[str]] = None,
        prefix: str = "",
        select_strategy: str = "all",
        **kwargs: Any,
@@ -39,6 +40,8 @@ class DataSelector(vuetify.VDataTableVirtual):
            The facility to restrict data selection to. Options: HFIR, SNS
        instrument : str, optional
            The instrument to restrict data selection to. Please use the instrument acronym (e.g. CG-2).
        extensions : List[str], optional
            A list of file extensions to restrict selection to. If unset, then all files will be shown.
        prefix : str, optional
            A subdirectory within the user's chosen experiment to show files. If not specified, the user will be shown a
            folder browser and will be able to see all files in the experiment that they have access to.
@@ -62,6 +65,7 @@ class DataSelector(vuetify.VDataTableVirtual):
            self._label = None

        self._v_model = v_model
        self._extensions = extensions if extensions is not None else []
        self._prefix = prefix
        self._select_strategy = select_strategy

@@ -151,7 +155,7 @@ class DataSelector(vuetify.VDataTableVirtual):
                    )

    def create_model(self, facility: str, instrument: str) -> None:
        self._model = DataSelectorModel(facility, instrument, self._prefix)
        self._model = DataSelectorModel(facility, instrument, self._extensions, self._prefix)

    def create_viewmodel(self) -> None:
        server = get_server(None, client_type="vue3")
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ class DataSelectorViewModel:
        self.datafiles_bind = binding.new_bind()
        self.reset_bind = binding.new_bind()

    def set_directory(self, directory_path: str) -> None:
    def set_directory(self, directory_path: str = "") -> None:
        self.model.set_directory(directory_path)
        self.update_view()

Loading