From 473ea6255c634fa47ee8c8e24de910785b9b095b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 6 Mar 2021 18:14:25 +0300 Subject: render list of plugins on the client --- js/PrefHelpers.js | 134 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 104 insertions(+), 30 deletions(-) (limited to 'js/PrefHelpers.js') diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index b72dbc881..296028f44 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -308,44 +308,101 @@ const Helpers = { }, }, Plugins: { - clearPluginData: function(name) { - if (confirm(__("Clear stored data for this plugin?"))) { - Notify.progress("Loading, please wait..."); + _list_of_plugins: [], + _search_query: "", + enableSelected: function() { + const form = dijit.byId("changePluginsForm"); - xhr.post("backend.php", {op: "pref-prefs", method: "clearPluginData", name: name}, () => { - Helpers.Prefs.refresh(); - }); + if (form.validate()) { + xhr.post("backend.php", form.getValues(), () => { + Notify.close(); + if (confirm(__('Selected plugins have been enabled. Reload?'))) { + window.location.reload(); + } + }) } }, - checkForUpdate: function(name = null) { - Notify.progress("Checking for plugin updates..."); + search: function() { + this._search_query = dijit.byId("changePluginsForm").getValues().search; + this.render_contents(); + }, + reload: function() { + xhr.json("backend.php", {op: "pref-prefs", method: "getPluginsList"}, (reply) => { + this._list_of_plugins = reply; + this.render_contents(); + }); + }, + render_contents: function() { + const container = document.querySelector(".prefs-plugin-list"); - xhr.json("backend.php", {op: "pref-prefs", method: "checkForPluginUpdates", name: name}, (reply) => { - Notify.close(); + container.innerHTML = ""; + let results_rendered = 0; - if (reply) { - let plugins_with_updates = 0; + const is_admin = this._list_of_plugins.is_admin; - reply.forEach((p) => { - if (p.rv.o) { - const button = dijit.getEnclosingWidget(App.find(`*[data-update-btn-for-plugin="${p.plugin}"]`)); + const search_tokens = this._search_query + .split(/ {1,}/) + .filter((stoken) => (stoken.length > 0 ? stoken : null)); - if (button) { - button.domNode.show(); - ++plugins_with_updates; - } - } - }); + this._list_of_plugins.plugins.forEach((plugin) => { + + if (search_tokens.length == 0 || + Object.values(plugin).filter((pval) => + search_tokens.filter((stoken) => + (pval.toString().indexOf(stoken) != -1 ? stoken : null) + ).length == search_tokens.length).length > 0) { + + ++results_rendered; + + container.innerHTML += ` +
  • + +
    + ${plugin.description} +
    +
    + ${plugin.is_system ? + App.FormFields.button_tag(App.FormFields.icon("security"), "", + {disabled: true}) : ''} + ${plugin.more_info ? + App.FormFields.button_tag(App.FormFields.icon("help"), "", + {class: 'alt-info', onclick: `window.open("${App.escapeHtml(plugin.more_info)}")`}) : ''} + ${is_admin && plugin.is_local ? + App.FormFields.button_tag(App.FormFields.icon("update"), "", + {title: __("Update"), class: 'alt-warning', "data-update-btn-for-plugin": plugin.name, style: 'display : none', + onclick: `Helpers.Plugins.update("${App.escapeHtml(plugin.name)}")`}) : ''} + ${is_admin && plugin.has_data ? + App.FormFields.button_tag(App.FormFields.icon("clear"), "", + {title: __("Clear data"), onclick: `Helpers.Plugins.clearData("${App.escapeHtml(plugin.name)}")`}) : ''} + ${is_admin && plugin.is_local ? + App.FormFields.button_tag(App.FormFields.icon("delete"), "", + {title: __("Uninstall"), onclick: `Helpers.Plugins.uninstall("${App.escapeHtml(plugin.name)}")`}) : ''} +
    +
    ${plugin.version}
    +
  • + `; + } + }); - if (plugins_with_updates > 0) - App.find(".update-all-plugins-btn").show(); - else - Notify.info("All local plugins are up-to-date."); + if (results_rendered == 0) { + container.innerHTML = `
  • ${__("Could not find any plugins for this search query.")}
  • `; + } + + dojo.parser.parse(container); - } else { - Notify.error("Unable to check for plugin updates."); - } - }); + }, + clearData: function(name) { + if (confirm(__("Clear stored data for %s?").replace("%s", name))) { + Notify.progress("Loading, please wait..."); + + xhr.post("backend.php", {op: "pref-prefs", method: "clearPluginData", name: name}, () => { + Helpers.Prefs.refresh(); + }); + } }, uninstall: function(plugin) { const msg = __("Uninstall plugin %s?").replace("%s", plugin); @@ -436,7 +493,13 @@ const Helpers = { }, search: function() { this.search_query = this.attr('value').search.toLowerCase(); - this.render_contents(); + + if ('requestIdleCallback' in window) + window.requestIdleCallback(() => { + this.render_contents(); + }); + else + this.render_contents(); }, render_contents: function() { const container = dialog.domNode.querySelector(".contents"); @@ -610,6 +673,12 @@ const Helpers = { dialog.plugins_to_update.push(p.plugin); } + const update_button = dijit.getEnclosingWidget( + App.find(`*[data-update-btn-for-plugin="${p.plugin}"]`)); + + if (update_button) + update_button.domNode.show(); + container.innerHTML += `
  • ${p.plugin}

    @@ -622,6 +691,11 @@ const Helpers = {
  • ` }); + + if (!enable_update_btn) { + container.innerHTML = `
  • ${name ? __("Plugin %s is up-to-date").replace("%s", name) : + __("All local plugins are up-to-date.")}
  • `; + } } dijit.getEnclosingWidget(dialog.domNode.querySelector(".update-btn")).attr('disabled', !enable_update_btn); -- cgit v1.2.3