Add dismiss functionality for cloud-init build status</message>
<message>Implement a new API endpoint to clear the build status to idle, allowing users to dismiss messages after a build is cancelled, completed, or errored. Update the dashboard UI to include a dismiss link that appears under relevant conditions, enhancing user experience by providing a clearer interface for managing build statuses. Modify the JavaScript to handle the dismissal action and ensure proper status updates are reflected in the UI.
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
<button type="button" id="buildCloudInitCancelBtn" class="btn btn-outline" style="display:none; margin-left:0.5rem;">Cancel build</button>
|
||||
</div>
|
||||
<div id="buildCloudInitStatus" class="mono" style="min-height:1.2em;"></div>
|
||||
<a href="#" id="buildCloudInitDismiss" style="display:none;">Dismiss</a>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
@@ -140,14 +141,27 @@
|
||||
var el = document.getElementById('buildCloudInitStatus');
|
||||
var btn = document.getElementById('buildCloudInitBtn');
|
||||
var cancelBtn = document.getElementById('buildCloudInitCancelBtn');
|
||||
var dismissEl = document.getElementById('buildCloudInitDismiss');
|
||||
var busy = ['resolving','downloading','decompressing','injecting','finalizing'].indexOf(d.phase) >= 0;
|
||||
if (btn) btn.disabled = busy;
|
||||
if (cancelBtn) { cancelBtn.style.display = busy ? 'inline-block' : 'none'; cancelBtn.disabled = false; }
|
||||
if (dismissEl) dismissEl.style.display = (d.phase === 'done' || d.phase === 'error' || d.phase === 'cancelled') ? 'inline' : 'none';
|
||||
if (d.phase === 'idle' && !d.message) el.textContent = '';
|
||||
else if (d.phase === 'done') { el.textContent = 'Done: ' + (d.output_name || '') + ' — see Admin page Cloud-init images.'; }
|
||||
else if (d.phase === 'error') el.textContent = 'Error: ' + (d.error || '');
|
||||
else if (d.phase === 'cancelled') el.textContent = 'Build cancelled.';
|
||||
else el.textContent = (d.phase || '') + ': ' + (d.message || '');
|
||||
else if (d.phase === 'cancelled') {
|
||||
el.textContent = 'Build cancelled.';
|
||||
if (btn) btn.disabled = false;
|
||||
if (!window._buildClearScheduled) {
|
||||
window._buildClearScheduled = true;
|
||||
setTimeout(function() {
|
||||
authFetch('/api/build-cloudinit-status-clear', { method: 'POST', headers: {'Content-Type':'application/json'} }).then(function() { fetchBuildStatus(); }).finally(function() { window._buildClearScheduled = false; });
|
||||
}, 3000);
|
||||
}
|
||||
} else {
|
||||
window._buildClearScheduled = false;
|
||||
el.textContent = (d.phase || '') + ': ' + (d.message || '');
|
||||
}
|
||||
if (busy) setTimeout(fetchBuildStatus, 5000);
|
||||
}).catch(function() {});
|
||||
}
|
||||
@@ -228,6 +242,8 @@
|
||||
document.getElementById('buildCloudInitBtn').onclick = startBuild;
|
||||
var cancelBuildBtn = document.getElementById('buildCloudInitCancelBtn');
|
||||
if (cancelBuildBtn) cancelBuildBtn.onclick = cancelBuild;
|
||||
var dismissBuildBtn = document.getElementById('buildCloudInitDismiss');
|
||||
if (dismissBuildBtn) dismissBuildBtn.onclick = function(e) { e.preventDefault(); authFetch('/api/build-cloudinit-status-clear', { method: 'POST', headers: {'Content-Type':'application/json'} }).then(function() { fetchBuildStatus(); }); };
|
||||
document.getElementById('buildVariant').onchange = function() {
|
||||
authFetch('/api/raspios-latest-url?variant=' + encodeURIComponent(document.getElementById('buildVariant').value)).then(function(r) { return r.json(); }).then(function(d) {
|
||||
document.getElementById('buildRaspiosUrl').textContent = (d.ok && d.filename) ? d.filename : (d.error || '');
|
||||
|
||||
Reference in New Issue
Block a user