diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-03-31 14:54:34 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 09:39:04 +0200 |
commit | 5fe9aadc0e84bac277db7e6ab78b8731c2ba31fc (patch) | |
tree | 0e1e6605eb0b39c1e2e66c27f553b0df0ca465a3 /src | |
parent | 46a54f5debe317ccb3a473ec4b54d3755fe6606c (diff) | |
download | wallabag-progress.tar.gz wallabag-progress.tar.zst wallabag-progress.zip |
Set progressprogress
Diffstat (limited to 'src')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 42 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig | 2 |
2 files changed, 15 insertions, 29 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ba3db806..d7f53aea 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -608,46 +608,32 @@ class EntryController extends Controller | |||
608 | } | 608 | } |
609 | 609 | ||
610 | /** | 610 | /** |
611 | * Get the progress of an entry. | ||
612 | * | ||
613 | * @param Entry $entry | ||
614 | * | ||
615 | * @Route("/progress/{entry}", name="get_progress") | ||
616 | * | ||
617 | * @return JsonResponse | ||
618 | */ | ||
619 | public function getEntriesProgressAction(Entry $entry) | ||
620 | { | ||
621 | $this->checkUserAction($entry); | ||
622 | |||
623 | $json = $this->get('serializer')->serialize($entry->getProgress(), 'json'); | ||
624 | |||
625 | return (new JsonResponse())->setJson($json); | ||
626 | } | ||
627 | |||
628 | /** | ||
629 | * Set the progress of an entry. | 611 | * Set the progress of an entry. |
630 | * | 612 | * |
631 | * @param Entry $entry | 613 | * @param Entry $entry |
632 | * @param int $progress | 614 | * @param int $progress |
633 | * | 615 | * |
634 | * @Route("/set-progress/{entry}", name="set_progress") | 616 | * @Route("/progress/{entry}/{progress}", name="set_progress") |
635 | * | 617 | * |
636 | * @return JsonResponse | 618 | * @return JsonResponse |
637 | */ | 619 | */ |
638 | public function setEntriesProgressAction(Entry $entry, $progress) | 620 | public function setEntriesProgressAction(Entry $entry, $progress = 0) |
639 | { | 621 | { |
640 | $this->checkUserAction($entry); | 622 | $this->checkUserAction($entry); |
641 | $response = new JsonResponse(); | 623 | $response = new JsonResponse(); |
642 | 624 | ||
643 | if (is_null($progress)) { | 625 | $progress = (int) $progress; |
644 | $response->setStatusCode(Response::HTTP_BAD_REQUEST); | 626 | if ($progress >= 0 && $progress <= 100) { |
645 | } else { | 627 | $em = $this->getDoctrine()->getManager(); |
646 | $progress = (int) $progress; | 628 | |
647 | if ($progress >= 0 && $progress <= 100) { | 629 | $entry->setProgress($progress); |
648 | $entry->setProgress($progress); | 630 | |
649 | $response->setStatusCode(Response::HTTP_OK); | 631 | $this->get('logger')->info('Set progress to ' . $progress); |
650 | } | 632 | |
633 | $em->persist($entry); | ||
634 | $em->flush(); | ||
635 | |||
636 | $response->setStatusCode(Response::HTTP_OK); | ||
651 | } | 637 | } |
652 | 638 | ||
653 | return $response; | 639 | return $response; |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 4cff7bf2..0cfd2760 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig | |||
@@ -211,7 +211,7 @@ | |||
211 | {% endblock %} | 211 | {% endblock %} |
212 | 212 | ||
213 | {% block content %} | 213 | {% block content %} |
214 | <div id="article"> | 214 | <div id="article" data-progress="{{ entry.progress }}"> |
215 | <header class="mbm"> | 215 | <header class="mbm"> |
216 | <h1>{{ entry.title|striptags|raw }} <a href="{{ path('edit', { 'id': entry.id }) }}" title="{{ 'entry.view.edit_title'|trans }}">✎</a></h1> | 216 | <h1>{{ entry.title|striptags|raw }} <a href="{{ path('edit', { 'id': entry.id }) }}" title="{{ 'entry.view.edit_title'|trans }}">✎</a></h1> |
217 | </header> | 217 | </header> |