From ca493459b309c7883eac6b0b30091291f61d8f89 Mon Sep 17 00:00:00 2001 From: FedericoNembrini <25205086+FedericoNembrini@users.noreply.github.com> Date: Sun, 28 Jun 2020 13:43:44 +0200 Subject: [PATCH] Add application button for temperature profiles Add "setTargetFromProfile" and "setTargetToZero" wrapper for setting entire profiles Add helper function to retrieve the temperature profiles description --- AUTHORS.md | 1 + src/octoprint/static/js/app/helpers.js | 17 +++++++++ .../static/js/app/viewmodels/temperature.js | 35 +++++++++++++++++++ src/octoprint/static/less/octoprint.less | 8 +++++ .../templates/tabs/temperature.jinja2 | 18 +++++++++- 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 32763a221..db2e16367 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -121,6 +121,7 @@ date of first contribution): * [Josh Friend](https://github.com/joshfriend) * [Lachlan Cresswell](https://github.com/lachyc) * [Khoi Pham](https://github.com/osubuu) + * [Federico Nembrini](https://github.com/FedericoNembrini) 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/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index fcc3e4e58..70bd06a38 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -621,6 +621,23 @@ function formatTemperature(temp, showF, offThreshold) { } } +// Return the temperatures string from the given temperature profile +function formatTemperatureProfileDescription(temperatureProfile, hasBed, hasChamber) { + if(temperatureProfile === undefined) return "-"; + + var temperatureProfileDescription = gettext("Extruder") + ": " + formatTemperature(temperatureProfile.extruder); + + if(hasBed) { + temperatureProfileDescription += " - " + gettext("Bed") + ": " + formatTemperature(temperatureProfile.bed); + } + + if(hasChamber) { + temperatureProfileDescription += " - " + gettext("Chamber") + ": " + formatTemperature(temperatureProfile.chamber); + } + + return temperatureProfileDescription; +} + function formatNumberK(num) { if (num > 1000) { num = num / 1000.0; diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 8965d05ff..7c1b82627 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -616,6 +616,26 @@ $(function() { return self.setTargetToValue(item, value); }; + // Wrapper of self.setTargetFromProfile() to apply all the temperature from a temperature profile + self.setTargetsFromProfile = function(temperatureProfile) { + if(temperatureProfile === undefined) { + console.log("temperatureProfile is undefined!"); + return; + } + + if(self.hasBed()) { + self.setTargetFromProfile(self.bedTemp, temperatureProfile); + } + + if(self.hasChamber()) { + self.setTargetFromProfile(self.chamberTemp, temperatureProfile); + } + + self.tools().forEach(function(element) { + self.setTargetFromProfile(element, temperatureProfile); + }); + }; + self.setTargetFromProfile = function(item, profile) { if (!profile) return OctoPrintClient.createRejectedDeferred(); @@ -634,6 +654,21 @@ $(function() { return self.setTargetToValue(item, target); }; + // Wrapper of self.setTargetToZero() to set off all the temperatures + self.setTargetsToZero = function() { + if(self.hasBed()) { + self.setTargetToZero(self.bedTemp); + } + + if(self.hasChamber()) { + self.setTargetToZero(self.chamberTemp); + } + + self.tools().forEach(function(element) { + self.setTargetToZero(element); + }); + }; + self.setTargetToZero = function(item) { self.clearAutosendTarget(item); return self.setTargetToValue(item, 0); diff --git a/src/octoprint/static/less/octoprint.less b/src/octoprint/static/less/octoprint.less index a4a7dd42e..38e718bc9 100644 --- a/src/octoprint/static/less/octoprint.less +++ b/src/octoprint/static/less/octoprint.less @@ -487,6 +487,14 @@ table { &.temperature_target { width: 42%; overflow: visible; + + & > span { + line-height: 1.9em; + } + + & > .btn-group { + float: right; + } } &.temperature_offset { diff --git a/src/octoprint/templates/tabs/temperature.jinja2 b/src/octoprint/templates/tabs/temperature.jinja2 index 96698eeb2..14a5a6799 100644 --- a/src/octoprint/templates/tabs/temperature.jinja2 +++ b/src/octoprint/templates/tabs/temperature.jinja2 @@ -9,7 +9,23 @@