mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
fix(instances): a VM list notices a change made while the page was read
The VM lists took the poll's first answer as what the page showed: a VM started or stopped between the page's read and that answer kept its old state and buttons until the next change. The page now carries the states read before its rows, and the poll compares its first answer with them.
This commit is contained in:
parent
b7354df4f6
commit
52bb6487a3
8 changed files with 29 additions and 18 deletions
|
|
@ -1,8 +1,9 @@
|
|||
// A VM list follows libvirt: it polls the states of its VMs (instances:states)
|
||||
// at once, then every 5 s, as the VM page, and reloads when an answer differs
|
||||
// from the one before: a VM started or stopped, made, removed or renamed
|
||||
// outside the page included. The page in use or the job panel showing
|
||||
// something: it waits for the next answer. poll.js gives the polling.
|
||||
// from the states the page was rendered with, then from the answer before: a
|
||||
// VM started or stopped, made, removed or renamed outside the page included.
|
||||
// The page in use or the job panel showing something: it waits for the next
|
||||
// answer. poll.js gives the polling.
|
||||
function vmStatesKey(states) {
|
||||
return Object.keys(states).sort().map(function (id) {
|
||||
var host = states[id];
|
||||
|
|
@ -12,12 +13,11 @@ function vmStatesKey(states) {
|
|||
}).join(";");
|
||||
}
|
||||
|
||||
function followVmStates(url) {
|
||||
var last = null;
|
||||
// the first answer, at once, is what the page was rendered with
|
||||
function followVmStates(url, rendered) {
|
||||
var last = vmStatesKey(rendered);
|
||||
return pollWhileVisible(5000, function () { return $.getJSON(url); }, function (data) {
|
||||
var key = vmStatesKey(data.computes);
|
||||
if (last !== null && key !== last) {
|
||||
if (key !== last) {
|
||||
if (!pageInUse() && !window.backgroundJobRunning) {
|
||||
window.location.reload();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
// Starts following the VM list's states (vm_states_poll.html).
|
||||
followVmStates(JSON.parse(document.getElementById("vm-states-url").textContent));
|
||||
followVmStates(JSON.parse(document.getElementById("vm-states-url").textContent),
|
||||
JSON.parse(document.getElementById("vm-states").textContent));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue