Scheduler: Run button, single card-level Save, remove per-row Save

- Run button (blue) fires script immediately, opens log panel;
  stamps log with manual run timestamp before exec
- Save moved to card footer — one button saves all cron expressions
  for the orchestrator and all its children at once
- Toggle still auto-saves immediately on flip (enable/disable is instant)
- Removed onblur from cron inputs — cron only saves on explicit Save
- api/run.php: validates id, appends timestamp, execs script in background
This commit is contained in:
Gmer4Lfe
2026-05-23 17:22:52 -04:00
parent 6050816fe4
commit 131d9093b0
3 changed files with 114 additions and 24 deletions
@@ -4,16 +4,16 @@ $tree = vv_job_tree();
?>
<div id="vv-scheduler">
<p class="vv-hint">Orchestrators run their child scripts in the correct order.
Disable an orchestrator and enable individual scripts below it to run them
in isolation for debugging or testing.</p>
<p class="vv-hint">Toggle enables/saves immediately. Edit cron expressions then hit
<strong>Save</strong> at the bottom of the card. <strong>Run</strong> fires the script
now and opens its log.</p>
<?php foreach ($tree as $orch): $oid = htmlspecialchars($orch['id']); ?>
<div class="vv-card vv-wide vv-sched-card" data-id="<?= $oid ?>">
<!-- Orchestrator row -->
<div class="vv-job-row">
<label class="vv-toggle" title="Enable/disable">
<label class="vv-toggle" title="Enable/disable (saves immediately)">
<input type="checkbox" class="vv-enabled"
<?= $orch['enabled'] ? 'checked' : '' ?>
onchange="vvSaveJob(this)">
@@ -21,8 +21,8 @@ $tree = vv_job_tree();
</label>
<span class="vv-job-label"><?= htmlspecialchars($orch['label']) ?></span>
<input type="text" class="vv-cron" value="<?= htmlspecialchars($orch['cron']) ?>"
placeholder="cron expression" onblur="vvSaveJob(this)">
<button class="vv-btn-sm" onclick="vvSaveJob(this)">Save</button>
placeholder="cron expression">
<button class="vv-btn-sm vv-run-btn" onclick="vvRunJob(this)">&#9654; Run</button>
<button class="vv-log-btn vv-btn-sm" onclick="vvToggleLog(this)">Log</button>
<span class="vv-job-status"></span>
<?php if (!empty($orch['children'])): ?>
@@ -30,7 +30,7 @@ $tree = vv_job_tree();
<?php endif; ?>
</div>
<!-- Log panel -->
<!-- Orchestrator log panel -->
<div class="vv-log-panel" style="display:none;">
<div class="vv-log-toolbar">
<span class="vv-log-ts"></span>
@@ -39,13 +39,13 @@ $tree = vv_job_tree();
<pre class="vv-log-pre">(no log yet)</pre>
</div>
<!-- Children -->
<!-- Children (Advanced) -->
<?php if (!empty($orch['children'])): ?>
<div class="vv-children" style="display:none;">
<?php foreach ($orch['children'] as $child): $cid = htmlspecialchars($child['id']); ?>
<div class="vv-script" data-id="<?= $cid ?>">
<div class="vv-job-row">
<label class="vv-toggle" title="Enable/disable">
<label class="vv-toggle" title="Enable/disable (saves immediately)">
<input type="checkbox" class="vv-enabled"
<?= $child['enabled'] ? 'checked' : '' ?>
onchange="vvSaveJob(this)">
@@ -53,8 +53,8 @@ $tree = vv_job_tree();
</label>
<span class="vv-job-label"><?= htmlspecialchars($child['label']) ?></span>
<input type="text" class="vv-cron" value="<?= htmlspecialchars($child['cron']) ?>"
placeholder="cron expression" onblur="vvSaveJob(this)">
<button class="vv-btn-sm" onclick="vvSaveJob(this)">Save</button>
placeholder="cron expression">
<button class="vv-btn-sm vv-run-btn" onclick="vvRunJob(this)">&#9654; Run</button>
<button class="vv-log-btn vv-btn-sm" onclick="vvToggleLog(this)">Log</button>
<span class="vv-job-status"></span>
</div>
@@ -70,6 +70,12 @@ $tree = vv_job_tree();
</div>
<?php endif; ?>
<!-- Card footer: single Save for all crons in this card -->
<div class="vv-card-footer">
<button class="vv-save-btn" onclick="vvSaveCard(this)">Save Schedule</button>
<span class="vv-save-status"></span>
</div>
</div>
<?php endforeach; ?>
</div>
@@ -77,22 +83,67 @@ $tree = vv_job_tree();
<script>
const vvLogTimers = {};
// Toggle auto-saves its single job immediately
function vvSaveJob(el) {
const row = el.closest('.vv-job-row');
const job = el.closest('[data-id]');
const id = job.dataset.id;
const job = el.closest('[data-id]');
const id = job.dataset.id;
const enabled = job.querySelector('.vv-enabled').checked;
const cron = job.querySelector('.vv-cron').value.trim();
const status = row.querySelector('.vv-job-status');
const status = job.querySelector('.vv-job-status');
fetch('/plugins/varaverk/api/scheduler.php', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id, enabled, cron})
})
.then(r => r.json())
.then(d => { if (status) vvFlashStatus(status, d.ok ? '✓' : '✗ ' + (d.error ?? ''), d.ok); });
}
// Save button at card bottom: saves all jobs (orch + children) in this card
function vvSaveCard(btn) {
const card = btn.closest('.vv-sched-card');
const status = card.querySelector('.vv-save-status');
const jobs = card.querySelectorAll('[data-id]');
let pending = jobs.length;
let allOk = true;
status.textContent = 'Saving…';
jobs.forEach(job => {
const id = job.dataset.id;
const enabled = job.querySelector('.vv-enabled').checked;
const cron = job.querySelector('.vv-cron').value.trim();
fetch('/plugins/varaverk/api/scheduler.php', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id, enabled, cron})
})
.then(r => r.json())
.then(d => {
if (!d.ok) allOk = false;
if (--pending === 0) vvFlashStatus(status, allOk ? '✓ Saved' : '✗ Some failed', allOk);
});
});
}
// Run: fires script immediately, opens log panel
function vvRunJob(btn) {
const job = btn.closest('[data-id]');
const id = job.dataset.id;
const logBtn = job.querySelector('.vv-log-btn');
if (logBtn && !logBtn.classList.contains('active')) vvToggleLog(logBtn);
fetch('/plugins/varaverk/api/run.php', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id})
})
.then(r => r.json())
.then(d => {
if (status) vvFlashStatus(status, d.ok ? '✓' : '✗ ' + (d.error ?? ''), d.ok);
if (!d.ok) {
const pre = job.querySelector('.vv-log-pre');
if (pre) pre.textContent = '✗ ' + (d.error ?? 'Failed to start');
}
});
}
@@ -105,10 +156,10 @@ function vvToggleAdvanced(btn) {
}
function vvToggleLog(btn) {
const job = btn.closest('[data-id]');
const id = job.dataset.id;
const panel = job.querySelector('.vv-log-panel');
const open = panel.style.display !== 'none';
const job = btn.closest('[data-id]');
const id = job.dataset.id;
const panel = job.querySelector('.vv-log-panel');
const open = panel.style.display !== 'none';
if (open) {
panel.style.display = 'none';
@@ -142,9 +193,9 @@ function vvFetchLog(panel, id) {
function vvClearLog(btn) {
const panel = btn.closest('.vv-log-panel');
const job = btn.closest('[data-id]');
const id = job.dataset.id;
fetch('/plugins/varaverk/api/log.php?id=' + encodeURIComponent(id) + '&clear=1', {method:'POST'})
.then(() => vvFetchLog(panel, id))
fetch('/plugins/varaverk/api/log.php?id=' + encodeURIComponent(job.dataset.id) + '&clear=1',
{method: 'POST'})
.then(() => vvFetchLog(panel, job.dataset.id))
.catch(() => {});
}
</script>