diff --git a/README.md b/README.md index 72c026b..7e82bd4 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,24 @@ - Every cox can define which boats they use - Link for specific trip - Basic auth (with e.g. ekrv) to prevent spam bots? (Or on first login there are 2 input fields: name + e.g. name of "strom") + + +# DB + +- users + - id: i32 + - name: String + - pw: Option + - is_cox: bool + - is_admin: bool +- day + - day: chrono::NaiveDate + - planned_amount_cox: i32 + - planned_starting_time: Option + - open_registration: bool +- trip + - day: String + - user_id: i32 + - cox_id: Option + - begin: Option + - created: chrono::DateTime diff --git a/db.sqlite b/db.sqlite index 66cfff7..23949f0 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/migration/src/m20230209_074936_create_trip.rs b/migration/src/m20230209_074936_create_trip.rs index d83ead1..064ecad 100644 --- a/migration/src/m20230209_074936_create_trip.rs +++ b/migration/src/m20230209_074936_create_trip.rs @@ -43,7 +43,13 @@ impl MigrationTrait for Migration { .not_null() .default(Expr::current_timestamp()), ) - .primary_key(Index::create().col(Trip::Day).col(Trip::UserId)) + .primary_key( + Index::create() + .col(Trip::Day) + .col(Trip::UserId) + .col(Trip::CoxId) + .col(Trip::Begin), + ) .to_owned(), ) .await diff --git a/src/rest/restreg.rs b/src/rest/restreg.rs index f646b28..4f628f6 100644 --- a/src/rest/restreg.rs +++ b/src/rest/restreg.rs @@ -3,7 +3,7 @@ use rocket::{ response::{Flash, Redirect}, Route, State, }; -use sea_orm::{ActiveModelTrait, DatabaseConnection, EntityTrait, Set}; +use sea_orm::{ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter, Set}; use crate::models::{day, trip, user}; @@ -14,6 +14,8 @@ struct RegisterForm { day: NaiveDateForm, #[field(validate = len(3..))] name: String, + time: Option, + cox_id: Option, } #[put("/", data = "")] @@ -42,6 +44,8 @@ async fn register( let trip = trip::ActiveModel { day: Set(day.clone()), user_id: Set(user.id), + begin: Set(register.time.clone()), + cox_id: Set(register.cox_id.clone()), ..Default::default() }; @@ -65,6 +69,8 @@ async fn register( struct DeleteForm { day: NaiveDateForm, user: i32, + cox_id: Option, + begin: Option, } #[delete("/", data = "")] @@ -87,7 +93,11 @@ async fn delete( ); } - let trip = trip::Entity::find_by_id((format!("{}", day.day.format("%Y-%m-%d")), user.id)) + let trip = trip::Entity::find() + .filter(trip::Column::Day.eq(format!("{}", day.day.format("%Y-%m-%d")))) + .filter(trip::Column::UserId.eq(user.id)) + .filter(trip::Column::CoxId.eq(delete.cox_id)) + .filter(trip::Column::Begin.eq(delete.begin.clone())) .one(db.inner()) .await .unwrap(); @@ -101,6 +111,8 @@ async fn delete( trip::Entity::delete(trip::ActiveModel { day: Set(trip.day), user_id: Set(trip.user_id), + //cox_id: Set(delete.cox_id), + begin: Set(delete.begin.clone()), ..Default::default() }) .exec(db.inner()) diff --git a/templates/index.html.tera b/templates/index.html.tera index 3bd7e8e..4a613ab 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -5,15 +5,46 @@ {% for day_with_trip in data %} {% set day = day_with_trip.day %} {% set day_string = day.day | date(format="%Y-%m-%d") %} - {% set trips = day_with_trip.trips %} + {% set_global default_trips = [] %} + {% set_global indep_trips = [] %} + {% for trip in day_with_trip.trips %} + {% if trip.trip.begin or trip.trip.cox_id %} + {% set_global indep_trips = indep_trips | concat(with=trip) %} + {% else %} + {% set_global default_trips = default_trips | concat(with=trip) %} + {% endif %} + {% endfor %} - {% set cox = trips | filter(attribute="user.is_cox", value=true) %} + + {% set cox = default_trips | filter(attribute="user.is_cox", value=true) %} {% set amount_cox = cox | length %} {% set cox_needed = amount_cox < day.planned_amount_cox %}
- {{ day.day | date(format="%d.%m.%Y")}} + {{ day.day | date(format="%A, %d.%m.%Y", locale="de_AT")}} + {% if user.is_cox %} +
+ NEUE AUSFAHRT +
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ {% endif %} {% if user.is_admin %}
@@ -43,18 +74,20 @@ {% endif %} {% if day.planned_amount_cox > 0%} - {% set rowers = trips | filter(attribute="user.is_cox", value=false) | sort(attribute="trip.created") %} + {% set rowers = default_trips | filter(attribute="user.is_cox", value=false) | sort(attribute="trip.created") %} {% if cox_needed %} {% set cox_left = day.planned_amount_cox - amount_cox %}
Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!
{% endif %} Abfahrtszeit: {{ day.planned_starting_time }} Uhr -
{{ trips | length }} angemeldete Person{{ trips | length | pluralize(plural="en") }}: {{ cox | length }} Steuerperson{{ cox | length | pluralize(plural="en") }} ({% for c in cox %}{{ c.user.name }} {% if c.user.name == user.name %} +
{{ default_trips | length }} angemeldete Person{{ default_trips | length | pluralize(plural="en") }}: {{ cox | length }} Steuerperson{{ cox | length | pluralize(plural="en") }} ({% for c in cox %}{{ c.user.name }} {% if c.user.name == user.name %}
+ +
{% endif %} {% endfor %}), {{ rowers | length }} Ruderer:
@@ -68,6 +101,8 @@ + + @@ -97,9 +132,63 @@ {% else %} Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen) {% endif %} - {% else %} - (Noch) keine Ausfahrt geplant {% endif %} + {% for trip in indep_trips %} + {% if trip.trip.begin %} + {{trip.user.name}} @ {{trip.trip.begin}} + {% set rowers = indep_trips | filter(attribute="trip.cox_id", value=trip.user.id) %} + {% if trip.user.name == user.name and rowers | length == 0 %} +
+ + + + + + +
+ {% endif %} + : +
    + {% for r in rowers %} +
  1. + {{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }}) + {% if r.user.name == user.name %} +
    + + + + + + + + +
    + {% endif %} +
  2. + {% endfor %} +
+
+ + +
+ + + +
+
+ + +
+
+ +
+
+
+
+ {% endif %} + {% endfor %} + + +
{% endfor %}