|
1 | | - |
2 | | -{% extends "idr_gallery/base.html" %} |
3 | | - |
4 | | -{% block content %} |
| 1 | +{% extends "idr_gallery/base.html" %} {% block content %} |
5 | 2 |
|
6 | 3 | <style> |
7 | | - article { |
8 | | - max-width: 800px; |
9 | | - margin: 0 auto; |
10 | | - padding: 20px; |
11 | | - } |
| 4 | + article { |
| 5 | + max-width: 800px; |
| 6 | + margin: 0 auto; |
| 7 | + padding: 20px; |
| 8 | + } |
| 9 | + ul { |
| 10 | + list-style: none; |
| 11 | + background: white; |
| 12 | + margin: 0; |
| 13 | + padding: 15px; |
| 14 | + margin-bottom: 20px; |
| 15 | + border-radius: 5px; |
| 16 | + } |
12 | 17 | </style> |
13 | 18 |
|
14 | 19 | <article> |
15 | | - <h1>Image is not viewable</h1> |
16 | | - <h2>Study: {{ idr_study }}</h2> |
17 | | - <h2>Image Name: {{ image.name }}</h2> |
18 | | - <h3>ID: {{ image.id }}</h3> |
19 | | - <p> |
20 | | - Due to infrastructure limitations, this image is not viewable. |
21 | | - The IDR only supports the viewing of OME-Zarr images. |
22 | | - </p> |
23 | | - |
24 | | - {% if fileset %} |
25 | | - <h3>Image Files</h3> |
26 | | - <p>The following files are associated with this image and can be downloaded for offline viewing or analysis:</p> |
27 | | - <ul> |
28 | | - {% for file in fileset.file_urls %} |
29 | | - <li> |
30 | | - {% if file.url %} |
31 | | - <a href="{{ file.url }}">{{ file.path }}</a> |
32 | | - {% else %} |
33 | | - {{ file.path }} |
34 | | - {% endif %} |
35 | | - </li> |
36 | | - {% endfor %} |
37 | | - </ul> |
38 | | - {% else %} |
39 | | - <p>No associated fileset.</p> |
40 | | - {% endif %} |
41 | | - |
42 | | - <ul style="background: white;"> |
43 | | - <li>Image Path: {{ img_path }}</li> |
44 | | - <li>Data Location: {{ data_location }}</li> |
45 | | - <li>Is Zarr?: {{ is_zarr }}</li> |
46 | | - <li>Download URL: <a href="{{ download_url }}">{{ download_url }}</a></li> |
47 | | - <li>BIA NGFF ID: {{ bia_ngff_id }}</li> |
48 | | - </ul> |
| 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> |
| 28 | + |
| 29 | + {% 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> |
| 33 | + {% 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> |
| 40 | + {% 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> |
49 | 60 | </article> |
50 | 61 |
|
| 62 | +<script> |
| 63 | + const IDR_ID_NAME = "{{ idr_study }}"; |
| 64 | + let IDR_ID = IDR_ID_NAME.split("-")[0]; |
| 65 | + let DOWNLOAD_URL = "{{ download_url }}"; |
| 66 | + |
| 67 | + function checkLinks() { |
| 68 | + let links = Array.from(document.querySelectorAll("a")); |
| 69 | + // links = links.slice(0,50) |
| 70 | + links.forEach((link) => { |
| 71 | + // ignore image viewer links |
| 72 | + if (!link.href || link.href.includes("img_detail")) return; |
| 73 | + // no cors-origin check for now, just check if the link is valid |
| 74 | + fetch(link.href, { method: "HEAD" }) |
| 75 | + .then((response) => { |
| 76 | + link.style.color = response.ok ? "green" : "orange"; |
| 77 | + link.title = response.ok ? "Link is valid" : "Link is broken"; |
| 78 | + }) |
| 79 | + .catch((error) => { |
| 80 | + // show "pink" and re-try with server-side check, to avoid CORS issues |
| 81 | + console.error("Error checking link:", error); |
| 82 | + link.style.color = "pink"; |
| 83 | + link.title = "Error checking link"; |
| 84 | + |
| 85 | + fetch(`/link_check/?url=${encodeURIComponent(link.href)}`) |
| 86 | + .then((res) => res.json()) |
| 87 | + .then((data) => { |
| 88 | + console.log("Link check data:", data); |
| 89 | + if (data.is_valid) { |
| 90 | + link.style.color = "green"; |
| 91 | + link.title = "Link is valid (checked with server)"; |
| 92 | + } else { |
| 93 | + link.style.color = "red"; |
| 94 | + link.title = `Link is broken: ${data.error}`; |
| 95 | + } |
| 96 | + }); |
| 97 | + }); |
| 98 | + }); |
| 99 | + } |
| 100 | + |
| 101 | + document.addEventListener("DOMContentLoaded", function () { |
| 102 | + // Load download URLs from TSV file in GitHub to fix the download URL for this image |
| 103 | + fetch( |
| 104 | + "https://raw.githubusercontent.com/will-moore/idr.openmicroscopy.org/refs/heads/download_urls/_data/download_urls.tsv", |
| 105 | + ) |
| 106 | + .then((response) => response.text()) |
| 107 | + .then((data) => { |
| 108 | + const lines = data.split("\n"); |
| 109 | + |
| 110 | + // Use first line as header to find column names... |
| 111 | + const headers = lines[0].split("\t"); |
| 112 | + |
| 113 | + const idrIndex = headers.indexOf("idrid"); |
| 114 | + |
| 115 | + // Find the line for this IDR ID |
| 116 | + const studyLine = lines.find( |
| 117 | + (line) => line.split("\t")[idrIndex] === IDR_ID, |
| 118 | + ); |
| 119 | + console.log(`Found line for ${IDR_ID}:`, studyLine); |
| 120 | + if (studyLine) { |
| 121 | + const cells = studyLine.split("\t"); |
| 122 | + const downloadUrlIndex = headers.indexOf("download_url"); |
| 123 | + // downloadUrl e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0047-neuert-yeastmrna/ |
| 124 | + const downloadUrl = cells[downloadUrlIndex]; |
| 125 | + const baseUrl = downloadUrl.split(IDR_ID)[0]; // e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/ |
| 126 | + console.log(`Download URL for ${IDR_ID}:`, downloadUrl); |
| 127 | + if (downloadUrl) { |
| 128 | + // update all ".file_download" links to this download URL |
| 129 | + const fileDownloadLinks = |
| 130 | + document.querySelectorAll(".file_download"); |
| 131 | + fileDownloadLinks.forEach((link) => { |
| 132 | + link.href = link.href.replace(DOWNLOAD_URL, baseUrl); |
| 133 | + }); |
| 134 | + } |
| 135 | + } else { |
| 136 | + console.warn(`No download URL found for ${IDR_ID} in TSV file`); |
| 137 | + } |
| 138 | + |
| 139 | + // After updating links, check them if ?check_links=1 is in the URL |
| 140 | + const urlParams = new URLSearchParams(window.location.search); |
| 141 | + if (urlParams.get("check_links")) { |
| 142 | + checkLinks(); |
| 143 | + } |
| 144 | + }); |
| 145 | + }); |
| 146 | +</script> |
| 147 | + |
51 | 148 | {% endblock %} |
0 commit comments