SWU: Support updating single items via UI

Closes #2615
This commit is contained in:
Gina Häußge committed 2018-05-05 15:13:25 +02:00
1 parent bfbf9fb66e
commit 99ef84788a
4 files changed
+57 -74

No files matched your search

@@ -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
@@ -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 = "<p>" + gettext("This will update the following components and restart the server:") + "</p>";
html += "<ul>";
_.each(items, function(item) {
html += "<li>"
+ "<span class=\"name\" title=\"" + item.fullNameRemote + "\">" + item.fullNameRemote + "</span>";
if (item.releaseNotes) {
html += "<br><a href=\"" + item.releaseNotes + "\" target=\"_blank\" rel=\"noreferrer noopener\">" + gettext("Release Notes") + "</a>"
}
html += "</li>";
});
html += "</ul>";
html += "<p>" + gettext("Be sure to read through any linked release notes, especially those for OctoPrint since they might contain important information you need to know <strong>before</strong> upgrading.") + "</p>"
+ "<p><strong>" + gettext("This action may disrupt any ongoing print jobs.") + "</strong></p>"
+ "<p>" + gettext("Depending on your printer's controller and general setup, restarting OctoPrint may cause your printer to be reset.") + "</p>"
+ "<p>" + gettext("Are you sure you want to proceed?") + "</p>";
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() {
@@ -1,35 +0,0 @@
<div id="softwareupdate_confirmation_dialog" class="modal hide fade">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
<h3>{{ _('Are you sure you want to update now?') }}</h3>
</div>
<div class="modal-body">
<p>
{{ _('This will update the following components and restart the server:') }}
</p>
<ul>
<!-- ko foreach: availableAndPossible -->
<li>
<span class="name" data-bind="text: fullNameRemote, attr: {title: fullNameRemote}"></span>
<div class="releaseNotes" data-bind="visible: releaseNotes"><a data-bind="attr: {href: releaseNotes}" target="_blank" rel="noreferrer noopener">{{ _('Release Notes') }}</a></div>
</li>
<!-- /ko -->
</ul>
<p>
{{ _('Be sure to read through any linked release notes, especially those for OctoPrint since they might contain important information you need to know <strong>before</strong> upgrading.') }}
</p>
<p>
<strong>{{ _('This action may disrupt any ongoing print jobs.') }}</strong>
</p>
<p>
{{ _('Depending on your printer\'s controller and general setup, restarting OctoPrint may cause your printer to be reset.') }}
</p>
<p>
{{ _('Are you sure you want to proceed?') }}
</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" aria-hidden="true">{{ _('Cancel') }}</a>
<a href="#" class="btn btn-danger" data-bind="click: function() { $root.confirmUpdate(); }">{{ _('Proceed') }}</a>
</div>
</div>
@@ -29,6 +29,7 @@
<span data-bind="invisible: !updateAvailable"><i class="fa fa-bell-o" title="{{ _('Update available') }}"></i></span>
</td>
<td class="settings_plugin_softwareupdate_column_information">
<a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$data]) }, visible: updateAvailable" class="btn btn-primary pull-right">{{ _('Update') }}</a>
<strong data-bind="text: displayName"></strong>: <span data-bind="text: displayVersion"></span> <span data-bind="invisible: updatePossible"><i class="fa fa-exclamation-triangle" data-bind="css: {'fa-unlink': !online && information && information.needs_online, 'fa-exclamation-triangle': !(!online && information && information.needs_online)}, attr: {title: $root.iconTitleForEntry($data)}"></i></span><br>
<small class="muted">
<span class="line">{{ _('Installed:') }} <span data-bind="text: information.local.name"></span></span>
@@ -58,7 +59,8 @@
</ul>
</div>
<button class="btn btn-primary btn-block" data-bind="click: function() { $root.performCheck(true, false, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fa fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Check for update now') }}</button>
<button class="btn btn-primary btn-block" data-bind="click: function() { $root.update(); }, enable: !updateInProgress, css: {disabled: updateInProgress}"><i class="fa fa-spinner fa-spin" data-bind="visible: updateInProgress"></i> {{ _('Update all') }}</button>
<button class="btn btn-block" data-bind="click: function() { $root.performCheck(true, false, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fa fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Check for update now') }}</button>
<div>
<div><small><a href="#" class="muted" onclick="$(this).children().toggleClass('fa-caret-right fa-caret-down').parent().parent().parent().next().slideToggle('fast')"><i class="fa fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>