From: Nicolas Lœuillet Date: Sat, 16 Sep 2017 11:01:33 +0000 (+0200) Subject: Merge pull request #3347 from Kdecherf/entry-stats X-Git-Tag: 2.3.0~31^2~10 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=ed5e175c200501e2ee115ff5d8cd3f3ea47a1c2f;hp=79ea33c9d3139961ff292651f7c3d2ef57b4ea50;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3347 from Kdecherf/entry-stats Entry view: update .stats margins and color --- diff --git a/app/Resources/static/themes/_global/index.js b/app/Resources/static/themes/_global/index.js index 3ec26488..fddb476d 100644 --- a/app/Resources/static/themes/_global/index.js +++ b/app/Resources/static/themes/_global/index.js @@ -9,7 +9,7 @@ import 'material-design-icons-iconfont/dist/material-design-icons.css'; import 'lato-font/css/lato-font.css'; import './global.scss'; -/* Shortcuts*/ +/* Shortcuts */ import './js/shortcuts/entry'; import './js/shortcuts/main'; diff --git a/app/Resources/static/themes/_global/js/shortcuts/main.js b/app/Resources/static/themes/_global/js/shortcuts/main.js index c81bf869..b99fa802 100644 --- a/app/Resources/static/themes/_global/js/shortcuts/main.js +++ b/app/Resources/static/themes/_global/js/shortcuts/main.js @@ -1,6 +1,6 @@ import Mousetrap from 'mousetrap'; -/** Shortcuts **/ +/* Shortcuts */ /* Go to */ Mousetrap.bind('g u', () => { window.location.href = Routing.generate('homepage'); }); diff --git a/composer.json b/composer.json index e609af40..fa0a4a39 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,8 @@ "symfony/dom-crawler": "^3.1", "friendsofsymfony/jsrouting-bundle": "^1.6", "bdunogier/guzzle-site-authenticator": "^1.0.0@dev", - "defuse/php-encryption": "^2.1" + "defuse/php-encryption": "^2.1", + "html2text/html2text": "^4.1" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "~2.2", diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php index 6de561e0..0ecfd18b 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php @@ -19,7 +19,7 @@ class LoadTagData extends AbstractFixture implements OrderedFixtureInterface $manager->persist($tag1); - $this->addReference('foo-tag', $tag1); + $this->addReference('foo-bar-tag', $tag1); $tag2 = new Tag(); $tag2->setLabel('bar'); @@ -35,6 +35,13 @@ class LoadTagData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('baz-tag', $tag3); + $tag4 = new Tag(); + $tag4->setLabel('foo'); + + $manager->persist($tag4); + + $this->addReference('foo-tag', $tag4); + $manager->flush(); } diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index de259e7f..838b9734 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -2,6 +2,7 @@ namespace Wallabag\CoreBundle\Helper; +use Html2Text\Html2Text; use JMS\Serializer\SerializationContext; use JMS\Serializer\SerializerBuilder; use PHPePub\Core\EPub; @@ -408,7 +409,8 @@ class EntriesExport $bar = str_repeat('=', 100); foreach ($this->entries as $entry) { $content .= "\n\n" . $bar . "\n\n" . $entry->getTitle() . "\n\n" . $bar . "\n\n"; - $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent()))) . "\n\n"; + $html = new Html2Text($entry->getContent(), ['do_links' => 'none', 'width' => 100]); + $content .= $html->getText(); } return Response::create( diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index ecc159fc..05f0e0ba 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -133,7 +133,7 @@ class EntryRepository extends EntityRepository { $qb = $this->createQueryBuilder('e') ->leftJoin('e.tags', 't') - ->where('e.user =:userId')->setParameter('userId', $userId); + ->where('e.user = :userId')->setParameter('userId', $userId); if (null !== $isArchived) { $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived); @@ -152,8 +152,23 @@ class EntryRepository extends EntityRepository } if ('' !== $tags) { - foreach (explode(',', $tags) as $tag) { - $qb->andWhere('t.label = :label')->setParameter('label', $tag); + foreach (explode(',', $tags) as $i => $tag) { + $entryAlias = 'e' . $i; + $tagAlias = 't' . $i; + + // Complexe queries to ensure multiple tags are associated to an entry + // https://stackoverflow.com/a/6638146/569101 + $qb->andWhere($qb->expr()->in( + 'e.id', + $this->createQueryBuilder($entryAlias) + ->select($entryAlias . '.id') + ->leftJoin($entryAlias . '.tags', $tagAlias) + ->where($tagAlias . '.label = :label' . $i) + ->getDQL() + )); + + // bound parameter to the main query builder + $qb->setParameter('label' . $i, $tag); } } @@ -181,7 +196,7 @@ class EntryRepository extends EntityRepository ->innerJoin('e.tags', 't') ->innerJoin('e.user', 'u') ->addSelect('t', 'u') - ->where('e.user=:userId')->setParameter('userId', $userId) + ->where('e.user = :userId')->setParameter('userId', $userId) ; return $qb->getQuery()->getResult(); @@ -323,7 +338,7 @@ class EntryRepository extends EntityRepository { $qb = $this->createQueryBuilder('e') ->select('count(e)') - ->where('e.user=:userId')->setParameter('userId', $userId) + ->where('e.user = :userId')->setParameter('userId', $userId) ; return (int) $qb->getQuery()->getSingleScalarResult(); diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 5e1f692e..455d47d1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -392,7 +392,7 @@ tag: page_title: 'Etiquetas' list: number_on_the_page: "{0} I a pas cap d'etiquetas.|{1} I a una etiqueta.|]1,Inf[ I a %count% etiquetas." - see_untagged_entries: "Afichar las entradas sens pas cap d'etiquetas" + see_untagged_entries: "Afichar las entradas sens etiquetas" new: add: 'Ajustar' placeholder: "Podètz ajustar mai qu'una etiqueta, separadas per de virgula." diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index f4c8a630..fcec3f3b 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -292,6 +292,9 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertContains('foo', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "foo" tag'); + $this->assertContains('bar', array_column($content['_embedded']['items'][0]['tags'], 'label'), 'Entries tags should have "bar" tag'); + $this->assertArrayHasKey('_links', $content); $this->assertArrayHasKey('self', $content['_links']); $this->assertArrayHasKey('first', $content['_links']); diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 3e216381..ab7f23cc 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -239,7 +239,8 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertSame($contentInDB->getLanguage(), $content[0]['language']); $this->assertSame($contentInDB->getReadingtime(), $content[0]['reading_time']); $this->assertSame($contentInDB->getDomainname(), $content[0]['domain_name']); - $this->assertSame(['foo bar', 'baz'], $content[0]['tags']); + $this->assertContains('baz', $content[0]['tags']); + $this->assertContains('foo', $content[0]['tags']); } public function testXmlExport() diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 6167fe2d..c6ca4937 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -184,13 +184,13 @@ class RssControllerTest extends WallabagCoreTestCase $em->flush(); $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar'); + $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); $this->assertSame(302, $client->getResponse()->getStatusCode()); } }