|
22 | 22 | </div> |
23 | 23 |
|
24 | 24 | <div id="sidebar-container"></div> |
25 | | - <script src="sidebar.js"></script> |
26 | 25 |
|
27 | 26 | <div id="editor-view"> |
28 | 27 | <div class="container"> |
@@ -55,120 +54,7 @@ <h3>Description</h3> |
55 | 54 | </div> |
56 | 55 | </div> |
57 | 56 | </div> |
58 | | - |
59 | | - <script> |
60 | | - const API_URL = 'http://127.0.0.1:8000/combined-data'; |
61 | | - const GITHUB_RAW_URL = 'https://raw.githubusercontent.com/oss-slu/DigitalBonesBox/data/DataPelvis/descriptions/'; |
62 | | - |
63 | | - let combinedData = { bonesets: [], bones: [], subbones: [] }; |
64 | | - |
65 | | - async function fetchCombinedData() { |
66 | | - try { |
67 | | - const response = await fetch(API_URL); |
68 | | - if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); |
69 | | - return await response.json(); |
70 | | - } catch (error) { |
71 | | - console.error("Error fetching data:", error); |
72 | | - alert("Failed to load data."); |
73 | | - return { bonesets: [], bones: [], subbones: [] }; |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - function populateDropdowns() { |
78 | | - const bonesetSelect = document.getElementById('boneset-select'); |
79 | | - bonesetSelect.innerHTML = '<option value="">--Please select a Boneset--</option>'; |
80 | | - combinedData.bonesets.forEach(set => { |
81 | | - const option = document.createElement('option'); |
82 | | - option.value = set.id; |
83 | | - option.textContent = set.name; |
84 | | - bonesetSelect.appendChild(option); |
85 | | - }); |
86 | | - } |
87 | | - |
88 | | - document.getElementById('boneset-select').addEventListener('change', (e) => { |
89 | | - const selectedBonesetId = e.target.value; |
90 | | - const boneSelect = document.getElementById('bone-select'); |
91 | | - const subboneSelect = document.getElementById('subbone-select'); |
92 | | - |
93 | | - boneSelect.innerHTML = '<option value="">--Please select a Bone--</option>'; |
94 | | - subboneSelect.innerHTML = '<option value="">--Please choose a Sub-Bone--</option>'; |
95 | | - subboneSelect.disabled = true; |
96 | | - |
97 | | - const relatedBones = combinedData.bones.filter(b => b.boneset === selectedBonesetId); |
98 | | - relatedBones.forEach(bone => { |
99 | | - const option = document.createElement('option'); |
100 | | - option.value = bone.id; |
101 | | - option.textContent = bone.name; |
102 | | - boneSelect.appendChild(option); |
103 | | - }); |
104 | | - |
105 | | - boneSelect.disabled = false; |
106 | | - loadDescription(selectedBonesetId); |
107 | | - }); |
108 | | - |
109 | | - document.getElementById('bone-select').addEventListener('change', (e) => { |
110 | | - const selectedBoneId = e.target.value; |
111 | | - const subboneSelect = document.getElementById('subbone-select'); |
112 | | - |
113 | | - subboneSelect.innerHTML = '<option value="">--Please choose a Sub-Bone--</option>'; |
114 | | - const relatedSubbones = combinedData.subbones.filter(sb => sb.bone === selectedBoneId); |
115 | | - relatedSubbones.forEach(sb => { |
116 | | - const option = document.createElement('option'); |
117 | | - option.value = sb.id; |
118 | | - option.textContent = sb.name; |
119 | | - subboneSelect.appendChild(option); |
120 | | - }); |
121 | | - |
122 | | - subboneSelect.disabled = relatedSubbones.length === 0; |
123 | | - loadDescription(selectedBoneId); |
124 | | - }); |
125 | | - |
126 | | - document.getElementById('subbone-select').addEventListener('change', (e) => { |
127 | | - const selectedSubboneId = e.target.value; |
128 | | - if (selectedSubboneId) loadDescription(selectedSubboneId); |
129 | | - }); |
130 | | - |
131 | | - async function loadDescription(id) { |
132 | | - const container = document.getElementById('description-Container'); |
133 | | - container.innerHTML = ""; |
134 | | - const descUrl = `${GITHUB_RAW_URL}${id}_description.json`; |
135 | | - |
136 | | - try { |
137 | | - const response = await fetch(descUrl); |
138 | | - const data = await response.json(); |
139 | | - |
140 | | - const nameItem = document.createElement('li'); |
141 | | - nameItem.innerHTML = `<strong>${data.name}</strong>`; |
142 | | - container.appendChild(nameItem); |
143 | | - |
144 | | - data.description.forEach(point => { |
145 | | - const li = document.createElement('li'); |
146 | | - li.textContent = point; |
147 | | - container.appendChild(li); |
148 | | - }); |
149 | | - } catch (error) { |
150 | | - container.innerHTML = "<li>Error loading description.</li>"; |
151 | | - console.error("Failed to fetch description:", error); |
152 | | - } |
153 | | - } |
154 | | - |
155 | | - document.addEventListener('DOMContentLoaded', async () => { |
156 | | - combinedData = await fetchCombinedData(); |
157 | | - populateDropdowns(); |
158 | | - |
159 | | - const boneset = combinedData.bonesets[0]; |
160 | | - if (boneset) { |
161 | | - document.getElementById('boneset-select').value = boneset.id; |
162 | | - const event = new Event('change'); |
163 | | - document.getElementById('boneset-select').dispatchEvent(event); |
164 | | - } |
165 | | - }); |
166 | | - </script> |
167 | | - |
168 | | - |
169 | | - <script type="module" src="../js/main.js"></script> |
170 | | - |
171 | | - |
| 57 | + <script type="module" src="js/main.js"></script> |
172 | 58 |
|
173 | 59 | </body> |
174 | 60 |
|
|
0 commit comments