From f0ee7f343efd6be98ea5bceed0983568210eb9f9 Mon Sep 17 00:00:00 2001 From: FabioSan Date: Mon, 4 Mar 2019 17:58:56 -0800 Subject: [PATCH 1/3] Hides temperature tab if the machine has no heated bed nor extruders. --- AUTHORS.md | 1 + src/octoprint/server/views.py | 2 +- src/octoprint/static/js/app/main.js | 45 ++++++++++++++----- .../static/js/app/viewmodels/temperature.js | 10 ++++- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 3428b6b41..ae9b33cf7 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -98,6 +98,7 @@ date of first contribution): * [Jubaleth](https://github.com/jubaleth) * [Daniel Joyce](https://github.com/DanielJoyce) * [Andy Qua](https://github.com/AndyQ) + * [Fabio Santos](https://github.com/Fabi0San) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 76c8d720e..4ee4051d2 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -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")), + temperature=(gettext("Temperature"), dict(template="tabs/temperature.jinja2", _div="temp", data_bind="visible: tempTabVisible")), 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")), diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index 0f7996871..e0ca0fecc 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -123,6 +123,33 @@ $(function() { browserVisibilityCallbacks.push(callback); }; + exports.hashFromTabChange = false; + exports.updateTab = function () { + if (exports.hashFromTabChange) { + exports.hashFromTabChange = false; + return; + } + var tabs = $('#tabs'); + + var hashtag = window.location.hash; + if (hashtag) { + var selectedTab = tabs.find('a[href="' + hashtag + '"]:visible'); + if (selectedTab.length) { + selectedTab.tab("show"); + return; + } + } + + var firstTab = tabs.find('a[data-toggle=tab]:visible').eq(0); + if (firstTab.length) { + var firstHash = firstTab[0].hash; + if (firstHash !== exports.selectedTab) { + firstTab.tab("show"); + } else { + window.location.hash = firstHash; + } + } + }; return exports; })(); @@ -544,16 +571,6 @@ $(function() { onTabChange(OCTOPRINT_INITIAL_TAB); onAfterTabChange(OCTOPRINT_INITIAL_TAB, undefined); - var changeTab = function() { - var hashtag = window.location.hash; - if (!hashtag) return; - - var tab = $('#tabs').find('a[href="' + hashtag + '"]'); - if (tab) { - tab.tab("show"); - } - }; - // Fix input element click problems on dropdowns $(".dropdown input, .dropdown label").click(function(e) { e.stopPropagation(); @@ -676,6 +693,10 @@ $(function() { callViewModels(allViewModels, "onStartupComplete"); setOnViewModels(allViewModels, "_startupComplete", true); + // this will also allow selecting any tabs that will be hidden later due to overflowing since our + // overflow plugin tabdrop hasn't run yet + OctoPrint.coreui.updateTab(); + // make sure we can track the browser tab visibility OctoPrint.coreui.onBrowserVisibilityChange(function(status) { log.debug("Browser tab is now " + (status ? "visible" : "hidden")); @@ -683,11 +704,11 @@ $(function() { }); $(window).on("hashchange", function() { - changeTab(); + OctoPrint.coreui.updateTab(); }); if (window.location.hash !== "") { - changeTab(); + OctoPrint.coreui.updateTab(); } log.info("Application startup complete"); diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 7c1e43b55..ffd0c8071 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -71,6 +71,8 @@ $(function() { self.hasBed = ko.observable(true); + self.tempTabVisible = ko.observable(true); + self.bedTemp = self._createToolEntry(); self.bedTemp["name"](gettext("Bed")); self.bedTemp["key"]("bed"); @@ -138,6 +140,12 @@ $(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(); + } if (!self._printerProfileInitialized) { self._triggerBacklog(); @@ -789,6 +797,6 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: TemperatureViewModel, dependencies: ["loginStateViewModel", "settingsViewModel"], - elements: ["#temp", "#change_offset_dialog"] + elements: ["#temp", "#change_offset_dialog", "#temp_link"] }); }); From 21c9c518585804be53e552b453a2a8c5c2ca30f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Mar 2019 17:29:00 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=99=BB=20Backport=20some=20more=20pieces?= =?UTF-8?q?=20from=20`devel`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/static/js/app/main.js | 39 ++++++++----------- .../static/js/app/viewmodels/temperature.js | 12 ++++-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index e0ca0fecc..a7697b0b8 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -122,13 +122,13 @@ $(function() { exports.onBrowserVisibilityChange = function(callback) { browserVisibilityCallbacks.push(callback); }; - exports.hashFromTabChange = false; - exports.updateTab = function () { + exports.updateTab = function() { if (exports.hashFromTabChange) { exports.hashFromTabChange = false; return; } + var tabs = $('#tabs'); var hashtag = window.location.hash; @@ -150,6 +150,7 @@ $(function() { } } }; + return exports; })(); @@ -536,9 +537,6 @@ $(function() { }); }; - // Use bootstrap tabdrop for tabs and pills - $('.nav-pills, .nav-tabs').tabdrop(); - // Allow components to react to tab change var onTabChange = function(current, previous) { log.debug("Selected OctoPrint tab changed: previous = " + previous + ", current = " + current); @@ -553,24 +551,22 @@ $(function() { var tabs = $('#tabs').find('a[data-toggle="tab"]'); tabs.on('show', function (e) { var current = e.target.hash; - var previous = e.relatedTarget.hash; + var previous = e.relatedTarget ? e.relatedTarget.hash : undefined; onTabChange(current, previous); }); tabs.on('shown', function (e) { var current = e.target.hash; - var previous = e.relatedTarget.hash; + var previous = e.relatedTarget ? e.relatedTarget.hash : undefined; onAfterTabChange(current, previous); // make sure we also update the hash but stick to the current scroll position var scrollmem = $('body').scrollTop() || $('html').scrollTop(); + OctoPrint.coreui.hashFromTabChange = true; window.location.hash = current; $('html,body').scrollTop(scrollmem); }); - onTabChange(OCTOPRINT_INITIAL_TAB); - onAfterTabChange(OCTOPRINT_INITIAL_TAB, undefined); - // Fix input element click problems on dropdowns $(".dropdown input, .dropdown label").click(function(e) { e.stopPropagation(); @@ -689,14 +685,6 @@ $(function() { callViewModels(allViewModels, "onAllBound", [allViewModels]); log.info("... binding done"); - // startup complete - callViewModels(allViewModels, "onStartupComplete"); - setOnViewModels(allViewModels, "_startupComplete", true); - - // this will also allow selecting any tabs that will be hidden later due to overflowing since our - // overflow plugin tabdrop hasn't run yet - OctoPrint.coreui.updateTab(); - // make sure we can track the browser tab visibility OctoPrint.coreui.onBrowserVisibilityChange(function(status) { log.debug("Browser tab is now " + (status ? "visible" : "hidden")); @@ -707,11 +695,18 @@ $(function() { OctoPrint.coreui.updateTab(); }); - if (window.location.hash !== "") { - OctoPrint.coreui.updateTab(); - } - log.info("Application startup complete"); + + // startup complete + callViewModels(allViewModels, "onStartupComplete"); + setOnViewModels(allViewModels, "_startupComplete", true); + + // this will also allow selecting any tabs that will be hidden later due to overflowing since our + // overflow plugin tabdrop hasn't run yet + OctoPrint.coreui.updateTab(); + + // Use bootstrap tabdrop for tabs and pills + $('.nav-pills, .nav-tabs').tabdrop(); }; var fetchSettings = function() { diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index ffd0c8071..9fd1aa345 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -760,8 +760,9 @@ $(function() { } }; - self.onAfterTabChange = function(current, previous) { - if (current !== "#temp") { + self.initOrUpdate = function() { + if (OctoPrint.coreui.selectedTab !== "#temp" || !$("#temp").is(":visible")) { + // do not try to initialize the graph when it's not visible or its sizing will be off return; } @@ -772,6 +773,10 @@ $(function() { } }; + self.onAfterTabChange = function() { + self.initOrUpdate(); + }; + self.onStartup = function() { var graph = $("#temperature-graph"); if (graph.length && !OctoPrint.coreui.browser.mobile) { @@ -789,6 +794,7 @@ $(function() { }; self.onStartupComplete = function() { + self.initOrUpdate(); self._printerProfileUpdated(); }; @@ -797,6 +803,6 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: TemperatureViewModel, dependencies: ["loginStateViewModel", "settingsViewModel"], - elements: ["#temp", "#change_offset_dialog", "#temp_link"] + elements: ["#temp", "#temp_link", "#change_offset_dialog"] }); }); From 92ad53a9eccf7415d59a08eda2a9c60f8497f7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Mar 2019 17:29:00 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=20Use=20ko=20computed=20for=20vis?= =?UTF-8?q?ibility=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/views.py | 2 +- .../static/js/app/viewmodels/temperature.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 4ee4051d2..b3dc4939a 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -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")), diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 9fd1aa345..957886e23 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -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();