Added Czech translations to charts. Added logging to actix.
This commit is contained in:
@@ -24,6 +24,7 @@ cfg_if! { if #[cfg(feature = "ssr")] {
|
|||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use crate::backend::user::admin_email;
|
use crate::backend::user::admin_email;
|
||||||
use crate::backend::user::emails_for_notify;
|
use crate::backend::user::emails_for_notify;
|
||||||
|
use crate::locales::trl;
|
||||||
use rust_decimal::prelude::ToPrimitive;
|
use rust_decimal::prelude::ToPrimitive;
|
||||||
|
|
||||||
async fn find_sum_by_uuid(uuid: &Uuid, tx: &mut Transaction<'_, Postgres>) -> Result<ReservationSum, Error> {
|
async fn find_sum_by_uuid(uuid: &Uuid, tx: &mut Transaction<'_, Postgres>) -> Result<ReservationSum, Error> {
|
||||||
@@ -446,7 +447,7 @@ fn chart(data: &Vec<ChartData>, title: &str, month: bool) -> String {
|
|||||||
let mut chart = BarChart::new_with_theme(
|
let mut chart = BarChart::new_with_theme(
|
||||||
vec![("Bookings", data.iter().map(|d| d.count.to_f32().unwrap_or_default()).collect()).into()],
|
vec![("Bookings", data.iter().map(|d| d.count.to_f32().unwrap_or_default()).collect()).into()],
|
||||||
if month {
|
if month {
|
||||||
data.iter().map(|d| Month::try_from(d.period.to_u8().unwrap_or_default()).unwrap_or(Month::January).name().to_string()).collect()
|
data.iter().map(|d| trl(Month::try_from(d.period.to_u8().unwrap_or_default()).unwrap_or(Month::January).name())()).collect()
|
||||||
} else {
|
} else {
|
||||||
data.iter().map(|d| d.period.to_string()).collect()
|
data.iter().map(|d| d.period.to_string()).collect()
|
||||||
},
|
},
|
||||||
@@ -472,7 +473,7 @@ pub async fn month_chart(year: i32) -> Result<ApiResponse<String>, ServerFnError
|
|||||||
perm_check!(is_logged_in);
|
perm_check!(is_logged_in);
|
||||||
|
|
||||||
let data = month_chart_data(year).await?;
|
let data = month_chart_data(year).await?;
|
||||||
Ok(ApiResponse::Data(chart(&data, "Month bookings", true)))
|
Ok(ApiResponse::Data(chart(&data, &trl("Month bookings")(), true)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
@@ -481,7 +482,7 @@ pub async fn year_chart() -> Result<ApiResponse<String>, ServerFnError> {
|
|||||||
perm_check!(is_logged_in);
|
perm_check!(is_logged_in);
|
||||||
|
|
||||||
let data = year_chart_data().await?;
|
let data = year_chart_data().await?;
|
||||||
Ok(ApiResponse::Data(chart(&data, "Year bookings", false)))
|
Ok(ApiResponse::Data(chart(&data, &trl("Year bookings")(), false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
|
|||||||
@@ -143,7 +143,21 @@ lazy_static! {
|
|||||||
("Update title", "Upravit titulek"),
|
("Update title", "Upravit titulek"),
|
||||||
("Are you sure you want to delete banner?", "Opravdu chcete smazat banner?"),
|
("Are you sure you want to delete banner?", "Opravdu chcete smazat banner?"),
|
||||||
("Delete banner", "Smazat banner"),
|
("Delete banner", "Smazat banner"),
|
||||||
("Appearance", "Vzhled")
|
("Appearance", "Vzhled"),
|
||||||
|
("Month bookings", "Rezrvace po měsících"),
|
||||||
|
("Year bookings", "Rezervace po letech"),
|
||||||
|
("January", "Leden"),
|
||||||
|
("February", "Únor"),
|
||||||
|
("March", "Březen"),
|
||||||
|
("April", "Duben"),
|
||||||
|
("May", "Květen"),
|
||||||
|
("June", "Červen"),
|
||||||
|
("July", "Červenec"),
|
||||||
|
("August", "Srpen"),
|
||||||
|
("September", "Září"),
|
||||||
|
("October", "Říjen"),
|
||||||
|
("November", "Listpopad"),
|
||||||
|
("December", "Prosinec"),
|
||||||
])),
|
])),
|
||||||
("sk", HashMap::from( [
|
("sk", HashMap::from( [
|
||||||
("Dashboard", "Prehlad"),
|
("Dashboard", "Prehlad"),
|
||||||
@@ -155,8 +169,30 @@ lazy_static! {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_locales() -> Vec<Option<String>> {
|
||||||
|
#[cfg(not(feature = "ssr"))]
|
||||||
|
{
|
||||||
|
use_context::<Locales>().unwrap_or(Locales(vec![])).0
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
{
|
||||||
|
use actix_web::HttpRequest;
|
||||||
|
|
||||||
|
let req = use_context::<HttpRequest>();
|
||||||
|
if let Some(r) = req {
|
||||||
|
if let Some(al) = r.head().headers.get("accept-language") {
|
||||||
|
Locales(al.to_str().unwrap_or("").split(",").map(|l| Some(l.to_string())).collect()).0
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_dictionary() -> Option<&'static HashMap<&'static str, &'static str>> {
|
pub fn get_dictionary() -> Option<&'static HashMap<&'static str, &'static str>> {
|
||||||
let locs = use_context::<Locales>().unwrap_or(Locales(vec![])).0;
|
let locs = get_locales();
|
||||||
for loc in locs {
|
for loc in locs {
|
||||||
if let Some(key) = loc {
|
if let Some(key) = loc {
|
||||||
if let Some(k) = key.split("-").collect::<Vec<_>>().get(0) {
|
if let Some(k) = key.split("-").collect::<Vec<_>>().get(0) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use actix_web::middleware::Logger;
|
||||||
use leptos_captcha::spow::pow::Pow;
|
use leptos_captcha::spow::pow::Pow;
|
||||||
use log::error;
|
use log::error;
|
||||||
use rezervator::backend::appearance::check_appearance;
|
use rezervator::backend::appearance::check_appearance;
|
||||||
@@ -78,6 +79,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(Data::new(AppData::new(pool.clone(), mailing.clone())))
|
.app_data(Data::new(AppData::new(pool.clone(), mailing.clone())))
|
||||||
|
.wrap(Logger::default())
|
||||||
.wrap(Authentication)
|
.wrap(Authentication)
|
||||||
.wrap(SessionMiddleware::new(
|
.wrap(SessionMiddleware::new(
|
||||||
CookieSessionStore::default(),
|
CookieSessionStore::default(),
|
||||||
|
|||||||
Reference in New Issue
Block a user