From 5740248b969fa20a6d087b1167b810cdad464684 Mon Sep 17 00:00:00 2001 From: Max Hohlfeld Date: Mon, 11 Nov 2024 20:27:01 +0100 Subject: [PATCH] refactor: rework index --- src/filters.rs | 15 +++++++++++++- templates/availability/new_or_edit.html | 24 +++++++++++++++++------ templates/index.html | 26 ++++++++++++++----------- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/filters.rs b/src/filters.rs index 6049564e..44e429ad 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,3 +1,5 @@ +use crate::models::Function; + pub fn show_area_query(a: &Option, first: bool) -> ::askama::Result { let char = if first { '?' } else { '&' }; @@ -27,7 +29,7 @@ pub fn insert_value(option: &Option) -> askama::Result { pub fn is_some_and_eq(option: &Option, other: &T) -> askama::Result where - T: Eq + T: Eq, { Ok(option.as_ref().is_some_and(|x| x == other)) } @@ -35,3 +37,14 @@ where pub fn invert(b: &bool) -> askama::Result { return Ok(!b); } + +pub fn show_tree(f: &Function) -> askama::Result { + let tags = match f { + Function::Posten => r#"Posten"#, + Function::Wachhabender => { + r#"PostenWachhabender"# + } + }; + + Ok(format!(r#"
{tags}
"#)) +} diff --git a/templates/availability/new_or_edit.html b/templates/availability/new_or_edit.html index c1575da6..a25ba418 100644 --- a/templates/availability/new_or_edit.html +++ b/templates/availability/new_or_edit.html @@ -79,14 +79,26 @@
- {% if id.is_some() %} - - {% else %} - - {% endif %} +
diff --git a/templates/index.html b/templates/index.html index 603a315b..38e28674 100644 --- a/templates/index.html +++ b/templates/index.html @@ -141,13 +141,7 @@ {{ u.name }} - {% match u.function %} - {% when Function::Posten %} - Posten - {% when Function::Wachhabender %} - Wachhabender - {% else %} - {% endmatch %} + {{ u.function|show_tree|safe }} {% if availabillity.start_time.is_some() && availabillity.end_time.is_some() %} @@ -163,10 +157,20 @@ {% if availabillity.user_id == user.id %}
- Bearbeiten - + + + + + Bearbeiten + +
{% endif %}