From b6a97686afbfaa87f45e822636354feb1adaad5e Mon Sep 17 00:00:00 2001 From: bloodearnest Date: Thu, 14 Mar 2024 19:04:29 +0000 Subject: [PATCH 1/5] Use iframe to display all file contents. This means changing the contents url for files to render csv/txt files as html, and just serve up other files. Also, I split the download parts of serve_file into its own function, as serve_file is more complex, and the caching logic doesn't apply to downloads. Changed some test assertions to assert that the url to the content is present, rather than the content itself. --- airlock/file_browser_api.py | 15 ---- airlock/templates/file_browser/contents.html | 28 ++----- airlock/templates/file_browser/csv.html | 23 ++++-- airlock/templates/file_browser/index.html | 11 --- airlock/views/helpers.py | 79 +++++++++++++++++--- airlock/views/request.py | 16 ++-- airlock/views/workspace.py | 2 +- pyproject.toml | 3 +- tests/functional/test_e2e.py | 22 ++++-- tests/integration/views/test_helpers.py | 68 +++++++++++++++-- tests/integration/views/test_request.py | 11 ++- tests/integration/views/test_workspace.py | 18 +++-- 12 files changed, 199 insertions(+), 97 deletions(-) diff --git a/airlock/file_browser_api.py b/airlock/file_browser_api.py index 5e999d5c..8e4c30b9 100644 --- a/airlock/file_browser_api.py +++ b/airlock/file_browser_api.py @@ -47,18 +47,6 @@ class PathNotFound(Exception): # but this allow it to be overridden. display_text: str = None - DISPLAY_TYPES = { - "html": "iframe", - "jpeg": "image", - "jpg": "image", - "png": "image", - "svg": "image", - "csv": "table", - "tsv": "table", - "txt": "preformatted", - "log": "preformatted", - } - def __post_init__(self): # ensure is UrlPath self.relpath = UrlPath(self.relpath) @@ -121,9 +109,6 @@ def suffix(self): def file_type(self): return self.suffix().lstrip(".") - def display_type(self): - return self.DISPLAY_TYPES.get(self.file_type(), "preformatted") - def breadcrumbs(self): item = self crumbs = [item] diff --git a/airlock/templates/file_browser/contents.html b/airlock/templates/file_browser/contents.html index 96f7bced..3b279758 100644 --- a/airlock/templates/file_browser/contents.html +++ b/airlock/templates/file_browser/contents.html @@ -59,28 +59,12 @@ {% #card title=path_item.name container=True custom_button=add_button %}
- {% if path_item.display_type == "iframe" %} - - {% elif path_item.display_type == "image" %} -
- -
- {% elif path_item.display_type == "table" %} -
- {% include "file_browser/csv.html" with contents=path_item.contents %} -
- {% else %} -
-
{{ path_item.contents }}
-
- {% endif %} +