diff --git a/static/css/style.css b/static/css/style.css index d668371..9ac3dd9 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -19,6 +19,7 @@ /* Drive cards styling */ .drive-card { transition: all 0.3s ease; + height: 100%; } .drive-card.available { diff --git a/static/js/main.js b/static/js/main.js new file mode 100644 index 0000000..00cdbab --- /dev/null +++ b/static/js/main.js @@ -0,0 +1,61 @@ +/** + * Disk Checker - Main JavaScript + * Handles HTMX events and dynamic content rendering + */ + +// Render drives after HTMX loads them +function renderDrives(data) { + const container = document.getElementById('drives-content'); + if (!container) return; + + container.innerHTML = ''; + + if (!data.drives || data.drives.length === 0) { + container.innerHTML = '

No drives found.

'; + return; + } + + data.drives.forEach(drive => { + const col = document.createElement('div'); + col.className = 'col-md-4 mb-3'; + + const card = document.createElement('div'); + card.className = `drive-card ${drive.mounted ? 'disabled' : 'available'}`; + + card.innerHTML = ` +
+
${drive.name}
+

+ Size: ${drive.size}
+ Model: ${drive.model || 'Unknown'}
+ ${drive.serial ? `Serial: ${drive.serial}
` : ''} + ${drive.mount_point ? `Mounted at: ${drive.mount_point}
` : ''} +

+
+ ${drive.mounted + ? 'Mounted - Unavailable' + : 'Available for Benchmark' + } +
+
+ `; + + col.appendChild(card); + container.appendChild(col); + }); +} + +// Listen for HTMX events +document.addEventListener('htmx:afterRequest', function(evt) { + if (evt.detail.target.id === 'drives-content') { + renderDrives(JSON.parse(evt.detail.xhr.response)); + } +}); + +// Optional: Listen for HTMX load event as fallback +document.addEventListener('htmx:load', function(evt) { + if (evt.target.id === 'drives-content') { + // HTMX will load the content via hx-get + // The afterRequest event will handle rendering + } +}); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index a686e65..8ce1073 100644 --- a/templates/base.html +++ b/templates/base.html @@ -18,9 +18,9 @@
{% block content %}{% endblock %} - {% block extra_js %}{% endblock %}
+ {% block extra_js %}{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 8692da1..c83e1a7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,51 +43,5 @@ {% endblock %} {% block extra_js %} - + {% endblock %} \ No newline at end of file