mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-17 17:08:37 +00:00
Merge pull request #2506 from wallabag/fix-export-with-tags
Fixed entries export filtered with a tag
This commit is contained in:
commit
67b270d996
4 changed files with 50 additions and 20 deletions
|
@ -4,8 +4,10 @@ namespace Wallabag\CoreBundle\Controller;
|
||||||
|
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Wallabag\CoreBundle\Entity\Entry;
|
use Wallabag\CoreBundle\Entity\Entry;
|
||||||
|
use Wallabag\CoreBundle\Entity\Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The try/catch can be removed once all formats will be implemented.
|
* The try/catch can be removed once all formats will be implemented.
|
||||||
|
@ -51,15 +53,24 @@ class ExportController extends Controller
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function downloadEntriesAction($format, $category)
|
public function downloadEntriesAction(Request $request, $format, $category)
|
||||||
{
|
{
|
||||||
$method = ucfirst($category);
|
$method = ucfirst($category);
|
||||||
$methodBuilder = 'getBuilderFor'.$method.'ByUser';
|
$methodBuilder = 'getBuilderFor'.$method.'ByUser';
|
||||||
|
|
||||||
|
if ($category == 'tag_entries') {
|
||||||
|
$tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneBySlug($request->query->get('tag'));
|
||||||
|
|
||||||
|
$entries = $this->getDoctrine()
|
||||||
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
|
->findAllByTagId($this->getUser()->getId(), $tag->getId());
|
||||||
|
} else {
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->$methodBuilder($this->getUser()->getId())
|
->$methodBuilder($this->getUser()->getId())
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->get('wallabag_core.helper.entries_export')
|
return $this->get('wallabag_core.helper.entries_export')
|
||||||
|
|
|
@ -53,19 +53,23 @@
|
||||||
<!-- Export -->
|
<!-- Export -->
|
||||||
<aside id="download-form">
|
<aside id="download-form">
|
||||||
{% set currentRoute = app.request.attributes.get('_route') %}
|
{% set currentRoute = app.request.attributes.get('_route') %}
|
||||||
|
{% set currentTag = '' %}
|
||||||
|
{% if tag is defined %}
|
||||||
|
{% set currentTag = tag %}
|
||||||
|
{% endif %}
|
||||||
{% if currentRoute == 'homepage' %}
|
{% if currentRoute == 'homepage' %}
|
||||||
{% set currentRoute = 'unread' %}
|
{% set currentRoute = 'unread' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h2>{{ 'entry.list.export_title'|trans }}</h2>
|
<h2>{{ 'entry.list.export_title'|trans }}</h2>
|
||||||
<a href="javascript: void(null);" id="download-form-close" class="close-button--popup close-button">×</a>
|
<a href="javascript: void(null);" id="download-form-close" class="close-button--popup close-button">×</a>
|
||||||
<ul>
|
<ul>
|
||||||
{% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub' }) }}">EPUB</a></li>{% endif %}
|
{% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub', 'tag' : currentTag }) }}">EPUB</a></li>{% endif %}
|
||||||
{% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi' }) }}">MOBI</a></li>{% endif %}
|
{% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi', 'tag' : currentTag }) }}">MOBI</a></li>{% endif %}
|
||||||
{% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf' }) }}">PDF</a></li>{% endif %}
|
{% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf', 'tag' : currentTag }) }}">PDF</a></li>{% endif %}
|
||||||
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json' }) }}">JSON</a></li>{% endif %}
|
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json', 'tag' : currentTag }) }}">JSON</a></li>{% endif %}
|
||||||
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv' }) }}">CSV</a></li>{% endif %}
|
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv', 'tag' : currentTag }) }}">CSV</a></li>{% endif %}
|
||||||
{% if craue_setting('export_txt') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt' }) }}">TXT</a></li>{% endif %}
|
{% if craue_setting('export_txt') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt', 'tag' : currentTag }) }}">TXT</a></li>{% endif %}
|
||||||
{% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %}
|
{% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml', 'tag' : currentTag }) }}">XML</a></li>{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
|
|
@ -99,18 +99,22 @@
|
||||||
<!-- Export -->
|
<!-- Export -->
|
||||||
<div id="export" class="side-nav fixed right-aligned">
|
<div id="export" class="side-nav fixed right-aligned">
|
||||||
{% set currentRoute = app.request.attributes.get('_route') %}
|
{% set currentRoute = app.request.attributes.get('_route') %}
|
||||||
|
{% set currentTag = '' %}
|
||||||
|
{% if tag is defined %}
|
||||||
|
{% set currentTag = tag %}
|
||||||
|
{% endif %}
|
||||||
{% if currentRoute == 'homepage' %}
|
{% if currentRoute == 'homepage' %}
|
||||||
{% set currentRoute = 'unread' %}
|
{% set currentRoute = 'unread' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h4 class="center">{{ 'entry.list.export_title'|trans }}</h4>
|
<h4 class="center">{{ 'entry.list.export_title'|trans }}</h4>
|
||||||
<ul>
|
<ul>
|
||||||
{% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub' }) }}">EPUB</a></li>{% endif %}
|
{% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub', 'tag' : currentTag }) }}">EPUB</a></li>{% endif %}
|
||||||
{% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi' }) }}">MOBI</a></li>{% endif %}
|
{% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi', 'tag' : currentTag }) }}">MOBI</a></li>{% endif %}
|
||||||
{% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf' }) }}">PDF</a></li>{% endif %}
|
{% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf', 'tag' : currentTag }) }}">PDF</a></li>{% endif %}
|
||||||
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json' }) }}">JSON</a></li>{% endif %}
|
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json', 'tag' : currentTag }) }}">JSON</a></li>{% endif %}
|
||||||
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv' }) }}">CSV</a></li>{% endif %}
|
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv', 'tag' : currentTag }) }}">CSV</a></li>{% endif %}
|
||||||
{% if craue_setting('export_txt') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt' }) }}">TXT</a></li>{% endif %}
|
{% if craue_setting('export_txt') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt', 'tag' : currentTag }) }}">TXT</a></li>{% endif %}
|
||||||
{% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %}
|
{% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml', 'tag' : currentTag }) }}">XML</a></li>{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,17 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||||
$this->assertEquals('application/pdf', $headers->get('content-type'));
|
$this->assertEquals('application/pdf', $headers->get('content-type'));
|
||||||
$this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition'));
|
$this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition'));
|
||||||
$this->assertEquals('binary', $headers->get('content-transfer-encoding'));
|
$this->assertEquals('binary', $headers->get('content-transfer-encoding'));
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo');
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||||
|
|
||||||
|
$headers = $client->getResponse()->headers;
|
||||||
|
$this->assertEquals('application/pdf', $headers->get('content-type'));
|
||||||
|
$this->assertEquals('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition'));
|
||||||
|
$this->assertEquals('binary', $headers->get('content-transfer-encoding'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTxtExport()
|
public function testTxtExport()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue