From 9331b2001d0a855bed38f5397efa39765891288b Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 2 Nov 2023 22:19:13 +0100 Subject: [PATCH 1/6] improve code with clippy --- src/model/logbook.rs | 6 +++--- src/tera/log.rs | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/model/logbook.rs b/src/model/logbook.rs index f03f209..b856afa 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -124,7 +124,7 @@ pub enum LogbookCreateError { impl From for LogbookCreateError { fn from(value: LogbookUpdateError) -> Self { - return match value { + match value { LogbookUpdateError::NotYourEntry => LogbookCreateError::NotYourEntry, LogbookUpdateError::TooManyRowers(a, b) => LogbookCreateError::TooManyRowers(a, b), LogbookUpdateError::RowerCreateError(a, b) => { @@ -140,7 +140,7 @@ impl From for LogbookCreateError { LogbookUpdateError::UserNotAllowedToUseBoat => { LogbookCreateError::UserNotAllowedToUseBoat } - }; + } } } @@ -429,7 +429,7 @@ ORDER BY departure DESC return Err(LogbookUpdateError::SteeringPersonNotInRowers); } - if !boat.shipmaster_allowed(&user).await && self.shipmaster != user.id { + if !boat.shipmaster_allowed(user).await && self.shipmaster != user.id { //second part: //shipmaster has //entered a diff --git a/src/tera/log.rs b/src/tera/log.rs index 013b67f..f9ee2fb 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -217,12 +217,10 @@ async fn create_kiosk( User::find_by_id(db, boat.owner.unwrap() as i32) .await .unwrap() + } else if let Some(shipmaster) = data.shipmaster { + User::find_by_id(db, shipmaster as i32).await.unwrap() } 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() - } + User::find_by_id(db, data.rowers[0] as i32).await.unwrap() }; Log::create( db, From 95e1ea302884fa1214950b6c4005525f7469ac58 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 3 Nov 2023 14:20:58 +0100 Subject: [PATCH 2/6] allow guests to see + upload ergo entries; show ergo menu item for guests --- src/tera/ergo.rs | 22 ++++++---------------- templates/includes/macros.html.tera | 6 ++++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/tera/ergo.rs b/src/tera/ergo.rs index b2a8aab..b2decf6 100644 --- a/src/tera/ergo.rs +++ b/src/tera/ergo.rs @@ -67,11 +67,7 @@ async fn reset(db: &State, _user: AdminUser) -> Flash { } #[get("/")] -async fn index( - db: &State, - user: NonGuestUser, - flash: Option>, -) -> Template { +async fn index(db: &State, user: User, flash: Option>) -> Template { let users = User::ergo(db).await; let thirty = sqlx::query_as!( @@ -94,7 +90,7 @@ async fn index( if let Some(msg) = flash { context.insert("flash", &msg.into_inner()); } - context.insert("loggedin_user", &user.user); + context.insert("loggedin_user", &user); context.insert("users", &users); context.insert("thirty", &thirty); context.insert("dozen", &dozen); @@ -113,7 +109,7 @@ pub struct ErgoToAdd<'a> { async fn new_thirty( db: &State, mut data: Form>, - created_by: NonGuestUser, + created_by: User, ) -> Flash { let user = User::find_by_id(db, data.user as i32).await.unwrap(); @@ -139,10 +135,7 @@ async fn new_thirty( Log::create( db, - format!( - "{} created thirty-ergo entry: {data:?}", - created_by.user.name - ), + format!("{} created thirty-ergo entry: {data:?}", created_by.name), ) .await; @@ -153,7 +146,7 @@ async fn new_thirty( async fn new_dozen( db: &State, mut data: Form>, - created_by: NonGuestUser, + created_by: User, ) -> Flash { let user = User::find_by_id(db, data.user as i32).await.unwrap(); @@ -179,10 +172,7 @@ async fn new_dozen( Log::create( db, - format!( - "{} created dozen-ergo entry: {data:?}", - created_by.user.name - ), + format!("{} created dozen-ergo entry: {data:?}", created_by.name), ) .await; diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 7d53179..8cc6daf 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -78,6 +78,12 @@ + {% else %} + {% if loggedin_user.weight and loggedin_user.sex and loggedin_user.dob %} + + Ergo + + {% endif %} {% endif %} {% if loggedin_user.is_admin %} Date: Fri, 3 Nov 2023 14:30:43 +0100 Subject: [PATCH 3/6] [TASK] guest user menu ergo --- templates/includes/macros.html.tera | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index 7d53179..fdd4d70 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -19,6 +19,29 @@ {% include "includes/question-icon" %} FAQs + {% if loggedin_user.is_guest and loggedin_user.weight and loggedin_user.sex and loggedin_user.dob %} + + {% include "includes/book" %} + Ergo + + + {% endif %} {% if not loggedin_user.is_guest %} Date: Fri, 3 Nov 2023 14:35:15 +0100 Subject: [PATCH 4/6] [TASK] guest user menu ergo --- templates/includes/macros.html.tera | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index bac6b2e..f97150c 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -101,13 +101,8 @@ - {% else %} - {% if loggedin_user.weight and loggedin_user.sex and loggedin_user.dob %} - - Ergo - - {% endif %} - {% endif %} {% if loggedin_user.is_admin %} + {% endif %} + {% if loggedin_user.is_admin %} Date: Sat, 4 Nov 2023 15:07:16 +0100 Subject: [PATCH 5/6] show proper amount of guests (changed bc cox is now included in rowers) --- templates/includes/forms/log.html.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index b4a1b72..eab4a57 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -181,7 +181,7 @@ {% endif %} {% set amount_rowers = log.rowers | length %} - {% set amount_guests = log.boat.amount_seats - amount_rowers -1 %} + {% set amount_guests = log.boat.amount_seats - amount_rowers %} {% if allowed_to_close and state == "on_water" %} {{ log::home(log=log, only_ones=only_ones) }} {% else %} From 0f8c7a365ec64c4e8d7dc2bc0a1a708996cc9af9 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 4 Nov 2023 16:27:17 +0100 Subject: [PATCH 6/6] push --- frontend/main.ts | 2 -- templates/includes/macros.html.tera | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/main.ts b/frontend/main.ts index 3d4fcf2..ab42d06 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -104,7 +104,6 @@ function setMaxAmountRowers(name: string, rowers: number) { //} let input = document.querySelector('#'+name); - if(input) { choiceObjects[name].config.maxItemCount = rowers; if (rowers === 0) { @@ -201,7 +200,6 @@ interface ChoiceEvent extends Event{ } function initNewChoice(select: HTMLInputElement) { - let seats = 0; if (select.dataset && select.dataset.seats) { seats = +select.dataset.seats; diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index f97150c..a051759 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -175,7 +175,7 @@ {% endif %} {% for d in data %} -