[UI][PLUGIN][Directory] Add UI for Directory listing ordering. This uses a GET parameter, which subits the field in order_by and the operator in order_op. Using order_by=filed^ is still supported
This commit is contained in:
parent
6cfb69d64b
commit
ea5a4df1a4
|
@ -8,9 +8,14 @@
|
|||
|
||||
<div>
|
||||
<p>{% trans %}Sort by:{% endtrans %}</p>
|
||||
{% for option in sort_options %}
|
||||
<a {{ option.active ? 'class="active"' : '' }} href="{{ option.url }}">{{ option.label }}</a>
|
||||
<form method="GET">
|
||||
{% for field in sort_form_fields %}
|
||||
<label for="order_by_{{ field.value }}">{{ field.label }}</label>
|
||||
<input id="order_by_{{ field.value }}" type="radio" name="order_by" value="{{ field.value }}" {% if field.checked %}checked="checked"{% endif %}>
|
||||
{% endfor %}
|
||||
<button type="submit" name="order_op" value="ASC">{% trans %}Ascending{% endtrans %}</button>
|
||||
<button type="submit" name="order_op" value="DESC">{% trans %}Descending{% endtrans %}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="section-padding">
|
||||
|
|
|
@ -31,7 +31,7 @@ use App\Util\Exception\ClientException;
|
|||
use Component\Collection\Util\Controller\CircleController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class Directory extends FeedController
|
||||
class Directory extends CircleController
|
||||
{
|
||||
public const PER_PAGE = 32;
|
||||
public const ALLOWED_FIELDS = ['nickname', 'created', 'modified', 'activity', 'subscribers'];
|
||||
|
@ -62,7 +62,11 @@ class Directory extends FeedController
|
|||
$order_by_op = 'ASC';
|
||||
} else {
|
||||
$order_by_field = $order_by_qs;
|
||||
$order_by_op = 'ASC';
|
||||
$order_by_op = match ($this->string('order_op')) {
|
||||
'ASC' => 'ASC',
|
||||
'DESC' => 'DESC',
|
||||
default => 'ASC',
|
||||
};
|
||||
}
|
||||
|
||||
if (!\in_array($order_by_field, self::ALLOWED_FIELDS)) {
|
||||
|
@ -129,17 +133,12 @@ class Directory extends FeedController
|
|||
};
|
||||
// -------- *** --------
|
||||
|
||||
$sort_options = [];
|
||||
$sort_form_fields = [];
|
||||
foreach (self::ALLOWED_FIELDS as $al) {
|
||||
$sort_options[] = [
|
||||
'active' => false,
|
||||
'url' => '?order_by=' . $al . '^',
|
||||
'label' => _m('{order_by} ascending', ['{order_by}' => ucfirst($al)]),
|
||||
];
|
||||
$sort_options[] = [
|
||||
'active' => false,
|
||||
'url' => '?order_by=' . $al . 'v',
|
||||
'label' => _m('{order_by} descending', ['{order_by}' => ucfirst($al)]),
|
||||
$sort_form_fields[] = [
|
||||
'checked' => $order_by_field === $al,
|
||||
'value' => $al,
|
||||
'label' => _m(ucfirst($al)),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -148,7 +147,7 @@ class Directory extends FeedController
|
|||
'actors' => $query_fn($actor_type),
|
||||
'title' => $title,
|
||||
'empty_message' => $empty_message,
|
||||
'sort_options' => $sort_options,
|
||||
'sort_form_fields' => $sort_form_fields,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user