Files
unraid-podman/webui/plugins/podman/javascript/settings.js
T
maggesandClaude Sonnet 5 46a8503498
Build Packages / Build .txz packages (push) Failing after 8m53s
Lint / ShellCheck (push) Successful in 43s
Lint / Validate .plg XML (push) Successful in 11s
Lint / EditorConfig (push) Failing after 6s
Rework Terminal into a real live console; polish danger buttons and Settings
Terminal panel now opens a genuinely interactive shell (ttyd bound to a
unix socket, proxied through Unraid's own /logterminal/ nginx location —
the same mechanism Unraid's own Docker "Console" button uses) instead of
one-shot exec calls, shown inline with a Disconnect action; bash is the
default shell. Container/shell selectors and action buttons are now
correctly bottom-aligned (root cause: Unraid's theme puts a 10px margin
on every <button>, never reset before).

Destructive actions (Disconnect, Compose/Template Delete, Volumes/Images/
Networks Remove) get a consistent, solid red treatment at rest instead of
only tinting on hover, via new --bad-strong/--bad-contrast tokens.

Settings panel restructured: a real save toolbar instead of a button
buried in an empty-label row, card subtitles, a toggle switch instead of
a bare checkbox, and installed-package versions shown as chips.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 21:19:47 +00:00

99 lines
4.0 KiB
JavaScript

/**
* javascript/settings.js
*
* Settings panel: reads/writes unraid-podman's own configuration via
* ajax/settings.php (podman.cfg + the autostart list) — not a
* PodmanClient/libpod concern, see that file's header comment.
*/
(function () {
'use strict';
const P = window.Podman;
let autostartNames = [];
function renderAutostart() {
const tbody = P.el('autostart-tbody');
tbody.innerHTML = autostartNames.length
? autostartNames.map(function (name, i) {
return '<tr data-index="' + i + '">' +
'<td class="tnum">' + (i + 1) + '</td>' +
'<td>' + P.escapeHtml(name) + '</td>' +
'<td class="podman-actions"><div class="podman-actions-row">' +
'<button class="podman-btn podman-btn-icon" data-action="up"' + (i === 0 ? ' disabled' : '') + ' title="Move up">&#8593;</button>' +
'<button class="podman-btn podman-btn-icon" data-action="down"' + (i === autostartNames.length - 1 ? ' disabled' : '') + ' title="Move down">&#8595;</button>' +
'<button class="podman-btn podman-btn-icon" data-action="remove" title="Remove from autostart">&#128465;</button>' +
'</div></td></tr>';
}).join('')
: '<tr><td colspan="3" class="podman-empty-note">No containers in the autostart chain.</td></tr>';
}
function saveAutostart() {
return P.post('settings', 'autostart_save', { names: autostartNames }).catch(function (err) {
alert('Could not save autostart order: ' + err.message);
});
}
function fillForm(settings) {
P.el('settings-storage-path').value = settings.storagePath;
P.el('settings-storage-size').value = settings.storageImageSizeGb;
P.el('settings-enabled').checked = settings.enabled;
P.el('settings-stop-timeout').value = settings.stopTimeoutSeconds;
autostartNames = settings.autostart.slice();
renderAutostart();
const versions = settings.packageVersions || {};
const order = ['PODMAN', 'CONMON', 'CRUN', 'NETAVARK', 'AARDVARK_DNS', 'PASST', 'FUSE_OVERLAYFS'];
const chipsHtml = order.map(function (k) {
const name = k.toLowerCase().replace(/_/g, '-');
const version = versions[k + '_INSTALLED_VERSION'];
return '<span class="podman-version-chip">' + P.escapeHtml(name) + ' <b>' + P.escapeHtml(version || '?') + '</b></span>';
}).join('');
P.el('settings-package-versions').innerHTML = chipsHtml || '<span class="podman-empty-note">No version manifest found.</span>';
}
function load() {
return P.get('settings', 'get').then(fillForm).catch(function (err) {
alert('Could not load settings: ' + err.message);
});
}
function save() {
const body = {
storagePath: P.el('settings-storage-path').value.trim(),
storageImageSizeGb: parseInt(P.el('settings-storage-size').value, 10) || 20,
enabled: P.el('settings-enabled').checked,
stopTimeoutSeconds: parseInt(P.el('settings-stop-timeout').value, 10) || 10,
};
return P.post('settings', 'save', body).then(function () {
alert('Saved. Restart podman (rc.podman restart) to apply storage/enabled changes.');
}).catch(function (err) {
alert('Save failed: ' + err.message);
});
}
function init() {
P.el('settings-save-btn').addEventListener('click', save);
P.el('autostart-tbody').addEventListener('click', function (e) {
const btn = e.target.closest('button[data-action]');
if (!btn) return;
const i = parseInt(btn.closest('tr').dataset.index, 10);
const action = btn.dataset.action;
if (action === 'remove') {
autostartNames.splice(i, 1);
} else if (action === 'up' && i > 0) {
[autostartNames[i - 1], autostartNames[i]] = [autostartNames[i], autostartNames[i - 1]];
} else if (action === 'down' && i < autostartNames.length - 1) {
[autostartNames[i + 1], autostartNames[i]] = [autostartNames[i], autostartNames[i + 1]];
}
renderAutostart();
saveAutostart();
});
return load();
}
P.registerPanel('settings', { init: init, refresh: load });
})();