diff --git a/src/components/Widgets/Weather.vue b/src/components/Widgets/Weather.vue
index 02aea987..cb6d2d68 100644
--- a/src/components/Widgets/Weather.vue
+++ b/src/components/Widgets/Weather.vue
@@ -7,44 +7,18 @@
{{ description }}
-
-
-
- Minimum
- {{ minTemp }}
-
-
- Maximum
- {{ maxTemp }}
-
-
- Feels Like
- {{ feelsLike }}
-
-
-
-
-
- Wind
- {{ wind }}
-
-
- Clouds
- {{ clouds }}
-
-
- Humidity
- {{ humidity }}
-
-
- Pressure
- {{ pressure }}
-
-
- Visibility
- {{ visibility }}
-
+
+
+
+ {{weather.label}}
+ {{ weather.value }}
+
+
+
+
+ {{ showDetails ? 'Show Less' : ' Expand Details' }}
+
@@ -63,14 +37,8 @@ export default {
icon: null,
description: null,
temp: null,
- minTemp: null,
- maxTemp: null,
- feelsLike: null,
- pressure: null,
- visibility: null,
- humidity: null,
- wind: null,
- clouds: null,
+ showDetails: false,
+ weatherDetails: [],
};
},
computed: {
@@ -97,9 +65,11 @@ export default {
},
},
methods: {
+ /* Adds units symbol to temperature, depending on metric or imperial */
processTemp(temp) {
return `${Math.round(temp)}${this.tempDisplayUnits}`;
},
+ /* Fetches the weather from OpenWeatherMap, and processes results */
fetchWeather() {
axios.get(this.endpoint)
.then((response) => {
@@ -107,19 +77,36 @@ export default {
this.icon = data.weather[0].icon;
this.description = data.weather[0].description;
this.temp = this.processTemp(data.main.temp);
- this.minTemp = this.processTemp(data.main.temp_min);
- this.maxTemp = this.processTemp(data.main.temp_max);
- this.feelsLike = this.processTemp(data.main.feels_like);
- this.pressure = `${data.main.pressure}hPa`;
- this.humidity = `${data.main.humidity}%`;
- this.visibility = data.visibility;
- this.wind = `${data.wind.speed}${this.speedDisplayUnits}`;
- this.clouds = `${data.clouds.all}%`;
+ if (!this.options.hideDetails) {
+ this.makeWeatherData(data);
+ }
})
.catch(() => {
this.throwError('Failed to fetch weather');
});
},
+ /* If showing additional info, then generate this data too */
+ makeWeatherData(data) {
+ this.weatherDetails = [
+ [
+ { label: 'Min Temp', value: this.processTemp(data.main.temp_min) },
+ { label: 'Max Temp', value: this.processTemp(data.main.temp_max) },
+ { label: 'Feels Like', value: this.processTemp(data.main.feels_like) },
+ ],
+ [
+ { label: 'Pressure', value: `${data.main.pressure}hPa` },
+ { label: 'Humidity', value: `${data.main.humidity}%` },
+ { label: 'visibility', value: data.visibility },
+ { label: 'wind', value: `${data.wind.speed}${this.speedDisplayUnits}` },
+ { label: 'clouds', value: `${data.clouds.all}%` },
+ ],
+ ];
+ },
+ /* Show/ hide additional weather info */
+ toggleDetails() {
+ this.showDetails = !this.showDetails;
+ },
+ /* Validate input props, and print warning if incorrect */
checkProps() {
const ops = this.options;
let valid = true;
@@ -137,6 +124,7 @@ export default {
}
return valid;
},
+ /* Just outputs an error message */
throwError(error) {
ErrorHandler(error);
this.error = true;
@@ -153,9 +141,14 @@ export default {