0.7.0: after_action setting (stay on page with job status vs jump to log), settings UI
This commit is contained in:
1 parent
642a11f505
commit
cbf899b94b
6 files changed
+110
-5
No files matched your search
@@ -33,6 +33,7 @@ function vmm_config(): array
|
||||
'default_bridge' => '',
|
||||
'enable' => true,
|
||||
'job_timeout' => 900,
|
||||
'after_action' => 'stay', // stay | log
|
||||
'vm_dir_cache' => '',
|
||||
];
|
||||
if (!is_file(VMM_CONF)) {
|
||||
@@ -651,6 +652,47 @@ function vmm_job_log(string $id, int $maxBytes = 65536): string
|
||||
return "... (truncated)\n" . $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where to go after an action created a job: the job log, or back to the page
|
||||
* the action came from (default, keeps the dashboard in view).
|
||||
*/
|
||||
function vmm_after_job_target(string $jobId, string $back): string
|
||||
{
|
||||
$conf = vmm_config();
|
||||
if (($conf['after_action'] ?? 'stay') === 'log') {
|
||||
return 'vmmngr_jobs.php?id=' . urlencode($jobId);
|
||||
}
|
||||
$sep = str_contains($back, '?') ? '&' : '?';
|
||||
return $back . $sep . 'job=' . urlencode($jobId);
|
||||
}
|
||||
|
||||
function vmm_job_status_html(string $id): string
|
||||
{
|
||||
$job = vmm_job_get($id);
|
||||
if ($job === null) {
|
||||
return '';
|
||||
}
|
||||
$state = (string)$job['state'];
|
||||
$cls = $state === 'failed' ? 'vmm-err' : 'vmm-ok';
|
||||
return sprintf(
|
||||
'<div style="margin:8px 0;padding:8px 10px;border:1px solid rgba(127,127,127,.35);border-radius:4px;">'
|
||||
. 'Job <span class="vmm-mono">%s</span> · %s %s · <span class="%s">%s</span> · <a href="vmmngr_jobs.php?id=%s">%s</a></div>',
|
||||
htmlspecialchars($id, ENT_QUOTES),
|
||||
htmlspecialchars((string)$job['verb'], ENT_QUOTES),
|
||||
htmlspecialchars((string)$job['vm'], ENT_QUOTES),
|
||||
$cls,
|
||||
htmlspecialchars($state . ($job['rc'] !== null ? ' (rc ' . $job['rc'] . ')' : ''), ENT_QUOTES),
|
||||
urlencode($id),
|
||||
gettext('Log')
|
||||
);
|
||||
}
|
||||
|
||||
function vmm_job_running(string $id): bool
|
||||
{
|
||||
$job = vmm_job_get($id);
|
||||
return $job !== null && in_array($job['state'], ['queued', 'running'], true);
|
||||
}
|
||||
|
||||
function vmm_job_new(string $verb, string $name, array $argv = [], int $timeout = 0): array
|
||||
{
|
||||
vmm_ensure_state_dirs();
|
||||
|
||||
Reference in new issue
Block a user