forked from Ruderverein-Donau-Linz/rowt
allow boatdamage add in kiosk mode
This commit is contained in:
parent
e86d84d34c
commit
8852e1cdd6
@ -9,7 +9,6 @@
|
||||
- [] reload page -> don't throw input away!
|
||||
|
||||
## Backend
|
||||
- [] variable for kiosk mode (needed especially for header)
|
||||
- [] boat_damage -> Add user_select
|
||||
|
||||
# Nice to have
|
||||
|
@ -9,13 +9,38 @@ use rocket_dyn_templates::Template;
|
||||
use sqlx::SqlitePool;
|
||||
use tera::Context;
|
||||
|
||||
use crate::model::{
|
||||
boat::Boat,
|
||||
boatdamage::{BoatDamage, BoatDamageFixed, BoatDamageToAdd, BoatDamageVerified},
|
||||
user::{CoxUser, TechUser, User},
|
||||
use crate::{
|
||||
model::{
|
||||
boat::Boat,
|
||||
boatdamage::{BoatDamage, BoatDamageFixed, BoatDamageToAdd, BoatDamageVerified},
|
||||
user::{CoxUser, TechUser, User},
|
||||
},
|
||||
tera::log::KioskCookie,
|
||||
};
|
||||
|
||||
#[get("/")]
|
||||
async fn index_kiosk(
|
||||
db: &State<SqlitePool>,
|
||||
flash: Option<FlashMessage<'_>>,
|
||||
_kiosk: KioskCookie,
|
||||
) -> Template {
|
||||
let boatdamages = BoatDamage::all(db).await;
|
||||
let boats = Boat::all(db).await;
|
||||
let coxes = User::cox(db).await;
|
||||
|
||||
let mut context = Context::new();
|
||||
if let Some(msg) = flash {
|
||||
context.insert("flash", &msg.into_inner());
|
||||
}
|
||||
|
||||
context.insert("boatdamages", &boatdamages);
|
||||
context.insert("boats", &boats);
|
||||
context.insert("coxes", &coxes);
|
||||
|
||||
Template::render("boatdamages", context.into_json())
|
||||
}
|
||||
|
||||
#[get("/", rank = 2)]
|
||||
async fn index(db: &State<SqlitePool>, flash: Option<FlashMessage<'_>>, user: User) -> Template {
|
||||
let boatdamages = BoatDamage::all(db).await;
|
||||
let boats = Boat::all(db).await;
|
||||
@ -39,7 +64,7 @@ pub struct FormBoatDamageToAdd<'r> {
|
||||
pub lock_boat: bool,
|
||||
}
|
||||
|
||||
#[post("/", data = "<data>")]
|
||||
#[post("/", data = "<data>", rank = 2)]
|
||||
async fn create<'r>(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<FormBoatDamageToAdd<'r>>,
|
||||
@ -54,7 +79,36 @@ async fn create<'r>(
|
||||
match BoatDamage::create(db, boatdamage_to_add).await {
|
||||
Ok(_) => Flash::success(
|
||||
Redirect::to("/boatdamage"),
|
||||
"Ausfahrt erfolgreich hinzugefügt",
|
||||
"Bootsschaden erfolgreich hinzugefügt",
|
||||
),
|
||||
Err(e) => Flash::error(Redirect::to("/boatdamage"), format!("Fehler: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
pub struct FormBoatDamageToAddKiosk<'r> {
|
||||
pub boat_id: i64,
|
||||
pub desc: &'r str,
|
||||
pub lock_boat: bool,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[post("/", data = "<data>")]
|
||||
async fn create_from_kiosk<'r>(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<FormBoatDamageToAddKiosk<'r>>,
|
||||
_kiosk: KioskCookie,
|
||||
) -> Flash<Redirect> {
|
||||
let boatdamage_to_add = BoatDamageToAdd {
|
||||
boat_id: data.boat_id,
|
||||
desc: data.desc,
|
||||
lock_boat: data.lock_boat,
|
||||
user_id_created: data.user_id,
|
||||
};
|
||||
match BoatDamage::create(db, boatdamage_to_add).await {
|
||||
Ok(_) => Flash::success(
|
||||
Redirect::to("/boatdamage"),
|
||||
"Bootsschaden erfolgreich hinzugefügt",
|
||||
),
|
||||
Err(e) => Flash::error(Redirect::to("/boatdamage"), format!("Fehler: {e}")),
|
||||
}
|
||||
@ -110,5 +164,12 @@ async fn verified<'r>(
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![index, create, fixed, verified]
|
||||
routes![
|
||||
index,
|
||||
index_kiosk,
|
||||
create,
|
||||
fixed,
|
||||
verified,
|
||||
create_from_kiosk
|
||||
]
|
||||
}
|
||||
|
@ -26,6 +26,9 @@
|
||||
<div id="new-damage">
|
||||
<form action="/boatdamage" method="post" class="grid gap-3">
|
||||
{{ log::boat_select(only_ones=false, id='boat') }}
|
||||
{% if not loggedin_user %}
|
||||
{{ macros::select(label='Gemeldet von', data=coxes, name='user_id') }}
|
||||
{% endif %}
|
||||
{{ macros::input(label='Beschreibung des Schadens', name='desc', type='text', required=true, wrapper_class='col-span-4') }}
|
||||
<div class="col-span-4">
|
||||
{{ macros::checkbox(label='Boot sperren', name='lock_boat', type='text', required=true) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user