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"] }); });