Skip to content

Commit 66653be

Browse files
committed
Update archived_image.html page to handle download links
1 parent bc4d6e8 commit 66653be

3 files changed

Lines changed: 81 additions & 48 deletions

File tree

idr_gallery/templates/idr_gallery/archived_image.html

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,66 @@
1717
</style>
1818

1919
<article>
20-
<h1>This Image is not viewable</h1>
21-
<h2>Image Name: {{ image.name }}</h2>
22-
<strong>ID: {{ image.id }}</strong><br />
23-
<strong>Study: {{ idr_study }}</strong>
24-
<p>
25-
Due to infrastructure limitations, this image is not viewable. The IDR only
26-
supports the viewing of OME-Zarr images.
27-
</p>
20+
<div style="display: flex; gap: 20px; flex-direction: row;">
21+
<div style="flex: 0 0 96px;">
22+
<img src="{% url 'render_thumbnail' image.id %}" alt="Thumbnail for {{ image.name }}" border: 1px solid #ccc; border-radius: 5px;">
23+
</div>
24+
<div style="flex: 1 1 auto">
25+
26+
<h2>Image Name: {{ image.name }}</h2>
27+
<strong>ID: {{ image.id }}</strong><br />
28+
<strong>Study: {{ idr_study }}</strong>
29+
<p>
30+
This image is not viewable online. <br/>
31+
The IDR only supports the viewing of OME-Zarr images.
32+
</p>
33+
</div>
34+
</div>
2835

