From c79a342ce8b65cfd9f8e74a86b66f4274f307ffa Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 14 Mar 2023 14:00:53 +0100 Subject: [PATCH] push --- README.md | 21 ++++ db.sqlite | Bin 40960 -> 40960 bytes migration/src/m20230209_074936_create_trip.rs | 8 +- src/rest/restreg.rs | 16 ++- templates/index.html.tera | 103 ++++++++++++++++-- 5 files changed, 138 insertions(+), 10 deletions(-) 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 66cfff7daddc74524e7f495b838d82516f5e14a6..23949f0ca653b7884e520bed368989114c553b22 100644 GIT binary patch delta 588 zcmZoTz|?SnX@az%4g&)N7ZAe$+e95>c^wA5Xd_DtM6U;=$jr$sC;&wQ6aPyF{+Ik;HwzZr<>%pMmS%*iW!n5TpG$z331ldP z00RU6M*fXJLs#%e_;WId8^c{}0uD6Q~Z0tdUes3>Er@?=NuqnjmpW(zYj3sp_tF0TZp@5n0x>B>zCi~^iM z)7kiEG4Q|N%wmA_oJfk%5u1t^p8P^0T4}Sn#u;3YhaVqY9YuGocEY z@-w0eZ2oV*g+J23l8uj9kr8f{1uF{IoCSqz#*D%>W#VO4L^#ug7w8p6{tXQL8~7h> z77SRzALGZ!&LG{$%fT6tk(rZOP+*XpXq;@4mX>N{Zjx-2VqlVLY?7FqXpm-ZX_jc1 zmXc~}YL=2{Zf=^KmYSTJmTa1sm}qX8WRh%Rk!WIOVGN25M*go1{9pNBZWb(fz|YA8 di=540^SK1rnL%z~5CF, + 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 %}