From 603cc8963871fe382ee71a083692ff0d81460322 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 7 Mar 2021 20:11:54 +0300 Subject: check updates one plugin at a time --- js/PrefHelpers.js | 128 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 78 insertions(+), 50 deletions(-) (limited to 'js/PrefHelpers.js') diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 04ee10a41..eaa571a89 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -358,7 +358,7 @@ const Helpers = { // only user-enabled actually counts in the checkbox when saving because system plugin checkboxes are disabled (see below) container.innerHTML += ` -
  • +
  • ${p.plugin}

    - ${p.rv.e ? `
    ${p.rv.e}
    ` : ''} - ${p.rv.o ? `
    ${p.rv.o}
    ` : ''} + ${p.rv.stderr ? `
    ${p.rv.stderr}
    ` : ''} + ${p.rv.stdout ? `
    ${p.rv.stdout}
    ` : ''}
    - ${p.rv.s ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.s) : + ${p.rv.git_status ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.git_status) : App.FormFields.icon("check") + " " + __("Update done.")}
  • @@ -648,67 +649,94 @@ const Helpers = { dijit.getEnclosingWidget(dialog.domNode.querySelector(".update-btn")).attr('disabled', !enable_update_btn); }); }, - content: ` - + checkNextPlugin: function() { + const name = dialog.plugins_to_check.shift(); - - `, - }); + if (name) { + this.checkUpdates(name); + } else { + const num_updated = dialog.plugins_to_update.length; - const tmph = dojo.connect(dialog, 'onShow', function () { - dojo.disconnect(tmph); + if (num_updated > 0) + dialog.attr('title', + App.l10n.ngettext('Updates pending for %d plugin', 'Updates pending for %d plugins', num_updated) + .replace("%d", num_updated)); + else + dialog.attr('title', __("No updates available")); + + dijit.getEnclosingWidget(dialog.domNode.querySelector(".update-btn")) + .attr('disabled', num_updated == 0); + + } + }, + checkUpdates: function(name) { + console.log('checkUpdates', name); - xhr.json("backend.php", {op: "pref-prefs", method: "checkForPluginUpdates", name: name}, (reply) => { const container = dialog.domNode.querySelector(".update-results"); - let enable_update_btn = false; - if (!reply) { - container.innerHTML = `
  • ${__("Operation failed: check event log.")}
  • `; - } else { - container.innerHTML = ""; + dialog.attr('title', __("Checking: %s").replace("%s", name)); - dialog.plugins_to_update = []; + //container.innerHTML = `
  • ${__("Checking: %s...").replace("%s", name)}
  • `; - reply.forEach((p) => { - if (p.rv.s == 0) { - enable_update_btn = true; - dialog.plugins_to_update.push(p.plugin); - } + xhr.json("backend.php", {op: "pref-prefs", method: "checkForPluginUpdates", name: name}, (reply) => { - const update_button = dijit.getEnclosingWidget( - App.find(`*[data-update-btn-for-plugin="${p.plugin}"]`)); + if (!reply) { + container.innerHTML += `
  • ${__("%s: Operation failed: check event log.").replace("%s", name)}
  • `; + } else { - if (update_button) - update_button.domNode.show(); + reply.forEach((p) => { + if (p.rv.need_update) { + dialog.plugins_to_update.push(p.plugin); - container.innerHTML += - ` -
  • ${p.plugin}

    - ${p.rv.e ? `
    ${p.rv.e}
    ` : ''} - ${p.rv.o ? `
    ${p.rv.o}
    ` : ''} -
    - ${p.rv.s ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.s) : - App.FormFields.icon("check") + " " + __("Ready to update")} -
    -
  • - ` - }); + const update_button = dijit.getEnclosingWidget( + App.find(`*[data-update-btn-for-plugin="${p.plugin}"]`)); - if (!enable_update_btn) { - container.innerHTML = `
  • ${name ? __("Plugin %s is up-to-date").replace("%s", name) : - __("All local plugins are up-to-date.")}
  • `; + if (update_button) + update_button.domNode.show(); + } + + if (p.rv.need_update || p.rv.git_status != 0) { + container.innerHTML += + ` +
  • ${p.plugin}

    + ${p.rv.stderr ? `
    ${p.rv.stderr}
    ` : ''} + ${p.rv.stdout ? `
    ${p.rv.stdout}
    ` : ''} +
    + ${p.rv.git_status ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.git_status) : + App.FormFields.icon("check") + " " + __("Ready to update")} +
    +
  • + ` + } + dialog.checkNextPlugin(); + }); } - } - dijit.getEnclosingWidget(dialog.domNode.querySelector(".update-btn")).attr('disabled', !enable_update_btn); + }); - }); + }, + content: ` + + + `, + }); + + const tmph = dojo.connect(dialog, 'onShow', function () { + dojo.disconnect(tmph); + + dialog.plugins_to_update = []; + + if (name) { + dialog.checkUpdates(name); + } else { + dialog.plugins_to_check = [...document.querySelectorAll('*[data-plugin-name][data-plugin-local=true]')].map((p) => p.getAttribute('data-plugin-name')); + dialog.checkNextPlugin(); + } }); dialog.show(); -- cgit v1.2.3