Commit 2a227516 authored by Duggan, John's avatar Duggan, John
Browse files

Display uploaded files via a treeview

parent ceb90f65
Loading
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ class MainModel:
        self.plot_json = PlotJSON()
        self.resource_params = ResourceParameters()

        self.file_tree: Dict[str, Any] = {}

    def download_files(self) -> bytes:
        archive = BytesIO()
        with zipfile.ZipFile(archive, "w") as zip_obj:
@@ -83,6 +85,15 @@ class MainModel:

        return archive.read()

    def get_file_from_path(self, path: str) -> Dict[str, Any]:
        parts = path.split("/")
        file = self.file_tree
        for part in parts:
            if part in file:
                file = file[part]

        return file

    def set_file_contents(self, index: int, json_data: str) -> None:
        self.config.input_files[index]["content"] = json_data

@@ -94,13 +105,34 @@ class MainModel:
        if not files:
            self.config.input_files = []

        self.file_tree = {}
        for index, file in enumerate(files):
            relative_path = relative_paths[index]
            parts = relative_path.split("/")[1:]

            decoded_file = file.copy()
            decoded_file["content"] = decoded_file["content"].decode("latin1")
            decoded_file["relative_path"] = "/".join(relative_path.split("/")[1:])
            self.config.input_files.append(decoded_file)
            decoded_file["path"] = "/".join(parts)

            current_level = self.file_tree
            for part in parts[:-1]:
                if part not in current_level:
                    current_level[part] = {}
                current_level = current_level[part]
            current_level[parts[-1]] = decoded_file

        self.config.input_files = self.set_files_from_tree(self.file_tree)

    def set_files_from_tree(self, tree: Dict[str, Any]) -> List[Dict[str, Any]]:
        # Converts the file tree to a structure usable by our treeview.
        file_list: List[Dict[str, Any]] = []
        for key, value in tree.items():
            if "path" in value:
                file_list.append(value)
            else:
                file_list.append({"path": key, "name": key, "children": self.set_files_from_tree(value)})

        return file_list

    def set_plot(self, json_data: str) -> None:
        self.plot_json = PlotJSON.model_validate_json(json_data)
+5 −5
Original line number Diff line number Diff line
@@ -125,13 +125,13 @@ class MainViewModel:
        self.model.set_files(files, relative_paths)
        self.config_bind.update_in_view(self.model.config)

    def edit_file(self, index: int) -> None:
        if index >= len(self.model.config.input_files):
    def edit_file(self, path: List[str]) -> None:
        if not path:
            return

        file = self.model.config.input_files[index]
        self.view_state.editor_index = index
        self.view_state.editor_path = file["relative_path"]
        file = self.model.get_file_from_path(path[0])

        self.view_state.editor_path = file["path"]
        self.view_state.editor_content = file["content"]

        self.view_state_bind.update_in_view(self.view_state)
+10 −7
Original line number Diff line number Diff line
@@ -44,15 +44,18 @@ class ConfigTab:
                )

            with GridLayout(classes="mb-2", columns=3, stretch=True):
                with vuetify.VList(density="compact"):
                with VBoxLayout():
                    vuetify.VListSubheader("Uploaded Files")
                    vuetify.VListItem("No files available.", v_if="config.input_files.length < 1")
                    vuetify.VListItem(
                        "{{ file.relative_path }}",
                        v_else=True,
                        v_for="(file, index) in config.input_files",
                        click=(self.view_model.edit_file, "[index]"),
                    vuetify.VTreeview(
                        v_if="config.input_files.length > 0",
                        activatable=True,
                        active_strategy="single-leaf",
                        items=("config.input_files",),
                        item_title="name",
                        item_value="path",
                        update_activated=(self.view_model.edit_file, "[$event]"),
                    )
                    vuetify.VListItem("No files available.", v_else=True)
                with VBoxLayout(column_span=2, stretch=True):
                    with VBoxLayout():
                        InputField("state.editor_path")