From e049761f36b8de9cca08c11ed8f23fa0a4b49ac5 Mon Sep 17 00:00:00 2001 From: Tim Dreyer <74516735+eyerrock@users.noreply.github.com> Date: Thu, 24 Apr 2025 22:43:04 +0200 Subject: [PATCH] feat: show only running containers checkbox --- src/web/snippet/dockerContainersList.html | 39 ++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/web/snippet/dockerContainersList.html b/src/web/snippet/dockerContainersList.html index 2eca23a..420b7c9 100644 --- a/src/web/snippet/dockerContainersList.html +++ b/src/web/snippet/dockerContainersList.html @@ -21,6 +21,12 @@ autocomplete="off" /> +
+
+ + +
+
@@ -101,6 +107,7 @@ const $existingList = $("#existingList"); const $searchbar = $("#searchbar"); + const $showOnlyRunning = $("#showOnlyRunning"); const $showUnexposed = $("#showUnexposed"); // objects to store container entries @@ -122,6 +129,22 @@ localStorage.setItem("showUnexposed", $showUnexposed.prop("checked")); } + // load showOnlyRunning checkbox state from local storage + function loadShowOnlyRunningState() { + const storedState = localStorage.getItem("showOnlyRunning"); + if (storedState !== null) { + $showOnlyRunning.prop("checked", storedState === "true"); + } + } + + // save showOnlyRunning checkbox state to local storage + function saveShowOnlyRunningState() { + localStorage.setItem( + "showOnlyRunning", + $showOnlyRunning.prop("checked") + ); + } + // fetch docker containers function getDockerContainers() { $networkedList.html('
'); @@ -182,6 +205,14 @@ // process each container containers.forEach((container) => { + // skip containers that are not running, if the checkbox is checked + if ( + $showOnlyRunning.is(":checked") && + container.State !== "running" + ) { + return; + } + // skip containers in network mode "none" if (container.HostConfig.NetworkMode === "none") { return; @@ -227,8 +258,9 @@ // add the container to the networked list, using it's name as address container.Ports.forEach((portObject) => { // skip unexposed ports if the checkbox is not checked - if (!portObject.PublicPort && !$showUnexposed.is(":checked")) + if (!portObject.PublicPort && !$showUnexposed.is(":checked")) { return; + } const port = portObject.PublicPort || portObject.PrivatePort; @@ -389,6 +421,11 @@ getDockerContainers(); }); + $showOnlyRunning.on("change", () => { + saveShowOnlyRunningState(); // save the new state to local storage + getDockerContainers(); + }); + // debounce searchbar input with 300ms delay, then filter list // this prevents excessive calls to the filter function $searchbar.on(