diff --git a/public/src/admin/extend/plugins.js b/public/src/admin/extend/plugins.js index 6a8816d5a4..1419dffe32 100644 --- a/public/src/admin/extend/plugins.js +++ b/public/src/admin/extend/plugins.js @@ -11,22 +11,13 @@ define('admin/extend/plugins', [ const Plugins = {}; Plugins.init = function () { const pluginsList = $('.plugins'); - const numPlugins = pluginsList[0].querySelectorAll('li').length; let pluginID; - if (!numPlugins) { - translator.translate('
  • [[admin/extend/plugins:none-found]]

  • ', function (html) { - pluginsList.append(html); - }); - return; - } - if (window.location.hash) { $(`.nav-pills button[data-bs-target="${window.location.hash}"]`).trigger('click'); } - const searchInputEl = document.querySelector('#plugin-search'); - searchInputEl.value = ''; + const searchInputEl = $('#plugin-search'); pluginsList.on('click', 'button[data-action="toggleActive"]', function () { const pluginEl = $(this).parents('li'); @@ -159,13 +150,18 @@ define('admin/extend/plugins', [ }); }); - $(searchInputEl).on('input propertychange', function () { + $(searchInputEl).on('input propertychange', utils.debounce(function () { const term = $(this).val(); $('.plugins li').each(function () { const pluginId = $(this).attr('data-plugin-id'); - $(this).toggleClass('hide', pluginId && pluginId.indexOf(term) === -1); + $(this).toggleClass('hide', pluginId && !pluginId.includes(term)); }); + const activeTab = $('#plugin-tabs [data-bs-target].active').attr('data-bs-target'); + if (activeTab === '#download') { + searchAllPlugins(term); + } + const tabEls = document.querySelectorAll('.plugins .tab-pane'); tabEls.forEach((tabEl) => { const remaining = tabEl.querySelectorAll('li:not(.hide)').length; @@ -174,7 +170,7 @@ define('admin/extend/plugins', [ noticeEl.classList.toggle('hide', remaining !== 0); } }); - }); + }, 250)); $('#plugin-submit-usage').on('click', function () { socket.emit('admin.config.setMultiple', { @@ -256,11 +252,16 @@ define('admin/extend/plugins', [ }); }); }); - - populateUpgradeablePlugins(); - populateActivePlugins(); }; + async function searchAllPlugins(term) { + const { download, incompatible } = ajaxify.data; + const all = term ? download.concat(incompatible) : download; + const found = all.filter(p => p && p.name.includes(term)).slice(0, 100); + const html = await app.parseAndTranslate('admin/extend/plugins', 'download', { download: found }); + $('#download ul').html(html); + } + function confirmInstall(pluginID, callback) { bootbox.confirm(translator.compile('admin/extend/plugins:alert.possibly-incompatible', pluginID), function (confirm) { callback(confirm); @@ -348,23 +349,5 @@ define('admin/extend/plugins', [ }).fail(callback); }; - function populateUpgradeablePlugins() { - $('#installed ul li').each(function () { - if ($(this).find('[data-action="upgrade"]').length) { - $('#upgrade ul').append($(this).clone(true)); - } - }); - } - - function populateActivePlugins() { - $('#installed ul li').each(function () { - if ($(this).hasClass('active')) { - $('#active ul').append($(this).clone(true)); - } else { - $('#deactive ul').append($(this).clone(true)); - } - }); - } - return Plugins; }); diff --git a/src/controllers/admin/plugins.js b/src/controllers/admin/plugins.js index 62743e00a3..7cc09c98bf 100644 --- a/src/controllers/admin/plugins.js +++ b/src/controllers/admin/plugins.js @@ -17,6 +17,7 @@ pluginsController.get = async function (req, res) { const compatiblePkgNames = compatible.map(pkgData => pkgData.name); const installedPlugins = compatible.filter(plugin => plugin && (plugin.installed || (nconf.get('plugins:active') && plugin.active))); const activePlugins = all.filter(plugin => plugin && (plugin.installed || nconf.get('plugins:active')) && plugin.active); + const inactivePlugins = all.filter(plugin => plugin && (plugin.installed || nconf.get('plugins:active')) && !plugin.active); const trendingScores = trending.reduce((memo, cur) => { memo[cur.label] = cur.value; @@ -30,18 +31,17 @@ pluginsController.get = async function (req, res) { return plugin; }); + const upgrade = compatible.filter(p => p.installed && p.outdated); res.render('admin/extend/plugins', { installed: installedPlugins, installedCount: installedPlugins.length, + active: activePlugins, activeCount: activePlugins.length, - inactiveCount: Math.max(0, installedPlugins.length - activePlugins.length), + inactive: inactivePlugins, + inactiveCount: inactivePlugins.length, canChangeState: !nconf.get('plugins:active'), - upgradeCount: compatible.reduce((count, current) => { - if (current.installed && current.outdated) { - count += 1; - } - return count; - }, 0), + upgrade: upgrade, + upgradeCount: upgrade.length, download: compatible.filter(plugin => !plugin.installed), incompatible: all.filter(plugin => !compatiblePkgNames.includes(plugin.name)), trending: trendingPlugins, diff --git a/src/views/admin/extend/plugins.tpl b/src/views/admin/extend/plugins.tpl index 49beec0ee7..0b6c26b0e8 100644 --- a/src/views/admin/extend/plugins.tpl +++ b/src/views/admin/extend/plugins.tpl @@ -13,7 +13,7 @@ {{{ if !canChangeState }}}
    [[error:plugins-set-in-configuration]]
    {{{ end }}} -