mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
refactor(templates): the host pages' scripts load from static files
The host pages lose their last inline scripts: the overview's charts (host_graphs.js), the New pool, New network and New interface dialogs (pool_dialog.js, network_dialog.js, interface_dialog.js), a network's and a network filter's XML editors and dialogs (network_page.js, nwfilter_page.js, nwfilters_page.js), the secrets page's labels (secrets_page.js, its texts from the view as usage_texts) and a pool's page with the ISO upload (storage_page.js). Their URLs and messages are data attributes of the elements they belong to; the upload reads its token and address from its form. No template has an inline script or an inline event handler any more.
This commit is contained in:
parent
946629b035
commit
50dcaba699
23 changed files with 431 additions and 407 deletions
|
|
@ -143,12 +143,17 @@ class GraphScriptTestCase(TestCase):
|
|||
details.return_value.get_node_info.return_value = ("h", "x86_64", 1024, 2, "cpu", "qemu+tcp://h/system")
|
||||
details.return_value.get_cpu_topology.return_value = TOPOLOGY
|
||||
page = self.client.get(reverse("overview", args=[compute.id])).content.decode()
|
||||
script = next(s for s in html.fromstring(page).xpath("//script[not(@src)]/text()") if "pollWhileVisible(" in s)
|
||||
doc = html.fromstring(page)
|
||||
self.assertIn("/static/js/host_graphs.js", doc.xpath("//script/@src"))
|
||||
(state,) = doc.xpath("//span[@id='graph_state']")
|
||||
dataset = {"url": state.get("data-url"), "averageOver": state.get("data-average-over"),
|
||||
"updated": "Updated at %(time)s.", "stale": "Not updated since %(time)s."}
|
||||
script = (settings.BASE_DIR / "static/js/host_graphs.js").read_text()
|
||||
js = """
|
||||
const vm = require("vm");
|
||||
const charts = [], requests = [];
|
||||
const element = (dataset) => ({dataset, textContent: "", classList: {add: () => {}, remove: () => {}}});
|
||||
const elements = {graph_state: element({updated: "Updated at %(time)s.", stale: "Not updated since %(time)s."}),
|
||||
const elements = {graph_state: element(DATASET),
|
||||
cpu_now: element({}), mem_now: element({})};
|
||||
let poll;
|
||||
const page = {
|
||||
|
|
@ -180,7 +185,8 @@ class GraphScriptTestCase(TestCase):
|
|||
console.log(JSON.stringify({requests, label, shown, state: elements.graph_state.textContent,
|
||||
cpu: charts[0].data.datasets[0].data,
|
||||
mem: charts[1].data.datasets[0].data, memMax: charts[1].options.scales.y.max}));
|
||||
""".replace("SCRIPT", json.dumps(script)).replace("CHARTS", json.dumps(CHARTS_JS.read_text()))
|
||||
""".replace("SCRIPT", json.dumps(script)).replace("CHARTS", json.dumps(CHARTS_JS.read_text())).replace(
|
||||
"DATASET", json.dumps(dataset))
|
||||
out = subprocess.run(["node", "-e", js], capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(out.returncode, 0, out.stderr)
|
||||
result = json.loads(out.stdout)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue