From 33baf479b53d96e84b065d53c13ffa10ddc71559 Mon Sep 17 00:00:00 2001 From: Max Hohlfeld Date: Sun, 23 Jun 2024 11:12:53 +0200 Subject: [PATCH] feat: move export to own view --- .editorconfig | 16 +++ src/endpoints/export/get_availability.rs | 36 +++++++ .../get_availability_data.rs} | 4 +- src/endpoints/export/mod.rs | 2 + src/endpoints/mod.rs | 9 +- templates/area/new.html | 70 ++++++------ templates/base.html | 64 +++++------ templates/export/availabilityxml.html | 42 ++++++++ templates/index.html | 66 +++--------- templates/location/new.html | 102 +++++++++--------- templates/location/overview.html | 3 - templates/nav.html | 80 +++++++++----- templates/user/login.html | 52 +++++---- 13 files changed, 316 insertions(+), 230 deletions(-) create mode 100644 .editorconfig create mode 100644 src/endpoints/export/get_availability.rs rename src/endpoints/{get_export.rs => export/get_availability_data.rs} (96%) create mode 100644 src/endpoints/export/mod.rs create mode 100644 templates/export/availabilityxml.html diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..95ee2154 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true +max_line_length = off + +[*.html] +indent_style = space +indent_size = 2 diff --git a/src/endpoints/export/get_availability.rs b/src/endpoints/export/get_availability.rs new file mode 100644 index 00000000..6b4207f8 --- /dev/null +++ b/src/endpoints/export/get_availability.rs @@ -0,0 +1,36 @@ +use actix_web::{web, HttpResponse, Responder}; +use askama::Template; +use askama_actix::TemplateToResponse; +use sqlx::PgPool; + +use crate::models::{Area, User, Role}; + +#[derive(Template)] +#[template(path = "export/availabilityxml.html")] +struct AvailabilityExportTemplate { + user: User, + areas: Option> +} + +#[actix_web::get("/export/availability")] +pub async fn get( + user: web::ReqData, + pool: web::Data +) -> impl Responder { + if user.role != Role::Admin && user.role != Role::AreaManager { + return HttpResponse::Unauthorized().finish(); + } + + let areas = if user.role == Role::Admin { + Some(Area::read_all(pool.get_ref()).await.unwrap()) + } else { + None + }; + + let template = AvailabilityExportTemplate { + user: user.into_inner(), + areas + }; + + return template.to_response(); +} diff --git a/src/endpoints/get_export.rs b/src/endpoints/export/get_availability_data.rs similarity index 96% rename from src/endpoints/get_export.rs rename to src/endpoints/export/get_availability_data.rs index aff91eaf..0f65af4d 100644 --- a/src/endpoints/get_export.rs +++ b/src/endpoints/export/get_availability_data.rs @@ -1,5 +1,5 @@ use actix_identity::Identity; -use actix_web::{http::header::{ContentDisposition, ContentType, Header, CONTENT_DISPOSITION}, web, HttpResponse, Responder}; +use actix_web::{http::header::{ContentDisposition, ContentType, CONTENT_DISPOSITION}, web, HttpResponse, Responder}; use chrono::{Months, NaiveDate, NaiveTime, Utc}; use serde::{Deserialize, Serialize}; use sqlx::PgPool; @@ -33,7 +33,7 @@ struct ExportAvailabillityXml { assigned: bool, } -#[actix_web::get("/export-availabillities")] +#[actix_web::get("/export/availabilitydata")] pub async fn get( pool: web::Data, user: Identity, diff --git a/src/endpoints/export/mod.rs b/src/endpoints/export/mod.rs new file mode 100644 index 00000000..8fabad39 --- /dev/null +++ b/src/endpoints/export/mod.rs @@ -0,0 +1,2 @@ +pub mod get_availability; +pub mod get_availability_data; diff --git a/src/endpoints/mod.rs b/src/endpoints/mod.rs index b0d3c5d4..a9def783 100644 --- a/src/endpoints/mod.rs +++ b/src/endpoints/mod.rs @@ -2,13 +2,13 @@ use actix_web::web::ServiceConfig; use chrono::NaiveDate; use serde::Deserialize; +mod area; +mod assignment; mod availability; mod events; +mod export; mod location; mod user; -mod assignment; -mod get_export; -mod area; #[derive(Deserialize)] pub struct IdPath { @@ -54,5 +54,6 @@ pub fn init(cfg: &mut ServiceConfig) { cfg.service(area::get_new::get); cfg.service(area::post_new::post); - cfg.service(get_export::get); + cfg.service(export::get_availability::get); + cfg.service(export::get_availability_data::get); } diff --git a/templates/area/new.html b/templates/area/new.html index a0d40ea4..8fba2321 100644 --- a/templates/area/new.html +++ b/templates/area/new.html @@ -7,44 +7,44 @@

