diff --git a/modules/default/weather/current.html b/modules/default/weather/current.html
new file mode 100644
index 00000000..949d2fbc
--- /dev/null
+++ b/modules/default/weather/current.html
@@ -0,0 +1,16 @@
+
+
+
+ {{current.windSpeed}}
+ {{current.cardinalWindDirection()}}
+
+
+ 00:00
+
+
+
+ {{current.temperature}}°
+
+
+
+
\ No newline at end of file
diff --git a/modules/default/weather/forecast.html b/modules/default/weather/forecast.html
new file mode 100644
index 00000000..514a96df
--- /dev/null
+++ b/modules/default/weather/forecast.html
@@ -0,0 +1,3 @@
+Forecast template not yet implemented.
+
+{{forecast | dump}}
\ No newline at end of file
diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js
index 7f33ffa8..51eb8e75 100644
--- a/modules/default/weather/weather.js
+++ b/modules/default/weather/weather.js
@@ -15,7 +15,7 @@ Module.register("weather",{
weatherProvider: "openweathermap",
units: config.units,
roundTemp: false,
- displayType: "full" //current, forecast, full
+ type: "current" //current, forecast
},
// Module properties.
@@ -51,18 +51,17 @@ Module.register("weather",{
this.scheduleUpdate(0)
},
- // Generate the dom. This is now pretty simple for debugging.
- getDom: function() {
- switch (this.config.displayType) {
- case "current":
- return this.currentWeatherView()
- break;
- case "forecast":
- return this.weatherForecastView()
- break;
- default:
- return this.fullWeatherView()
- break;
+ // Select the template depending on the display type.
+ getTemplate: function () {
+ return this.config.type.toLowerCase() + ".html"
+ },
+
+ // Add all the data to the template.
+ getTemplateData: function () {
+ return {
+ config: this.config,
+ current: this.weatherProvider.currentWeather(),
+ forecast: this.weatherProvider.weatherForecast()
}
},
@@ -81,113 +80,18 @@ Module.register("weather",{
}
setTimeout(() => {
- switch (this.config.displayType) {
- case "current":
- this.weatherProvider.fetchCurrentWeather()
- break;
+ switch (this.config.type) {
case "forecast":
this.weatherProvider.fetchWeatherForecast()
break;
default:
+ case "current":
this.weatherProvider.fetchCurrentWeather()
- this.weatherProvider.fetchWeatherForecast()
break;
}
}, nextLoad);
},
- /* Views */
-
- // Generate the current weather view
- currentWeatherView: function () {
-
- var currentWeather = this.weatherProvider.currentWeather()
- var wrapper = document.createElement("div")
-
- if (currentWeather === null) {
- return wrapper
- }
-
- // Detail bar.
-
- var detailBar = document.createElement("div")
-
- this.addValueToWrapper(detailBar, null, "wi wi-strong-wind dimmed", "span", true) // Wind Icon
- this.addValueToWrapper(detailBar, currentWeather.windSpeed ? Math.round(currentWeather.windSpeed) : null) // WindSpeed
- this.addValueToWrapper(detailBar, currentWeather.windDirection ? this.translate(currentWeather.cardinalWindDirection()) + " " : " ", "", "sup") // WindDirection
-
- var now = new Date();
- var sunriseSunsetTime = (currentWeather.sunrise < now && currentWeather.sunset > now) ? currentWeather.sunset : currentWeather.sunrise
- var sunriseSunsetIcon = (currentWeather.sunrise < now && currentWeather.sunset > now) ? "wi-sunset" : "wi-sunrise"
- this.addValueToWrapper(detailBar, null, "wi dimmed " + sunriseSunsetIcon, "span", true) // Sunrise / Sunset Icon
- this.addValueToWrapper(detailBar, moment(sunriseSunsetTime).format("HH:mm")) // Sunrise / Sunset Time
-
- detailBar.className = "normal medium"
- wrapper.appendChild(detailBar)
-
- // Main info
-
- var mainInfo = document.createElement("div")
-
- this.addValueToWrapper(mainInfo, null, "weathericon wi wi-" + currentWeather.weatherType, "span", true) // Wind Icon
- this.addValueToWrapper(mainInfo, currentWeather.temperature.toFixed(this.config.roundTemp ? 0 : 1) + "°", "bright" ) // WindSpeed
-
- mainInfo.className = "large light"
- wrapper.appendChild(mainInfo)
-
- return wrapper
- },
-
- weatherForecastView: function() {
- // This is just a dummy view to test it ... it needs A LOT of work :)
- // Currently it outputs a div, it should be a table.
-
- var wrapper = document.createElement("div")
- wrapper.className = "small"
-
- if (this.weatherProvider.weatherForecast() === null) {
- return wrapper
- }
-
- this.weatherProvider.weatherForecast().forEach((weatherObject) => {
- var day = document.createElement("div")
-
- this.addValueToWrapper(day, moment(weatherObject.date).format("dd"))
- this.addValueToWrapper(day, weatherObject.maxTemperature ? weatherObject.maxTemperature.toFixed(this.config.roundTemp ? 0 : 1) : null, "bright")
- this.addValueToWrapper(day, weatherObject.minTemperature ? weatherObject.minTemperature.toFixed(this.config.roundTemp ? 0 : 1) : null, "dimmed")
-
- wrapper.appendChild(day)
- });
-
- return wrapper
- },
-
- fullWeatherView: function() {
- var wrapper = document.createElement("div")
-
- wrapper.appendChild(this.currentWeatherView())
- wrapper.appendChild(this.weatherForecastView())
-
- return wrapper
- },
-
- // A convenience function to add an element to a wrapper with a specific value and class.
- addValueToWrapper: function(wrapper, value, classNames, element = "span", forceAdd = false, addSpacer = true) {
- if (value === null && !forceAdd) {
- return
- }
-
- var valueWrapper = document.createElement(element)
- valueWrapper.className = classNames
- if (addSpacer) {
- valueWrapper.innerHTML = " "
- }
-
- if (value !== null) {
- valueWrapper.innerHTML += value
- }
-
- wrapper.appendChild(valueWrapper)
- }
+
});