From 7ef19b1c12cc9060528036faf7a3abc45cea0416 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Fri, 27 Mar 2026 09:26:25 +0000 Subject: [PATCH 1/2] feat(plugins): Implement auto-hide functionality for empty plugin tabs --- front/pluginsCore.php | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/front/pluginsCore.php b/front/pluginsCore.php index 1fa8ab13..4e0592ad 100755 --- a/front/pluginsCore.php +++ b/front/pluginsCore.php @@ -417,11 +417,84 @@ async function prefetchPluginBadges() { $(`#histCount_${prefix}`).text(0); } }); + + // Auto-hide tabs with zero results + autoHideEmptyTabs(counts, prefixes); + } catch (err) { console.error('[plugins] badge prefetch failed:', err); } } +// --------------------------------------------------------------- +// Hide plugin tabs (left-nav + pane) where all three counts are 0. +// Within visible plugins, hide inner sub-tabs whose count is 0. +// If the active tab was hidden, activate the first visible one. +function autoHideEmptyTabs(counts, prefixes) { + prefixes.forEach(prefix => { + const c = counts[prefix] || { objects: 0, events: 0, history: 0 }; + const total = c.objects + c.events + c.history; + const $li = $(`#tabs-location li:has(a[href="#${prefix}"])`); + const $pane = $(`#tabs-content-location > #${prefix}`); + + if (total === 0) { + // Hide the entire plugin tab + $li.hide(); + $pane.removeClass('active').hide(); + } else { + // Ensure visible (in case a previous filter hid it) + $li.show(); + $pane.show(); + + // Hide inner sub-tabs with zero count + const subTabs = [ + { href: `#objectsTarget_${prefix}`, count: c.objects }, + { href: `#eventsTarget_${prefix}`, count: c.events }, + { href: `#historyTarget_${prefix}`, count: c.history }, + ]; + + let activeSubHidden = false; + subTabs.forEach(st => { + const $subLi = $pane.find(`ul.nav-tabs li:has(a[href="${st.href}"])`); + const $subPane = $pane.find(st.href); + if (st.count === 0) { + if ($subLi.hasClass('active')) activeSubHidden = true; + $subLi.hide(); + $subPane.removeClass('active').hide(); + } else { + $subLi.show(); + $subPane.show(); + } + }); + + // If the active inner sub-tab was hidden, activate the first visible one + if (activeSubHidden) { + const $firstVisibleSubLi = $pane.find('ul.nav-tabs li:visible').first(); + if ($firstVisibleSubLi.length) { + $firstVisibleSubLi.addClass('active'); + const target = $firstVisibleSubLi.find('a').attr('href'); + $pane.find(target).addClass('active'); + } + } + } + }); + + // If the active left-nav tab was hidden, activate the first visible one + const $activeLi = $(`#tabs-location li.active:visible`); + if ($activeLi.length === 0) { + const $firstVisibleLi = $(`#tabs-location li:visible`).first(); + if ($firstVisibleLi.length) { + $firstVisibleLi.addClass('active'); + const targetPrefix = $firstVisibleLi.find('a').attr('href')?.replace('#', ''); + if (targetPrefix) { + $(`#tabs-content-location > #${targetPrefix}`).addClass('active'); + // Trigger shown.bs.tab so deferred DataTables initialize + $firstVisibleLi.find('a').tab('show'); + } + } + } +} + function generateTabs() { // Reset the tabs by clearing previous headers and content From 13e91731be80e3a0387369f188e0c372cfc9d6d4 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Fri, 27 Mar 2026 09:49:21 +0000 Subject: [PATCH 2/2] feat(plugins): Improve auto-hide functionality for empty plugin tabs by ensuring proper visibility handling and Bootstrap integration --- front/pluginsCore.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/front/pluginsCore.php b/front/pluginsCore.php index 4e0592ad..36685e51 100755 --- a/front/pluginsCore.php +++ b/front/pluginsCore.php @@ -438,13 +438,14 @@ function autoHideEmptyTabs(counts, prefixes) { const $pane = $(`#tabs-content-location > #${prefix}`); if (total === 0) { - // Hide the entire plugin tab - $li.hide(); - $pane.removeClass('active').hide(); + // Hide the entire plugin tab and strip active from both nav item and pane + $li.removeClass('active').hide(); + $pane.removeClass('active').css('display', ''); } else { - // Ensure visible (in case a previous filter hid it) + // Ensure nav item visible (in case a previous filter hid it) $li.show(); - $pane.show(); + // Clear any inline display override so Bootstrap CSS controls pane visibility via .active + $pane.css('display', ''); // Hide inner sub-tabs with zero count const subTabs = [ @@ -460,20 +461,19 @@ function autoHideEmptyTabs(counts, prefixes) { if (st.count === 0) { if ($subLi.hasClass('active')) activeSubHidden = true; $subLi.hide(); - $subPane.removeClass('active').hide(); + $subPane.removeClass('active').css('display', ''); } else { $subLi.show(); - $subPane.show(); + $subPane.css('display', ''); } }); // If the active inner sub-tab was hidden, activate the first visible one + // via Bootstrap's tab lifecycle so shown.bs.tab fires for deferred DataTable init if (activeSubHidden) { - const $firstVisibleSubLi = $pane.find('ul.nav-tabs li:visible').first(); - if ($firstVisibleSubLi.length) { - $firstVisibleSubLi.addClass('active'); - const target = $firstVisibleSubLi.find('a').attr('href'); - $pane.find(target).addClass('active'); + const $firstVisibleSubA = $pane.find('ul.nav-tabs li:visible:first a'); + if ($firstVisibleSubA.length) { + $firstVisibleSubA.tab('show'); } } }