Neuen Bereich anlegen

-
- -
-
-
-
- -
-
-
+
+ +
+
+
+
+ +
+
+
-
-
-
-
- -
- -
-
+
+
+
+
+ +
+ +
+
diff --git a/templates/base.html b/templates/base.html index 6dc1a333..bba187b7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,43 +2,43 @@ - - - Brass - Brasiwa Leipzig - - - + + + Brass - Brasiwa Leipzig + + + - + [class*=" icon"], + [class^=icon] { + display: inline-block; + width: 1em; + height: 1em; + stroke-width: 0; + stroke: currentColor; + fill: currentColor; + line-height: 1; + position: relative; + top: -.05em; + vertical-align: middle; + } + - {% block body %} - {% endblock %} + {% block body %} + {% endblock %} diff --git a/templates/export/availabilityxml.html b/templates/export/availabilityxml.html new file mode 100644 index 00000000..3494a2b7 --- /dev/null +++ b/templates/export/availabilityxml.html @@ -0,0 +1,42 @@ +{% extends "nav.html" %} + +{% block content %} +
+
+

+ Verfügbarkeiten nach XML exportieren +

+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ + {% if user.role == Role::Admin %} +
+ +
+
+ +
+
+
+ {% endif %} + +
+
+
+{% endblock %} diff --git a/templates/index.html b/templates/index.html index a6b150de..7eaa450f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -40,7 +40,7 @@ {% if event.canceled %}Veranstaltung abgesagt!{% endif %}
{{ event.name }}
- + {% if user.role == Role::AreaManager || user.role == Role::Admin %} Planen bearbeiten @@ -89,24 +89,25 @@ - {% for availabillity in availabillities %} - {% let u = availabillity.user.as_ref().unwrap() %} - + {% for availabillity in availabillities %} + {% let u = availabillity.user.as_ref().unwrap() %} + {{ u.name }} {% match u.function %} - {% when Function::Posten %} - Posten - {% when Function::Wachhabender %} - Wachhabender - {% else %} + {% when Function::Posten %} + Posten + {% when Function::Wachhabender %} + Wachhabender + {% else %} {% endmatch %} {% if availabillity.start_time.is_some() && availabillity.end_time.is_some() %} - {{ availabillity.start_time.as_ref().unwrap().format("%R") }} bis {{ availabillity.end_time.as_ref().unwrap().format("%R") }} + {{ availabillity.start_time.as_ref().unwrap().format("%R") }} bis {{ + availabillity.end_time.as_ref().unwrap().format("%R") }} {% else %} - ganztägig + ganztägig {% endif %} @@ -121,7 +122,7 @@ {% endif %} - {% endfor %} + {% endfor %}
@@ -130,52 +131,13 @@ -
-
-

- Verfügbarkeiten nach XML exportieren -

-
-
- -
- -
-
- -
- -
- -
-
- - {% if user.role == Role::Admin %} -
- -
-
- -
-
-
- {% endif %} - -
-
-
- {% endblock %} diff --git a/templates/nav.html b/templates/nav.html index 79029684..ddc778c1 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -4,7 +4,7 @@