Stop polling idle agent update controls
CI / Test (rest) (pull_request) Successful in 22s
CI / Lint (pull_request) Successful in 11s
CI / Build (windows/amd64) (pull_request) Successful in 8s
CI / Test (store) (pull_request) Successful in 40s
CI / Build (linux/amd64) (pull_request) Successful in 7s
CI / Build (linux/arm64) (pull_request) Successful in 8s
CI / Test (server-http) (pull_request) Successful in 1m45s
e2e / Playwright vs docker-compose (pull_request) Successful in 1m26s

This commit is contained in:
2026-08-22 12:31:08 +01:00
parent facef5b254
commit 80dac33f0a
3 changed files with 30 additions and 26 deletions
-20
View File
@@ -29,32 +29,12 @@
{{template "fleet_update_inner" .}}
<script>
let fleetUpdateUIState = null
function fleetBoxes(){return Array.from(document.querySelectorAll('.fleet-host:not(:disabled)'))}
function fleetReview(){const n=fleetBoxes().filter(x=>x.checked).length;document.getElementById('fleet-selected-count').textContent=n;document.getElementById('fleet-timeout').textContent=n+' × 95s';document.getElementById('fleet-update-start-btn').disabled=n===0}
function fleetFilter(){const q=document.getElementById('fleet-filter-name').value.toLowerCase(),v=document.getElementById('fleet-filter-version').value.toLowerCase(),s=document.getElementById('fleet-filter-state').value;document.querySelectorAll('.fleet-candidate').forEach(r=>r.style.display=r.dataset.name.toLowerCase().includes(q)&&r.dataset.version.toLowerCase().includes(v)&&(s==='all'||r.dataset.state===s)?'':'none')}
function fleetSelectVisible(on){document.querySelectorAll('.fleet-candidate').forEach(r=>{const x=r.querySelector('.fleet-host:not(:disabled)');if(x&&r.style.display!=='none')x.checked=on});fleetReview()}
function fleetSelectOnly(id){fleetBoxes().forEach(x=>x.checked=x.value===id);fleetReview()}
async function fleetStart(e){e.preventDefault();const ids=fleetBoxes().filter(x=>x.checked).map(x=>x.value),out=document.getElementById('fleet-start-error');out.textContent='';const res=await fetch('/api/fleet/update',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({host_ids:ids,canary_first:document.getElementById('fleet-canary').checked})});if(res.ok){location.reload();return false}const body=await res.json();out.textContent=body.message||body.code||'Unable to start';return false}
function fleetCaptureUIState(){
const name=document.getElementById('fleet-filter-name'),version=document.getElementById('fleet-filter-version'),state=document.getElementById('fleet-filter-state'),canary=document.getElementById('fleet-canary')
if(!name)return
fleetUpdateUIState={name:name.value,version:version.value,state:state.value,canary:canary.checked,selected:fleetBoxes().filter(x=>x.checked).map(x=>x.value)}
}
function fleetRestoreUIState(){
if(!fleetUpdateUIState||!document.getElementById('fleet-filter-name'))return
document.getElementById('fleet-filter-name').value=fleetUpdateUIState.name
document.getElementById('fleet-filter-version').value=fleetUpdateUIState.version
document.getElementById('fleet-filter-state').value=fleetUpdateUIState.state
document.getElementById('fleet-canary').checked=fleetUpdateUIState.canary
const selected=new Set(fleetUpdateUIState.selected)
fleetBoxes().forEach(x=>x.checked=selected.has(x.value))
fleetFilter();fleetReview()
}
document.body.addEventListener('htmx:beforeSwap',e=>{if(e.detail.target.id==='fleet-update-panel')fleetCaptureUIState()})
document.body.addEventListener('htmx:afterSwap',e=>{if(e.detail.target.id==='fleet-update-panel')fleetRestoreUIState()})
if(document.getElementById('fleet-selected-count'))fleetReview()
</script>
@@ -7,11 +7,11 @@
*/}}
{{define "fleet_update_inner"}}
{{$page := .Page}}
<div id="fleet-update-panel" class="mt-5"
<div id="fleet-update-panel" class="mt-5"{{if and $page.Active (eq $page.Active.Status "running")}}
hx-get="{{$page.PollURL}}"
hx-trigger="every 3s [document.visibilityState==='visible']"
hx-select="#fleet-update-panel"
hx-swap="outerHTML">
hx-swap="outerHTML"{{end}}>
{{if and $page.Active (eq $page.Active.Status "running")}}