From 7fc2f15f6b6de0526574fdabcbc87fe0e36f88cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Guillot?= Date: Wed, 17 Jul 2024 20:20:19 +0200 Subject: [PATCH] Added: - turbo-stream for Chapter updates - progressbar for chapter scrapping - minor optimisations --- assets/bootstrap.js | 24 +++++++++ assets/controllers.json | 2 +- .../chapter_progress_controller.js | 2 +- src/Controller/MangaController.php | 1 + src/Entity/Chapter.php | 2 + src/Entity/Manga.php | 1 + src/Manager/Toolbar/Definition/Toolbar.php | 2 +- src/MessageHandler/DownloadChapterHandler.php | 9 ++-- src/MessageHandler/RefreshMetadataHandler.php | 2 +- templates/activity/index.html.twig | 5 +- templates/broadcast/Chapter.stream.html.twig | 21 ++++++++ templates/manga/_chapter_list.html.twig | 53 ++----------------- templates/manga/_chapter_row.html.twig | 48 +++++++++++++++++ templates/manga/_list.html.twig | 2 - 14 files changed, 111 insertions(+), 63 deletions(-) create mode 100644 templates/broadcast/Chapter.stream.html.twig create mode 100644 templates/manga/_chapter_row.html.twig diff --git a/assets/bootstrap.js b/assets/bootstrap.js index 4ab2df6..cfa3957 100644 --- a/assets/bootstrap.js +++ b/assets/bootstrap.js @@ -9,3 +9,27 @@ export const app = startStimulusApp(require.context( // register any custom, 3rd party controllers here // app.register('some_controller_name', SomeImportedController); + +//DEBUG TURBO +// import * as Turbo from "@hotwired/turbo" +// +// Turbo.session.drive = false +// Turbo.start() +// +// // Écouteurs existants +// document.addEventListener("turbo:before-stream-render", (event) => { +// console.log("Before stream render", event.target); +// }); +// +// document.addEventListener("turbo:stream-render", (event) => { +// console.log("Stream rendered", event.target); +// }); +// +// // Nouvel écouteur pour les événements de création +// document.addEventListener("turbo:before-fetch-request", (event) => { +// console.log("Before fetch request", event.detail.fetchOptions); +// }); +// +// document.addEventListener("turbo:before-fetch-response", (event) => { +// console.log("Before fetch response", event.detail.fetchResponse); +// }); diff --git a/assets/controllers.json b/assets/controllers.json index ed1f20f..71abe9d 100644 --- a/assets/controllers.json +++ b/assets/controllers.json @@ -15,7 +15,7 @@ "fetch": "eager" }, "mercure-turbo-stream": { - "enabled": false, + "enabled": true, "fetch": "eager" } } diff --git a/assets/controllers/chapter_progress_controller.js b/assets/controllers/chapter_progress_controller.js index f54b149..0481c11 100644 --- a/assets/controllers/chapter_progress_controller.js +++ b/assets/controllers/chapter_progress_controller.js @@ -31,7 +31,7 @@ export default class extends Controller { } handleProgressUpdate(data) { - this.currentPage = data.pageIndex + 1; + this.currentPage = data.pageIndex; this.totalPages = data.totalPages; this.updateProgressBar(); diff --git a/src/Controller/MangaController.php b/src/Controller/MangaController.php index e76446a..3f3b71c 100644 --- a/src/Controller/MangaController.php +++ b/src/Controller/MangaController.php @@ -28,6 +28,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\String\Slugger\SluggerInterface; class MangaController extends AbstractController diff --git a/src/Entity/Chapter.php b/src/Entity/Chapter.php index 0045d18..07d4ccc 100644 --- a/src/Entity/Chapter.php +++ b/src/Entity/Chapter.php @@ -6,8 +6,10 @@ use App\Repository\ChapterRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\UX\Turbo\Attribute\Broadcast; #[ORM\Entity(repositoryClass: ChapterRepository::class)] +#[Broadcast()] class Chapter { #[ORM\Id] diff --git a/src/Entity/Manga.php b/src/Entity/Manga.php index 9cdc515..72a271a 100644 --- a/src/Entity/Manga.php +++ b/src/Entity/Manga.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation\Groups; #[ORM\Entity(repositoryClass: MangaRepository::class)] class Manga diff --git a/src/Manager/Toolbar/Definition/Toolbar.php b/src/Manager/Toolbar/Definition/Toolbar.php index 4bf64bf..3c60582 100644 --- a/src/Manager/Toolbar/Definition/Toolbar.php +++ b/src/Manager/Toolbar/Definition/Toolbar.php @@ -4,7 +4,7 @@ namespace App\Manager\Toolbar\Definition; use App\Manager\Toolbar\Element\ToolbarElement; -class Toolbar +abstract class Toolbar { private array $leftGroup = []; private array $rightGroup = []; diff --git a/src/MessageHandler/DownloadChapterHandler.php b/src/MessageHandler/DownloadChapterHandler.php index a7c95a7..79de201 100644 --- a/src/MessageHandler/DownloadChapterHandler.php +++ b/src/MessageHandler/DownloadChapterHandler.php @@ -17,9 +17,9 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler; readonly class DownloadChapterHandler { public function __construct( - private ChapterRepository $chapterRepository, - private MangaScraperService $mangaScraperService, - private NotificationService $notificationService, + private ChapterRepository $chapterRepository, + private MangaScraperService $mangaScraperService, + private NotificationService $notificationService, private ContentSourceRepository $contentSourceRepository ) { @@ -46,8 +46,7 @@ readonly class DownloadChapterHandler ->setBaseUrl('https://api.mangadex.org/') ->setImageSelector('img') ->setChapterUrlFormat('at-home/server/%s') - ->setScrapingType('mangadex') - ; + ->setScrapingType('mangadex'); // (new ContentSource()) // ->setBaseUrl('https://lelscans.net') diff --git a/src/MessageHandler/RefreshMetadataHandler.php b/src/MessageHandler/RefreshMetadataHandler.php index 2f4db4c..86b6bc4 100644 --- a/src/MessageHandler/RefreshMetadataHandler.php +++ b/src/MessageHandler/RefreshMetadataHandler.php @@ -32,7 +32,7 @@ readonly class RefreshMetadataHandler $lastChapters = $this->mangadexProvider->addAllChaptersToManga($manga); try { - foreach ($manga->getChapters() as $chapter) { + foreach ($lastChapters as $chapter) { $this->entityManager->persist($chapter); } diff --git a/templates/activity/index.html.twig b/templates/activity/index.html.twig index 0316579..0b2b32e 100644 --- a/templates/activity/index.html.twig +++ b/templates/activity/index.html.twig @@ -5,6 +5,7 @@ {% endif %} {% endblock %} {% block body %} +
@@ -24,7 +25,7 @@ {% for manga in status %} - + @@ -40,7 +41,7 @@ data-controller="chapter-progress" data-chapter-progress-chapter-id-value="{{ manga.chapterId }}">
-
+
0 / 0
diff --git a/templates/broadcast/Chapter.stream.html.twig b/templates/broadcast/Chapter.stream.html.twig new file mode 100644 index 0000000..6c2d2e1 --- /dev/null +++ b/templates/broadcast/Chapter.stream.html.twig @@ -0,0 +1,21 @@ +{% block create %} + + + +{% endblock %} + +{% block update %} + + + + + + +{% endblock %} + +{% block remove %} +{% endblock %} diff --git a/templates/manga/_chapter_list.html.twig b/templates/manga/_chapter_list.html.twig index 1db5a62..9376682 100644 --- a/templates/manga/_chapter_list.html.twig +++ b/templates/manga/_chapter_list.html.twig @@ -1,5 +1,5 @@ -
+
{% for volume, chapters in chapters_by_volume %} {% set is_first = loop.first %} {% set volume_cbz_path = chapters|first.cbzPath %} @@ -63,7 +63,7 @@ Actions - + {% if all_chapters_same_cbz and volume_cbz_path is not null %} @@ -85,54 +85,7 @@ {% else %} {% for chapter in chapters %} - - {% if chapter.cbzPath is not null %} - - - {{ '%02d'|format(chapter.number) }} - - - {% else %} - {{ '%02d'|format(chapter.number) }} - {% endif %} - - - {% if chapter.cbzPath is not null %} - - {{ chapter.title ?? 'No title' }} - - {% else %} - {{ chapter.title ?? 'No title' }} - {% endif %} - - - {% if chapter.cbzPath is null %} - - {% else %} - - {% endif %} - - - - - + {% include 'manga/_chapter_row.html.twig' with {'chapter': chapter, 'manga': manga} %} {% endfor %} {% endif %} diff --git a/templates/manga/_chapter_row.html.twig b/templates/manga/_chapter_row.html.twig new file mode 100644 index 0000000..16c92b8 --- /dev/null +++ b/templates/manga/_chapter_row.html.twig @@ -0,0 +1,48 @@ + + {% if chapter.cbzPath is not null %} + + + {{ '%02d'|format(chapter.number) }} + + + {% else %} + {{ '%02d'|format(chapter.number) }} + {% endif %} + + + {% if chapter.cbzPath is not null %} + + {{ chapter.title ?? 'No title' }} + + {% else %} + {{ chapter.title ?? 'No title' }} + {% endif %} + + + {% if chapter.cbzPath is null %} + + {% else %} + + {% endif %} + + + + + diff --git a/templates/manga/_list.html.twig b/templates/manga/_list.html.twig index 2e554e8..8aa43e4 100644 --- a/templates/manga/_list.html.twig +++ b/templates/manga/_list.html.twig @@ -1,6 +1,5 @@ {% block body %} {% if currentView == 'poster' %} - {# Vue poster actuelle #}
{% for manga in mangas %} @@ -25,7 +24,6 @@ {% endfor %}
{% elseif currentView == 'resume' %} - {# Vue résumé #}
{% for manga in mangas %}