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();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"appname": "VM Manager",
|
||||
"version": "0.6.1",
|
||||
"version": "0.7.0",
|
||||
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
||||
"vm_source": "auto",
|
||||
"bridges": ["ix0bridge"],
|
||||
"default_bridge": "ix0bridge",
|
||||
"enable": true,
|
||||
"job_timeout": 900,
|
||||
"after_action": "stay",
|
||||
"ram_budget_pct": 85
|
||||
}
|
||||
+10
-1
@@ -18,10 +18,15 @@ if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && isset($
|
||||
exit;
|
||||
}
|
||||
$job = vmm_job_new($verb, $vmName);
|
||||
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||
header('Location: ' . vmm_after_job_target((string)$job['id'], 'vmmngr.php'));
|
||||
exit;
|
||||
}
|
||||
|
||||
$activeJob = (string)($_GET['job'] ?? '');
|
||||
if ($activeJob !== '' && vmm_job_running($activeJob)) {
|
||||
header('Refresh: 3');
|
||||
}
|
||||
|
||||
$conf = vmm_config();
|
||||
$vmprov = vmm_resolve('vm');
|
||||
$vms = $vmprov['available'] ? vmm_list() : [];
|
||||
@@ -46,6 +51,10 @@ vmm_nav('dashboard');
|
||||
|
||||
<form action="vmmngr.php" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||
|
||||
<?php if ($activeJob !== ''): ?>
|
||||
<?=vmm_job_status_html($activeJob); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
|
||||
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -6,6 +6,16 @@
|
||||
require_once 'vmmngr-boot.inc';
|
||||
require_once 'vmmngr-config-lib.inc';
|
||||
|
||||
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST['act'] ?? '') === 'save_settings') {
|
||||
$conf = vmm_config();
|
||||
$conf['after_action'] = ($_POST['after_action'] ?? 'stay') === 'log' ? 'log' : 'stay';
|
||||
$conf['vm_source'] = in_array($_POST['vm_source'] ?? '', ['auto', 'system', 'bundle'], true) ? $_POST['vm_source'] : 'auto';
|
||||
vmm_save_config($conf);
|
||||
$_SESSION['vmmngr_error'] = gettext('Settings saved.');
|
||||
header('Location: vmmngr_config.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST['act'] ?? '') === 'register') {
|
||||
$added = vmm_register_boot();
|
||||
$_SESSION['vmmngr_error'] = $added === []
|
||||
@@ -30,6 +40,36 @@ vmm_nav('config'); ?>
|
||||
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $bs = vmm_boot_state(); $conf = vmm_config(); ?>
|
||||
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
||||
<colgroup><col class="area_data_settings_col_tag"><col class="area_data_settings_col_data"></colgroup>
|
||||
<thead><?php html_separator2(); html_titleline2(gettext('Behaviour'), 2); ?></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="celltag"><?=gettext('After an action');?></td>
|
||||
<td class="celldata">
|
||||
<select name="after_action">
|
||||
<option value="stay" <?=($conf['after_action'] ?? 'stay') === 'stay' ? 'selected' : '';?>><?=gettext('stay on the page, show job status');?></option>
|
||||
<option value="log" <?=($conf['after_action'] ?? 'stay') === 'log' ? 'selected' : '';?>><?=gettext('jump to the job log');?></option>
|
||||
</select>
|
||||
<button type="submit" class="formbtn" name="act" value="save_settings" style="margin-left:8px;"><?=gettext('Save');?></button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="celltag">vm_source</td>
|
||||
<td class="celldata">
|
||||
<select name="vm_source">
|
||||
<?php foreach (['auto', 'system', 'bundle'] as $src): ?>
|
||||
<option value="<?=$src;?>" <?=($conf['vm_source'] ?? 'auto') === $src ? 'selected' : '';?>><?=$src;?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<?php $bs = vmm_boot_state(); ?>
|
||||
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
||||
<colgroup><col class="area_data_settings_col_tag"><col class="area_data_settings_col_data"></colgroup>
|
||||
|
||||
+15
-2
@@ -83,7 +83,7 @@ if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && isset($
|
||||
exit;
|
||||
}
|
||||
$job = vmm_job_new('start', $name);
|
||||
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||
header('Location: ' . vmm_after_job_target((string)$job['id'], 'vmmngr_vm.php?name=' . urlencode($name)));
|
||||
exit;
|
||||
}
|
||||
$check = vmm_action_check($verb, $vmName, (string)($_POST['confirm'] ?? ''));
|
||||
@@ -93,7 +93,7 @@ if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && isset($
|
||||
exit;
|
||||
}
|
||||
$job = vmm_job_new($verb, $vmName);
|
||||
header('Location: vmmngr_jobs.php?id=' . urlencode((string)$job['id']));
|
||||
header('Location: ' . vmm_after_job_target((string)$job['id'], 'vmmngr_vm.php?name=' . urlencode($name)));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,11 @@ if (vmm_vm_state($name) === 'absent') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$activeJob = (string)($_GET['job'] ?? '');
|
||||
if ($activeJob !== '' && vmm_job_running($activeJob)) {
|
||||
header('Refresh: 3');
|
||||
}
|
||||
|
||||
$info = vmm_info($name);
|
||||
$pgtitle = [gettext('Extensions'), gettext('VM Manager'), $name];
|
||||
$jobs = vmm_job_list(10, $name);
|
||||
@@ -114,6 +119,14 @@ vmm_nav('dashboard');
|
||||
|
||||
<form action="vmmngr_vm.php?name=<?=urlencode($name);?>" method="post" name="iform" id="iform"><table id="area_data"><tbody><tr><td id="area_data_frame">
|
||||
|
||||
<?php if ($activeJob !== ''): ?>
|
||||
<?=vmm_job_status_html($activeJob); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($_SESSION['vmmngr_error'])): ?>
|
||||
<?php print_info_box(vmm_h((string)$_SESSION['vmmngr_error'])); unset($_SESSION['vmmngr_error']); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($info['error'])): ?>
|
||||
<?php print_info_box(sprintf(gettext('Could not read VM details: %s'), vmm_h((string)$info['error']))); ?>
|
||||
<?php else: ?>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.6.1
|
||||
0.7.0
|
||||
Reference in new issue
Block a user