mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-15 21:41:06 +00:00
Merge pull request #4278 from wallabag/fix/4240
Fix entries export from search view
This commit is contained in:
commit
f38b8f0d86
5 changed files with 104 additions and 17 deletions
|
@ -16,12 +16,15 @@ cache:
|
|||
- $HOME/.npm
|
||||
- $HOME/.yarn-cache
|
||||
|
||||
if: |
|
||||
type = pull_request OR \
|
||||
branch = master
|
||||
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
- nightly
|
||||
|
||||
node_js:
|
||||
- "5"
|
||||
|
@ -34,11 +37,10 @@ env:
|
|||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 7.2
|
||||
- php: 7.3
|
||||
env: CS_FIXER=run VALIDATE_TRANSLATION_FILE=run ASSETS=build DB=sqlite
|
||||
allow_failures:
|
||||
- php: 7.4
|
||||
- php: nightly
|
||||
|
||||
# exclude v1 branches
|
||||
branches:
|
||||
|
|
|
@ -68,6 +68,18 @@ class ExportController extends Controller
|
|||
);
|
||||
|
||||
$title = 'Tag ' . $tag->getLabel();
|
||||
} elseif ('search' === $category) {
|
||||
$searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
|
||||
$currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
|
||||
|
||||
$entries = $repository->getBuilderForSearchByUser(
|
||||
$this->getUser()->getId(),
|
||||
$searchTerm,
|
||||
$currentRoute
|
||||
)->getQuery()
|
||||
->getResult();
|
||||
|
||||
$title = 'Search ' . $searchTerm;
|
||||
} else {
|
||||
$entries = $repository
|
||||
->$methodBuilder($this->getUser()->getId())
|
||||
|
|
|
@ -96,16 +96,21 @@
|
|||
{% if tag is defined %}
|
||||
{% set currentTag = tag %}
|
||||
{% endif %}
|
||||
{% set exportSearchTerm = null %}
|
||||
{% if searchTerm is defined %}
|
||||
{% set exportSearchTerm = searchTerm %}
|
||||
{% endif %}
|
||||
{% set previousRoute = app.request.attributes.get('currentRoute') %}
|
||||
<h2>{{ 'entry.list.export_title'|trans }}</h2>
|
||||
<a href="javascript: void(null);" id="download-form-close" class="close-button--popup close-button">×</a>
|
||||
<ul>
|
||||
{% 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', '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', 'tag' : currentTag }) }}">PDF</a></li>{% endif %}
|
||||
{% if craue_setting('export_json') %}<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_csv') %}<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', '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', 'tag' : currentTag }) }}">XML</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">EPUB</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">MOBI</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">PDF</a></li>{% endif %}
|
||||
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json', 'tag' : currentTag, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">JSON</a></li>{% endif %}
|
||||
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv', 'tag' : currentTag, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">CSV</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">TXT</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">XML</a></li>{% endif %}
|
||||
</ul>
|
||||
</aside>
|
||||
|
||||
|
|
|
@ -63,15 +63,20 @@
|
|||
{% if tag is defined %}
|
||||
{% set currentTag = tag.slug %}
|
||||
{% endif %}
|
||||
{% set exportSearchTerm = null %}
|
||||
{% if searchTerm is defined %}
|
||||
{% set exportSearchTerm = searchTerm %}
|
||||
{% endif %}
|
||||
{% set previousRoute = app.request.attributes.get('currentRoute') %}
|
||||
<h4 class="center">{{ 'entry.list.export_title'|trans }}</h4>
|
||||
<ul>
|
||||
{% 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', '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', 'tag' : currentTag }) }}">PDF</a></li>{% endif %}
|
||||
{% if craue_setting('export_json') %}<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_csv') %}<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', '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', 'tag' : currentTag }) }}">XML</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">EPUB</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">MOBI</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">PDF</a></li>{% endif %}
|
||||
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json', 'tag' : currentTag, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">JSON</a></li>{% endif %}
|
||||
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv', 'tag' : currentTag, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">CSV</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">TXT</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, 'search_entry[term]' : exportSearchTerm, 'currentRoute' : previousRoute }) }}">XML</a></li>{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -3,9 +3,13 @@
|
|||
namespace Tests\Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
|
||||
class ExportControllerTest extends WallabagCoreTestCase
|
||||
{
|
||||
private $adminEntry;
|
||||
private $bobEntry;
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
@ -243,6 +247,30 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertContains('foo', $content[0]['tags']);
|
||||
}
|
||||
|
||||
public function testJsonExportFromSearch()
|
||||
{
|
||||
$this->setUpForJsonExportFromSearch();
|
||||
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/search.json?search_entry[term]=entry+search¤tRoute=homepage');
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertSame(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$headers = $client->getResponse()->headers;
|
||||
$this->assertSame('application/json', $headers->get('content-type'));
|
||||
$this->assertSame('attachment; filename="Search entry search articles.json"', $headers->get('content-disposition'));
|
||||
$this->assertSame('UTF-8', $headers->get('content-transfer-encoding'));
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
$this->tearDownForJsonExportFromSearch();
|
||||
}
|
||||
|
||||
public function testXmlExport()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
|
@ -282,6 +310,41 @@ class ExportControllerTest extends WallabagCoreTestCase
|
|||
$this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at);
|
||||
}
|
||||
|
||||
private function setUpForJsonExportFromSearch()
|
||||
{
|
||||
$client = $this->getClient();
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$userRepository = $client->getContainer()
|
||||
->get('wallabag_user.user_repository.test');
|
||||
|
||||
$user = $userRepository->findOneByUserName('admin');
|
||||
$this->adminEntry = new Entry($user);
|
||||
$this->adminEntry->setUrl('http://0.0.0.0/entry-search-admin');
|
||||
$this->adminEntry->setTitle('test title entry search admin');
|
||||
$this->adminEntry->setContent('this is my content /o/');
|
||||
$em->persist($this->adminEntry);
|
||||
|
||||
$user = $userRepository->findOneByUserName('bob');
|
||||
$this->bobEntry = new Entry($user);
|
||||
$this->bobEntry->setUrl('http://0.0.0.0/entry-search-bob');
|
||||
$this->bobEntry->setTitle('test title entry search bob');
|
||||
$this->bobEntry->setContent('this is my content /o/');
|
||||
$em->persist($this->bobEntry);
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
private function tearDownForJsonExportFromSearch()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$em->remove($this->adminEntry);
|
||||
$em->remove($this->bobEntry);
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
private function getSanitizedFilename($title)
|
||||
{
|
||||
return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $title));
|
||||
|
|
Loading…
Reference in a new issue