mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 11:01:04 +00:00
Merge pull request #5381 from wallabag/tag-search-results
This commit is contained in:
commit
ebfbdb4519
4 changed files with 65 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Pagerfanta\Adapter\ArrayAdapter;
|
||||
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
@ -190,4 +191,35 @@ class TagController extends Controller
|
|||
|
||||
return $this->redirect($redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag search results with the current search term.
|
||||
*
|
||||
* @Route("/tag/search/{filter}", name="tag_this_search")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function tagThisSearchAction($filter, Request $request)
|
||||
{
|
||||
$currentRoute = $request->query->has('currentRoute') ? $request->query->get('currentRoute') : '';
|
||||
|
||||
/** @var QueryBuilder $qb */
|
||||
$qb = $this->get('wallabag_core.entry_repository')->getBuilderForSearchByUser($this->getUser()->getId(), $filter, $currentRoute);
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entries = $qb->getQuery()->getResult();
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
|
||||
$entry,
|
||||
$filter
|
||||
);
|
||||
|
||||
$em->persist($entry);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,6 +237,7 @@ entry:
|
|||
toogle_as_star: Toggle starred
|
||||
delete: Delete
|
||||
export_title: Export
|
||||
assign_search_tag: Assign this search as a tag to each result
|
||||
filters:
|
||||
title: Filters
|
||||
status_label: Status
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
{% include "@WallabagCore/themes/common/Entry/_feed_link.html.twig" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if currentRoute == 'search' %}<div><a href="{{ path('tag_this_search', {'filter': searchTerm, 'currentRoute': app.request.get('currentRoute') }) }}" title="{{ 'entry.list.assign_search_tag'|trans }}">{{ 'entry.list.assign_search_tag'|trans }}</a></div>{% endif %}
|
||||
{% if entries.getNbPages > 1 %}
|
||||
{{ pagerfanta(entries, 'twitter_bootstrap_translated', {'proximity': 1}) }}
|
||||
{% endif %}
|
||||
|
|
|
@ -476,4 +476,35 @@ class TagControllerTest extends WallabagCoreTestCase
|
|||
$this->assertNotFalse(array_search('cache', $tags, true), 'Tag cache is assigned to the entry');
|
||||
$this->assertNotFalse(array_search('caché', $tags, true), 'Tag caché is assigned to the entry');
|
||||
}
|
||||
|
||||
public function testAssignTagsOnSearchResults()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
// Search on unread list
|
||||
$crawler = $client->request('GET', '/unread/list');
|
||||
|
||||
$form = $crawler->filter('form[name=search]')->form();
|
||||
$data = [
|
||||
'search_entry[term]' => 'title',
|
||||
];
|
||||
|
||||
$crawler = $client->submit($form, $data);
|
||||
|
||||
$client->click($crawler->selectLink('entry.list.assign_search_tag')->link());
|
||||
$client->followRedirect();
|
||||
|
||||
$entries = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->getBuilderForSearchByUser($this->getLoggedInUserId(), 'title', 'unread')
|
||||
->getQuery()->getResult();
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$tags = $entry->getTagsLabel();
|
||||
|
||||
$this->assertContains('title', $tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue