♻ Use ko computed for visibility state

This commit is contained in:
Gina Häußge committed 2019-03-12 13:42:45 +01:00
1 parent 21c9c51858
commit 92ad53a9ec
2 files changed
+8 -8

No files matched your search

+1 -1
View File
@@ -560,7 +560,7 @@ def fetch_template_data(refresh=False):
# tabs
templates["tab"]["entries"] = dict(
temperature=(gettext("Temperature"), dict(template="tabs/temperature.jinja2", _div="temp", data_bind="visible: tempTabVisible")),
temperature=(gettext("Temperature"), dict(template="tabs/temperature.jinja2", _div="temp", data_bind="visible: visible")),
control=(gettext("Control"), dict(template="tabs/control.jinja2", _div="control")),
gcodeviewer=(gettext("GCode Viewer"), dict(template="tabs/gcodeviewer.jinja2", _div="gcode")),
terminal=(gettext("Terminal"), dict(template="tabs/terminal.jinja2", _div="term")),
@@ -68,10 +68,14 @@ $(function() {
self.changeOffsetDialog = undefined;
self.tools = ko.observableArray([]);
self.hasTools = ko.pureComputed(function() {
return self.tools().length > 0;
});
self.hasBed = ko.observable(true);
self.tempTabVisible = ko.observable(true);
self.visible = ko.pureComputed(function() {
return self.hasTools() || self.hasBed();
});
self.bedTemp = self._createToolEntry();
self.bedTemp["name"](gettext("Bed"));
@@ -140,12 +144,8 @@ $(function() {
// write back
self.heaterOptions(heaterOptions);
self.tools(tools);
var tempTabVisible = self.hasBed() || numExtruders > 0;
if (tempTabVisible !== self.tempTabVisible()) {
self.tempTabVisible(tempTabVisible);
OctoPrint.coreui.updateTab();
}
OctoPrint.coreui.updateTab();
if (!self._printerProfileInitialized) {
self._triggerBacklog();