Merge branch 'main' of gitlab.com:PhilippHofer/rot
This commit is contained in:
commit
394c0db900
@ -5,7 +5,7 @@
|
|||||||
- [] after an hour(?) of inactivity -> show large popup w/ "maybe old data (ignore) (reload page)" (ignore bc maybe use is actively doing something -> don't throw input away!)
|
- [] after an hour(?) of inactivity -> show large popup w/ "maybe old data (ignore) (reload page)" (ignore bc maybe use is actively doing something -> don't throw input away!)
|
||||||
|
|
||||||
## Backend
|
## Backend
|
||||||
- [] add `always_show` to `planned_trips` (e.g. for wanderfahrten)
|
- [] Don't show events if time > 1h(?) ago
|
||||||
|
|
||||||
# Nice to have
|
# Nice to have
|
||||||
## Frontend
|
## Frontend
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
|
use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
|
||||||
|
use chrono::{Datelike, Local, NaiveDate};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
async_trait,
|
async_trait,
|
||||||
http::{Cookie, Status},
|
http::{Cookie, Status},
|
||||||
@ -12,6 +13,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlx::{FromRow, SqlitePool};
|
use sqlx::{FromRow, SqlitePool};
|
||||||
|
|
||||||
|
use super::{planned_event::PlannedEvent, Day};
|
||||||
|
|
||||||
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
@ -168,6 +171,46 @@ ORDER BY last_access DESC
|
|||||||
.await
|
.await
|
||||||
.unwrap(); //Okay, because we can only create a User of a valid id
|
.unwrap(); //Okay, because we can only create a User of a valid id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_days(&self, db: &SqlitePool) -> Vec<Day> {
|
||||||
|
let mut days = Vec::new();
|
||||||
|
for i in 0..self.amount_days_to_show() {
|
||||||
|
let date = (Local::now() + chrono::Duration::days(i)).date_naive();
|
||||||
|
|
||||||
|
if self.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, self.amount_days_to_show()).await {
|
||||||
|
if self.is_guest {
|
||||||
|
let day = Day::new_guest(db, date, true).await;
|
||||||
|
if !day.planned_events.is_empty() {
|
||||||
|
days.push(day);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
days.push(Day::new(db, date, true).await);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
days
|
||||||
|
}
|
||||||
|
|
||||||
|
fn amount_days_to_show(&self) -> i64 {
|
||||||
|
if self.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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use chrono::{Datelike, Duration, Local, NaiveDate};
|
|
||||||
use rocket::{
|
use rocket::{
|
||||||
catch, catchers,
|
catch, catchers,
|
||||||
fairing::AdHoc,
|
fairing::AdHoc,
|
||||||
@ -14,12 +13,10 @@ use sqlx::SqlitePool;
|
|||||||
|
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
log::Log,
|
log::Log,
|
||||||
planned_event::PlannedEvent,
|
|
||||||
tripdetails::TripDetails,
|
tripdetails::TripDetails,
|
||||||
triptype::TripType,
|
triptype::TripType,
|
||||||
user::User,
|
user::User,
|
||||||
usertrip::{UserTrip, UserTripError},
|
usertrip::{UserTrip, UserTripError},
|
||||||
Day,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mod admin;
|
mod admin;
|
||||||
@ -27,25 +24,8 @@ mod auth;
|
|||||||
mod cox;
|
mod cox;
|
||||||
mod misc;
|
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("/")]
|
#[get("/")]
|
||||||
async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
|
async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
|
||||||
let mut days = Vec::new();
|
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
|
|
||||||
if user.is_cox || user.is_admin {
|
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);
|
context.insert("trip_types", &triptypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
let show_next_n_days = amount_days_to_show(user.is_cox);
|
let days = user.get_days(db).await;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(msg) = flash {
|
if let Some(msg) = flash {
|
||||||
context.insert("flash", &msg.into_inner());
|
context.insert("flash", &msg.into_inner());
|
||||||
|
Loading…
Reference in New Issue
Block a user