From d9b010b33a7ea624c5a354858f8eb05f183d6e18 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Sun, 27 Feb 2022 23:35:30 +0100 Subject: [PATCH] Fix group links --- src/server.rs | 30 ++++++++++++++++++++++++++++++ src/templates.rs | 2 ++ templates/admin.html | 2 +- templates/admin_group.html | 4 ++-- templates/group.html | 4 ++-- templates/index.html | 2 +- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/server.rs b/src/server.rs index 0a096f6..c040877 100644 --- a/src/server.rs +++ b/src/server.rs @@ -114,6 +114,14 @@ pub async fn start_server( handle_admin(req, config.clone(), templates.clone(), dbs.clone()) } }); + app.at(&format!("{}admin/g/", config.root_url)).get({ + let config = config.clone(); + let templates = templates.clone(); + let dbs = dbs.clone(); + move |req: tide::Request<()>| { + handle_admin(req, config.clone(), templates.clone(), dbs.clone()) + } + }); app.at(&format!("{}admin/ad/:ad", config.root_url)).get({ let config = config.clone(); let templates = templates.clone(); @@ -234,6 +242,17 @@ async fn serve_group<'a>( }) .collect::>(), ), + parent_group_name: &dbs + .group + .get(&group.parent) + .unwrap() + .map_or_else(String::new, |parent_group| { + bincode::deserialize::(&parent_group) + .map_or_else( + |_| String::new(), + |parent_group| parent_group.name, + ) + }), group: &to_json(group), groups: &to_json( dbs.group_by_group @@ -316,6 +335,17 @@ async fn serve_admin_group<'a>( }) .collect::>(), ), + parent_group_name: &dbs + .group + .get(&group.parent) + .unwrap() + .map_or_else(String::new, |parent_group| { + bincode::deserialize::(&parent_group) + .map_or_else( + |_| String::new(), + |parent_group| parent_group.name, + ) + }), group: &to_json(group), groups: &to_json( dbs.group_by_group diff --git a/src/templates.rs b/src/templates.rs index d11f07d..2d7a45a 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -105,6 +105,7 @@ pub struct GroupTemplate<'a> { pub ads: &'a Json, pub group: &'a Json, pub groups: &'a Json, + pub parent_group_name: &'a str, pub new_ad_form_refill: Option, } @@ -115,6 +116,7 @@ pub struct AdminGroupTemplate<'a> { pub ads: &'a Json, pub group: &'a Json, pub groups: &'a Json, + pub parent_group_name: &'a str, pub new_group_form_refill: Option, } diff --git a/templates/admin.html b/templates/admin.html index 0ec0112..023d1bd 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -29,7 +29,7 @@ {{/if}} {{#each groups}} - {{this.title}}
+ {{this.title}}
{{/each}} {{#if ads}} diff --git a/templates/admin_group.html b/templates/admin_group.html index 9ed3fe8..6a2f1aa 100644 --- a/templates/admin_group.html +++ b/templates/admin_group.html @@ -17,7 +17,7 @@

Administration – {{title}}

{{group.title}}

- Groupe parent
+ Groupe parent
{{#if errors}}
@@ -31,7 +31,7 @@ {{/if}} {{#each groups}} - {{this.title}}
+ {{this.title}}
{{/each}} {{#if ads}} diff --git a/templates/group.html b/templates/group.html index 789364d..c2450c2 100644 --- a/templates/group.html +++ b/templates/group.html @@ -17,7 +17,7 @@

{{title}}

{{group.title}}

- Groupe parent
+ Groupe parent
{{#if errors}}
@@ -31,7 +31,7 @@ {{/if}} {{#each groups}} - {{this.title}}
+ {{this.title}}
{{/each}} {{#if ads}} diff --git a/templates/index.html b/templates/index.html index e489694..91c4535 100644 --- a/templates/index.html +++ b/templates/index.html @@ -31,7 +31,7 @@

Ceci est une démo du nouveau site ĞMarché en développement.

{{#each groups}} - {{this.title}}
+ {{this.title}}
{{/each}} {{#if ads}}