diff --git a/.sqlx/query-7bc06d40e0e7f43f73861bb5fa9fe954aea7c821abf785b68d0731fcaf0f4845.json b/.sqlx/query-7bc06d40e0e7f43f73861bb5fa9fe954aea7c821abf785b68d0731fcaf0f4845.json new file mode 100644 index 00000000..52dd109b --- /dev/null +++ b/.sqlx/query-7bc06d40e0e7f43f73861bb5fa9fe954aea7c821abf785b68d0731fcaf0f4845.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE event SET canceled = $1 WHERE id = $2;", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Bool", + "Int4" + ] + }, + "nullable": [] + }, + "hash": "7bc06d40e0e7f43f73861bb5fa9fe954aea7c821abf785b68d0731fcaf0f4845" +} diff --git a/web/snapshots/brass_web__endpoints__events__get_edit__inner_produces_template.snap b/web/snapshots/brass_web__endpoints__events__get_edit__inner_produces_template.snap index f00f3a92..ddcc93f1 100644 --- a/web/snapshots/brass_web__endpoints__events__get_edit__inner_produces_template.snap +++ b/web/snapshots/brass_web__endpoints__events__get_edit__inner_produces_template.snap @@ -12,6 +12,37 @@ snapshot_kind: text + +
+
+
+
+
+ +
+
+ +
+
+
+
+ + + +
@@ -19,7 +50,7 @@ snapshot_kind: text
- +
@@ -32,10 +63,10 @@ snapshot_kind: text
- +
- +
@@ -48,10 +79,9 @@ snapshot_kind: text
- - @@ -70,7 +100,7 @@ snapshot_kind: text
@@ -87,7 +117,7 @@ snapshot_kind: text
@@ -105,7 +135,7 @@ snapshot_kind: text
+ value="2" />
@@ -120,7 +150,7 @@ snapshot_kind: text
+ value="Tuchuniform" />
@@ -133,7 +163,7 @@ snapshot_kind: text
- +
@@ -144,10 +174,24 @@ snapshot_kind: text
- +
diff --git a/web/src/endpoints/events/mod.rs b/web/src/endpoints/events/mod.rs index e4c9d5ac..9b067bdd 100644 --- a/web/src/endpoints/events/mod.rs +++ b/web/src/endpoints/events/mod.rs @@ -9,6 +9,7 @@ pub mod get_new; pub mod get_plan; pub mod post_new; pub mod post_edit; +pub mod put_cancelation; #[derive(Template)] #[cfg_attr(not(test), template(path = "events/new_or_edit.html"))] diff --git a/web/src/endpoints/events/put_cancelation.rs b/web/src/endpoints/events/put_cancelation.rs new file mode 100644 index 00000000..5f7c90e6 --- /dev/null +++ b/web/src/endpoints/events/put_cancelation.rs @@ -0,0 +1,56 @@ +use actix_http::header::LOCATION; +use actix_web::{web, HttpResponse, Responder}; +use sqlx::PgPool; + +use crate::{ + endpoints::IdPath, + models::{Event, Role, User}, + utils::{self, ApplicationError}, +}; + +#[actix_web::put("/events/{id}/cancel")] +pub async fn put_cancel( + user: web::ReqData, + pool: web::Data, + path: web::Path, +) -> Result { + handle_set_event_cancelation_to(user, pool, path, true).await +} + +#[actix_web::put("/events/{id}/uncancel")] +pub async fn put_uncancel( + user: web::ReqData, + pool: web::Data, + path: web::Path, +) -> Result { + handle_set_event_cancelation_to(user, pool, path, false).await +} + +async fn handle_set_event_cancelation_to( + user: web::ReqData, + pool: web::Data, + path: web::Path, + cancelation_state: bool, +) -> Result { + if user.role != Role::Admin && user.role != Role::AreaManager { + return Err(ApplicationError::Unauthorized); + } + + let Some(event) = Event::read_by_id_including_location(pool.get_ref(), path.id).await? else { + return Ok(HttpResponse::NotFound().finish()); + }; + + if event.canceled != cancelation_state { + if user.role != Role::Admin && user.area_id != event.location.as_ref().unwrap().area_id { + return Ok(HttpResponse::BadRequest().body("Can't use location outside of your area")); + } + + Event::update_cancelation(pool.get_ref(), event.id, cancelation_state).await?; + } + + let url = utils::get_return_url_for_date(&event.date); + println!("redirecto to {url}"); + Ok(HttpResponse::Ok() + .insert_header(("HX-LOCATION", url)) + .finish()) +} diff --git a/web/src/endpoints/mod.rs b/web/src/endpoints/mod.rs index 9bd5ee5f..8777faa7 100644 --- a/web/src/endpoints/mod.rs +++ b/web/src/endpoints/mod.rs @@ -56,6 +56,8 @@ pub fn init(cfg: &mut ServiceConfig) { cfg.service(availability::post_new::post); cfg.service(availability::post_update::post); + cfg.service(events::put_cancelation::put_cancel); + cfg.service(events::put_cancelation::put_uncancel); cfg.service(events::get_new::get); cfg.service(events::post_new::post); cfg.service(events::get_plan::get); diff --git a/web/src/models/event.rs b/web/src/models/event.rs index 222533bb..db7f982b 100644 --- a/web/src/models/event.rs +++ b/web/src/models/event.rs @@ -158,4 +158,10 @@ impl Event { Ok(()) } + + pub async fn update_cancelation(pool: &PgPool, id: i32, canceled: bool) -> Result<()> { + query!("UPDATE event SET canceled = $1 WHERE id = $2;", canceled, id).execute(pool).await?; + + Ok(()) + } } diff --git a/web/src/models/location.rs b/web/src/models/location.rs index ea3020c1..60752adc 100644 --- a/web/src/models/location.rs +++ b/web/src/models/location.rs @@ -51,7 +51,7 @@ impl Location { let locations = records .iter() .map(|lr| Location { - id: lr.id, + id: lr.locationid, name: lr.name.to_string(), area_id: lr.areaid, area: Some(Area { diff --git a/web/static/style.scss b/web/static/style.scss index 5f8a3254..9a8ae246 100644 --- a/web/static/style.scss +++ b/web/static/style.scss @@ -27,6 +27,7 @@ $primary: $crimson, @forward "bulma/sass/elements/table"; @forward "bulma/sass/elements/title"; @forward "bulma/sass/elements/delete"; +@forward "bulma/sass/elements/notification"; @forward "bulma/sass/form"; diff --git a/web/templates/events/new_or_edit.html b/web/templates/events/new_or_edit.html index 43d0e923..606e6d12 100644 --- a/web/templates/events/new_or_edit.html +++ b/web/templates/events/new_or_edit.html @@ -13,6 +13,37 @@ + {% if let Some(event) = event %} +
+
+
+
+
+ +
+
+ +
+
+
+
+ {% endif %} + + {% let disabled = event.is_some() && event.as_ref().unwrap().canceled %} +
@@ -21,7 +52,7 @@
+ %} value="{{ event.name }}" {% endif %} {{ disabled|cond_show("disabled") }} />
@@ -35,11 +66,11 @@ {% let f = "%H:%M" %}
+ %}{{ event.start_time.format(f) }}{% else %}0:00{% endif %}" {{ disabled|cond_show("disabled") }} />
+ %}{{ event.end_time.format(f) }}{% else %}23:59{% endif %}" {{ disabled|cond_show("disabled") }} />
@@ -52,12 +83,12 @@
- {% for location in locations %} - {% endfor %} @@ -78,7 +109,8 @@
{% if wh_disabled %} @@ -101,7 +133,8 @@
{% if fa_disabled %} @@ -123,11 +156,13 @@
+ {% if let Some(event)=event %} value="{{ event.amount_of_posten }}" {% endif %} {{ + disabled|cond_show("disabled") }} />
{% if posten_planned %}

- Mindestens {{ amount_of_planned_posten }} Posten, da bereits diese Anzahl eingeplant ist. Zum verringern + Mindestens {{ amount_of_planned_posten }} Posten, da bereits diese Anzahl eingeplant ist. Zum + verringern diese erst entplanen!

{% endif %} @@ -143,7 +178,7 @@
+ value="{{ event.clothing }}" {% endif %} {{ disabled|cond_show("disabled") }} />
@@ -157,7 +192,7 @@
+ %} {{ disabled|cond_show("disabled") }} />
@@ -168,10 +203,26 @@
- +
diff --git a/web/templates/index.html b/web/templates/index.html index 2b93f4cd..560ec2b1 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -96,11 +96,14 @@ Bearbeiten - als abgesagt markieren {% endif %} - {% if event.canceled %}Veranstaltung abgesagt!{% endif %} + {% if event.canceled %} +
+ Veranstaltung abgesagt! +
+ {% endif %}

Uhrzeit: {{ event.start_time.format("%R") }} Uhr - {{ event.end_time.format("%R") }} Uhr