rephrase-scheckbuch-button #460

Merged
philipp merged 7 commits from rephrase-scheckbuch-button into staging 2024-04-29 22:29:14 +02:00
5 changed files with 31 additions and 9 deletions

View File

@ -70,23 +70,39 @@ impl Notification {
}
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
sqlx::query_as!(
Self,
let rows = sqlx::query!(
"
SELECT * FROM notification
SELECT id, user_id, message, read_at, datetime(created_at, 'localtime') as created_at, category, link FROM notification
WHERE
user_id = ?
AND (
read_at IS NULL
OR read_at >= datetime('now', '-14 days')
)
AND created_at is not NULL
ORDER BY read_at DESC, created_at DESC;
",
user.id
)
.fetch_all(db)
.await
.unwrap()
.unwrap();
rows.into_iter()
.map(|rec| Notification {
id: rec.id,
user_id: rec.user_id,
message: rec.message,
read_at: rec.read_at,
created_at: NaiveDateTime::parse_from_str(
&rec.created_at.unwrap(),
"%Y-%m-%d %H:%M:%S",
)
.unwrap(),
category: rec.category,
link: rec.link,
})
.collect()
}
pub async fn mark_read(self, db: &SqlitePool) {

View File

@ -250,7 +250,13 @@ async fn create_kiosk(
} else if let Some(shipmaster) = data.shipmaster {
User::find_by_id(db, shipmaster as i32).await.unwrap()
} else {
User::find_by_id(db, data.rowers[0] as i32).await.unwrap()
let Some(rower) = data.rowers.get(0) else {
return Flash::error(
Redirect::to("/log"),
"Ausfahrt ohne Benutzer kann nicht angelegt werden.",
);
};
User::find_by_id(db, *rower as i32).await.unwrap()
};
Log::create(
db,

View File

@ -9,7 +9,7 @@
{{ macros::input(label='Startzeit', name='tripdetails.planned_starting_time', type='time', required=true) }}
{{ macros::input(label='Anzahl Steuerleute', name='planned_amount_cox', type='number', required=true, min='0') }}
{{ macros::input(label='Anzahl Ruderer (ohne Steuerperson)', name='tripdetails.max_people', type='number', required=true, min='0') }}
{{ macros::checkbox(label='Gäste erlauben', name='tripdetails.allow_guests') }}
{{ macros::checkbox(label='Scheckbuch-Anmeldungen erlauben', name='tripdetails.allow_guests') }}
{{ macros::checkbox(label='Immer anzeigen', name='tripdetails.always_show') }}
{{ macros::input(label='Anmerkungen', name='tripdetails.notes', type='input') }}
{{ macros::select(label='Typ', data=trip_types, name='tripdetails.trip_type', default='Reguläre Ausfahrt') }}

View File

@ -4,7 +4,7 @@
<input class="day-js" type="hidden" name="day" value="" />
{{ macros::input(label='Startzeit (zB "10:00")', name='planned_starting_time', type='time', required=true) }}
{{ macros::input(label='Anzahl Ruderer (ohne Steuerperson)', name='max_people', type='number', required=true, min='0') }}
{{ macros::checkbox(label='Gäste erlauben', name='allow_guests') }}
{{ macros::checkbox(label='Scheckbuch-Anmeldungen erlauben', name='allow_guests') }}
{{ macros::checkbox(label='Immer anzeigen', name='always_show') }}
{{ macros::input(label='Anmerkungen', name='notes', type='input') }}
{{ macros::select(label='Typ', data=trip_types, name='trip_type', default='Reguläre Ausfahrt') }}

View File

@ -30,7 +30,7 @@
<div class="relative flex justify-between items-center p-3">
<div class="grow me-4">
<small class="uppercase text-gray-600 dark:text-gray-100">
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M",) }}
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(format="%d.%m.%Y %H:%M",) }}
</small>
<div class="mt-1">{{ notification.message | safe }}</div>
</div>
@ -55,7 +55,7 @@
{% if notification.read_at %}
<div class="p-3 relative">
<small class="uppercase text-gray-600 dark:text-gray-100">
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M") }}
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(format="%d.%m.%Y %H:%M") }}
</small>
<div class="mt-1">{{ notification.message | safe }}</div>
</div>