From 04128c7870c7aebe619cdb76a53a76ee8cd8e924 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 4 Mar 2021 15:52:37 +0300 Subject: add search to plugin installer --- js/PrefHelpers.js | 60 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 14 deletions(-) (limited to 'js/PrefHelpers.js') diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index b599e7e3f..889d93232 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -370,8 +370,10 @@ const Helpers = { PI_ERR_NO_TEMPDIR: "PI_ERR_NO_TEMPDIR", PI_ERR_PLUGIN_NOT_FOUND: "PI_ERR_PLUGIN_NOT_FOUND", PI_ERR_NO_WORKDIR: "PI_ERR_NO_WORKDIR", - title: __("List of plugins"), + title: __("Available plugins"), need_refresh: false, + entries: false, + search_query: "", onHide: function() { if (this.need_refresh) { Helpers.Prefs.refresh(); @@ -428,18 +430,26 @@ const Helpers = { install_dialog.show(); }, - refresh: function() { + search: function() { + this.search_query = this.attr('value').search.toLowerCase(); + this.render_contents(); + }, + render_contents: function() { const container = dialog.domNode.querySelector(".contents"); - container.innerHTML = `
  • ${__("Looking for plugins...")}
  • `; - xhr.json("backend.php", {op: "pref-prefs", method: "getAvailablePlugins"}, (reply) => { + if (!dialog.entries) { + container.innerHTML = `
  • ${__("Operation failed: check event log.")}
  • `; + } else { + container.innerHTML = ""; - if (!reply) { - container.innerHTML = `
  • ${__("Operation failed: check event log.")}
  • `; - } else { - container.innerHTML = ""; + let results_rendered = 0; + + dialog.entries.forEach((plugin) => { + if (!dialog.search_query || + (plugin.name.toLowerCase().indexOf(dialog.search_query) != -1 || plugin.description.toLowerCase().indexOf(dialog.search_query) != -1)) { + + ++results_rendered; - reply.forEach((plugin) => { container.innerHTML += `
  • ${plugin.name} @@ -456,17 +466,39 @@ const Helpers = {

  • ` - }); + } + }); - dojo.parser.parse(container); + if (results_rendered == 0) { + container.innerHTML = `
  • ${__("Could not find any plugins for this search query.")}
  • `; } + + dojo.parser.parse(container); + } + }, + reload: function() { + const container = dialog.domNode.querySelector(".contents"); + container.innerHTML = `
  • ${__("Looking for plugins...")}
  • `; + + const installed = [...document.querySelectorAll('*[data-plugin-name]')].map((p) => p.getAttribute('data-plugin-name')); + + xhr.json("backend.php", {op: "pref-prefs", method: "getAvailablePlugins", 'installed[]': installed}, (reply) => { + dialog.entries = reply; + dialog.render_contents(); }); }, content: ` - +
    +
    + +
    +
     
    +
    + + `, @@ -474,7 +506,7 @@ const Helpers = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - dialog.refresh(); + dialog.reload(); }); dialog.show(); -- cgit v1.2.3-54-g00ecf