Skip to content

Commit 7a1b351

Browse files
committed
Integrate HTMX for dynamic description loading
1 parent 382075f commit 7a1b351

File tree

3 files changed

+26
-47
lines changed

3 files changed

+26
-47
lines changed

templates/boneset.html

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title>Bone Set Viewer</title>
88
<link rel="stylesheet" href="style.css" />
99
<link rel="icon" type="image/x-icon" href="favicon.ico">
10-
10+
<script src="https://unpkg.com/htmx.org@1.9.10" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
1111
</head>
1212

1313
<body>
@@ -33,21 +33,36 @@ <h1>Bone Set Viewer</h1>
3333
<div style="display: flex; flex-direction: column; gap: 10px;">
3434
<label for="bonesets">Choose a Boneset, Bone, or Sub-bone:</label>
3535
<div style="display: flex; gap: 10px; align-items: center;">
36-
<select id="boneset-select">
36+
<select id="boneset-select"
37+
name="boneId"
38+
hx-get="http://127.0.0.1:8000/api/description/"
39+
hx-target="#description-Container"
40+
hx-trigger="change">
3741
<option value="">--Please select a Boneset--</option>
3842
</select>
39-
<select id="bone-select" disabled>
43+
<select id="bone-select"
44+
name="boneId"
45+
hx-get="http://127.0.0.1:8000/api/description/"
46+
hx-target="#description-Container"
47+
hx-trigger="change"
48+
disabled>
4049
<option value="">--Please select a Bone--</option>
4150
</select>
42-
<select id="subbone-select" disabled>
51+
<select id="subbone-select"
52+
name="boneId"
53+
hx-get="http://127.0.0.1:8000/api/description/"
54+
hx-target="#description-Container"
55+
hx-trigger="change"
56+
disabled>
4357
<option value="">--Please choose a Sub-Bone--</option>
4458
</select>
4559
</div>
4660
</div>
4761

4862
<div id="bone-Description-Container">
4963
<h3>Description</h3>
50-
<ul id="description-Container"></ul>
64+
<ul id="description-Container">
65+
</ul>
5166
</div>
5267

5368
<div class="navigation-buttons">
@@ -58,46 +73,9 @@ <h3>Description</h3>
5873
<div class="viewer-wrapper">
5974
<img id="bone-image" alt="Bone Image" />
6075
<div id="annotations-overlay"></div>
61-
</div>
62-
63-
<script>
64-
//const BASE_IMAGE_URL = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/images/bony_pelvis.png";
65-
//const BASE_ANNOTATION_URL = "https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/images/bony_pelvis.png";
66-
67-
const imageId = " "; // replace with dynamic logic later if needed
68-
69-
async function fetchImageAndAnnotations(id) {
70-
const imageUrl = `${BASE_IMAGE_URL}${id}`;
71-
const annotationUrl = `${BASE_ANNOTATION_URL}${id}_annotation.json`;
72-
73-
try {
74-
// Try loading the image
75-
const img = new Image();
76-
img.src = imageUrl;
77-
img.onload = () => {
78-
console.log("Image found:", imageUrl);
79-
document.getElementById("bone-image").src = imageUrl;
80-
};
81-
img.onerror = () => {
82-
console.error("Image not found:", imageUrl);
83-
};
84-
85-
// Try fetching the annotation JSON
86-
const response = await fetch(annotationUrl);
87-
if (!response.ok) throw new Error("Annotation fetch failed");
88-
const annotations = await response.json();
89-
console.log("Annotation found:", annotations);
90-
} catch (err) {
91-
console.error("Annotation not found or error parsing:", err);
92-
}
93-
}
94-
95-
document.addEventListener("DOMContentLoaded", () => {
96-
fetchImageAndAnnotations(imageId);
97-
});
98-
</script>
76+
</div>
9977

100-
</div>
78+
</div>
10179
</div>
10280
<script type="module" src="js/main.js"></script>
10381

templates/js/api.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// js/api.js
1+
22
export async function fetchCombinedData() {
3+
// --- CORRECTED: Use the full URL of the backend server ---
34
const API_URL = 'http://127.0.0.1:8000/combined-data';
45

56
try {
@@ -11,4 +12,4 @@ export async function fetchCombinedData() {
1112
alert("Failed to load data.");
1213
return { bonesets: [], bones: [], subbones: [] };
1314
}
14-
}
15+
}

templates/js/dropdowns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function setupDropdownListeners(combinedData) {
3434
});
3535

3636
boneSelect.disabled = relatedBones.length === 0;
37-
if (selectedBonesetId) loadDescription(selectedBonesetId);
37+
// if (selectedBonesetId) loadDescription(selectedBonesetId);
3838
});
3939

4040
boneSelect.addEventListener('change', (e) => {

0 commit comments

Comments
 (0)