diff --git a/static/css/style.css b/static/css/style.css index 9ac3dd9..43426f3 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -16,7 +16,31 @@ font-size: 0.9rem; } -/* Drive cards styling */ +/* Drive selector cards */ +.drive-selector-card { + transition: all 0.2s ease; +} + +.drive-selector-card .btn-check:checked + .btn { + background-color: #e7f1ff; + border-color: #0d6efd; + box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25); +} + +.drive-selector-card .btn { + border-radius: 0.5rem; + padding: 1rem; +} + +.drive-selector-card .btn:hover { + background-color: #f8f9fa; +} + +.drive-selector-card .btn-check:checked + .btn:hover { + background-color: #e7f1ff; +} + +/* General drive cards */ .drive-card { transition: all 0.3s ease; height: 100%; diff --git a/static/js/main.js b/static/js/main.js index 00cdbab..83f65dd 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -3,6 +3,9 @@ * Handles HTMX events and dynamic content rendering */ +// Global state +let selectedDrive = null; + // Render drives after HTMX loads them function renderDrives(data) { const container = document.getElementById('drives-content'); @@ -45,16 +48,161 @@ function renderDrives(data) { }); } -// Listen for HTMX events -document.addEventListener('htmx:afterRequest', function(evt) { - if (evt.detail.target.id === 'drives-content') { - renderDrives(JSON.parse(evt.detail.xhr.response)); +// Render drive selector for benchmark tab (available drives only) +function renderDriveSelector(data) { + const container = document.getElementById('drive-cards'); + if (!container) return; + + container.innerHTML = ''; + + if (!data.drives || data.drives.length === 0) { + container.innerHTML = '

No drives found.

'; + return; + } + + // Filter to show only available drives + const availableDrives = data.drives.filter(drive => !drive.mounted); + + if (availableDrives.length === 0) { + container.innerHTML = '
No available drives. All drives are mounted.
'; + return; + } + + availableDrives.forEach(drive => { + const col = document.createElement('div'); + col.className = 'col-md-4 mb-3'; + + const cardWrapper = document.createElement('div'); + cardWrapper.className = 'drive-selector-card'; + cardWrapper.dataset.drivePath = drive.path; + + // Radio input (hidden) + const radio = document.createElement('input'); + radio.type = 'radio'; + radio.name = 'selected_drive'; + radio.value = drive.path; + radio.id = `drive-${drive.name}`; + radio.className = 'btn-check'; + radio.setAttribute('autocomplete', 'off'); + + // Label as card + const label = document.createElement('label'); + label.htmlFor = `drive-${drive.name}`; + label.className = 'btn btn-outline-primary w-100 text-start'; + label.innerHTML = ` +
+
+
${drive.name}
+ ${drive.size} ${drive.model || ''} +
+
+ Available +
+
+ ${drive.serial ? `SN: ${drive.serial}` : ''} + `; + + cardWrapper.appendChild(radio); + cardWrapper.appendChild(label); + col.appendChild(cardWrapper); + container.appendChild(col); + + // Add click handler to show selected drive info + radio.addEventListener('change', function() { + if (this.checked) { + selectDrive(drive); + } + }); + }); +} + +// Handle drive selection +function selectDrive(drive) { + selectedDrive = drive; + console.log('Selected drive:', drive); + + // Update UI to show selection + const infoDiv = document.getElementById('selected-drive-info'); + if (infoDiv) { + infoDiv.innerHTML = ` +
+ Selected: ${drive.name} (${drive.path}) +
${drive.size} - ${drive.model || 'Unknown model'} +
+ `; + } + + // Show clear selection button + const clearContainer = document.getElementById('clear-selection-container'); + if (clearContainer) { + clearContainer.style.display = 'block'; + } + + // Enable benchmark configuration section + const configDiv = document.getElementById('benchmark-config'); + if (configDiv) { + configDiv.classList.remove('opacity-50'); + configDiv.querySelector('.card-body').innerHTML = ` +

Drive ${drive.name} selected. Configure benchmark parameters below.

+ + `; + } +} + +// Handle drive deselection (clear selection) +function clearDriveSelection() { + selectedDrive = null; + console.log('Cleared drive selection'); + + // Clear selected drive info + const infoDiv = document.getElementById('selected-drive-info'); + if (infoDiv) { + infoDiv.innerHTML = ''; + } + + // Hide clear selection button + const clearContainer = document.getElementById('clear-selection-container'); + if (clearContainer) { + clearContainer.style.display = 'none'; + } + + // Disable benchmark configuration section + const configDiv = document.getElementById('benchmark-config'); + if (configDiv) { + configDiv.classList.add('opacity-50'); + configDiv.querySelector('.card-body').innerHTML = ` +

Select a drive above to configure benchmark parameters.

+ `; + } + + // Uncheck all radio buttons + const radios = document.querySelectorAll('input[name="selected_drive"]'); + radios.forEach(radio => { radio.checked = false; }); +} + +// Listen for clear selection button click +document.addEventListener('click', function(evt) { + if (evt.target.id === 'clear-selection-btn' || evt.target.closest('#clear-selection-btn')) { + clearDriveSelection(); } }); -// Optional: Listen for HTMX load event as fallback +// Listen for HTMX events +document.addEventListener('htmx:afterRequest', function(evt) { + // Render drives in home page + if (evt.detail.target.id === 'drives-content') { + renderDrives(JSON.parse(evt.detail.xhr.response)); + } + + // Render drive selector in benchmark page + if (evt.detail.target.id === 'drive-cards') { + renderDriveSelector(JSON.parse(evt.detail.xhr.response)); + } +}); + +// Listen for HTMX load event as fallback document.addEventListener('htmx:load', function(evt) { - if (evt.target.id === 'drives-content') { + if (evt.target.id === 'drive-cards') { // HTMX will load the content via hx-get // The afterRequest event will handle rendering } diff --git a/templates/benchmark.html b/templates/benchmark.html index 92b1047..55a80da 100644 --- a/templates/benchmark.html +++ b/templates/benchmark.html @@ -8,16 +8,48 @@

Benchmark

Configure and run disk benchmarks.

- -
+ +
+
+
Select Drive to Benchmark
+
-
Select Drive
-

Choose a drive to benchmark from the list below.

+

Choose an available drive from the list below.

- -
+ +
+
+ + +
+ + +
+ +
+
+ + +
+
+
Benchmark Configuration
+
+
+

Select a drive above to configure benchmark parameters.

+{% endblock %} + +{% block extra_js %} + {% endblock %} \ No newline at end of file