forked from Ruderverein-Donau-Linz/rowt
push
This commit is contained in:
parent
5cb486b5ce
commit
c79a342ce8
21
README.md
21
README.md
@ -6,3 +6,24 @@
|
|||||||
- Every cox can define which boats they use
|
- Every cox can define which boats they use
|
||||||
- Link for specific trip
|
- 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")
|
- 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<String>
|
||||||
|
- is_cox: bool
|
||||||
|
- is_admin: bool
|
||||||
|
- day
|
||||||
|
- day: chrono::NaiveDate
|
||||||
|
- planned_amount_cox: i32
|
||||||
|
- planned_starting_time: Option<String>
|
||||||
|
- open_registration: bool
|
||||||
|
- trip
|
||||||
|
- day: String
|
||||||
|
- user_id: i32
|
||||||
|
- cox_id: Option<i32>
|
||||||
|
- begin: Option<String>
|
||||||
|
- created: chrono::DateTime
|
||||||
|
@ -43,7 +43,13 @@ impl MigrationTrait for Migration {
|
|||||||
.not_null()
|
.not_null()
|
||||||
.default(Expr::current_timestamp()),
|
.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(),
|
.to_owned(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -3,7 +3,7 @@ use rocket::{
|
|||||||
response::{Flash, Redirect},
|
response::{Flash, Redirect},
|
||||||
Route, State,
|
Route, State,
|
||||||
};
|
};
|
||||||
use sea_orm::{ActiveModelTrait, DatabaseConnection, EntityTrait, Set};
|
use sea_orm::{ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter, Set};
|
||||||
|
|
||||||
use crate::models::{day, trip, user};
|
use crate::models::{day, trip, user};
|
||||||
|
|
||||||
@ -14,6 +14,8 @@ struct RegisterForm {
|
|||||||
day: NaiveDateForm,
|
day: NaiveDateForm,
|
||||||
#[field(validate = len(3..))]
|
#[field(validate = len(3..))]
|
||||||
name: String,
|
name: String,
|
||||||
|
time: Option<String>,
|
||||||
|
cox_id: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/", data = "<register>")]
|
#[put("/", data = "<register>")]
|
||||||
@ -42,6 +44,8 @@ async fn register(
|
|||||||
let trip = trip::ActiveModel {
|
let trip = trip::ActiveModel {
|
||||||
day: Set(day.clone()),
|
day: Set(day.clone()),
|
||||||
user_id: Set(user.id),
|
user_id: Set(user.id),
|
||||||
|
begin: Set(register.time.clone()),
|
||||||
|
cox_id: Set(register.cox_id.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,6 +69,8 @@ async fn register(
|
|||||||
struct DeleteForm {
|
struct DeleteForm {
|
||||||
day: NaiveDateForm,
|
day: NaiveDateForm,
|
||||||
user: i32,
|
user: i32,
|
||||||
|
cox_id: Option<i32>,
|
||||||
|
begin: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/", data = "<delete>")]
|
#[delete("/", data = "<delete>")]
|
||||||
@ -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())
|
.one(db.inner())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -101,6 +111,8 @@ async fn delete(
|
|||||||
trip::Entity::delete(trip::ActiveModel {
|
trip::Entity::delete(trip::ActiveModel {
|
||||||
day: Set(trip.day),
|
day: Set(trip.day),
|
||||||
user_id: Set(trip.user_id),
|
user_id: Set(trip.user_id),
|
||||||
|
//cox_id: Set(delete.cox_id),
|
||||||
|
begin: Set(delete.begin.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.exec(db.inner())
|
.exec(db.inner())
|
||||||
|
@ -5,15 +5,46 @@
|
|||||||
{% for day_with_trip in data %}
|
{% for day_with_trip in data %}
|
||||||
{% set day = day_with_trip.day %}
|
{% set day = day_with_trip.day %}
|
||||||
{% set day_string = day.day | date(format="%Y-%m-%d") %}
|
{% 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 amount_cox = cox | length %}
|
||||||
{% set cox_needed = amount_cox < day.planned_amount_cox %}
|
{% set cox_needed = amount_cox < day.planned_amount_cox %}
|
||||||
|
|
||||||
<div class="bg-gray p-3 mb-1 data-block" data-needed="{{ cox_needed}}">
|
<div class="bg-gray p-3 mb-1 data-block" data-needed="{{ cox_needed}}">
|
||||||
<strong class="block">{{ day.day | date(format="%d.%m.%Y")}}</strong>
|
<strong class="block">{{ day.day | date(format="%A, %d.%m.%Y", locale="de_AT")}}</strong>
|
||||||
|
|
||||||
|
{% if user.is_cox %}
|
||||||
|
<details class="text-right">
|
||||||
|
<summary class="button">NEUE AUSFAHRT</summary>
|
||||||
|
<form method="post" class="text-left" action="/register">
|
||||||
|
<input type="hidden" name="_method" value="put" />
|
||||||
|
<input type="hidden" name="day" value="{{ day_string }}" />
|
||||||
|
<div class="row content-align-bottom">
|
||||||
|
<div class="four columns">
|
||||||
|
<label for="name">Name</label>
|
||||||
|
<input class="u-full-width" type="text" id="name" name="name" value="{{ user.name }}" />
|
||||||
|
</div>
|
||||||
|
<div class="four columns">
|
||||||
|
<label for="time">Time</label>
|
||||||
|
<input class="u-full-width" type="text" id="time" name="time" value="17:00" />
|
||||||
|
</div>
|
||||||
|
<div class="four columns">
|
||||||
|
<input class="button-primary" type="submit" value="Speichern">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
{% if user.is_admin %}
|
{% if user.is_admin %}
|
||||||
<details class="text-right" style="margin-top: -3rem;">
|
<details class="text-right" style="margin-top: -3rem;">
|
||||||
<summary class="button">✎</summary>
|
<summary class="button">✎</summary>
|
||||||
@ -43,18 +74,20 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if day.planned_amount_cox > 0%}
|
{% 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 %}
|
{% if cox_needed %}
|
||||||
{% set cox_left = day.planned_amount_cox - amount_cox %}
|
{% set cox_left = day.planned_amount_cox - amount_cox %}
|
||||||
<div class="block text-red">Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!</div>
|
<div class="block text-red">Es {{ cox_left | pluralize(singular="wird", plural="werden")}} noch {{ cox_left }} Steuerperson{{ cox_left | pluralize(plural="en")}} gesucht!</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<strong class="block mt-1">Abfahrtszeit: {{ day.planned_starting_time }} Uhr</strong>
|
<strong class="block mt-1">Abfahrtszeit: {{ day.planned_starting_time }} Uhr</strong>
|
||||||
|
|
||||||
<div style="max-width: 75%">{{ 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 %}
|
<div style="max-width: 75%">{{ 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 %}
|
||||||
<form method="post" action="/register">
|
<form method="post" action="/register">
|
||||||
<input type="hidden" name="_method" value="delete" />
|
<input type="hidden" name="_method" value="delete" />
|
||||||
<input type="hidden" name="day" value="{{ day.day}}" />
|
<input type="hidden" name="day" value="{{ day.day}}" />
|
||||||
<input type="hidden" name="user" value="{{ c.user.id}}" />
|
<input type="hidden" name="user" value="{{ c.user.id}}" />
|
||||||
|
<input type="hidden" name="cox_id" value="{{ c.trip.cox_id}}" />
|
||||||
|
<input type="hidden" name="begin" value="{{ c.trip.begin}}" />
|
||||||
<input type="submit" value="Abmelden" style="float: left;" />
|
<input type="submit" value="Abmelden" style="float: left;" />
|
||||||
</form>
|
</form>
|
||||||
{% endif %} {% endfor %}), {{ rowers | length }} Ruderer:</div>
|
{% endif %} {% endfor %}), {{ rowers | length }} Ruderer:</div>
|
||||||
@ -68,6 +101,8 @@
|
|||||||
<input type="hidden" name="_method" value="delete" />
|
<input type="hidden" name="_method" value="delete" />
|
||||||
<input type="hidden" name="day" value="{{ day.day}}" />
|
<input type="hidden" name="day" value="{{ day.day}}" />
|
||||||
<input type="hidden" name="user" value="{{ r.user.id}}" />
|
<input type="hidden" name="user" value="{{ r.user.id}}" />
|
||||||
|
<input type="hidden" name="cox_id" value="{{ r.trip.cox_id}}" />
|
||||||
|
<input type="hidden" name="begin" value="{{ r.trip.begin}}" />
|
||||||
|
|
||||||
<input type="submit" value="Abmelden" />
|
<input type="submit" value="Abmelden" />
|
||||||
|
|
||||||
@ -97,9 +132,63 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen)
|
Anmeldung an diesem Tag leider nicht möglich (zB bei USI Kursen)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
(Noch) keine Ausfahrt geplant
|
|
||||||
{% endif %}
|
{% 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 %}
|
||||||
|
<form method="post" action="/register">
|
||||||
|
<input type="hidden" name="_method" value="delete" />
|
||||||
|
<input type="hidden" name="day" value="{{ day.day}}" />
|
||||||
|
<input type="hidden" name="user" value="{{ trip.user.id}}" />
|
||||||
|
<input type="hidden" name="cox_id" value="{{ trip.trip.cox_id}}" />
|
||||||
|
<input type="hidden" name="begin" value="{{ trip.trip.begin}}" />
|
||||||
|
<input type="submit" value="Abmelden" style="float: left;" />
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
:
|
||||||
|
<ol>
|
||||||
|
{% for r in rowers %}
|
||||||
|
<li>
|
||||||
|
{{ r.user.name }} (angemeldet seit {{ r.trip.created | date(format="%d.%m. %H:%M", timezone="Europe/Vienna") }})
|
||||||
|
{% if r.user.name == user.name %}
|
||||||
|
<form method="post" action="/register">
|
||||||
|
<input type="hidden" name="_method" value="delete" />
|
||||||
|
<input type="hidden" name="day" value="{{ day.day}}" />
|
||||||
|
<input type="hidden" name="user" value="{{ r.user.id}}" />
|
||||||
|
<input type="hidden" name="cox_id" value="{{ trip.cox_id}}" />
|
||||||
|
<input type="hidden" name="begin" value="{{ trip.begin}}" />
|
||||||
|
|
||||||
|
<input type="submit" value="Abmelden" />
|
||||||
|
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
|
<details class="text-right">
|
||||||
|
<summary class="button">+</summary>
|
||||||
|
<form method="post" class="text-left" action="/register">
|
||||||
|
<input type="hidden" name="_method" value="put" />
|
||||||
|
<input type="hidden" name="day" value="{{ day_string }}" />
|
||||||
|
<input type="hidden" name="cox_id" value="{{ trip.user.id }}" />
|
||||||
|
<div class="row content-align-bottom">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="name">Name</label>
|
||||||
|
<input class="u-full-width" type="text" id="name" name="name" value="{{ user.name }}" />
|
||||||
|
</div>
|
||||||
|
<div class="six columns">
|
||||||
|
<input class="button-primary" type="submit" value="Speichern">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user