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..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")), + 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/main.js b/src/octoprint/static/js/app/main.js index 0f7996871..a7697b0b8 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -122,6 +122,34 @@ $(function() { exports.onBrowserVisibilityChange = function(callback) { 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; })(); @@ -509,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); @@ -526,34 +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); - - 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(); @@ -672,10 +685,6 @@ $(function() { callViewModels(allViewModels, "onAllBound", [allViewModels]); log.info("... binding done"); - // startup complete - callViewModels(allViewModels, "onStartupComplete"); - setOnViewModels(allViewModels, "_startupComplete", true); - // make sure we can track the browser tab visibility OctoPrint.coreui.onBrowserVisibilityChange(function(status) { log.debug("Browser tab is now " + (status ? "visible" : "hidden")); @@ -683,14 +692,21 @@ $(function() { }); $(window).on("hashchange", function() { - changeTab(); + OctoPrint.coreui.updateTab(); }); - if (window.location.hash !== "") { - changeTab(); - } - 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 7c1e43b55..957886e23 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -68,9 +68,15 @@ $(function() { self.changeOffsetDialog = undefined; self.tools = ko.observableArray([]); - + self.hasTools = ko.pureComputed(function() { + return self.tools().length > 0; + }); self.hasBed = ko.observable(true); + self.visible = ko.pureComputed(function() { + return self.hasTools() || self.hasBed(); + }); + self.bedTemp = self._createToolEntry(); self.bedTemp["name"](gettext("Bed")); self.bedTemp["key"]("bed"); @@ -139,6 +145,8 @@ $(function() { self.heaterOptions(heaterOptions); self.tools(tools); + OctoPrint.coreui.updateTab(); + if (!self._printerProfileInitialized) { self._triggerBacklog(); } @@ -752,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; } @@ -764,6 +773,10 @@ $(function() { } }; + self.onAfterTabChange = function() { + self.initOrUpdate(); + }; + self.onStartup = function() { var graph = $("#temperature-graph"); if (graph.length && !OctoPrint.coreui.browser.mobile) { @@ -781,6 +794,7 @@ $(function() { }; self.onStartupComplete = function() { + self.initOrUpdate(); self._printerProfileUpdated(); }; @@ -789,6 +803,6 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: TemperatureViewModel, dependencies: ["loginStateViewModel", "settingsViewModel"], - elements: ["#temp", "#change_offset_dialog"] + elements: ["#temp", "#temp_link", "#change_offset_dialog"] }); });