Record implemented MySQL pilots and remaining app integration gates. Include the existing opt-in pages-cli agent skill source without installing it.
409 lines
26 KiB
JavaScript
409 lines
26 KiB
JavaScript
/* Shared configuration navigation and bounded live resource charts. */
|
||
async function configJSON(url, options = {}) {
|
||
const response = await fetch(url, {cache: "no-store", ...options});
|
||
const text = await response.text();
|
||
let data;
|
||
try { data = JSON.parse(text); } catch (_) {
|
||
throw new Error(response.ok ? configMessages.requestFailed : text.trim() || response.statusText);
|
||
}
|
||
if (!response.ok) throw new Error(data.error || response.statusText);
|
||
return data;
|
||
}
|
||
|
||
async function configAction(button, resultID, work) {
|
||
if (button) button.disabled = true;
|
||
const result = document.getElementById(resultID);
|
||
if (result) result.textContent = "";
|
||
try { await work(); if (result) result.textContent = "✓"; }
|
||
catch (error) { if (result) result.textContent = error.message; else alert(error.message); }
|
||
finally { if (button) button.disabled = false; }
|
||
}
|
||
|
||
let activeConfigPanel = "";
|
||
let configPanelController = null;
|
||
function setupConfigDialogs() {
|
||
for (const button of document.querySelectorAll('[data-config-open]')) {
|
||
const dialog = document.getElementById(button.dataset.configOpen);
|
||
if (!dialog || button.dataset.configReady) continue;
|
||
button.dataset.configReady = '1';
|
||
button.addEventListener('click', () => dialog.showModal());
|
||
for (const close of dialog.querySelectorAll('[data-config-close]')) close.addEventListener('click', () => dialog.close());
|
||
dialog.addEventListener('click', event => { if (event.target === dialog) dialog.close(); });
|
||
}
|
||
const promote = (form, title) => {
|
||
if (!form || form.dataset.dialogReady) return;
|
||
form.dataset.dialogReady = '1';
|
||
const anchor = form.parentElement;
|
||
const dialog = document.createElement('dialog');
|
||
dialog.className = 'config-form-dialog';
|
||
const header = document.createElement('header');
|
||
const heading = document.createElement('h2'); heading.textContent = title;
|
||
const close = document.createElement('button'); close.type='button'; close.textContent='×'; close.setAttribute('aria-label', configMessages.close || 'Close');
|
||
header.append(heading, close); dialog.append(header, form); document.body.append(dialog);
|
||
const trigger = document.createElement('button'); trigger.type='button'; trigger.className='config-icon-button'; trigger.textContent='⚙'; trigger.title=title; trigger.setAttribute('aria-label', title);
|
||
anchor?.insertBefore(trigger, anchor.firstChild); trigger.addEventListener('click',()=>dialog.showModal()); close.addEventListener('click',()=>dialog.close());
|
||
};
|
||
promote(document.getElementById('asset-form'), document.querySelector('#panel-assets h1')?.textContent || 'Assets');
|
||
for (const form of document.querySelectorAll('#panel-auth-providers > form, #panel-auth > form')) promote(form, form.querySelector('input[name=action]')?.value || 'Account settings');
|
||
}
|
||
document.addEventListener('DOMContentLoaded', setupConfigDialogs);
|
||
function toggleSidebar() {
|
||
const sidebar = document.getElementById("config-sidebar");
|
||
const closed = sidebar.classList.toggle("collapsed");
|
||
sidebar.closest(".config-layout").classList.toggle("sidebar-collapsed", closed);
|
||
sidebar.querySelector(".sidebar-toggle").setAttribute("aria-expanded", String(!closed));
|
||
}
|
||
function showConfigPanel(name, updateURL = true) {
|
||
if (name === "nav") name = "nav-home";
|
||
if (name === "resources") name = "scheduler";
|
||
const target = document.getElementById("panel-" + name);
|
||
if (!target?.classList.contains("config-panel")) return showConfigPanel("home", updateURL);
|
||
configPanelController?.abort();
|
||
configPanelController = new AbortController();
|
||
activeConfigPanel = name;
|
||
if (name !== 'scheduler') document.getElementById('monitor-settings-dialog')?.close();
|
||
for (const panel of document.querySelectorAll(".config-panel")) panel.classList.toggle("active", panel === target);
|
||
for (const group of document.querySelectorAll(".config-nav-group")) group.open = false;
|
||
for (const link of document.querySelectorAll(".sidebar-nav a[data-panel]")) {
|
||
const active = link.dataset.panel === name;
|
||
link.classList.toggle("active", active);
|
||
if (active) { link.setAttribute("aria-current", "page"); link.closest("details").open = true; }
|
||
else link.removeAttribute("aria-current");
|
||
}
|
||
if (updateURL) {
|
||
const url = new URL(location.href);
|
||
url.searchParams.set("panel", name);
|
||
history.replaceState(null, "", url);
|
||
}
|
||
configResources.activate(name === "scheduler");
|
||
if (["events", "queue", "logs"].includes(name)) loadSchedulerPanel(name, configPanelController.signal);
|
||
if (name === "adapters" || name === "adapters-builtin") loadAdapterPanel();
|
||
if (name === "assets") loadAssetPanel();
|
||
if (name === "machine-learning") window.pagesMLSettings?.load();
|
||
}
|
||
|
||
function resourceIORates(before, after) {
|
||
const unavailable = {read:NaN, write:NaN};
|
||
if (!before?.io?.available || !after?.io?.available || !after.io.process_id || before.io.process_id !== after.io.process_id) return unavailable;
|
||
const seconds = (after.time - before.time) / 1000;
|
||
const counters = [before.io.read_bytes, before.io.write_bytes, after.io.read_bytes, after.io.write_bytes];
|
||
if (!(seconds > 0) || !counters.every(n => Number.isSafeInteger(n) && n >= 0)) return unavailable;
|
||
const read = after.io.read_bytes - before.io.read_bytes, write = after.io.write_bytes - before.io.write_bytes;
|
||
if (read < 0 || write < 0) return unavailable;
|
||
return {read:read/seconds, write:write/seconds};
|
||
}
|
||
|
||
const monitorPreferences = (() => {
|
||
const key = 'pageswiki.monitor.display.v1';
|
||
const fields = ['resource-history-hours','resource-stat-interval','resource-graph-interval','resource-live'];
|
||
return {
|
||
restore() {
|
||
try {
|
||
const saved = JSON.parse(localStorage.getItem(key) || '{}');
|
||
for (const id of fields) {
|
||
const input = document.getElementById(id), value = saved[id];
|
||
if (id === 'resource-live' && typeof value === 'boolean') input.checked = value;
|
||
else if (id === 'resource-history-hours' && ['1','24','168'].includes(value)) input.value = value;
|
||
else if (id.includes('-interval') && Number.isInteger(value) && value >= 1 && value <= 60) input.value = String(value);
|
||
}
|
||
const stat = document.getElementById('resource-stat-interval'), graph = document.getElementById('resource-graph-interval');
|
||
graph.value = String(Math.max(Number(stat.value), Number(graph.value)));
|
||
} catch (_) { /* Storage can be disabled or hold an older format. */ }
|
||
},
|
||
save() {
|
||
try { localStorage.setItem(key, JSON.stringify(Object.fromEntries(fields.map(id => {
|
||
const input = document.getElementById(id);
|
||
return [id, input.type === 'checkbox' ? input.checked : input.type === 'number' ? Number(input.value) : input.value];
|
||
})))); } catch (_) { /* Monitoring still works without storage. */ }
|
||
}
|
||
};
|
||
})();
|
||
|
||
const configResources = (() => {
|
||
const samples = [];
|
||
const historySamples = [], liveSamples = [];
|
||
let active = false, timer = null, controller = null, generation = 0;
|
||
let historyAt = 0, graphAt = 0, historyHours = '', monitorLoaded = false, previousLive = null;
|
||
const seconds = (id, fallback) => {
|
||
const input = document.getElementById(id);
|
||
return input?.checkValidity() && input.value !== '' ? Number(input.value) : fallback;
|
||
};
|
||
const statDelay = () => seconds('resource-stat-interval', 1) * 1000;
|
||
const graphDelay = () => Math.max(statDelay(), seconds('resource-graph-interval', 5) * 1000);
|
||
const point = item => ({
|
||
time:item.timestamp_ms, io:item.io, cpu:parseFloat(item.cpu.load_average), memory:item.memory.heap_bytes,
|
||
storage:item.storage.total_bytes ? item.storage.used_bytes / item.storage.total_bytes * 100 : NaN,
|
||
queue:Number(item.queue.stats?.queued || 0) + Number(item.queue.active_workers || 0)
|
||
});
|
||
function renderGraphs(current, hours) {
|
||
liveSamples.push(point(current));
|
||
if (liveSamples.length > 361) liveSamples.splice(0, liveSamples.length - 361);
|
||
const cutoff = current.timestamp_ms - Number(hours) * 3600000;
|
||
const byTime = new Map([...historySamples, ...liveSamples].filter(item => item.time >= cutoff && item.time <= current.timestamp_ms).map(item => [item.time,item]));
|
||
const combined = [...byTime.values()].sort((a,b) => a.time - b.time);
|
||
for (let i=0;i<combined.length;i++) Object.assign(combined[i], resourceIORates(combined[i-1], combined[i]));
|
||
// Keep the last value per time bucket, including the fresh live tail.
|
||
// At most 361 SVG points even after this page has been open for days.
|
||
const first = combined[0]?.time || current.timestamp_ms;
|
||
const bucket = Math.max(1, (current.timestamp_ms - first) / 360);
|
||
const buckets = new Map();
|
||
for (const item of combined) buckets.set(Math.floor((item.time - first) / bucket), item);
|
||
samples.splice(0, samples.length, ...buckets.values());
|
||
for (const key of ['cpu','memory','io','queue']) plot(key);
|
||
document.getElementById('resource-time-range').textContent = samples.length ?
|
||
new Date(samples[0].time).toLocaleString() + ' — ' + new Date(samples.at(-1).time).toLocaleString() : '—';
|
||
}
|
||
const ns = "http://www.w3.org/2000/svg";
|
||
const node = (tag, attrs, text) => {
|
||
const result = document.createElementNS(ns, tag);
|
||
for (const [key,value] of Object.entries(attrs)) result.setAttribute(key, value);
|
||
if (text !== undefined) result.textContent = text;
|
||
return result;
|
||
};
|
||
function plot(key) {
|
||
const svg = document.querySelector('[data-resource-chart="' + key + '"]');
|
||
const series = key === 'io' ? ['read','write'] : [key];
|
||
const values = samples.flatMap(sample => series.map(name => sample[name])).filter(Number.isFinite);
|
||
if (!svg) return;
|
||
if (!values.length) {svg.replaceChildren();return;}
|
||
const high = Math.max(1, ...values) * 1.1;
|
||
const first = samples[0].time, last = samples[samples.length - 1].time;
|
||
const label = key === 'io' ? formatSchedulerBytes(high) + '/s' : key === "memory" ? formatSchedulerBytes(high) : high.toFixed(key === "cpu" ? 1 : 0);
|
||
svg.replaceChildren(
|
||
node("line", {x1:48,y1:112,x2:392,y2:112,class:"chart-axis"}),
|
||
node("text", {x:1,y:15}, label), node("text", {x:20,y:114}, "0")
|
||
);
|
||
for (const name of series) {
|
||
const className = 'chart-line' + (key === 'io' ? ' io-' + name : '');
|
||
let points = [];
|
||
const flush = () => {
|
||
if (!points.length) return;
|
||
svg.append(node('polyline', {points:points.map(p=>p.join(',')).join(' '),class:className}));
|
||
const end=points.at(-1);svg.append(node('circle',{cx:end[0],cy:end[1],r:2,fill:'currentColor',class:key==='io'?'io-'+name:''}));
|
||
points=[];
|
||
};
|
||
for (const sample of samples) {
|
||
if (!Number.isFinite(sample[name])) { flush(); continue; }
|
||
points.push([48+(sample.time-first)/Math.max(1,last-first)*344,112-sample[name]/high*98]);
|
||
}
|
||
flush();
|
||
}
|
||
}
|
||
async function sample() {
|
||
if (!active || document.hidden || controller) return;
|
||
controller = new AbortController();
|
||
const request = controller, version = generation;
|
||
try {
|
||
const hours = document.getElementById('resource-history-hours').value;
|
||
const fetchHistory = hours !== historyHours || Date.now() - historyAt >= 30000;
|
||
const [r, jobs, history, definitions] = await Promise.all([
|
||
configJSON("/_/api/v1/queue/resources", {signal: request.signal}),
|
||
configJSON("/_/api/v1/queue/jobs?status=running&limit=100", {signal: request.signal}),
|
||
fetchHistory ? configJSON("/_/api/v1/queue/resources/history?hours=" + hours, {signal: request.signal}) : null,
|
||
!monitorLoaded ? configJSON("/_/api/v1/event", {signal: request.signal}) : null
|
||
]);
|
||
if (!active || version !== generation || request.signal.aborted) return;
|
||
const count = r.queue.stats || {};
|
||
const current = point(r), io = resourceIORates(previousLive, current);
|
||
previousLive = current;
|
||
const rate = value => Number.isFinite(value) ? formatSchedulerBytes(value) + '/s' : '—';
|
||
document.querySelector('[data-resource="io"]').textContent = configMessages.ioRead + ' ' + rate(io.read) + ' · ' + configMessages.ioWrite + ' ' + rate(io.write);
|
||
const queued = Number(count.queued || 0), running = Number(count.running || 0);
|
||
configJobs.renderRunning(jobs.jobs || []);
|
||
if (history) {
|
||
historyAt = Date.now(); historyHours = hours;
|
||
historySamples.splice(0, historySamples.length, ...(history.samples || []).map(point));
|
||
}
|
||
if (history || Date.now() - graphAt >= graphDelay()) {
|
||
graphAt = Date.now();
|
||
renderGraphs(r, hours);
|
||
}
|
||
if (!samples.length) document.querySelectorAll('[data-resource-chart]').forEach(svg => svg.replaceChildren());
|
||
const form = document.getElementById('resource-monitor-form');
|
||
const monitor = definitions?.events.find(item => item.uuid === 'builtin.resource.sample');
|
||
if (monitor && !form.dataset.dirty) {
|
||
form.elements.enabled.checked = monitor.enabled;
|
||
form.elements.interval.value = monitor.interval_seconds;
|
||
}
|
||
if (definitions) monitorLoaded = true;
|
||
document.getElementById('scheduler-queue-state').textContent = r.queue.paused ? configMessages.paused : '';
|
||
document.querySelector('[data-resource="cpu"]').textContent = (r.cpu.load_average || "—") + " / " + r.cpu.logical_cpus + " CPU";
|
||
document.querySelector('[data-resource="memory"]').textContent = formatSchedulerBytes(r.memory.heap_bytes);
|
||
document.querySelector('[data-resource="storage"]').textContent = formatSchedulerBytes(r.storage.used_bytes) + " / " + formatSchedulerBytes(r.storage.total_bytes);
|
||
document.querySelector('[data-resource="queue"]').textContent = queued + " " + configMessages.queued + " · " + running + " " + configMessages.running;
|
||
document.querySelector('[data-panel-error="resources"]').textContent = "";
|
||
} catch (error) {
|
||
if (error.name !== "AbortError") document.querySelector('[data-panel-error="resources"]').textContent = error.message;
|
||
} finally {
|
||
if (controller === request) controller = null;
|
||
if (version === generation && active && !document.hidden && document.getElementById("resource-live").checked) timer = setTimeout(sample, statDelay());
|
||
}
|
||
}
|
||
function activate(value) {
|
||
active = value;
|
||
generation++;
|
||
clearTimeout(timer); timer = null;
|
||
controller?.abort();
|
||
controller = null;
|
||
previousLive = null;
|
||
if (value && !document.hidden) timer = setTimeout(sample, 0);
|
||
}
|
||
return {activate, refresh() { historyAt = 0; graphAt = 0; monitorLoaded = false; activate(activeConfigPanel === 'scheduler'); }};
|
||
})();
|
||
|
||
// Job history is paged, not accumulated in the DOM. Log pages are fetched only
|
||
// when expanded; all requests are aborted when leaving the panel.
|
||
const configJobs = (() => {
|
||
let historyVersion = 0;
|
||
const esc = value => schedulerEscape(value);
|
||
function row(job) {
|
||
const duration = job.started_at_ms ? Math.max(0, ((job.finished_at_ms || Date.now()) - job.started_at_ms) / 1000).toFixed(1) + ' s' : '—';
|
||
const action = ['failed','cancelled','skipped'].includes(job.status) ? 'retry' : ['running','queued'].includes(job.status) ? 'cancel' : '';
|
||
const label = job.cancel_requested && job.status === 'running' ? configMessages.cancelRequested : configMessages[job.status] || job.status;
|
||
return '<tr data-job-row="' + esc(job.uuid) + '"><td><span class="mono">' + esc(job.event_type) + '</span> <small class="cell-clip" title="' + esc(job.event_key) + '">' + esc(job.event_key) +
|
||
'</small></td><td>' + esc(label) + (job.error ? ' <small class="cell-clip" title="' + esc(job.error) + '">' + esc(job.error) + '</small>' : '') + '</td><td>' + job.attempts + ' / ' + job.max_attempts + '</td><td>' +
|
||
esc(new Date(job.started_at_ms || job.created_at_ms).toLocaleString()) + '</td><td>' + duration + '</td><td>' +
|
||
(action ? '<button type="button" data-queue-action="' + action + '" data-job="' + esc(job.uuid) + '"' + (action === 'cancel' && job.cancel_requested ? ' disabled' : '') + '>' + esc(configMessages[action]) + '</button> ' : '') +
|
||
'<button type="button" data-job-logs="' + esc(job.uuid) + '" aria-expanded="false">' + esc(configMessages.logs) + '</button></td></tr>';
|
||
}
|
||
function renderRunning(jobs) {
|
||
const body = document.querySelector('#scheduler-jobs tbody');
|
||
// Preserve expanded logs and keyboard focus while refreshing job values.
|
||
const present = new Set(jobs.map(job => job.uuid));
|
||
for (const old of body.querySelectorAll('[data-job-row]')) {
|
||
if (!present.has(old.dataset.jobRow)) { if (old.nextElementSibling?.classList.contains('job-log-detail')) old.nextElementSibling.remove(); old.remove(); }
|
||
}
|
||
body.querySelector('[data-empty]')?.remove();
|
||
for (const job of jobs) {
|
||
const old = [...body.querySelectorAll('[data-job-row]')].find(node => node.dataset.jobRow === job.uuid);
|
||
if (!old) body.insertAdjacentHTML('beforeend', row(job));
|
||
else {
|
||
const fresh = document.createElement('tbody'); fresh.innerHTML = row(job);
|
||
for (let i = 0; i < 5; i++) old.cells[i].innerHTML = fresh.rows[0].cells[i].innerHTML;
|
||
const cancel = old.querySelector('[data-queue-action="cancel"]');
|
||
if (cancel) cancel.disabled = job.cancel_requested;
|
||
}
|
||
}
|
||
if (!jobs.length) body.innerHTML = '<tr data-empty><td colspan="6">' + esc(configMessages.emptyRunning) + '</td></tr>';
|
||
}
|
||
async function loadHistory(cursor = '', signal = configPanelController?.signal) {
|
||
const version = ++historyVersion;
|
||
const params = new URLSearchParams({status:document.getElementById('job-history-status').value,limit:'50',cursor});
|
||
const data = await configJSON('/_/api/v1/queue/jobs?' + params, {signal});
|
||
if (version !== historyVersion || signal?.aborted || activeConfigPanel !== 'logs') return;
|
||
document.querySelector('#job-history tbody').innerHTML = (data.jobs || []).map(row).join('') || '<tr><td colspan="6">—</td></tr>';
|
||
const more = document.getElementById('job-history-more');
|
||
more.hidden = !data.next_cursor; more.dataset.cursor = data.next_cursor || '';
|
||
}
|
||
async function loadLogs(button, older = false) {
|
||
const row = button.closest('tr');
|
||
let detail = older ? row : row.nextElementSibling;
|
||
const job = older ? detail.dataset.job : button.dataset.jobLogs;
|
||
if (!older && detail?.classList.contains('job-log-detail')) {
|
||
detail.remove(); button.setAttribute('aria-expanded', 'false'); return;
|
||
}
|
||
if (!older) {
|
||
row.insertAdjacentHTML('afterend', '<tr class="job-log-detail"><td colspan="6"><small></small><pre></pre><button type="button" data-older-logs hidden></button></td></tr>');
|
||
detail = row.nextElementSibling; detail.dataset.job = job;
|
||
detail.querySelector('small').textContent = job;
|
||
button.setAttribute('aria-expanded', 'true');
|
||
}
|
||
const pre = detail.querySelector('pre'), more = detail.querySelector('button');
|
||
pre.textContent = configMessages.loading; more.disabled = true;
|
||
try {
|
||
const params = new URLSearchParams({job_uuid:job,limit:'100'});
|
||
if (older && more.dataset.before) params.set('before_id',more.dataset.before);
|
||
const data = await configJSON('/_/api/v1/event/logs?' + params, {signal:configPanelController?.signal});
|
||
if (!detail.isConnected) return;
|
||
pre.textContent = data.logs.map(log => new Date(log.created_at_ms).toLocaleString() + ' [' + log.level + '] ' + log.message).join('\n') || '—';
|
||
more.hidden = data.logs.length < 100;
|
||
more.dataset.before = data.logs.at(-1)?.id || '';
|
||
more.textContent = configMessages.olderLogs;
|
||
} catch (error) {
|
||
if (error.name === 'AbortError') {
|
||
const toggle = detail.previousElementSibling?.querySelector('[data-job-logs]');
|
||
toggle?.setAttribute('aria-expanded', 'false'); detail.remove();
|
||
} else { pre.textContent = error.message; more.hidden = false; more.textContent = configMessages.retry; }
|
||
}
|
||
finally { more.disabled = false; }
|
||
}
|
||
document.addEventListener('click', event => {
|
||
const logs = event.target.closest('[data-job-logs], [data-older-logs]');
|
||
if (logs) loadLogs(logs, logs.hasAttribute('data-older-logs'));
|
||
const action = event.target.closest('[data-queue-action]');
|
||
if (action) configAction(action, '', async () => {
|
||
await configJSON('/_/api/v1/queue/' + action.dataset.queueAction, {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({uuid:action.dataset.job})});
|
||
if (activeConfigPanel === 'logs') await loadHistory();
|
||
else configResources.activate(activeConfigPanel === 'scheduler');
|
||
});
|
||
});
|
||
return {loadHistory, renderRunning};
|
||
})();
|
||
|
||
document.addEventListener("DOMContentLoaded", () => {
|
||
monitorPreferences.restore();
|
||
const monitorDialog = document.getElementById('monitor-settings-dialog');
|
||
const monitorOpen = document.getElementById('monitor-settings-open');
|
||
monitorOpen.addEventListener('click', () => {
|
||
monitorDialog.showModal(); monitorOpen.setAttribute('aria-expanded', 'true');
|
||
});
|
||
document.getElementById('monitor-settings-close').addEventListener('click', () => monitorDialog.close());
|
||
monitorDialog.addEventListener('click', event => {
|
||
if (event.target !== monitorDialog) return;
|
||
const bounds = monitorDialog.getBoundingClientRect();
|
||
if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) monitorDialog.close();
|
||
});
|
||
monitorDialog.addEventListener('close', () => {
|
||
monitorOpen.setAttribute('aria-expanded', 'false');
|
||
if (activeConfigPanel === 'scheduler') monitorOpen.focus();
|
||
});
|
||
document.querySelector(".sidebar-nav").addEventListener("click", event => {
|
||
const link = event.target.closest("a[data-panel]");
|
||
if (!link || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
||
event.preventDefault(); showConfigPanel(link.dataset.panel);
|
||
});
|
||
document.addEventListener("click", event => {
|
||
const link = event.target.closest("[data-config-panel]");
|
||
if (!link || event.ctrlKey || event.metaKey) return;
|
||
event.preventDefault(); showConfigPanel(link.dataset.configPanel);
|
||
});
|
||
document.getElementById("resource-live").addEventListener("change", () => { monitorPreferences.save(); configResources.activate(activeConfigPanel === "scheduler"); });
|
||
const statInterval = document.getElementById('resource-stat-interval');
|
||
const graphInterval = document.getElementById('resource-graph-interval');
|
||
const updateIntervals = () => {
|
||
if (!statInterval.checkValidity() || !graphInterval.checkValidity() || !statInterval.value || !graphInterval.value) return;
|
||
if (Number(graphInterval.value) < Number(statInterval.value)) graphInterval.value = statInterval.value;
|
||
monitorPreferences.save();
|
||
configResources.refresh();
|
||
};
|
||
statInterval.addEventListener('change', updateIntervals);
|
||
graphInterval.addEventListener('change', updateIntervals);
|
||
document.getElementById('resource-history-hours').addEventListener('change', () => { monitorPreferences.save(); configResources.refresh(); });
|
||
document.getElementById('monitor-refresh').addEventListener('click', () => configResources.refresh());
|
||
document.getElementById('job-history-status').addEventListener('change', () => loadSchedulerPanel('logs', configPanelController?.signal));
|
||
document.getElementById('job-history-refresh').addEventListener('click', () => loadSchedulerPanel('logs', configPanelController?.signal));
|
||
document.getElementById('job-history-more').addEventListener('click', event => configAction(event.currentTarget, '', () => configJobs.loadHistory(event.currentTarget.dataset.cursor)));
|
||
const monitorForm = document.getElementById('resource-monitor-form');
|
||
monitorForm.addEventListener('input', () => monitorForm.dataset.dirty = 'true');
|
||
monitorForm.addEventListener('submit', event => {
|
||
event.preventDefault();
|
||
configAction(event.submitter, 'resource-monitor-result', async () => {
|
||
await configJSON('/_/api/v1/event', {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({
|
||
uuid:'builtin.resource.sample',name:'Resource monitoring',event_type:'resource.sample',event_key:'local',payload:'{}',
|
||
schedule_kind:'interval',interval_seconds:Number(monitorForm.elements.interval.value),enabled:monitorForm.elements.enabled.checked,priority:100,max_attempts:1
|
||
})});
|
||
delete monitorForm.dataset.dirty;
|
||
});
|
||
});
|
||
document.getElementById('resource-monitor-run').addEventListener('click', event => configAction(event.currentTarget,'resource-monitor-result',async () => {
|
||
await configJSON('/_/api/v1/event/run',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({uuid:'builtin.resource.sample'})});
|
||
}));
|
||
document.addEventListener("visibilitychange", () => configResources.activate(activeConfigPanel === "scheduler"));
|
||
const schedule = document.querySelector('#event-definition-form [name="schedule_kind"]');
|
||
const updateSchedule = () => {
|
||
for (const field of document.querySelectorAll("[data-schedule-field]")) field.hidden = field.dataset.scheduleField !== schedule.value;
|
||
};
|
||
schedule.addEventListener("change", updateSchedule); updateSchedule();
|
||
showConfigPanel(new URLSearchParams(location.search).get("panel") || "home");
|
||
});
|