🚸 Display errors during loading

Also allow disabling loading screen.

Implements #3298
This commit is contained in:
Gina Häußge committed 2019-10-24 17:14:33 +02:00
1 parent d8bd684f96
commit 017515dcc1
7 files changed
+126 -89

No files matched your search

+3
View File
@@ -290,6 +290,9 @@ The following settings are only relevant to you if you want to do OctoPrint deve
# Whether to delete generated web assets on server startup (forcing a regeneration)
clean_on_startup: true
# enable or disable the loading animation
showLoadingAnimation: true
# Settings for the virtual printer
virtualPrinter:
+3
View File
@@ -185,6 +185,7 @@ def index():
enable_accesscontrol = userManager.enabled
enable_gcodeviewer = settings().getBoolean(["gcodeViewer", "enabled"])
enable_timelapse = settings().getBoolean(["webcam", "timelapseEnabled"])
enable_loading_animation = settings().getBoolean(["devel", "showLoadingAnimation"])
def default_template_filter(template_type, template_key):
if template_type == "navbar":
@@ -202,6 +203,7 @@ def index():
default_additional_etag = [enable_accesscontrol,
enable_gcodeviewer,
enable_timelapse,
enable_loading_animation,
wizard_active(_templates.get(locale))] + sorted(["{}:{}".format(to_unicode(k, errors="replace"),
to_unicode(v, errors="replace"))
for k, v in _plugin_vars.items()])
@@ -368,6 +370,7 @@ def index():
enableTemperatureGraph=settings().get(["feature", "temperatureGraph"]),
enableAccessControl=enable_accesscontrol,
accessControlActive=accesscontrol_active,
enableLoadingAnimation=enable_loading_animation,
enableSdSupport=settings().get(["feature", "sdSupport"]),
gcodeMobileThreshold=settings().get(["gcodeViewer", "mobileSizeThreshold"]),
gcodeThreshold=settings().get(["gcodeViewer", "sizeThreshold"]),
+1
View File
@@ -410,6 +410,7 @@ default_settings = {
"clean_on_startup": True
},
"useFrozenDictForPrinterState": True,
"showLoadingAnimation": True,
"virtualPrinter": {
"enabled": False,
"okAfterResend": False,
+101 -86
View File
@@ -590,113 +590,118 @@ $(function() {
}
var bindViewModels = function() {
log.info("Going to bind " + allViewModelData.length + " view models...");
_.each(allViewModelData, function(viewModelData) {
try {
if (!Array.isArray(viewModelData) || viewModelData.length !== 2) {
log.error("View model data for", viewModel.constructor.name, "has wrong format, expected 2-tuple (viewModel, targets), got:", viewModelData);
return;
}
var viewModel = viewModelData[0];
var targets = viewModelData[1];
if (targets === undefined) {
log.error("No binding targets defined for view model", viewMode.constructor.name);
return;
}
if (!_.isArray(targets)) {
targets = [targets];
}
try {
log.info("Going to bind " + allViewModelData.length + " view models...");
_.each(allViewModelData, function (viewModelData) {
try {
callViewModel(viewModel, "onBeforeBinding", undefined, true);
} catch (exc) {
log.error("Error calling onBeforeBinding on view model", viewModel.constructor.name, ":", (exc.stack || exc));
return;
}
if (!Array.isArray(viewModelData) || viewModelData.length !== 2) {
log.error("View model data for", viewModelData.constructor.name, "has wrong format, expected 2-tuple (viewModel, targets), got:", viewModelData);
return;
}
var viewModel = viewModelData[0];
var targets = viewModelData[1];
if (targets === undefined) {
log.error("No binding targets defined for view model", viewMode.constructor.name);
return;
}
if (targets !== undefined) {
if (!_.isArray(targets)) {
targets = [targets];
}
viewModel._bindings = [];
try {
callViewModel(viewModel, "onBeforeBinding", undefined, true);
} catch (exc) {
log.error("Error calling onBeforeBinding on view model", viewModel.constructor.name, ":", (exc.stack || exc));
return;
}
_.each(targets, function (target) {
if (target === undefined) {
log.error("Undefined target for view model", viewModel.constructor.name);
return;
if (targets !== undefined) {
if (!_.isArray(targets)) {
targets = [targets];
}
var object;
if (!(target instanceof jQuery)) {
try {
object = $(target);
} catch (exc) {
log.error("Error while attempting to jquery-fy target", target, "of view model", viewModel.constructor.name, ":", (exc.stack || exc));
viewModel._bindings = [];
_.each(targets, function (target) {
if (target === undefined) {
log.error("Undefined target for view model", viewModel.constructor.name);
return;
}
} else {
object = target;
}
if (object === undefined || !object.length) {
log.info("Did not bind view model", viewModel.constructor.name, "to target", target, "since it does not exist");
return;
}
var object;
if (!(target instanceof jQuery)) {
try {
object = $(target);
} catch (exc) {
log.error("Error while attempting to jquery-fy target", target, "of view model", viewModel.constructor.name, ":", (exc.stack || exc));
return;
}
} else {
object = target;
}
var element = object.get(0);
if (element === undefined) {
log.info("Did not bind view model", viewModel.constructor.name, "to target", target, "since it does not exist");
return;
}
if (object === undefined || !object.length) {
log.info("Did not bind view model", viewModel.constructor.name, "to target", target, "since it does not exist");
return;
}
try {
ko.applyBindings(viewModel, element);
viewModel._bindings.push(target);
var element = object.get(0);
if (element === undefined) {
log.info("Did not bind view model", viewModel.constructor.name, "to target", target, "since it does not exist");
return;
}
callViewModel(viewModel, "onBoundTo", [target, element], true);
try {
ko.applyBindings(viewModel, element);
viewModel._bindings.push(target);
log.debug("View model", viewModel.constructor.name, "bound to", target);
} catch (exc) {
log.error("Could not bind view model", viewModel.constructor.name, "to target", target, ":", (exc.stack || exc));
}
});
}
callViewModel(viewModel, "onBoundTo", [target, element], true);
viewModel._unbound = viewModel._bindings === undefined || viewModel._bindings.length === 0;
viewModel._bound = viewModel._bindings && viewModel._bindings.length > 0;
log.debug("View model", viewModel.constructor.name, "bound to", target);
} catch (exc) {
log.error("Could not bind view model", viewModel.constructor.name, "to target", target, ":", (exc.stack || exc));
}
});
}
callViewModel(viewModel, "onAfterBinding");
} catch (exc) {
var name;
try {
name = viewModel.constructor.name;
viewModel._unbound = viewModel._bindings === undefined || viewModel._bindings.length === 0;
viewModel._bound = viewModel._bindings && viewModel._bindings.length > 0;
callViewModel(viewModel, "onAfterBinding");
} catch (exc) {
name = "n/a";
var name;
try {
name = viewModel.constructor.name;
} catch (exc) {
name = "n/a";
}
log.error("Error while processing view model", name, "for binding:", (exc.stack || exc));
}
log.error("Error while processing view model", name, "for binding:", (exc.stack || exc));
}
});
});
callViewModels(allViewModels, "onAllBound", [allViewModels]);
log.info("... binding done");
callViewModels(allViewModels, "onAllBound", [allViewModels]);
log.info("... binding done");
// make sure we can track the browser tab visibility
OctoPrint.coreui.onBrowserVisibilityChange(function(status) {
log.debug("Browser tab is now " + (status ? "visible" : "hidden"));
callViewModels(allViewModels, "onBrowserTabVisibilityChange", [status]);
});
// make sure we can track the browser tab visibility
OctoPrint.coreui.onBrowserVisibilityChange(function (status) {
log.debug("Browser tab is now " + (status ? "visible" : "hidden"));
callViewModels(allViewModels, "onBrowserTabVisibilityChange", [status]);
});
$(window).on("hashchange", function() {
OctoPrint.coreui.updateTab();
});
$(window).on("hashchange", function () {
OctoPrint.coreui.updateTab();
});
log.info("Application startup complete");
log.info("Application startup complete");
viewModelMap["uiStateViewModel"].loading(false);
viewModelMap["uiStateViewModel"].loading(false);
} catch (exc) {
viewModelMap["uiStateViewModel"].showLoadingError("Application startup failed.");
throw(exc);
}
// startup complete
callViewModels(allViewModels, "onStartupComplete");
@@ -740,6 +745,9 @@ $(function() {
// Decoupling all consecutive calls from this done event handler hence is an easy way
// to avoid this problem. A zero timeout should do the trick nicely.
window.setTimeout(bindViewModels, 0);
})
.fail(function() {
viewModelMap["uiStateViewModel"].showLoadingError("Initial settings fetch failed.");
});
};
@@ -787,6 +795,9 @@ $(function() {
// This is to ensure that we have no concurrent requests triggered by socket events
// overriding each other's session during app initialization
dataUpdater.initialized();
})
.fail(function() {
viewModelMap["uiStateViewModel"].showLoadingError("Passive login failed.");
});
};
@@ -797,10 +808,14 @@ $(function() {
dataUpdater.connectCallback = onServerConnect;
// perform passive login first
onServerConnect().done(function() {
// then trigger a settings fetch
window.setTimeout(fetchSettings, 0);
});
onServerConnect()
.done(function() {
// then trigger a settings fetch
window.setTimeout(fetchSettings, 0);
});
})
.fail(function() {
viewModelMap["uiStateViewModel"].showLoadingError("Socket connection failed.");
});
}
);
@@ -5,7 +5,8 @@ $(function() {
self.loginState = parameters[0];
self.access = parameters[1];
self.loading = ko.observable(true);
self.loading = ko.observable(CONFIG_LOADINGANIMATION);
self.loading_error = ko.observable(false);
self.needlogin = ko.computed(function() {
return !self.loading() && !self.loginState.hasPermissionKo(self.access.permissions.STATUS)();
});
@@ -38,6 +39,15 @@ $(function() {
}
});
};
self.showLoadingError = function(error) {
log.error("Loading error: " + error + " Please check prior messages and 'octoprint.log' for possible reasons.");
// we can't do this with bindings since the bindings are not initialized yet if we need this
$("#page-container-loading-header").text("Loading failed");
$("#page-container-loading-spinner").removeClass("fa-spinner fa-spin").addClass("fa-exclamation-triangle text-error");
$("#page-container-loading-error").html(error + " " + _.sprintf("Please check your <a href='%(browser)s' target='_blank' rel='noopener noreferrer'>browser's error console</a> and <code><a href='%(octoprint)s' target='_blank' rel='noopener noreferrer'>octoprint.log</a></code> for possible reasons.", {browser: "https://faq.octoprint.org/browser-console", octoprint: "https://faq.octoprint.org/logs"})).show();
};
}
OCTOPRINT_VIEWMODELS.push({
+6 -2
View File
@@ -16,7 +16,7 @@
{% include 'initscript.jinja2' %}
</head>
<body>
<div class="page-container" id="page-container-main" style="display: none" data-bind="visible: visible">
<div class="page-container" id="page-container-main" {% if enableLoadAnimation -%}style="display: none"{%- endif %} data-bind="visible: visible">
<!-- ko allowBindings: false -->
<div id="navbar" class="navbar navbar-static-top">
<div class="navbar-inner" data-bind="css: appearanceClasses">
@@ -153,17 +153,21 @@
<!-- /ko -->
</div>
{% if enableLoadingAnimation %}
<div id="page-container-loading" data-bind="visible: loading">
<div class="wrapper">
<div class="outer">
<div class="inner">
<div class="content">
<i class="fa fa-spinner fa-spin fa-4x"></i>
<h1 id="page-container-loading-header">Loading OctoPrint's UI, please wait...</h1>
<i id="page-container-loading-spinner" class="fa fa-spinner fa-spin fa-4x"></i>
<p id="page-container-loading-error" style="display: none"></p>
</div>
</div>
</div>
</div>
</div>
{% endif %}
<div class="container" id="page-container-needlogin" style="display: none" data-bind="visible: needlogin">
<form class="form-signin">
@@ -5,6 +5,7 @@
var GCODE_WORKER = "{{ url_for('static', filename='gcodeviewer/js/Worker.js') }}";
var CONFIG_DEBUG = {% if debug -%} true; {% else %} false; {%- endif %}
var CONFIG_LOADINGANIMATION = {% if enableLoadingAnimation -%} true; {% else %} false; {%- endif %}
var CONFIG_GCODEFILESPERPAGE = 5000;
var CONFIG_TIMELAPSEFILESPERPAGE = 10;