diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 32fab98c2..b395d0db4 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -540,17 +540,17 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, json_data = flask.request.json - if "check" in json_data: - check_targets = map(lambda x: x.strip(), json_data["check"]) + if "targets" in json_data: + targets = map(lambda x: x.strip(), json_data["targets"]) else: - check_targets = None + targets = None if "force" in json_data and json_data["force"] in octoprint.settings.valid_boolean_trues: force = True else: force = False - to_be_checked, checks = self.perform_updates(check_targets=check_targets, force=force) + to_be_checked, checks = self.perform_updates(targets=targets, force=force) return flask.jsonify(dict(order=to_be_checked, checks=checks)) #~~ Asset API @@ -771,13 +771,15 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_dirty = True return information, update_available, update_possible, online, error - def perform_updates(self, check_targets=None, force=False): + def perform_updates(self, force=False, **kwargs): """ Performs the updates for the given check_targets. Will update all possible targets by default. - :param check_targets: an iterable defining the targets to update, if not supplied defaults to all targets + :param targets: an iterable defining the targets to update, if not supplied defaults to all targets """ + targets = kwargs.get("targets", kwargs.get("check_targets", None)) + checks = self._get_configured_checks() populated_checks = dict() for target, check in checks.items(): @@ -788,9 +790,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, except: self._logger.exception("Error while populating check prior to update for target {}".format(target)) - if check_targets is None: - check_targets = populated_checks.keys() - to_be_updated = sorted(set(check_targets) & set(populated_checks.keys())) + if targets is None: + targets = populated_checks.keys() + to_be_updated = sorted(set(targets) & set(populated_checks.keys())) if "octoprint" in to_be_updated: to_be_updated.remove("octoprint") tmp = ["octoprint"] + to_be_updated diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 45c325fbc..6a1192f43 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -37,7 +37,7 @@ }; OctoPrintSoftwareUpdateClient.prototype.check = function(force, opts) { - if (arguments.length == 1 && _.isObject(arguments[0])) { + if (arguments.length === 1 && _.isObject(arguments[0])) { var params = arguments[0]; force = params.force; opts = params.opts; @@ -46,28 +46,28 @@ return this.checkEntries({entries: [], force: force, opts: opts}); }; - OctoPrintSoftwareUpdateClient.prototype.update = function(entries, force, opts) { - if (arguments.length == 1 && _.isObject(arguments[0])) { + OctoPrintSoftwareUpdateClient.prototype.update = function(targets, force, opts) { + if (arguments.length === 1 && _.isObject(arguments[0])) { var params = arguments[0]; - entries = params.entries; + targets = params.targets; force = params.force; opts = params.opts; } - entries = entries || []; - if (typeof entries == "string") { - entries = [entries]; + targets = targets || []; + if (typeof targets === "string") { + targets = [targets]; } var data = { - entries: entries, + targets: targets, force: !!force }; return this.base.postJson(this.updateUrl, data, opts); }; OctoPrintSoftwareUpdateClient.prototype.updateAll = function(force, opts) { - if (arguments.length == 1 && _.isObject(arguments[0])) { + if (arguments.length === 1 && _.isObject(arguments[0])) { var params = arguments[0]; force = params.force; opts = params.opts; @@ -92,8 +92,6 @@ $(function() { self.settings = parameters[2]; self.popup = undefined; - self.forceUpdate = false; - self.updateInProgress = false; self.waitingForRestart = false; self.restartTimeout = undefined; @@ -140,7 +138,6 @@ $(function() { }); self.configurationDialog = undefined; - self.confirmationDialog = undefined; self._updateClicked = false; self.config_availableCheckTypes = ko.observableArray([]); @@ -504,6 +501,7 @@ $(function() { self.performUpdate = function(force, items) { if (!self.loginState.isAdmin()) return; + if (self.printerState.isPrinting()) return; self.updateInProgress = true; @@ -519,7 +517,7 @@ $(function() { }; self._showPopup(options); - OctoPrint.plugins.softwareupdate.updateAll(force, items) + OctoPrint.plugins.softwareupdate.update(items, force) .done(function(data) { self.currentlyBeingUpdated = data.checks; self._markWorking(gettext("Updating..."), gettext("Updating, please wait.")); @@ -538,7 +536,7 @@ $(function() { }); }; - self.update = function(force) { + self.update = function(force, items) { if (self.updateInProgress) { self._updateClicked = false; return; @@ -548,6 +546,10 @@ $(function() { return; } + if (items === undefined) { + items = self.availableAndPossible(); + } + if (self.printerState.isPrinting()) { self._showPopup({ title: gettext("Can't update while printing"), @@ -556,22 +558,37 @@ $(function() { }); self._updateClicked = false; } else { - self.forceUpdate = (force == true); - self.confirmationDialog.modal("show"); + var html = "
" + gettext("This will update the following components and restart the server:") + "
"; + html += "" + gettext("Be sure to read through any linked release notes, especially those for OctoPrint since they might contain important information you need to know before upgrading.") + "
" + + "" + gettext("This action may disrupt any ongoing print jobs.") + "
" + + "" + gettext("Depending on your printer's controller and general setup, restarting OctoPrint may cause your printer to be reset.") + "
" + + "" + gettext("Are you sure you want to proceed?") + "
"; + showConfirmationDialog({ + title: gettext("Are you sure you want to update now?"), + html: html, + proceed: gettext("Proceed"), + onproceed: function() { + self.performUpdate((force === true), + _.map(items, function(info) { return info.key })); + }, + onclose: function() { + self._updateClicked = false; + } + }); } }; - self.confirmUpdate = function() { - self.performUpdate(self.forceUpdate, - _.map(self.availableAndPossible(), function(info) { return info.key })); - self.confirmationDialog.modal("hide"); - }; - - self.confirmationHidden = function() { - self._updateClicked = false; - }; - self._showWorkingDialog = function(title) { if (!self.loginState.isAdmin()) { return; @@ -628,9 +645,6 @@ $(function() { self.workingDialog = $("#settings_plugin_softwareupdate_workingdialog"); self.workingOutput = $("#settings_plugin_softwareupdate_workingdialog_output"); self.configurationDialog = $("#settings_plugin_softwareupdate_configurationdialog"); - self.confirmationDialog = $("#softwareupdate_confirmation_dialog"); - - self.confirmationDialog.on("hidden", self.confirmationHidden); }; self.onServerDisconnect = function() { diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate.jinja2 deleted file mode 100644 index 725b2bf98..000000000 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate.jinja2 +++ /dev/null @@ -1,35 +0,0 @@ - diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index a8a60fed6..68b61d78a 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -29,6 +29,7 @@