SWU: Added cache timestamp to UI

Implements #1521
This commit is contained in:
Gina Häußge 2017-05-11 12:44:48 +02:00
parent b6fbe6fafd
commit 3bfc4725d2
3 changed files with 16 additions and 2 deletions

View file

@ -50,6 +50,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._version_cache_ttl = 0
self._version_cache_path = None
self._version_cache_dirty = False
self._version_cache_timestamp = None
self._console_logger = None
@ -156,6 +157,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
try:
with open(self._version_cache_path) as f:
data = yaml.safe_load(f)
timestamp = os.stat(self._version_cache_path).st_mtime
except:
self._logger.exception("Error while loading version cache from disk")
else:
@ -178,6 +180,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._version_cache = data
self._version_cache_dirty = False
self._version_cache_timestamp = timestamp
self._logger.info("Loaded version cache from disk")
except:
self._logger.exception("Error parsing in version cache data")
@ -194,6 +197,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
yaml.safe_dump(self._version_cache, stream=file_obj, default_flow_style=False, indent=" ", allow_unicode=True)
self._version_cache_dirty = False
self._version_cache_timestamp = time.time()
self._logger.info("Saved version cache to disk")
#~~ SettingsPlugin API
@ -463,7 +467,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
data["check"]["python_updater"] = True
return flask.jsonify(dict(status="updatePossible" if update_available and update_possible else "updateAvailable" if update_available else "current",
information=information))
information=information,
timestamp=self._version_cache_timestamp))
except exceptions.ConfigurationInvalid as e:
return flask.make_response("Update not properly configured, can't proceed: %s" % e.message, 500)
@ -489,6 +494,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
hash.update(str(data["possible"]))
hash.update(",".join(targets))
hash.update(str(self._version_cache_timestamp))
return hash.hexdigest()
def condition():

View file

@ -111,6 +111,11 @@ $(function() {
self.octoprintUnconfigured = ko.observable();
self.octoprintUnreleased = ko.observable();
self.cacheTimestamp = ko.observable();
self.cacheTimestampText = ko.pureComputed(function() {
return formatDate(self.cacheTimestamp());
});
self.config_cacheTtl = ko.observable();
self.config_notifyUsers = ko.observable();
self.config_checkoutFolder = ko.observable();
@ -256,6 +261,8 @@ $(function() {
};
self.fromCheckResponse = function(data, ignoreSeen, showIfNothingNew) {
self.cacheTimestamp(data.timestamp);
var versions = [];
_.each(data.information, function(value, key) {
value["key"] = key;

View file

@ -62,8 +62,9 @@
<div>
<div><small><a href="#" class="muted" onclick="$(this).children().toggleClass('icon-caret-right icon-caret-down').parent().parent().parent().next().slideToggle('fast')"><i class="icon-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
<div class="hide">
<small class="muted" style="display: block">Last cache refresh: <span data-bind="text: cacheTimestampText"></span></small>
<button class="btn btn-block" data-bind="click: function() { $root.performCheck(true, true, true); }, enable: !checking(), css: {disabled: checking()}"><i class="icon-spinner icon-spin" data-bind="visible: checking"></i> {{ _('Force check for update (overrides cache used for update checks)') }}</button>
<button class="btn btn-block btn-danger" data-bind="visible: CONFIG_DEBUG, click: function() { $root.update(true); }">{{ _('Force update now (even if no new versions are available)') }}</button>
<button class="btn btn-block btn-danger" data-bind="visible: CONFIG_DEBUG, click: function() { $root.update(true); }, enable: !checking(), css: {disabled: checking()}"><i class="icon-spinner icon-spin" data-bind="visible: checking"></i> {{ _('Force update now (even if no new versions are available)') }}</button>
</div>
</div>