[UI][PLUGIN][Directory] Use a single template for all results

This commit is contained in:
Hugo Sales 2022-01-01 21:52:30 +00:00
parent b1fbf7d6ef
commit 5662210a2d
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 13 additions and 30 deletions

View File

@ -40,7 +40,7 @@ class Directory extends FeedController
* Function responsible for displaying a list of actors of a given
* $actor_type, sorted by the `order_by` GET parameter, if given
*/
private function impl(Request $request, string $template, int $actor_type): array
private function impl(Request $request, int $actor_type, string $title, string $empty_message): array
{
if ($actor_type !== Actor::PERSON && $actor_type !== Actor::GROUP) {
throw new BugFoundException("Unimplemented for actor type: {$actor_type}");
@ -130,19 +130,21 @@ class Directory extends FeedController
// -------- *** --------
return [
'_template' => $template,
'actors' => $query_fn($actor_type),
'page' => $page,
'_template' => 'directory/actors.html.twig',
'actors' => $query_fn($actor_type),
'title' => $title,
'empty_message' => $empty_message,
'page' => $page,
];
}
public function people(Request $request): array
{
return $this->impl($request, 'directory/people.html.twig', Actor::PERSON);
return $this->impl($request, Actor::PERSON, title: _m('People'), empty_message: _m('No people here'));
}
public function groups(Request $request): array
{
return $this->impl($request, 'directory/groups.html.twig', Actor::GROUP);
return $this->impl($request, Actor::GROUP, title: _m('Groups'), empty_message: _m('No groups here'));
}
}

View File

@ -1,10 +1,10 @@
{% extends 'stdgrid.html.twig' %}
{% block title %}Actors{% endblock %}
{% block title %}{{ title }}{% endblock %}
{% block body %}
<section class="section-widget section-padding">
<h2 class="section-title">{{ "Actors" | trans }}</h2>
<h2 class="section-title">{{ title }}</h2>
<div class="section-padding">
{% if actors is defined and actors is not empty %}
@ -12,9 +12,10 @@
{% block profile_view %}{% include 'cards/profile/view.html.twig' %}{% endblock profile_view %}
<hr>
{% endfor %}
<p>{% trans %}Page: %page%{% endtrans %}</p>
{% else %}
<h1>{% trans %}No actors here.{% endtrans %}</h1>
<h3>{{ empty_message }}</h3>
{% endif %}
</div>
</section>
{% endblock body %}
{% endblock body %}

View File

@ -1,20 +0,0 @@
{% extends 'stdgrid.html.twig' %}
{% block title %}Groups{% endblock %}
{% block body %}
<section class="section-widget section-padding">
<h2 class="section-title">{{ "Groups" | trans }}</h2>
<div class="section-padding">
{% if groups is defined and groups is not empty %}
{% for actor in groups %}
{% block profile_view %}{% include 'cards/profile/view.html.twig' %}{% endblock profile_view %}
<hr>
{% endfor %}
{% else %}
<h1>{% trans %}No groups here.{% endtrans %}</h1>
{% endif %}
</div>
</section>
{% endblock body %}