feat: make upload stuff more compact
This commit is contained in:
@@ -705,7 +705,7 @@ function setupFirmwareView() {
|
||||
// Setup global firmware file input
|
||||
const globalFirmwareFile = document.getElementById('global-firmware-file');
|
||||
if (globalFirmwareFile) {
|
||||
globalFirmwareFile.addEventListener('change', handleGlobalFirmwareUpload);
|
||||
globalFirmwareFile.addEventListener('change', handleGlobalFirmwareFileSelect);
|
||||
}
|
||||
|
||||
// Setup target selection
|
||||
@@ -720,36 +720,105 @@ function setupFirmwareView() {
|
||||
} else {
|
||||
specificNodeSelect.style.display = 'none';
|
||||
}
|
||||
updateDeployButton();
|
||||
});
|
||||
});
|
||||
|
||||
// Setup specific node select change handler
|
||||
if (specificNodeSelect) {
|
||||
specificNodeSelect.addEventListener('change', updateDeployButton);
|
||||
}
|
||||
|
||||
// Setup deploy button
|
||||
const deployBtn = document.getElementById('deploy-btn');
|
||||
if (deployBtn) {
|
||||
deployBtn.addEventListener('click', handleDeployFirmware);
|
||||
}
|
||||
|
||||
// Initial button state
|
||||
updateDeployButton();
|
||||
}
|
||||
|
||||
// Handle global firmware upload
|
||||
async function handleGlobalFirmwareUpload(event) {
|
||||
// Handle file selection for the compact interface
|
||||
function handleGlobalFirmwareFileSelect(event) {
|
||||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
const fileInfo = document.getElementById('file-info');
|
||||
const deployBtn = document.getElementById('deploy-btn');
|
||||
|
||||
if (file) {
|
||||
fileInfo.textContent = `${file.name} (${(file.size / 1024).toFixed(1)}KB)`;
|
||||
fileInfo.classList.add('has-file');
|
||||
deployBtn.disabled = false;
|
||||
} else {
|
||||
fileInfo.textContent = 'No file selected';
|
||||
fileInfo.classList.remove('has-file');
|
||||
deployBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update deploy button state
|
||||
function updateDeployButton() {
|
||||
const deployBtn = document.getElementById('deploy-btn');
|
||||
const fileInput = document.getElementById('global-firmware-file');
|
||||
const targetType = document.querySelector('input[name="target-type"]:checked');
|
||||
const specificNodeSelect = document.getElementById('specific-node-select');
|
||||
|
||||
if (!deployBtn || !fileInput) return;
|
||||
|
||||
const hasFile = fileInput.files && fileInput.files.length > 0;
|
||||
const isValidTarget = targetType.value === 'all' ||
|
||||
(targetType.value === 'specific' && specificNodeSelect.value);
|
||||
|
||||
deployBtn.disabled = !hasFile || !isValidTarget;
|
||||
}
|
||||
|
||||
// Handle deploy firmware button click
|
||||
async function handleDeployFirmware() {
|
||||
const fileInput = document.getElementById('global-firmware-file');
|
||||
const targetType = document.querySelector('input[name="target-type"]:checked').value;
|
||||
const specificNode = document.getElementById('specific-node-select').value;
|
||||
|
||||
if (!fileInput.files || !fileInput.files[0]) {
|
||||
alert('Please select a firmware file first.');
|
||||
return;
|
||||
}
|
||||
|
||||
const file = fileInput.files[0];
|
||||
|
||||
if (targetType === 'specific' && !specificNode) {
|
||||
alert('Please select a specific node to update.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Disable deploy button during upload
|
||||
const deployBtn = document.getElementById('deploy-btn');
|
||||
deployBtn.disabled = true;
|
||||
deployBtn.classList.add('loading');
|
||||
deployBtn.textContent = '⏳ Deploying...';
|
||||
|
||||
if (targetType === 'all') {
|
||||
await uploadFirmwareToAllNodes(file);
|
||||
} else {
|
||||
await uploadFirmwareToSpecificNode(file, specificNode);
|
||||
}
|
||||
|
||||
// Reset interface after successful upload
|
||||
fileInput.value = '';
|
||||
document.getElementById('file-info').textContent = 'No file selected';
|
||||
document.getElementById('file-info').classList.remove('has-file');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Global firmware upload failed:', error);
|
||||
alert(`Upload failed: ${error.message}`);
|
||||
console.error('Firmware deployment failed:', error);
|
||||
alert(`Deployment failed: ${error.message}`);
|
||||
} finally {
|
||||
// Re-enable deploy button
|
||||
const deployBtn = document.getElementById('deploy-btn');
|
||||
deployBtn.disabled = false;
|
||||
deployBtn.classList.remove('loading');
|
||||
deployBtn.textContent = '🚀 Deploy Firmware';
|
||||
updateDeployButton();
|
||||
}
|
||||
|
||||
// Clear file input
|
||||
event.target.value = '';
|
||||
}
|
||||
|
||||
// Upload firmware to all nodes
|
||||
|
||||
Reference in New Issue
Block a user