From afa0fb8da123bd04c89be4938413faa7a2324d53 Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 31 Aug 2017 18:03:23 +0200 Subject: [PATCH 1/3] Fix JavaScript error in weatherforecast Change 5568e0c2adc73aa20bebb5bfc47df65fea273b05 introduces JavaScript errors, because it's calling toUpperCase() on a boolean value. --- modules/default/weatherforecast/weatherforecast.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index f54467e5..0168e559 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -142,10 +142,10 @@ Module.register("weatherforecast",{ var maxTempCell = document.createElement("td"); maxTempCell.innerHTML = forecast.maxTemp; - if(this.config.scale.toUpperCase() == "C") { + if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "C") { maxTempCell.innerHTML += " °C"; } else { - if(this.config.scale.toUpperCase() == "F") { + if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "F") { maxTempCell.innerHTML += " °F"; } } @@ -154,10 +154,10 @@ Module.register("weatherforecast",{ var minTempCell = document.createElement("td"); minTempCell.innerHTML = forecast.minTemp; - if(this.config.scale.toUpperCase() == "C") { + if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "C") { minTempCell.innerHTML += " °C"; } else { - if(this.config.scale.toUpperCase() == "F") { + if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "F") { minTempCell.innerHTML += " °F"; } } From 62ce7a0e37f8149ab8cb88cf877d6cd4e6c7cb83 Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 31 Aug 2017 18:18:19 +0200 Subject: [PATCH 2/3] Weather forecast settings match current weather This change makes the config of weather forecast more in line with current weather. It uses the configured units (metric, imperial, default) to determine the sign. --- .../weatherforecast/weatherforecast.js | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index 0168e559..8ccf0f54 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -140,27 +140,28 @@ Module.register("weatherforecast",{ icon.className = "wi weathericon " + forecast.icon; iconCell.appendChild(icon); - var maxTempCell = document.createElement("td"); - maxTempCell.innerHTML = forecast.maxTemp; - if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "C") { - maxTempCell.innerHTML += " °C"; - } else { - if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "F") { - maxTempCell.innerHTML += " °F"; + var degreeLabel = ""; + if(this.config.scale) { + switch(this.config.units) { + case "metric": + degreeLabel = " °C"; + break; + case "imperial": + degreeLabel = " °F"; + break; + case "default": + degreeLabel = "K"; + break; } } + + var maxTempCell = document.createElement("td"); + maxTempCell.innerHTML = forecast.maxTemp + degreeLabel; maxTempCell.className = "align-right bright max-temp"; row.appendChild(maxTempCell); var minTempCell = document.createElement("td"); - minTempCell.innerHTML = forecast.minTemp; - if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "C") { - minTempCell.innerHTML += " °C"; - } else { - if(typeof(this.config.scale) == "string" && this.config.scale.toUpperCase() == "F") { - minTempCell.innerHTML += " °F"; - } - } + minTempCell.innerHTML = forecast.minTemp + degreeLabel; minTempCell.className = "align-right min-temp"; row.appendChild(minTempCell); From 335ae0105fc346c5f94e5d2bf2668a472a6a36e2 Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 31 Aug 2017 18:36:52 +0200 Subject: [PATCH 3/3] Fix grunt errors --- .../default/weatherforecast/weatherforecast.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index 8ccf0f54..87fe40ae 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -143,15 +143,15 @@ Module.register("weatherforecast",{ var degreeLabel = ""; if(this.config.scale) { switch(this.config.units) { - case "metric": - degreeLabel = " °C"; - break; - case "imperial": - degreeLabel = " °F"; - break; - case "default": - degreeLabel = "K"; - break; + case "metric": + degreeLabel = " °C"; + break; + case "imperial": + degreeLabel = " °F"; + break; + case "default": + degreeLabel = "K"; + break; } }