diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-11-24 11:44:21 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 09:33:54 +0200 |
commit | 46a54f5debe317ccb3a473ec4b54d3755fe6606c (patch) | |
tree | 17876e70811c91d1ab45df7827addd6c6fc3c014 | |
parent | 29714661b1df78871ceaf0e079f11041a8641d4b (diff) | |
download | wallabag-46a54f5debe317ccb3a473ec4b54d3755fe6606c.tar.gz wallabag-46a54f5debe317ccb3a473ec4b54d3755fe6606c.tar.zst wallabag-46a54f5debe317ccb3a473ec4b54d3755fe6606c.zip |
WIP
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 46 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 48 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 33 |
3 files changed, 120 insertions, 7 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 768c4fdc..c276d5eb 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -344,6 +344,7 @@ class EntryRestController extends WallabagRestController | |||
344 | * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, | 344 | * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, |
345 | * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, | 345 | * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, |
346 | * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"}, | 346 | * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"}, |
347 | * {"name"="progress", "dataType"="integer", "required"=false, "format"="A percentage between 0 and 100", "description"="changed progress."}, | ||
347 | * } | 348 | * } |
348 | * ) | 349 | * ) |
349 | * | 350 | * |
@@ -641,6 +642,7 @@ class EntryRestController extends WallabagRestController | |||
641 | $picture = $request->request->get('preview_picture'); | 642 | $picture = $request->request->get('preview_picture'); |
642 | $publishedAt = $request->request->get('published_at'); | 643 | $publishedAt = $request->request->get('published_at'); |
643 | $authors = $request->request->get('authors', ''); | 644 | $authors = $request->request->get('authors', ''); |
645 | $progress = $request->request->get('progress'); | ||
644 | 646 | ||
645 | try { | 647 | try { |
646 | $this->get('wallabag_core.content_proxy')->updateEntry( | 648 | $this->get('wallabag_core.content_proxy')->updateEntry( |
@@ -667,26 +669,33 @@ class EntryRestController extends WallabagRestController | |||
667 | ]); | 669 | ]); |
668 | } | 670 | } |
669 | 671 | ||
670 | if (!is_null($isArchived)) { | 672 | if (null !== $isArchived) { |
671 | $entry->setArchived((bool) $isArchived); | 673 | $entry->setArchived((bool)$isArchived); |
672 | } | 674 | } |
673 | 675 | ||
674 | if (!is_null($isStarred)) { | 676 | if (null !== $isStarred) { |
675 | $entry->setStarred((bool) $isStarred); | 677 | $entry->setStarred((bool)$isStarred); |
676 | } | 678 | } |
677 | 679 | ||
678 | if (!empty($tags)) { | 680 | if (!empty($tags)) { |
679 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); | 681 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); |
680 | } | 682 | } |
681 | 683 | ||
682 | if (!is_null($isPublic)) { | 684 | if (null !== $isPublic) { |
683 | if (true === (bool) $isPublic && null === $entry->getUid()) { | 685 | if (true === (bool)$isPublic && null === $entry->getUid()) { |
684 | $entry->generateUid(); | 686 | $entry->generateUid(); |
685 | } elseif (false === (bool) $isPublic) { | 687 | } elseif (false === (bool)$isPublic) { |
686 | $entry->cleanUid(); | 688 | $entry->cleanUid(); |
687 | } | 689 | } |
688 | } | 690 | } |
689 | 691 | ||
692 | if (null !== $progress) { | ||
693 | $progress = (int) $progress; | ||
694 | if ($progress >= 0 && $progress <= 100) { | ||
695 | $entry->setProgress($progress); | ||
696 | } | ||
697 | } | ||
698 | |||
690 | $em = $this->getDoctrine()->getManager(); | 699 | $em = $this->getDoctrine()->getManager(); |
691 | $em->persist($entry); | 700 | $em->persist($entry); |
692 | $em->flush(); | 701 | $em->flush(); |
@@ -694,4 +703,27 @@ class EntryRestController extends WallabagRestController | |||
694 | // entry saved, dispatch event about it! | 703 | // entry saved, dispatch event about it! |
695 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | 704 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); |
696 | } | 705 | } |
706 | |||
707 | /** | ||
708 | * Get the progress of an entry. | ||
709 | * | ||
710 | * @ApiDoc( | ||
711 | * requirements={ | ||
712 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | ||
713 | * } | ||
714 | * ) | ||
715 | * | ||
716 | * @param Entry $entry | ||
717 | * | ||
718 | * @return JsonResponse | ||
719 | */ | ||
720 | public function getEntriesProgressAction(Entry $entry) | ||
721 | { | ||
722 | $this->validateAuthentication(); | ||
723 | $this->validateUserAccess($entry->getUser()->getId()); | ||
724 | |||
725 | $json = $this->get('serializer')->serialize($entry->getProgress(), 'json'); | ||
726 | |||
727 | return (new JsonResponse())->setJson($json); | ||
728 | } | ||
697 | } | 729 | } |
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index fafa49f1..ba3db806 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -6,7 +6,9 @@ use Pagerfanta\Adapter\DoctrineORMAdapter; | |||
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
9 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
9 | use Symfony\Component\HttpFoundation\Request; | 10 | use Symfony\Component\HttpFoundation\Request; |
11 | use Symfony\Component\HttpFoundation\Response; | ||
10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 12 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
11 | use Wallabag\CoreBundle\Entity\Entry; | 13 | use Wallabag\CoreBundle\Entity\Entry; |
12 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; | 14 | use Wallabag\CoreBundle\Form\Type\EntryFilterType; |
@@ -604,4 +606,50 @@ class EntryController extends Controller | |||
604 | { | 606 | { |
605 | return $this->showEntries('untagged', $request, $page); | 607 | return $this->showEntries('untagged', $request, $page); |
606 | } | 608 | } |
609 | |||
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. | ||
630 | * | ||
631 | * @param Entry $entry | ||
632 | * @param int $progress | ||
633 | * | ||
634 | * @Route("/set-progress/{entry}", name="set_progress") | ||
635 | * | ||
636 | * @return JsonResponse | ||
637 | */ | ||
638 | public function setEntriesProgressAction(Entry $entry, $progress) | ||
639 | { | ||
640 | $this->checkUserAction($entry); | ||
641 | $response = new JsonResponse(); | ||
642 | |||
643 | if (is_null($progress)) { | ||
644 | $response->setStatusCode(Response::HTTP_BAD_REQUEST); | ||
645 | } else { | ||
646 | $progress = (int) $progress; | ||
647 | if ($progress >= 0 && $progress <= 100) { | ||
648 | $entry->setProgress($progress); | ||
649 | $response->setStatusCode(Response::HTTP_OK); | ||
650 | } | ||
651 | } | ||
652 | |||
653 | return $response; | ||
654 | } | ||
607 | } | 655 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index a0503c39..639af6aa 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -211,6 +211,15 @@ class Entry | |||
211 | private $headers; | 211 | private $headers; |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * @var int | ||
215 | * | ||
216 | * @ORM\Column(name="progress", type="integer", nullable=true) | ||
217 | * | ||
218 | * @Groups({"entries_for_user", "export_all"}) | ||
219 | */ | ||
220 | private $progress = 0; | ||
221 | |||
222 | /** | ||
214 | * @Exclude | 223 | * @Exclude |
215 | * | 224 | * |
216 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") | 225 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") |
@@ -760,6 +769,20 @@ class Entry | |||
760 | } | 769 | } |
761 | 770 | ||
762 | /** | 771 | /** |
772 | * Set progress. | ||
773 | * | ||
774 | * @param int $progress | ||
775 | * | ||
776 | * @return Entry | ||
777 | */ | ||
778 | public function setProgress($progress) | ||
779 | { | ||
780 | $this->progress = $progress; | ||
781 | |||
782 | return $this; | ||
783 | } | ||
784 | |||
785 | /** | ||
763 | * @return array | 786 | * @return array |
764 | */ | 787 | */ |
765 | public function getHeaders() | 788 | public function getHeaders() |
@@ -778,4 +801,14 @@ class Entry | |||
778 | 801 | ||
779 | return $this; | 802 | return $this; |
780 | } | 803 | } |
804 | |||
805 | /** | ||
806 | * Get progress. | ||
807 | * | ||
808 | * @return int | ||
809 | */ | ||
810 | public function getProgress() | ||
811 | { | ||
812 | return $this->progress; | ||
813 | } | ||
781 | } | 814 | } |