push
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
use chrono::{Datelike, Duration, Local, NaiveDate};
|
||||
use rocket::{
|
||||
catch, catchers,
|
||||
fairing::AdHoc,
|
||||
@ -14,12 +13,10 @@ use sqlx::SqlitePool;
|
||||
|
||||
use crate::model::{
|
||||
log::Log,
|
||||
planned_event::PlannedEvent,
|
||||
tripdetails::TripDetails,
|
||||
triptype::TripType,
|
||||
user::User,
|
||||
usertrip::{UserTrip, UserTripError},
|
||||
Day,
|
||||
};
|
||||
|
||||
mod admin;
|
||||
@ -27,25 +24,8 @@ mod auth;
|
||||
mod cox;
|
||||
mod misc;
|
||||
|
||||
fn amount_days_to_show(is_cox: bool) -> i64 {
|
||||
if is_cox {
|
||||
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap(); //Ok,
|
||||
//december
|
||||
//has 31
|
||||
//days
|
||||
end_of_year
|
||||
.signed_duration_since(Local::now().date_naive())
|
||||
.num_days()
|
||||
+ 1
|
||||
} else {
|
||||
6
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
|
||||
let mut days = Vec::new();
|
||||
|
||||
let mut context = Context::new();
|
||||
|
||||
if user.is_cox || user.is_admin {
|
||||
@ -53,25 +33,7 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
|
||||
context.insert("trip_types", &triptypes);
|
||||
}
|
||||
|
||||
let show_next_n_days = amount_days_to_show(user.is_cox);
|
||||
for i in 0..show_next_n_days {
|
||||
let date = (Local::now() + Duration::days(i)).date_naive();
|
||||
|
||||
if user.is_guest {
|
||||
days.push(Day::new_guest(db, date, false).await);
|
||||
} else {
|
||||
days.push(Day::new(db, date, false).await);
|
||||
}
|
||||
}
|
||||
|
||||
for date in PlannedEvent::pinned_days(db, show_next_n_days).await {
|
||||
//TODO: extract the 2 if's (this block + prev. one) after the 2 for's
|
||||
if user.is_guest {
|
||||
days.push(Day::new_guest(db, date, true).await);
|
||||
} else {
|
||||
days.push(Day::new(db, date, true).await);
|
||||
}
|
||||
}
|
||||
let days = user.get_days(db).await;
|
||||
|
||||
if let Some(msg) = flash {
|
||||
context.insert("flash", &msg.into_inner());
|
||||
|
Reference in New Issue
Block a user