Fix group links

This commit is contained in:
Pascal Engélibert 2022-02-27 23:35:30 +01:00
parent aa1893feb2
commit d9b010b33a
Signed by: tuxmain
GPG Key ID: 3504BC6D362F7DCA
6 changed files with 38 additions and 6 deletions

View File

@ -114,6 +114,14 @@ pub async fn start_server(
handle_admin(req, config.clone(), templates.clone(), dbs.clone()) 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({ app.at(&format!("{}admin/ad/:ad", config.root_url)).get({
let config = config.clone(); let config = config.clone();
let templates = templates.clone(); let templates = templates.clone();
@ -234,6 +242,17 @@ async fn serve_group<'a>(
}) })
.collect::<Vec<AdWithId>>(), .collect::<Vec<AdWithId>>(),
), ),
parent_group_name: &dbs
.group
.get(&group.parent)
.unwrap()
.map_or_else(String::new, |parent_group| {
bincode::deserialize::<Group>(&parent_group)
.map_or_else(
|_| String::new(),
|parent_group| parent_group.name,
)
}),
group: &to_json(group), group: &to_json(group),
groups: &to_json( groups: &to_json(
dbs.group_by_group dbs.group_by_group
@ -316,6 +335,17 @@ async fn serve_admin_group<'a>(
}) })
.collect::<Vec<AdWithId>>(), .collect::<Vec<AdWithId>>(),
), ),
parent_group_name: &dbs
.group
.get(&group.parent)
.unwrap()
.map_or_else(String::new, |parent_group| {
bincode::deserialize::<Group>(&parent_group)
.map_or_else(
|_| String::new(),
|parent_group| parent_group.name,
)
}),
group: &to_json(group), group: &to_json(group),
groups: &to_json( groups: &to_json(
dbs.group_by_group dbs.group_by_group

View File

@ -105,6 +105,7 @@ pub struct GroupTemplate<'a> {
pub ads: &'a Json, pub ads: &'a Json,
pub group: &'a Json, pub group: &'a Json,
pub groups: &'a Json, pub groups: &'a Json,
pub parent_group_name: &'a str,
pub new_ad_form_refill: Option<NewAdQuery>, pub new_ad_form_refill: Option<NewAdQuery>,
} }
@ -115,6 +116,7 @@ pub struct AdminGroupTemplate<'a> {
pub ads: &'a Json, pub ads: &'a Json,
pub group: &'a Json, pub group: &'a Json,
pub groups: &'a Json, pub groups: &'a Json,
pub parent_group_name: &'a str,
pub new_group_form_refill: Option<AdminNewGroupQuery>, pub new_group_form_refill: Option<AdminNewGroupQuery>,
} }

View File

@ -29,7 +29,7 @@
{{/if}} {{/if}}
{{#each groups}} {{#each groups}}
<a href="{{root_url}}admin/g/{{this.name}}">{{this.title}}</a><br/> <a href="{{../root_url}}admin/g/{{this.name}}">{{this.title}}</a><br/>
{{/each}} {{/each}}
{{#if ads}} {{#if ads}}

View File

@ -17,7 +17,7 @@
<h1>Administration &#8211; {{title}}</h1> <h1>Administration &#8211; {{title}}</h1>
<h2>{{group.title}}</h2> <h2>{{group.title}}</h2>
<a href="{{root_url}}admin/g/{{group.parent}}">Groupe parent</a><br/> <a href="{{root_url}}admin/g/{{parent_group_name}}">Groupe parent</a><br/>
{{#if errors}} {{#if errors}}
<div id="errors"> <div id="errors">
@ -31,7 +31,7 @@
{{/if}} {{/if}}
{{#each groups}} {{#each groups}}
<a href="{{root_url}}admin/g/{{this.name}}">{{this.title}}</a><br/> <a href="{{../root_url}}admin/g/{{this.name}}">{{this.title}}</a><br/>
{{/each}} {{/each}}
{{#if ads}} {{#if ads}}

View File

@ -17,7 +17,7 @@
<h1>{{title}}</h1> <h1>{{title}}</h1>
<h2>{{group.title}}</h2> <h2>{{group.title}}</h2>
<a href="{{root_url}}admin/g/{{group.parent}}">Groupe parent</a><br/> <a href="{{root_url}}admin/g/{{parent_group_name}}">Groupe parent</a><br/>
{{#if errors}} {{#if errors}}
<div id="errors"> <div id="errors">
@ -31,7 +31,7 @@
{{/if}} {{/if}}
{{#each groups}} {{#each groups}}
<a href="{{root_url}}g/{{this.name}}">{{this.title}}</a><br/> <a href="{{../root_url}}g/{{this.name}}">{{this.title}}</a><br/>
{{/each}} {{/each}}
{{#if ads}} {{#if ads}}

View File

@ -31,7 +31,7 @@
<p>Ceci est une démo du nouveau site ĞMarché en développement.</p> <p>Ceci est une démo du nouveau site ĞMarché en développement.</p>
{{#each groups}} {{#each groups}}
<a href="{{root_url}}g/{{this.name}}">{{this.title}}</a><br/> <a href="{{../root_url}}g/{{this.name}}">{{this.title}}</a><br/>
{{/each}} {{/each}}
{{#if ads}} {{#if ads}}