🐛 Remove use of HTML entity degree symbol in temperature title attribute (#4490)
* Use unicode degree symbol in title attribute
This commit is contained in:
1 parent
671829a4f1
commit
1a5de41a0f
5 files changed
+134
-4
No files matched your search
@@ -165,6 +165,7 @@ date of first contribution):
|
||||
* [Johan Verrept](https://github.com/JoveToo)
|
||||
* [Nicu Surdu](https://github.com/surdu)
|
||||
* [Zack Lewis](https://github.com/lima3w)
|
||||
* [Billy Richardson](https://github.com/richardsondev)
|
||||
|
||||
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
|
||||
|
||||
@@ -652,13 +652,25 @@ function cleanTemperature(temp, offThreshold) {
|
||||
return temp;
|
||||
}
|
||||
|
||||
function formatTemperature(temp, showF, offThreshold) {
|
||||
function formatTemperature(temp, showF, offThreshold, returnUnicode) {
|
||||
if (temp === undefined || !_.isNumber(temp)) return "-";
|
||||
if (offThreshold !== undefined && temp < offThreshold) return gettext("off");
|
||||
|
||||
var degreeSymbol = "°";
|
||||
if (returnUnicode !== undefined && returnUnicode) {
|
||||
degreeSymbol = "\u00B0";
|
||||
}
|
||||
|
||||
if (showF) {
|
||||
return _.sprintf("%.1f°C (%.1f°F)", temp, (temp * 9) / 5 + 32);
|
||||
return _.sprintf(
|
||||
"%.1f%sC (%.1f%sF)",
|
||||
temp,
|
||||
degreeSymbol,
|
||||
(temp * 9) / 5 + 32,
|
||||
degreeSymbol
|
||||
);
|
||||
} else {
|
||||
return _.sprintf("%.1f°C", temp);
|
||||
return _.sprintf("%.1f%sC", temp, degreeSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
|
||||
<script type="text/html" id="temprow-template">
|
||||
<th class="temperature_tool" data-bind="text: name, attr: {title: name}"></th>
|
||||
<td class="temperature_actual" data-bind="html: formatTemperature(actual()), attr: {title: formatTemperature(actual())}"></td>
|
||||
<td class="temperature_actual" data-bind="html: formatTemperature(actual()), attr: {title: formatTemperature(actual(), undefined, undefined, true)}"></td>
|
||||
<td class="temperature_target">
|
||||
<form class="form-inline" style="margin:0" data-bind="submit: function(element) { $root.setTarget($data, element) }">
|
||||
<div class="input-prepend input-append">
|
||||
|
||||
@@ -10,9 +10,22 @@
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="lib/qunit-1.18.0.js"></script>
|
||||
<script src="lib/qunit-parameterize.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/lib/babel.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/lib/lodash.min.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/lib/sprintf.min.js"></script>
|
||||
<script src="../../../src/octoprint/static/js/app/helpers.js"></script>
|
||||
|
||||
<script>
|
||||
var catalog = {
|
||||
messages: undefined,
|
||||
plural_expr: undefined,
|
||||
locale: undefined,
|
||||
domain: undefined
|
||||
};
|
||||
|
||||
babel.Translations.load(catalog).install();
|
||||
</script>
|
||||
|
||||
<script src="test-helpers.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -85,3 +85,107 @@ QUnit.cases(
|
||||
"As expected: " + String(params.expected)
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.module("formatTemperature");
|
||||
QUnit.cases(
|
||||
(function () {
|
||||
var cases = [];
|
||||
|
||||
var params = [
|
||||
{
|
||||
input: undefined,
|
||||
showF: undefined,
|
||||
useUnicode: undefined,
|
||||
offThreshold: undefined,
|
||||
expected: "-"
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
showF: undefined,
|
||||
useUnicode: undefined,
|
||||
offThreshold: undefined,
|
||||
expected: "-"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: undefined,
|
||||
useUnicode: undefined,
|
||||
offThreshold: 1.1,
|
||||
expected: "off"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: undefined,
|
||||
useUnicode: undefined,
|
||||
offThreshold: 1.0,
|
||||
expected: "1.0°C"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: undefined,
|
||||
useUnicode: undefined,
|
||||
offThreshold: undefined,
|
||||
expected: "1.0°C"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: true,
|
||||
useUnicode: undefined,
|
||||
offThreshold: undefined,
|
||||
expected: "1.0°C (33.8°F)"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: true,
|
||||
useUnicode: true,
|
||||
offThreshold: undefined,
|
||||
expected: "1.0\u00B0C (33.8\u00B0F)"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: undefined,
|
||||
useUnicode: false,
|
||||
offThreshold: undefined,
|
||||
expected: "1.0°C"
|
||||
},
|
||||
{
|
||||
input: 1.0,
|
||||
showF: undefined,
|
||||
useUnicode: true,
|
||||
offThreshold: undefined,
|
||||
expected: "1.0\u00B0C"
|
||||
},
|
||||
{
|
||||
input: 1.1,
|
||||
showF: undefined,
|
||||
useUnicode: undefined,
|
||||
offThreshold: undefined,
|
||||
expected: "1.1°C"
|
||||
}
|
||||
];
|
||||
|
||||
var param, i;
|
||||
for (i = 0; i < params.length; i++) {
|
||||
param = params[i];
|
||||
param["title"] =
|
||||
String(param.input) +
|
||||
String(param.showF) +
|
||||
String(param.offThreshold) +
|
||||
String(param.useUnicode);
|
||||
cases.push(param);
|
||||
}
|
||||
|
||||
return cases;
|
||||
})()
|
||||
).test("formatTemperature", function (params, assert) {
|
||||
assert.equal(
|
||||
params.expected,
|
||||
formatTemperature(
|
||||
params.input,
|
||||
params.showF,
|
||||
params.offThreshold,
|
||||
params.useUnicode
|
||||
),
|
||||
"As expected: " + String(params.expected)
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user