Skip to content

Commit

Permalink
Rename index title message, fix weather formatting when there is no
Browse files Browse the repository at this point in the history
weather info
  • Loading branch information
kellpossible committed Apr 20, 2024
1 parent 92f555f commit 06ec34c
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 36 deletions.
3 changes: 2 additions & 1 deletion i18n/bg-BG/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ check-forecast-archive-below = За проверка на последно из
forecast-area-heading = Зона на опериране
# The Gudauri forecast area name
forecast-area-gudauri = Гудаури
gudauri-avalanche-forecast-heading = Лавинен бюлетин Гудаури
# The title used for the index page.
index-title = Лавинен бюлетин Гудаури
latest-forecast-heading = Последо издадена прогноза
avalanche-hazard-level-heading = Степен на лавинна опасност
forecast-archive-heading = Архив на издадените прогнози
Expand Down
3 changes: 2 additions & 1 deletion i18n/en-UK/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ check-forecast-archive-below = Please check the forecast archive below for the m
forecast-area-heading = Forecast Area
# The Gudauri forecast area name
forecast-area-gudauri = Gudauri
gudauri-avalanche-forecast-heading = Gudauri Avalanche Forecast
# The title used for the index page.
index-title = Gudauri Avalanche Forecast
latest-forecast-heading = Latest Forecast
avalanche-hazard-level-heading = Avalanche Hazard Level
forecast-archive-heading = Forecast Archive
Expand Down
3 changes: 2 additions & 1 deletion i18n/it-IT/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ see-facebook-page-message = See [Our Facebook Page]({ $url }) for discussion and
forecast-area-heading = Forecast Area
# The Gudauri forecast area name
forecast-area-gudauri = Gudauri
gudauri-avalanche-forecast-heading = Gudauri Avalanche Forecast
# The title used for the index page.
index-title = Gudauri Avalanche Forecast
latest-forecast-heading = Latest Forecast
avalanche-hazard-level-heading = Avalanche Hazard Level
forecast-archive-heading = Forecast Archive
Expand Down
3 changes: 2 additions & 1 deletion i18n/ka-GE/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ check-forecast-archive-below = ამ არეალზე უახლეს
forecast-area-heading = პროგნოზის არეა
# The Gudauri forecast area name
forecast-area-gudauri = გუდაური
gudauri-avalanche-forecast-heading = გუდაურის ზვავის პროგნოზი
# The title used for the index page.
index-title = გუდაურის ზვავის პროგნოზი
latest-forecast-heading = უახლესი პროგნოზი
avalanche-hazard-level-heading = ზვავსაშიშროების საფეხური
forecast-archive-heading = პროგნოზის არქივი
Expand Down
3 changes: 2 additions & 1 deletion i18n/pl-PL/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ see-facebook-page-message = See [Our Facebook Page]({ $url }) for discussion and
forecast-area-heading = Forecast Area
# The Gudauri forecast area name
forecast-area-gudauri = Gudauri
gudauri-avalanche-forecast-heading = Gudauri Avalanche Forecast
# The title used for the index page.
index-title = Gudauri Avalanche Forecast
latest-forecast-heading = Latest Forecast
avalanche-hazard-level-heading = Avalanche Hazard Level
forecast-archive-heading = Forecast Archive
Expand Down
3 changes: 2 additions & 1 deletion i18n/ru-RU/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ see-facebook-page-message = See [Our Facebook Page]({ $url }) for discussion and
forecast-area-heading = Forecast Area
# The Gudauri forecast area name
forecast-area-gudauri = Gudauri
gudauri-avalanche-forecast-heading = Gudauri Avalanche Forecast
# The title used for the index page.
index-title = Gudauri Avalanche Forecast
latest-forecast-heading = Latest Forecast
avalanche-hazard-level-heading = Avalanche Hazard Level
forecast-archive-heading = Forecast Archive
Expand Down
3 changes: 2 additions & 1 deletion i18n/zh-CN/avalanche_report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ see-facebook-page-message = See [Our Facebook Page]({ $url }) for discussion and
forecast-area-heading = Forecast Area
# The Gudauri forecast area name
forecast-area-gudauri = Gudauri
gudauri-avalanche-forecast-heading = Gudauri Avalanche Forecast
# The title used for the index page.
index-title = Gudauri Avalanche Forecast
latest-forecast-heading = Latest Forecast
avalanche-hazard-level-heading = Avalanche Hazard Level
forecast-archive-heading = Forecast Archive
Expand Down
54 changes: 35 additions & 19 deletions src/current_weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct QueryDeviceDataResponseItem {
pub yearlyrainin: Option<f64>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct WeatherDataItem {
#[serde(with = "time::serde::rfc3339")]
pub time: time::OffsetDateTime,
Expand Down Expand Up @@ -311,10 +311,27 @@ impl CurrentWeatherCacheService {
}
}

#[derive(Serialize)]
struct CurrentWeatherContext {
weather_stations: HashMap<WeatherStationId, Vec<WeatherDataItem>>,
wind_unit: WindUnit,
#[derive(Serialize, Debug)]
pub struct CurrentWeatherContext {
pub weather_stations: HashMap<WeatherStationId, Vec<WeatherDataItem>>,
pub wind_unit: WindUnit,
}

impl CurrentWeatherContext {
pub async fn from_service(
service: &CurrentWeatherService,
wind_unit: WindUnit,
) -> eyre::Result<Self> {
let mut weather_stations = HashMap::new();
for id in service.available_weather_stations() {
let data = service.current_weather(&id).await?;
weather_stations.insert(id, data);
}
Ok(Self {
weather_stations,
wind_unit,
})
}
}

#[derive(Deserialize, Default, Clone, Debug)]
Expand All @@ -328,24 +345,23 @@ pub async fn handler(
State(service): State<std::sync::Arc<CurrentWeatherService>>,
Extension(preferences): Extension<UserPreferences>,
Extension(templates): Extension<TemplatesWithContext>,
) -> Response {
) -> axum::response::Result<Response> {
tracing::debug!("Getting current weather");
let mut weather_stations = HashMap::new();
for id in service.available_weather_stations() {
let data = service.current_weather(&id).await.unwrap();
weather_stations.insert(id, data);
}
let context = CurrentWeatherContext {
weather_stations,
wind_unit: query
let context = CurrentWeatherContext::from_service(
&service,
query
.wind_unit
.or(preferences.wind_unit)
.unwrap_or_default(),
};
render(&templates.environment, "current_weather.html", &context)
.wrap_err("Error rendering current weather template")
.map_err(map_eyre_error)
.into_response()
)
.await
.map_err(map_eyre_error)?;
Ok(
render(&templates.environment, "current_weather.html", &context)
.wrap_err("Error rendering current weather template")
.map_err(map_eyre_error)
.into_response(),
)
}

pub async fn available_weather_stations_handler(
Expand Down
16 changes: 14 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
},
google_drive::{self, ListFileMetadata},
i18n::{self, I18nLoader},
options::{WeatherMaps, WeatherStationId},
state::AppState,
templates::{render, TemplatesWithContext},
user_preferences::{UserPreferences, WindUnit},
Expand Down Expand Up @@ -85,12 +86,19 @@ pub struct ForecastAccumulator {
pub files: Vec<ForecastFile>,
}

#[derive(Serialize, Debug)]
struct WeatherContext {
wind_unit: WindUnit,
weather_maps: WeatherMaps,
weather_station_ids: Vec<WeatherStationId>,
}

#[derive(Serialize, Debug)]
struct IndexContext {
current_forecast: Option<IndexForecast>,
forecasts: Vec<IndexForecast>,
errors: Vec<String>,
wind_unit: WindUnit,
weather: WeatherContext,
}

pub async fn handler(
Expand Down Expand Up @@ -241,7 +249,11 @@ pub async fn handler(
current_forecast,
forecasts,
errors,
wind_unit: preferences.wind_unit.unwrap_or_default(),
weather: WeatherContext {
wind_unit: preferences.wind_unit.unwrap_or_default(),
weather_station_ids: state.options.weather_stations.keys().cloned().collect(),
weather_maps: state.options.weather_maps.clone(),
},
};
let mut response = render(&templates.environment, "index.html", &index)
.map_err(map_eyre_error)?
Expand Down
7 changes: 6 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{collections::HashMap, net::SocketAddr, num::NonZeroU32, path::PathBuf};
use std::{
collections::{BTreeMap, HashMap},
net::SocketAddr,
num::NonZeroU32,
path::PathBuf,
};

use crate::serde::hide_secret;
use cronchik::CronSchedule;
Expand Down
12 changes: 8 additions & 4 deletions src/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% from "macros/elements.html" import divider %}
{% from "macros/language_select.html" import language_select %}
{% from "macros/forecast_intro.html" import forecast_intro %}
{% from "macros/weather.html" import weather, weather_wind_unit_select %}
{% from "macros/weather.html" import weather as weather_macro, weather_wind_unit_select %}
{% extends "base.html" %}
{% block head %}
<link rel="stylesheet" href="/dist/uPlot.css">
Expand Down Expand Up @@ -55,7 +55,7 @@ <h2 class="text-4xl font-bold">{{ fl("no-current-forecast-heading") }}</h2>
</td>
</tr>
{% endmacro %}
{% set page_title = fl("gudauri-avalanche-forecast-heading") %}
{% set page_title = fl("index-title") %}
{% block title %}
{{ page_title }}
{% endblock title %}
Expand All @@ -69,8 +69,12 @@ <h1 class="text-5xl font-bold text-center">{{ page_title }}</h1>
<p class="text-2xl font-bold text-rose-600">{{ fl("no-forecasts-available-message") }}</p>
{% else %}
<div class="py-5">{{ current_forecast_block(current_forecast=current_forecast) }}</div>
{{ divider() }}
<div class="py-2">{{ weather(wind_unit, show_wind_unit_select=true) }}</div>
{% if weather.weather_station_ids or weather.weather_maps %}
{{ divider() }}
<div class="py-2">
{{ weather_macro(weather.wind_unit, show_wind_unit_select=true, weather_maps=weather.weather_maps) }}
</div>
{% endif %}
{{ divider() }}
<div class="py-5">
<h2 class="text-2xl font-bold py-2">{{ fl("about-title") }}</h2>
Expand Down
6 changes: 3 additions & 3 deletions src/templates/macros/weather.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{# A user interface for displaying weather information and provides controls for customizing the display (such as selecting units) #}
{% macro weather(wind_unit, show_wind_unit_select=false, weather_maps=[], weather_stations=[]) %}
{% macro weather(wind_unit, show_wind_unit_select=false, weather_maps=[]) %}
{% set weather_id = "weather-" ~ uuid() %}
{% if show_wind_unit_select %}
{{ wind_unit_select(wind_unit, hx_get="/weather", hx_target=("#" ~ weather_id)) }}
{% endif %}
<div id="{{ weather_id }}">{{ weather_data(wind_unit, weather_maps, weather_stations ) }}</div>
<div id="{{ weather_id }}">{{ weather_data(wind_unit, weather_maps) }}</div>
{% endmacro %}
{# A panel to display weather information, both current and forecast. #}
{% macro weather_data(wind_unit, weather_maps=[], weather_stations=[]) %}
{% macro weather_data(wind_unit, weather_maps=[]) %}
<div hx-get="/current-weather" hx-trigger="load"></div>
{% if weather_maps %}
<h3 class="text-3xl text-center py-2">{{ fl("weather-forecast-heading") }}</h3>
Expand Down

0 comments on commit 06ec34c

Please sign in to comment.