aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2018-10-12 21:41:05 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-01-19 21:09:33 +0100
commit0447a75b06142afe59a179bb59ee94f1978aa7a9 (patch)
tree6fb21a4cef53c62cb7f2d703c0fb6957ce4de3cb
parentf85d220c19872dd7e9199fd150060555584a2886 (diff)
downloadwallabag-0447a75b06142afe59a179bb59ee94f1978aa7a9.tar.gz
wallabag-0447a75b06142afe59a179bb59ee94f1978aa7a9.tar.zst
wallabag-0447a75b06142afe59a179bb59ee94f1978aa7a9.zip
Use only one method to randomize
Instead of one per type, one for all is ok.
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php97
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php26
4 files changed, 42 insertions, 85 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 669e15d7..ab50ebdf 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -249,73 +249,28 @@ class EntryController extends Controller
249 } 249 }
250 250
251 /** 251 /**
252 * Shows random unread entry. 252 * Shows random entry depending on the given type.
253 * 253 *
254 * @param Entry $entry 254 * @param Entry $entry
255 * 255 *
256 * @Route("/unread/random", name="unread_random") 256 * @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"})
257 * 257 *
258 * @return \Symfony\Component\HttpFoundation\Response 258 * @return \Symfony\Component\HttpFoundation\RedirectResponse
259 */
260 public function showRandomUnreadEntryAction()
261 {
262 return $this->showRandomEntries('unread');
263 }
264
265 /**
266 * Shows random favorite entry.
267 *
268 * @param Entry $entry
269 *
270 * @Route("/starred/random", name="starred_random")
271 *
272 * @return \Symfony\Component\HttpFoundation\Response
273 */
274 public function showRandomStarredEntryAction()
275 {
276 return $this->showRandomEntries('starred');
277 }
278
279 /**
280 * Shows random archived entry.
281 *
282 * @param Entry $entry
283 *
284 * @Route("/archive/random", name="archive_random")
285 *
286 * @return \Symfony\Component\HttpFoundation\Response
287 */ 259 */
288 public function showRandomArchiveEntryAction() 260 public function redirectRandomEntryAction($type = 'all')
289 { 261 {
290 return $this->showRandomEntries('archive'); 262 try {
291 } 263 $entry = $this->get('wallabag_core.entry_repository')
264 ->getRandomEntry($this->getUser()->getId(), $type);
265 } catch (NoResultException $e) {
266 $bag = $this->get('session')->getFlashBag();
267 $bag->clear();
268 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
292 269
293 /** 270 return $this->redirect($this->generateUrl('homepage'));
294 * Shows random all entry. 271 }
295 *
296 * @param Entry $entry
297 *
298 * @Route("/untagged/random", name="untagged_random")
299 *
300 * @return \Symfony\Component\HttpFoundation\Response
301 */
302 public function showRandomUntaggedEntryAction()
303 {
304 return $this->showRandomEntries('untagged');
305 }
306 272
307 /** 273 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
308 * Shows random all entry.
309 *
310 * @param Entry $entry
311 *
312 * @Route("/all/random", name="all_random")
313 *
314 * @return \Symfony\Component\HttpFoundation\Response
315 */
316 public function showRandomAllEntryAction()
317 {
318 return $this->showRandomEntries();
319 } 274 }
320 275
321 /** 276 /**
@@ -624,30 +579,6 @@ class EntryController extends Controller
624 } 579 }
625 580
626 /** 581 /**
627 * Global method to retrieve random entries depending on the given type.
628 *
629 * @param string $type Entries type: unread, starred, archive or untagged
630 *
631 * @return \Symfony\Component\HttpFoundation\RedirectResponse
632 */
633 private function showRandomEntries($type)
634 {
635 $repository = $this->get('wallabag_core.entry_repository');
636
637 try {
638 $entry = $repository->getRandomEntry($this->getUser()->getId(), $type);
639 } catch (NoResultException $e) {
640 $bag = $this->get('session')->getFlashBag();
641 $bag->clear();
642 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
643
644 return $this->redirect($this->generateUrl('homepage'));
645 }
646
647 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
648 }
649
650 /**
651 * Fetch content and update entry. 582 * Fetch content and update entry.
652 * In case it fails, $entry->getContent will return an error message. 583 * In case it fails, $entry->getContent will return an error message.
653 * 584 *
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
index 7108efbd..f3baae2c 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
@@ -28,7 +28,7 @@
28 <div class="nb-results">{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}</div> 28 <div class="nb-results">{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}</div>
29 <div class="pagination"> 29 <div class="pagination">
30 <a href="{{ path('switch_view_mode') }}"><i class="listMode-btn material-icons md-24">{% if listMode == 0 %}list{% else %}view_module{% endif %}</i></a> 30 <a href="{{ path('switch_view_mode') }}"><i class="listMode-btn material-icons md-24">{% if listMode == 0 %}list{% else %}view_module{% endif %}</i></a>
31 <a href="{{ path(currentRoute ~ '_random') }}">random</a> 31 <a href="{{ path('random_entry', { 'type': currentRoute }) }}">random</a>
32 {% if app.user.config.rssToken %} 32 {% if app.user.config.rssToken %}
33 {% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %} 33 {% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
34 {% endif %} 34 {% endif %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
index 5deda0fc..31c4b5cb 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
@@ -28,7 +28,7 @@
28 <div class="nb-results"> 28 <div class="nb-results">
29 {{ 'entry.list.number_on_the_page'|transchoice(entries.count) }} 29 {{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}
30 <a href="{{ path('switch_view_mode') }}"><i class="material-icons">{% if listMode == 0 %}view_list{% else %}view_module{% endif %}</i></a> 30 <a href="{{ path('switch_view_mode') }}"><i class="material-icons">{% if listMode == 0 %}view_list{% else %}view_module{% endif %}</i></a>
31 <a href="{{ path(currentRoute ~ '_random') }}">random</a> 31 <a href="{{ path('random_entry', { 'type': currentRoute }) }}">random</a>
32 {% if app.user.config.rssToken %} 32 {% if app.user.config.rssToken %}
33 {% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %} 33 {% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
34 {% endif %} 34 {% endif %}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 005296ff..28291b5a 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -1495,4 +1495,30 @@ class EntryControllerTest extends WallabagCoreTestCase
1495 1495
1496 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); 1496 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1497 } 1497 }
1498
1499 public function testRandom()
1500 {
1501 $this->logInAs('admin');
1502 $client = $this->getClient();
1503
1504 $client->request('GET', '/unread/random');
1505 $this->assertSame(302, $client->getResponse()->getStatusCode());
1506 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1507
1508 $client->request('GET', '/starred/random');
1509 $this->assertSame(302, $client->getResponse()->getStatusCode());
1510 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1511
1512 $client->request('GET', '/archive/random');
1513 $this->assertSame(302, $client->getResponse()->getStatusCode());
1514 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1515
1516 $client->request('GET', '/untagged/random');
1517 $this->assertSame(302, $client->getResponse()->getStatusCode());
1518 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1519
1520 $client->request('GET', '/all/random');
1521 $this->assertSame(302, $client->getResponse()->getStatusCode());
1522 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');
1523 }
1498} 1524}