").append($("| ").text(text)));
+ }
+ $.getJSON(table.dataset.url, function (data) {
+ if (!data.length) {
+ note(table.dataset.empty);
+ return;
+ }
+ // Log messages contain user-entered names (snapshots, disks, clones);
+ // insert them as text, never as HTML.
+ tbody.empty();
+ $.each(data, function (id, row) {
+ $(" |
")
+ .append($("| ").addClass("text-nowrap").text(row['date']))
+ .append($(" | ").text(row['user']))
+ .append($(" | ").text(row['message']))
+ .append($(" | ").text(row['result']))
+ .appendTo(tbody);
+ });
+ }).fail(function () {
+ note(table.dataset.failed);
+ });
+ });
+})();
diff --git a/static/js/instance_status.js b/static/js/instance_status.js
new file mode 100644
index 00000000..b2cf27e9
--- /dev/null
+++ b/static/js/instance_status.js
@@ -0,0 +1,13 @@
+// The VM page reloads when the VM's state changes (instance.html, #vm-summary).
+backgroundJobRunning = false;
+// not "status": that is window.status, which the browser may not keep
+var vm_summary = document.getElementById("vm-summary");
+var vm_status = Number(vm_summary.dataset.status);
+var status_poll = pollWhileVisible(5000, function () {
+ return $.getJSON(vm_summary.dataset.statusUrl);
+}, function get_status(data) {
+ // an XML edit not saved yet stays: the reload waits until it is saved or undone
+ if (data['status'] != vm_status && !backgroundJobRunning && !(window.xmlEditUnsaved && window.xmlEditUnsaved())) {
+ window.location.reload();
+ }
+});
diff --git a/static/js/please_wait.js b/static/js/please_wait.js
index d19a563f..39aabe6b 100644
--- a/static/js/please_wait.js
+++ b/static/js/please_wait.js
@@ -13,3 +13,7 @@ function hidePleaseWaitDialog() {
pleaseModal.hide();
backgroundJobRunning = false;
}
+// a form marked data-please-wait shows the dialog while it is sent
+document.addEventListener("submit", function (event) {
+ if (event.target.matches("form[data-please-wait]")) showPleaseWaitDialog();
+});
diff --git a/webvirtcloud/tests/test_poll_js.py b/webvirtcloud/tests/test_poll_js.py
index c6791033..2bc212d9 100644
--- a/webvirtcloud/tests/test_poll_js.py
+++ b/webvirtcloud/tests/test_poll_js.py
@@ -2,7 +2,6 @@
none while the page is hidden. Its behaviour is checked with Node."""
import json
-import re
import shutil
import subprocess
import unittest
@@ -11,7 +10,7 @@ from pathlib import Path
from django.conf import settings
BASE = Path(settings.BASE_DIR)
-POLLING_TEMPLATES = ["instances/templates/instance.html", "computes/templates/overview.html"]
+POLLING_SOURCES = ["static/js/instance_status.js", "static/js/instance_stats.js", "computes/templates/overview.html"]
class PollTestCase(unittest.TestCase):
@@ -37,9 +36,9 @@ class PollTestCase(unittest.TestCase):
self.assertEqual(result.returncode, 0, result.stderr)
def test_pages_poll_through_poll_js(self):
- for template in POLLING_TEMPLATES:
- with self.subTest(template=template):
- source = (BASE / template).read_text()
+ for path in POLLING_SOURCES:
+ with self.subTest(path=path):
+ source = (BASE / path).read_text()
self.assertNotIn("setInterval", source)
self.assertIn("pollWhileVisible(", source)
@@ -47,11 +46,7 @@ class PollTestCase(unittest.TestCase):
def test_the_vm_page_reloads_only_when_the_state_changes(self):
# "status" is a property of the browser's window: a page variable of
# that name holds what the browser makes of it (a string, or nothing)
- source = (BASE / "instances/templates/instance.html").read_text()
- script = re.search(r"", source, re.S).group(1)
- script = script.replace("{{ instance.status|lower }}", "1").replace(
- "{% url 'instances:status' instance.id %}", "/instances/1/status/"
- )
+ script = (BASE / "static/js/instance_status.js").read_text()
js = """
const vm = require("vm");
const results = {};
@@ -60,6 +55,7 @@ class PollTestCase(unittest.TestCase):
const page = {
pollWhileVisible: (interval, request, onData) => { onData({status: answer}); return {stop() {}}; },
$: () => ({submit() {}}),
+ document: {getElementById: () => ({dataset: {status: "1", statusUrl: "/instances/1/status/"}})},
};
page.window = {location: {reload: () => reloads++}};
Object.defineProperty(page, "status", {get: () => "", set: () => {}});
|