diff --git a/src/tera/mod.rs b/src/tera/mod.rs index b5ab37c..3c2e6bd 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -19,6 +19,7 @@ use tera::Context; use crate::model::{ notification::Notification, + role::Role, user::{User, UserWithRoles}, }; @@ -53,6 +54,27 @@ async fn index(db: &State, user: User, flash: Option, user: User, flash: Option>) -> Template { + let mut context = Context::new(); + if let Some(msg) = flash { + context.insert("flash", &msg.into_inner()); + } + + let bootskundige = + User::all_with_role(db, &Role::find_by_name(db, "Bootsführer").await.unwrap()).await; + + let mut coxes = User::all_with_role(db, &Role::find_by_name(db, "cox").await.unwrap()).await; + + coxes.retain(|user| !bootskundige.contains(&user)); // Remove bootskundige from coxes list + + context.insert("coxes", &coxes); + context.insert("bootskundige", &bootskundige); + + context.insert("loggedin_user", &UserWithRoles::from_user(user, db).await); + Template::render("steering", context.into_json()) +} + #[post("/", data = "")] async fn wikiauth(db: &State, login: Form>) -> String { match User::login(db, login.name, login.password).await { @@ -86,7 +108,7 @@ pub struct Config { pub fn config(rocket: Rocket) -> Rocket { rocket - .mount("/", routes![index]) + .mount("/", routes![index, steering]) .mount("/auth", auth::routes()) .mount("/wikiauth", routes![wikiauth]) .mount("/log", log::routes()) diff --git a/templates/index.html.tera b/templates/index.html.tera index 9d6126d..040388e 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -81,6 +81,9 @@ Bootsreservierung +
  • + Steuerleute & Co +
  • {% endif %} diff --git a/templates/steering.html.tera b/templates/steering.html.tera new file mode 100644 index 0000000..4599673 --- /dev/null +++ b/templates/steering.html.tera @@ -0,0 +1,22 @@ +{% import "includes/macros" as macros %} +{% extends "base" %} +{% block content %} +
    +

    Steuerleute + Personen mit Steuerberechtigung

    +
    +
    +
      + {% for cox in coxes | sort(attribute='name') %}
    • {{ cox.name }}
    • {% endfor %} +
    +
    +
    +

    Bootskundige

    +
    +
    +
      + {% for cox in bootskundige | sort(attribute='name') %}
    • {{ cox.name }}
    • {% endfor %} +
    +
    +
    +
    +{% endblock content %}