diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2022-01-05 16:05:54 +0100 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2022-01-05 17:24:28 +0100 |
commit | 416e4a35bca6a12d18e86c571d16b1797670f44b (patch) | |
tree | 6060f1ffd98ff8592db8e4e47a38a77302dd3df5 /apps/weather_status/src/App.vue | |
parent | 3f7ab0ca831dcc2904530c13982ba13a8ae41d54 (diff) | |
download | nextcloud-server-416e4a35bca6a12d18e86c571d16b1797670f44b.tar.gz nextcloud-server-416e4a35bca6a12d18e86c571d16b1797670f44b.zip |
factorization in weather widget
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'apps/weather_status/src/App.vue')
-rw-r--r-- | apps/weather_status/src/App.vue | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/apps/weather_status/src/App.vue b/apps/weather_status/src/App.vue index cfe7eb3bb27..26430e08b1b 100644 --- a/apps/weather_status/src/App.vue +++ b/apps/weather_status/src/App.vue @@ -25,7 +25,7 @@ <Actions class="weather-status-menu-item__subheader" :default-icon="weatherIcon" - :menu-title="visibleMessage"> + :menu-title="currentWeatherMessage"> <ActionText v-if="gotWeather" :icon="futureWeatherIcon"> {{ forecastMessage }} @@ -233,66 +233,42 @@ export default { return t('weather_status', 'More weather for {adr}', { adr: this.address }) }, temperature() { - return this.forecasts.length > 0 ? this.forecasts[0].data.instant.details.air_temperature : '' + return this.getTemperature(this.forecasts, 0) + }, + futureTemperature() { + return this.getTemperature(this.forecasts, this.offset) }, weatherCode() { - console.debug('weatherCode', this.forecasts[0].data.next_1_hours.summary.symbol_code) - return this.forecasts.length > 0 ? this.forecasts[0].data.next_1_hours.summary.symbol_code : '' + return this.getWeatherCode(this.forecasts, 0) + }, + futureWeatherCode() { + return this.getWeatherCode(this.forecasts, this.offset) }, weatherIcon() { - if (this.loading) { - return 'icon-loading-small' - } else { - return this.weatherCode && this.weatherCode in weatherOptions - ? weatherOptions[this.weatherCode].icon - : 'icon-fair-day' - } + return this.getWeatherIcon(this.weatherCode, this.loading) + }, + futureWeatherIcon() { + return this.getWeatherIcon(this.futureWeatherCode, this.loading) }, /** * The message displayed in the top right corner * * @returns {String} */ - visibleMessage() { + currentWeatherMessage() { if (this.loading) { return t('weather_status', 'Loading weather') } else if (this.errorMessage) { return this.errorMessage } else { - return this.weatherCode && this.weatherCode in weatherOptions - ? weatherOptions[this.weatherCode].text( - this.getLocalizedTemperature(this.temperature), - this.temperatureUnit - ) - : t('weather_status', 'Set location for weather') - } - }, - futureTemperature() { - return this.forecasts.length > (this.offset - 1) ? this.forecasts[this.offset].data.instant.details.air_temperature : '' - }, - futureWeatherCode() { - return this.forecasts.length > (this.offset - 1) ? this.forecasts[this.offset].data.next_1_hours.summary.symbol_code : '' - }, - futureWeatherIcon() { - if (this.loading) { - return 'icon-loading-small' - } else { - return this.futureWeatherCode && this.futureWeatherCode in weatherOptions - ? weatherOptions[this.futureWeatherCode].icon - : 'icon-fair-day' + return this.getWeatherMessage(this.weatherCode, this.temperature) } }, forecastMessage() { if (this.loading) { return t('weather_status', 'Loading weather') } else { - return this.futureWeatherCode && this.futureWeatherCode in weatherOptions - ? weatherOptions[this.futureWeatherCode].text( - this.getLocalizedTemperature(this.futureTemperature), - this.temperatureUnit, - true - ) - : t('weather_status', 'Set location for weather') + return this.getWeatherMessage(this.futureWeatherCode, this.futureTemperature, true) } }, weatherLinkTarget() { @@ -517,6 +493,30 @@ export default { formatTime(time) { return moment(time).format('LT') }, + getTemperature(forecasts, offset = 0) { + return forecasts.length > offset ? forecasts[offset].data.instant.details.air_temperature : '' + }, + getWeatherCode(forecasts, offset = 0) { + return forecasts.length > offset ? forecasts[offset].data.next_1_hours.summary.symbol_code : '' + }, + getWeatherIcon(weatherCode, loading) { + if (loading) { + return 'icon-loading-small' + } else { + return weatherCode && weatherCode in weatherOptions + ? weatherOptions[weatherCode].icon + : 'icon-fair-day' + } + }, + getWeatherMessage(weatherCode, temperature, later = false) { + return weatherCode && weatherCode in weatherOptions + ? weatherOptions[weatherCode].text( + this.getLocalizedTemperature(temperature), + this.temperatureUnit, + later + ) + : t('weather_status', 'Set location for weather') + }, }, } </script> |