send triptype to frontend

This commit is contained in:
2023-04-28 21:19:51 +02:00
parent bd5a28b342
commit 3d5ad30904
8 changed files with 109 additions and 21 deletions

View File

@ -13,6 +13,7 @@ use sqlx::SqlitePool;
use crate::model::{
log::Log,
tripdetails::TripDetails,
triptype::TripType,
user::User,
usertrip::{UserTrip, UserTripError},
Day,
@ -26,6 +27,8 @@ mod cox;
async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
let mut days = Vec::new();
let mut context = Context::new();
let mut show_next_n_days = 6;
if user.is_cox {
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap();
@ -34,14 +37,16 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
.num_days()
+ 1;
}
if user.is_cox || user.is_admin {
let triptypes = TripType::all(db).await;
context.insert("trip_types", &triptypes);
}
for i in 0..show_next_n_days {
let date = (Local::now() + Duration::days(i)).date_naive();
days.push(Day::new(db, date).await);
}
let mut context = Context::new();
if let Some(msg) = flash {
context.insert("flash", &msg.into_inner());
}