Merge pull request #4972 from wallabag/fix/2533-filter-active-menu

Preselect currently active section in the filter menu
This commit is contained in:
Jérémy Benoist 2021-01-25 09:30:03 +01:00 committed by GitHub
commit b50cd2564c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 5 deletions

View file

@ -532,6 +532,8 @@ class EntryController extends Controller
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
$formOptions = [];
switch ($type) {
case 'search':
$qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
@ -541,12 +543,15 @@ class EntryController extends Controller
break;
case 'starred':
$qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
$formOptions['filter_starred'] = true;
break;
case 'archive':
$qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
$formOptions['filter_archived'] = true;
break;
case 'unread':
$qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
$formOptions['filter_unread'] = true;
break;
case 'all':
$qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
@ -555,7 +560,7 @@ class EntryController extends Controller
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
}
$form = $this->createForm(EntryFilterType::class);
$form = $this->createForm(EntryFilterType::class, [], $formOptions);
if ($request->query->has($form->getName())) {
// manually bind values from the request

View file

@ -118,12 +118,15 @@ class EntryFilterType extends AbstractType
])
->add('isArchived', CheckboxFilterType::class, [
'label' => 'entry.filters.archived_label',
'data' => $options['filter_archived'],
])
->add('isStarred', CheckboxFilterType::class, [
'label' => 'entry.filters.starred_label',
'data' => $options['filter_starred'],
])
->add('isUnread', CheckboxFilterType::class, [
'label' => 'entry.filters.unread_label',
'data' => $options['filter_unread'],
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if (false === $values['value']) {
return;
@ -177,6 +180,9 @@ class EntryFilterType extends AbstractType
$resolver->setDefaults([
'csrf_protection' => false,
'validation_groups' => ['filtering'],
'filter_archived' => false,
'filter_starred' => false,
'filter_unread' => false,
]);
}
}

View file

@ -857,7 +857,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter('li.entry'));
$data = [
'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
@ -866,7 +866,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter('li.entry'));
$data = [
'entry_filter[createdAt][left_date]' => '1970-01-01',
@ -919,7 +919,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter('li.entry'));
$crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('button[id=submit-filter]')->form();
@ -928,7 +928,7 @@ class EntryControllerTest extends WallabagCoreTestCase
];
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('li.entry'));
$this->assertCount(4, $crawler->filter('li.entry'));
$form = $crawler->filter('button[id=submit-filter]')->form();
$data = [
@ -948,6 +948,7 @@ class EntryControllerTest extends WallabagCoreTestCase
$form = $crawler->filter('button[id=submit-filter]')->form();
$form['entry_filter[isArchived]']->tick();
$form['entry_filter[isStarred]']->untick();
$form['entry_filter[isUnread]']->untick();
$crawler = $client->submit($form);
$this->assertCount(1, $crawler->filter('li.entry'));
@ -960,6 +961,30 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertCount(1, $crawler->filter('li.entry'));
}
public function testFilterPreselectedStatus()
{
$this->logInAs('admin');
$client = $this->getClient();
$crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('button[id=submit-filter]')->form();
$this->assertTrue($form['entry_filter[isUnread]']->hasValue());
$this->assertFalse($form['entry_filter[isArchived]']->hasValue());
$this->assertFalse($form['entry_filter[isStarred]']->hasValue());
$crawler = $client->request('GET', '/starred/list');
$form = $crawler->filter('button[id=submit-filter]')->form();
$this->assertFalse($form['entry_filter[isUnread]']->hasValue());
$this->assertFalse($form['entry_filter[isArchived]']->hasValue());
$this->assertTrue($form['entry_filter[isStarred]']->hasValue());
$crawler = $client->request('GET', '/all/list');
$form = $crawler->filter('button[id=submit-filter]')->form();
$this->assertFalse($form['entry_filter[isUnread]']->hasValue());
$this->assertFalse($form['entry_filter[isArchived]']->hasValue());
$this->assertFalse($form['entry_filter[isStarred]']->hasValue());
}
public function testFilterOnIsPublic()
{
$this->logInAs('admin');