From f38d506fe4f97deb4f29e0a76c2e828fb6e11671 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 3 Sep 2024 21:35:43 +0300 Subject: [PATCH] many updates :-( --- src/lib.rs | 12 ++++++++++++ src/model/mod.rs | 10 +++++++++- src/model/trip.rs | 17 ++++++++--------- src/model/user.rs | 19 ++++++------------- src/tera/mod.rs | 13 ++++++++----- src/tera/planned.rs | 19 +++++++++++++------ templates/includes/forms/log.html.tera | 2 +- templates/includes/macros.html.tera | 17 +++++++++-------- templates/planned.html.tera | 18 ++++++++++++++++-- 9 files changed, 82 insertions(+), 45 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1ec5a1a..29c2d01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,18 @@ pub mod rest; pub mod scheduled; +pub(crate) const AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD: i64 = 10; +pub(crate) const RENNRUDERBEITRAG: i32 = 11000; +pub(crate) const BOAT_STORAGE: i32 = 4500; +pub(crate) const FAMILY_TWO: i32 = 30000; +pub(crate) const FAMILY_THREE_OR_MORE: i32 = 35000; +pub(crate) const STUDENT_OR_PUPIL: i32 = 8000; +pub(crate) const REGULAR: i32 = 22000; +pub(crate) const UNTERSTUETZEND: i32 = 2500; +pub(crate) const FOERDERND: i32 = 8500; +pub(crate) const SCHECKBUCH: i32 = 3000; +pub(crate) const EINSCHREIBGEBUEHR: i32 = 3000; + #[cfg(test)] #[macro_export] macro_rules! testdb { diff --git a/src/model/mod.rs b/src/model/mod.rs index 2ab60e0..1af7c21 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,8 +1,10 @@ -use chrono::NaiveDate; +use chrono::{Local, NaiveDate}; use serde::Serialize; use sqlx::SqlitePool; use waterlevel::WaterlevelDay; +use crate::AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD; + use self::{ event::{Event, EventWithUserAndTriptype}, trip::{Trip, TripWithUserAndType}, @@ -42,18 +44,23 @@ pub struct Day { events: Vec, trips: Vec, is_pinned: bool, + regular_sees_this_day: bool, max_waterlevel: Option, weather: Option, } impl Day { pub async fn new(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self { + let today = Local::now().date_naive(); + let day_diff = (day - today).num_days() + 1; + let regular_sees_this_day = day_diff <= AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD; if is_pinned { Self { day, events: Event::get_pinned_for_day(db, day).await, trips: Trip::get_pinned_for_day(db, day).await, is_pinned, + regular_sees_this_day, max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await, weather: Weather::find_by_day(db, day).await, } @@ -63,6 +70,7 @@ impl Day { events: Event::get_for_day(db, day).await, trips: Trip::get_for_day(db, day).await, is_pinned, + regular_sees_this_day, max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await, weather: Weather::find_by_day(db, day).await, } diff --git a/src/model/trip.rs b/src/model/trip.rs index 908c9ad..fabc4de 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -4,6 +4,7 @@ use sqlx::SqlitePool; use super::{ event::{Event, Registration}, + log::Log, notification::Notification, tripdetails::TripDetails, triptype::TripType, @@ -329,18 +330,16 @@ WHERE day=? return Err(TripDeleteError::SomebodyAlreadyRegistered); } - if !self.is_trip_from_user(user.id) { + if !self.is_trip_from_user(user.id) && !user.has_role(db, "admin").await { return Err(TripDeleteError::NotYourTrip); } - sqlx::query!( - "DELETE FROM trip WHERE cox_id = ? AND id = ?", - user.id, - self.id - ) - .execute(db) - .await - .unwrap(); //TODO: fixme + Log::create(db, format!("{} deleted trip: {:#?}", user.user.name, self)).await; + + sqlx::query!("DELETE FROM trip WHERE id = ?", self.id) + .execute(db) + .await + .unwrap(); //TODO: fixme Ok(()) } diff --git a/src/model/user.rs b/src/model/user.rs index c310c59..d5f8a41 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -18,18 +18,11 @@ use super::{ family::Family, log::Log, mail::Mail, notification::Notification, role::Role, stat::Stat, tripdetails::TripDetails, Day, }; -use crate::tera::admin::user::UserEditForm; - -const RENNRUDERBEITRAG: i32 = 11000; -const BOAT_STORAGE: i32 = 4500; -const FAMILY_TWO: i32 = 30000; -const FAMILY_THREE_OR_MORE: i32 = 35000; -const STUDENT_OR_PUPIL: i32 = 8000; -const REGULAR: i32 = 22000; -const UNTERSTUETZEND: i32 = 2500; -const FOERDERND: i32 = 8500; -pub const SCHECKBUCH: i32 = 3000; -const EINSCHREIBGEBUEHR: i32 = 3000; +use crate::{ + tera::admin::user::UserEditForm, AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD, BOAT_STORAGE, + EINSCHREIBGEBUEHR, FAMILY_THREE_OR_MORE, FAMILY_TWO, FOERDERND, REGULAR, RENNRUDERBEITRAG, + SCHECKBUCH, STUDENT_OR_PUPIL, UNTERSTUETZEND, +}; #[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)] pub struct User { @@ -910,7 +903,7 @@ ORDER BY last_access DESC days_left_in_year } } else { - 10 + AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD } } diff --git a/src/tera/mod.rs b/src/tera/mod.rs index 9616a80..7bcc1ba 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -20,11 +20,14 @@ use serde::Deserialize; use sqlx::SqlitePool; use tera::Context; -use crate::model::{ - logbook::Logbook, - notification::Notification, - role::Role, - user::{User, UserWithDetails, SCHECKBUCH}, +use crate::{ + model::{ + logbook::Logbook, + notification::Notification, + role::Role, + user::{User, UserWithDetails}, + }, + SCHECKBUCH, }; pub(crate) mod admin; diff --git a/src/tera/planned.rs b/src/tera/planned.rs index 0dab434..4639227 100644 --- a/src/tera/planned.rs +++ b/src/tera/planned.rs @@ -8,12 +8,15 @@ use rocket_dyn_templates::Template; use sqlx::SqlitePool; use tera::Context; -use crate::model::{ - log::Log, - tripdetails::TripDetails, - triptype::TripType, - user::{AllowedForPlannedTripsUser, User, UserWithDetails}, - usertrip::{UserTrip, UserTripDeleteError, UserTripError}, +use crate::{ + model::{ + log::Log, + tripdetails::TripDetails, + triptype::TripType, + user::{AllowedForPlannedTripsUser, User, UserWithDetails}, + usertrip::{UserTrip, UserTripDeleteError, UserTripError}, + }, + AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD, }; #[get("/")] @@ -42,6 +45,10 @@ async fn index( &user.allowed_to_update_always_show_trip(db).await, ); context.insert("fee", &user.fee(db).await); + context.insert( + "amount_days_to_show_trips_ahead", + &AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD, + ); context.insert("loggedin_user", &UserWithDetails::from_user(user, db).await); context.insert("days", &days); Template::render("planned", context.into_json()) diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index bb5f193..ae9d752 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -5,7 +5,7 @@ {% macro show_boats() %} {% for cat, grouped_boats in boats | group_by(attribute="cat") %}
- + {{ cat }} ({{ grouped_boats | length }}) diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index af9449d..b4202b0 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -20,17 +20,18 @@ function setChoiceByLabel(choicesInstance, label) {

Heute geplante Ausfahrten

-
+
{% for planned_trip in planned_trips | sort(attribute='planned_starting_time') %} -
+
- {{ planned_trip.cox_name }} ({{ planned_trip.rower | length + 1 }} Personen) - {{ planned_trip.planned_starting_time }} - -
{% endfor %}
@@ -43,7 +44,7 @@ function setChoiceByLabel(choicesInstance, label) {
{% for _, reservations_for_event in reservations %} {% set reservation = reservations_for_event[0] %} -
+
{{ reservation.start_date | date(format="%d.%m.%Y") }} {% if reservation.end_date != reservation.start_date %} diff --git a/templates/planned.html.tera b/templates/planned.html.tera index ac25a81..99e55dc 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -100,7 +100,8 @@ style="order: {{ event.planned_starting_time | replace(from=":", to="") }}">
- {% if event.max_people == 0 %} + {% if event.always_show and not day.regular_sees_this_day %}🔮{% endif -%} + {%- if event.max_people == 0 %} ⚠ Absage {{ event.planned_starting_time }} Uhr @@ -274,6 +275,7 @@ data-coxneeded="false">
+ {% if trip.always_show and not day.regular_sees_this_day %}🔮{% endif -%} {% if trip.max_people == 0 %} ⚠ {{ trip.planned_starting_time }} @@ -382,13 +384,25 @@ {% if allowed_to_update_always_show_trip %}

Admin-Modus

+ {% if not day.regular_sees_this_day %}
- Diese Ausfahrt sehen aktuell nur Steuerleute (und Admins). {{ amount_days_to_show_trips_ahead }} Tage vorher sehen sie dann alle. + {% else %} + Diese Ausfahrt sehen alle Mitglieder. + {% endif %} +
+ {% endif %} + + {% include "includes/delete-icon" %} + Termin löschen +
{% endif %} {# --- END Admin Form --- #}