Files
unraid-podman/webui/plugins/podman/javascript/volumes.js
T
maggesandClaude Sonnet 5 8ac9cde621 Add Pod lifecycle management, fix nav registration and context-menu bugs
Pods panel could previously only list pods - there was no way to create
one, start/stop/restart it, or attach a container to it from the UI.
Adds a "New Pod" modal (name + port mappings), a per-pod lifecycle menu
(start/stop/restart/remove), and an optional "Pod" field on the Create
Container modal to join an existing pod's network namespace. Backend
verified live against the real podman socket (/pods/create, /pods/{name}/
restart, container "pod" field).

Also fixes three real bugs found via live testing:
- Podman.page used Menu="Podman" instead of Menu="Tasks:<rank>", so the
  plugin never actually appeared in Unraid's top navigation (traced through
  PageBuilder.php/DefaultPageLayout.php/Navigation/Main.php - only pages
  registered under "Tasks" become top-level tabs).
- app.js's shared context-menu component mis-mapped every item positioned
  after a 'separator' entry to the wrong DOM element (an off-by-one against
  menu.children, which includes the separator <div>s) - so "Remove", which
  always sits after a separator, silently did nothing when clicked. Fixed
  by indexing into querySelectorAll('button') instead.
- That same menu was positioned via "position: absolute" math that assumed
  a viewport-relative containing block, but Unraid's own page wrapper
  (webGui/styles/default-base.css's ".content") sets position:relative,
  so the menu rendered far from its anchor button. Switched to
  "position: fixed" with viewport-relative coordinates.

Incidentally, pods add a hidden "infra" container that was leaking into
the plain Containers list with no working lifecycle of its own (always
"running", so its own Remove was permanently disabled) - now filtered out
via libpod's IsInfra flag. And every action-buttons table cell used
"display: flex" directly on the <td>, which browsers can size
inconsistently row to row - moved onto an inner wrapper div instead, and
bumped .podman-btn-icon's touch target size.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 16:26:49 +00:00

86 lines
3.3 KiB
JavaScript

/**
* javascript/volumes.js
*
* Volumes panel: named-volume table + create/remove, backed by
* ajax/volumes.php. Container-level bind mounts (e.g. appdata under
* /mnt/user/appdata/...) are deliberately not shown here, since they
* aren't a libpod-managed resource at all — see that file's header
* comment. A named volume created here WITH a host path (v.hostPath) IS
* still a real, listed podman volume, just backed by that path instead
* of podman's own internal storage — see PodmanClient::createVolume().
*/
(function () {
'use strict';
const P = window.Podman;
let volumes = [];
function rowHtml(v) {
const pathCell = v.hostPath
? P.escapeHtml(v.hostPath) + ' <span class="podman-chip podman-chip-neutral" title="Bind-mounted to this host path">bind</span>'
: P.escapeHtml(v.mountpoint);
return '' +
'<tr data-name="' + P.escapeHtml(v.name) + '">' +
'<td>' + P.escapeHtml(v.name) + '</td>' +
'<td><span class="podman-chip podman-chip-neutral">' + P.escapeHtml(v.driver) + '</span></td>' +
'<td class="mono podman-row-sub">' + pathCell + '</td>' +
'<td class="tnum">' + v.usedBy + '</td>' +
'<td class="podman-actions"><div class="podman-actions-row"><button class="podman-btn podman-btn-icon" data-action="remove"' +
(v.usedBy > 0 ? ' disabled title="In use by a container"' : ' title="Remove"') + '>&#128465;</button></div></td>' +
'</tr>';
}
function render() {
const tbody = P.el('volumes-tbody');
tbody.innerHTML = volumes.length
? volumes.map(rowHtml).join('')
: '<tr><td colspan="5" class="podman-empty-note">No named volumes.</td></tr>';
}
function load() {
const tbody = P.el('volumes-tbody');
tbody.innerHTML = P.loadingRow(5);
return P.get('volumes', 'list').then(function (data) {
volumes = data;
render();
}).catch(function (err) {
tbody.innerHTML = P.errorRow(5, err.message);
});
}
function init() {
P.el('volumes-create-btn').addEventListener('click', function () {
P.openFormModal({
title: 'New Volume',
submitLabel: 'Create',
fields: [
{ name: 'name', label: 'Volume name', required: true, placeholder: 'my-volume' },
{
name: 'path', label: 'Host path (optional)', placeholder: '/mnt/cache/appdata/my-volume',
hint: 'Leave empty for a podman-managed volume. Set this to bind the volume ' +
'directly to an existing directory on disk (e.g. a cache pool path) instead.',
},
],
onSubmit: function (values) {
return P.post('volumes', 'create', { name: values.name, path: values.path || undefined }).then(load);
},
});
});
P.el('volumes-tbody').addEventListener('click', function (e) {
const btn = e.target.closest('button[data-action="remove"]');
if (!btn || btn.disabled) return;
const name = btn.closest('tr').dataset.name;
if (!confirm('Remove volume "' + name + '"? This deletes its data.')) return;
btn.disabled = true;
P.post('volumes', 'remove', { name: name }).then(load).catch(function (err) {
alert('Remove failed: ' + err.message);
btn.disabled = false;
});
});
return load();
}
P.registerPanel('volumes', { init: init, refresh: load });
})();