2936
{% if fileset %}
30-
<h3>Image Files</h3>
31-
{% if fileset.file_urls|length == 1 %}
32-
<p>There is 1 file associated with this image:</p>
37+
<h3>Download Image Files</h3>
38+
{% if data_location == "Github" %}
39+
<p>
40+
This image is defined by a {% if is_pattern %}.pattern{% else %}companion.ome{% endif %} file
41+
and sibling .tiff files which are on GitHub (links below).
42+
Each .tiff file is a symbolic link to the actual image file in
43+
<!-- link is updated from download_urls.tsv info -->
44+
<a id="download_url_tsv" target="_blank" class="file_download" href="{{ download_url }}">{{ download_url }}</a>.
45+
</p>
46+
{% elif fileset.file_urls|length == 1 %}
47+
<p>There is 1 file associated with this image. Click to download:</p>
48+
{% else %}
49+
<p>
50+
There are {{ fileset.file_urls|length }} files associated with this image
51+
which can be downloaded from the links below. For more download options,
52+
including bulk download using Globus or FTP clients, see the
53+
<a href="/about/download.html">IDR Data download page</a>.
54+
</p>
55+
{% endif %}
56+
57+
<ul>
58+
{% for file in fileset.file_urls %}
59+
<li>
60+
{% if file.url %}
61+
<a class="file_download" target="_blank" href="{{ file.url }}">{{ file.path }}</a>
62+
{% else %} {{ file.path }} {% endif %}
63+
</li>
64+
{% endfor %}
65+
</ul>
3366
{% else %}
34-
<p>
35-
There are {{ fileset.file_urls|length }} files associated with this image
36-
which can be downloaded from the links below. For more download options,
37-
including bulk download using Globus or FTP clients, see the
38-
<a href="/about/download.html">IDR Data download page</a>.
39-
</p>
67+
<!-- Only expected for some OME-Zarr images (this page won't show for them) -->
68+
<p>No associated fileset.</p>
4069
{% endif %}
41-
<ul>
42-
{% for file in fileset.file_urls %}
43-
<li>
44-
{% if file.url %}
45-
<a class="file_download" href="{{ file.url }}">{{ file.path }}</a>
46-
{% else %} {{ file.path }} {% endif %}
47-
</li>
48-
{% endfor %}
49-
</ul>
50-
{% else %}
51-
<p>No associated fileset.</p>
52-
{% endif %} Extra info (debug)
53-
<ul style="background: white">
54-
<li>Image Path: {{ img_path }}</li>
55-
<li>Data Location: {{ data_location }}</li>
56-
<li>Is Zarr?: {{ is_zarr }}</li>
57-
<li>Download URL: <a href="{{ download_url }}">{{ download_url }}</a></li>
58-
<li>BIA NGFF ID: {{ bia_ngff_id }}</li>
59-
</ul>
70+
71+
<details><summary>Extra info (debug)</summary>
72+
<ul style="background: white">
73+
<li>Image Path: {{ img_path }}</li>
74+
<li>Data Location: {{ data_location }}</li>
75+
<li>Is Zarr?: {{ is_zarr }}</li>
76+
<li>Download URL from IDR: <a href="{{ download_url }}">{{ download_url }}</a></li>
77+
<li>BIA NGFF ID: {{ bia_ngff_id }}</li>
78+
</ul>
79+
</details>
6080
</article>
6181

6282
<script>
@@ -122,6 +142,11 @@ <h3>Image Files</h3>
122142
const downloadUrlIndex = headers.indexOf("download_url");
123143
// downloadUrl e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0047-neuert-yeastmrna/
124144
const downloadUrl = cells[downloadUrlIndex];
145+
let link = document.getElementById("download_url_tsv");
146+
if (link) {
147+
link.textContent = downloadUrl;
148+
link.href = downloadUrl;
149+
}
125150
const baseUrl = downloadUrl.split(IDR_ID)[0]; // e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/
126151
console.log(`Download URL for ${IDR_ID}:`, downloadUrl);
127152
if (downloadUrl) {

idr_gallery/templates/idr_gallery/download_urls.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ <h1>Download URLs</h1>
120120
}
121121
relativePath = relativePath.split("/").slice(1).join("/");
122122
clientPathUrl = `https://github.com/IDR/${githubRepo}/blob/${branch}/${relativePath}`;
123-
console.log("Client path URL (Github):", clientPath, clientPathUrl);
124123

125124
} else if (downloadUrl.includes(idrId) && clientPath.includes(idrId)) {
126125
// e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0001-graml-sysgro

idr_gallery/views.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,18 @@ def image_viewer(request, iid, conn=None, **kwargs):
549549
parents = image.getAncestry()
550550
idrid_name = parents[-1].name # e.g. idr0002-heriche-condensation/experimentA
551551
idrid_name = idrid_name.split("/")[0] # e.g. idr0002-heriche-condensation
552+
idrid = idrid_name.split("-")[0] # e.g. idr0002
552553

553-
download_url = None
554554
bia_ngff_id = None
555-
if data_location == "IDR" or data_location == "Github":
556-
# then link to Download e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0002-heriche-condensation/
557-
# e.g. idr0002-heriche-condensation
558-
download_url = f"https://ftp.ebi.ac.uk/pub/databases/IDR/"
555+
github_url = None
556+
# link to Download e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0002-heriche-condensation/
557+
download_url = f"https://ftp.ebi.ac.uk/pub/databases/IDR/{idrid_name}"
558+
if data_location == "Github":
559+
# Link to Github...
560+
branch = "main"
561+
if idrid in ["idr0079", "idr0052", "idr0065", "idr0075", "idr0100"]:
562+
branch = "master"
563+
github_url = f"https://github.com/IDR/{idrid_name}/blob/{branch}"
559564

560565
if data_location == "Embassy_S3":
561566
# "mkngff" data is at https://uk1s3.embassy.ebi.ac.uk/bia-integrator-data/pages/idr_ngff_data.html
@@ -577,14 +582,17 @@ def image_viewer(request, iid, conn=None, **kwargs):
577582
if image.fileset is not None:
578583
paths = image.getImportedImageFilePaths()
579584
file_urls = []
580-
idrid = idrid_name.split("-")[0] # e.g. idr0002
581585
for path in paths["client_paths"]:
582586
if idrid in path:
583-
file_path = path.split(idrid, 1)[-1]
584-
# url_prefix = download_url.split(idrid, 1)[0] if download_url else ""
585-
# url encode the file path to handle spaces and special characters
586-
file_path = urllib.parse.quote(file_path)
587-
file_urls.append({"url": f"{download_url}{idrid}{file_path}", "path": file_path})
587+
# we want path *after* /idr0002-heriche-condensation/
588+
# split on idrid handles mismatch like idr0047-neuert-yeastmrna with path idr0047-neuert-yeastmRNA
589+
file_path = path.split(idrid_name, 1)[-1]
590+
# remove before first "/" if present
591+
file_path = file_path.split("/", 1)[-1] if "/" in file_path else file_path
592+
if data_location == "Github":
593+
file_urls.append({"url": f"{github_url}/{urllib.parse.quote(file_path)}", "path": file_path})
594+
else:
595+
file_urls.append({"url": f"{download_url}/{urllib.parse.quote(file_path)}", "path": file_path})
588596
else:
589597
file_urls.append({"url": None, "path": path})
590598
fileset_id = image.fileset.id.val
@@ -593,6 +601,7 @@ def image_viewer(request, iid, conn=None, **kwargs):
593601
"client_paths": paths["client_paths"],
594602
"file_urls": file_urls,
595603
}
604+
rsp_json["is_pattern"] = paths["client_paths"][0].endswith("pattern")
596605

597606
return rsp_json
598607

0 commit comments

Comments
 (0)