forked from Ruderverein-Donau-Linz/rowt
		
	finish day CRU
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1 +1,2 @@ | |||||||
| target/ | target/ | ||||||
|  | db.sqlite | ||||||
|   | |||||||
| @@ -21,6 +21,7 @@ | |||||||
|  |  | ||||||
| # Edge case | # Edge case | ||||||
| - Trip in the morning on usi rowing day | - Trip in the morning on usi rowing day | ||||||
|  | - after N people (/ cox) -> red highlighted -> queue | ||||||
|  |  | ||||||
| # Fancy | # Fancy | ||||||
| - Every cox can define which boats they use | - Every cox can define which boats they use | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -7,6 +7,7 @@ use std::collections::HashMap; | |||||||
|  |  | ||||||
| use chrono::Duration; | use chrono::Duration; | ||||||
| use chrono::Local; | use chrono::Local; | ||||||
|  | use rocket::response::Redirect; | ||||||
| use rocket::{form::Form, fs::FileServer, State}; | use rocket::{form::Form, fs::FileServer, State}; | ||||||
| use rocket_dyn_templates::context; | use rocket_dyn_templates::context; | ||||||
| use rocket_dyn_templates::Template; | use rocket_dyn_templates::Template; | ||||||
| @@ -49,17 +50,26 @@ struct DayForm { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[put("/day", data = "<day>")] | #[put("/day", data = "<day>")] | ||||||
| async fn create(db: &State<DatabaseConnection>, day: Form<DayForm>) -> Template { | async fn create(db: &State<DatabaseConnection>, day: Form<DayForm>) -> Redirect { | ||||||
|     let day = day::ActiveModel { |     let id = chrono::NaiveDate::parse_from_str(&day.day, "%Y-%m-%d").unwrap(); | ||||||
|         day: Set(chrono::NaiveDate::parse_from_str(&day.day, "%Y-%m-%d").unwrap()), |     let new_day = day::ActiveModel { | ||||||
|  |         day: Set(id), | ||||||
|         planned_amount_cox: Set(day.planned_amount_cox), |         planned_amount_cox: Set(day.planned_amount_cox), | ||||||
|         planned_starting_time: Set(day.planned_starting_time.clone()), |         planned_starting_time: Set(day.planned_starting_time.clone()), | ||||||
|         open_registration: Set(day.open_registration), |         open_registration: Set(day.open_registration), | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     day.insert(db.inner()).await.unwrap(); //TODO: fixme |     let day: Option<day::Model> = day::Entity::find_by_id(id).one(db.inner()).await.unwrap(); | ||||||
|  |     match day { | ||||||
|  |         Some(_) => { | ||||||
|  |             new_day.update(db.inner()).await.unwrap(); //TODO: fixme | ||||||
|  |         } | ||||||
|  |         None => { | ||||||
|  |             new_day.insert(db.inner()).await.unwrap(); //TODO: fixme | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     Template::render("index", context! {}) |     Redirect::to("/") | ||||||
| } | } | ||||||
|  |  | ||||||
| #[launch] | #[launch] | ||||||
|   | |||||||
| @@ -7,43 +7,44 @@ | |||||||
| 	<br /> | 	<br /> | ||||||
| 	 | 	 | ||||||
| 	{% if days[day_string] and days[day_string].planned_amount_cox > 0%} | 	{% if days[day_string] and days[day_string].planned_amount_cox > 0%} | ||||||
| 		{% set day = days[day_string] %} | 		{% set cur_day = days[day_string] %} | ||||||
| 		Geplante Steuerpersonen: {{ day.planned_amount_cox}}<br /> | 		Geplante Steuerpersonen: {{ cur_day.planned_amount_cox}}<br /> | ||||||
| 		Geplante Abfahrtszeit: {{ day.planned_starting_time }}<br /> | 		Geplante Abfahrtszeit: {{ cur_day.planned_starting_time }}<br /> | ||||||
| 		{% if day.open_registration %} | 		{% if cur_day.open_registration %} | ||||||
| 			ANMELDEN | 			ANMELDEN | ||||||
| 		{% 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 %} | 	{% else %} | ||||||
| 		(Noch) keine Ausfahrt geplant | 		(Noch) keine Ausfahrt geplant | ||||||
|  | 	{% endif %} | ||||||
|  |  | ||||||
| 		<details> | 		<details> | ||||||
| 			<summary class="button">+</summary> | 			<summary class="button">✎</summary> | ||||||
| 			<form method="post" action="/day"> | 			<form method="post" action="/day"> | ||||||
| 				<input type="hidden" name="_method" value="put" /> | 				<input type="hidden" name="_method" value="put" /> | ||||||
| 				<input type="hidden" name="day" value="{{ day | date(format="%Y-%m-%d") }}" /> | 				<input type="hidden" name="day" value="{{ day_string }}" /> | ||||||
| 				<div class="row"> | 				<div class="row"> | ||||||
| 					<div class="three columns"> | 					<div class="three columns"> | ||||||
| 						<label for="planned_amount_cox">Geplante Steuerpersonen</label> | 						<label for="planned_amount_cox">Geplante Steuerpersonen</label> | ||||||
| 						<input class="u-full-width" type="number" id="planned_amount_cox" name="planned_amount_cox"> | 						<input class="u-full-width" type="number" id="planned_amount_cox" name="planned_amount_cox" value="{{ cur_day.planned_amount_cox | default(value=2) }}"> | ||||||
| 					</div> | 					</div> | ||||||
| 					<div class="three columns"> | 					<div class="three columns"> | ||||||
| 						<label for="planned_starting_time">Geplante Abfahrtszeit</label> | 						<label for="planned_starting_time">Geplante Abfahrtszeit</label> | ||||||
| 						<input class="u-full-width" type="time" id="planned_starting_time" name="planned_starting_time"> | 						<input class="u-full-width" type="time" id="planned_starting_time" name="planned_starting_time" value="{{ cur_day.planned_starting_time | default(value='17:00') }}"> | ||||||
| 					</div> | 					</div> | ||||||
| 					<div class="three columns"> | 					<div class="three columns"> | ||||||
| 						<label for="open_registration">Registrierung offen</label> | 						<label for="open_registration">Registrierung offen</label> | ||||||
| 						<input class="u-full-width" type="checkbox" id="open_registration" name="open_registration" checked="true"/> | 						<input class="u-full-width" type="checkbox" id="open_registration" name="open_registration" {% if not cur_day or cur_day.open_registration %} checked="true" {% endif %}/> | ||||||
| 					</div> | 					</div> | ||||||
| 					<div class="three columns"> | 					<div class="three columns"> | ||||||
| 						<input class="button-primary" type="submit" value="Hinzufügen"> | 						<input class="button-primary" type="submit" value="Speichern"> | ||||||
| 					</div> | 					</div> | ||||||
|  |  | ||||||
| 				</div> | 				</div> | ||||||
| 			</form> | 			</form> | ||||||
| 		</details> | 		</details> | ||||||
| 	{% endif %} | 	 | ||||||
|  |  | ||||||
| 	<hr /> | 	<hr /> | ||||||
| {% endfor %} | {% endfor %} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user