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>2018-10-12 22:13:54 +0200
commitba335762a80e7860a166c9191502e9c35a5d76b4 (patch)
tree001ca9d25acb144dbf73c74de75fcae1a6197269
parent6c42fbf04372f04821a50402abd91b68d52856e7 (diff)
downloadwallabag-ba335762a80e7860a166c9191502e9c35a5d76b4.tar.gz
wallabag-ba335762a80e7860a166c9191502e9c35a5d76b4.tar.zst
wallabag-ba335762a80e7860a166c9191502e9c35a5d76b4.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 ac2e6688..0e9e1b91 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 586cd7b1..9a383685 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 6effe43e..4f8ad08f 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -1497,4 +1497,30 @@ class EntryControllerTest extends WallabagCoreTestCase
1497 1497
1498 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); 1498 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1499 } 1499 }
1500
1501 public function testRandom()
1502 {
1503 $this->logInAs('admin');
1504 $client = $this->getClient();
1505
1506 $client->request('GET', '/unread/random');
1507 $this->assertSame(302, $client->getResponse()->getStatusCode());
1508 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1509
1510 $client->request('GET', '/starred/random');
1511 $this->assertSame(302, $client->getResponse()->getStatusCode());
1512 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1513
1514 $client->request('GET', '/archive/random');
1515 $this->assertSame(302, $client->getResponse()->getStatusCode());
1516 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1517
1518 $client->request('GET', '/untagged/random');
1519 $this->assertSame(302, $client->getResponse()->getStatusCode());
1520 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1521
1522 $client->request('GET', '/all/random');
1523 $this->assertSame(302, $client->getResponse()->getStatusCode());
1524 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');
1525 }
1500} 1526}