1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-30 19:22:12 +00:00
This commit is contained in:
Kevin Decherf 2025-09-29 16:39:48 -05:00 committed by GitHub
commit e9f136c284
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 58 additions and 3 deletions

View file

@ -627,6 +627,16 @@ class EntryController extends AbstractController
$currentEntryId = $request->attributes->getInt('id');
$formOptions = [];
$direction = 'desc';
$sortBy = null;
if (null !== $request->get('entry_filter') && null !== $request->get('entry_filter')['sortType'] && '' !== $request->get('entry_filter')['sortType']) {
$direction = (null !== $request->get('entry_filter')['sortOrder'] && \in_array($request->get('entry_filter')['sortOrder'], ['asc', 'desc'], true)) ? $request->get('entry_filter')['sortOrder'] : 'desc';
if (\in_array($request->get('entry_filter')['sortType'], ['id','title','createdAt', 'url', 'readingTime'], true)) {
$sortBy = $request->get('entry_filter')['sortType'];
}
}
switch ($type) {
case 'search':
@ -654,7 +664,7 @@ class EntryController extends AbstractController
$qb = $this->entryRepository->getBuilderForSameDomainByUser($this->getUser()->getId(), $currentEntryId);
break;
case 'all':
$qb = $this->entryRepository->getBuilderForAllByUser($this->getUser()->getId());
$qb = $this->entryRepository->getBuilderForAllByUser($this->getUser()->getId(), $sortBy, $direction);
break;
default:
throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type));

View file

@ -205,6 +205,24 @@ class EntryFilterType extends AbstractType
'choices' => array_flip($this->repository->findDistinctLanguageByUser($user->getId())),
'label' => 'entry.filters.language_label',
])
->add('sortOrder', ChoiceFilterType::class, [
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { },
'choices' => [
'entry.sort.ascending' => 'asc',
'entry.sort.descending' => 'desc',
],
'label' => 'entry.sort.order_label',
])
->add('sortType', ChoiceFilterType::class, [
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { },
'choices' => [
'entry.sort.by.creation_date' => 'createdAt',
'entry.sort.by.title' => 'title',
'entry.sort.by.url' => 'url',
'entry.sort.by.reading_time' => 'readingTime',
],
'label' => 'entry.sort.status_label',
])
;
}

View file

@ -30,10 +30,11 @@ class EntryRepository extends ServiceEntityRepository
*
* @return QueryBuilder
*/
public function getBuilderForAllByUser($userId)
public function getBuilderForAllByUser($userId, $sortBy = 'createdAt', $direction = 'desc')
{
$sortBy = $sortBy ?: 'createdAt';
return $this
->getSortedQueryBuilderByUser($userId)
->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
;
}

View file

@ -276,6 +276,22 @@
<label for="entry_filter_createdAt_right_date" class="active">{{ 'entry.filters.created_at.to'|trans }}</label>
</div>
<div class="col s6">
{{ form_label(form.sortType) }}
</div>
<div class="col s6">
{{ form_label(form.sortOrder) }}
</div>
<div class="col s6">
{{ form_widget(form.sortType) }}
</div>
<div class="col s6">
{{ form_widget(form.sortOrder) }}
</div>
<div class="col s6">
<button type="reset" class="center waves-effect waves-green btn-flat">{{ 'entry.filters.action.clear'|trans }}</button>
</div>

View file

@ -237,6 +237,16 @@ entry:
untagged: Untagged entries
all: All entries
same_domain: Same domain
sort:
status_label: Sort by
order_label: Order
by:
creation_date: Creation date
title: Title
url: URL
reading_time: Reading time
ascending: Ascending
descending: Descending
list:
number_on_the_page: '{0} There are no entries.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
reading_time: estimated reading time