From d6b1216021c3e4baeda76baf355de3553455e617 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 21 Nov 2023 15:10:14 +0100 Subject: [PATCH 01/27] rename methods for more clarity --- .../ChillMainBundle/Controller/NewsItemHistoryController.php | 4 ++-- src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php index 8c645828b..ff7adf818 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php @@ -34,8 +34,8 @@ class NewsItemHistoryController extends AbstractController public function listAction(Request $request): Response { $filter = $this->buildFilterOrder(false); - $total = $this->newsItemRepository->countAllFilteredByUser($filter->getQueryString()); - $newsItems = $this->newsItemRepository->findAllFilteredByUser($filter->getQueryString()); + $total = $this->newsItemRepository->countAllFilteredBySearchTerm($filter->getQueryString()); + $newsItems = $this->newsItemRepository->findAllFilteredBySearchTerm($filter->getQueryString()); $pagination = $this->paginatorFactory->create($total); diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index 88b597647..44e1f2d39 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -71,7 +71,7 @@ class NewsItemRepository implements ObjectRepository return $qb; } - public function findAllFilteredByUser(string $pattern = null) + public function findAllFilteredBySearchTerm(string $pattern = null) { $qb = $this->buildBaseQuery($pattern); $qb->addOrderBy('n.startDate', 'DESC') @@ -97,7 +97,7 @@ class NewsItemRepository implements ObjectRepository ->getResult(); } - public function countAllFilteredByUser(string $pattern = null) + public function countAllFilteredBySearchTerm(string $pattern = null) { $qb = $this->buildBaseQuery($pattern); From 4a58d7f30080631373323ba64742cfdbd37e9b41 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 21 Nov 2023 20:34:28 +0100 Subject: [PATCH 02/27] attempt to write tests --- .../Dashboard/NewsItemControllerTest.php | 36 +++++++++++++ .../Dashboard/NewsItemRepositoryTest.php | 50 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemControllerTest.php create mode 100644 src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemRepositoryTest.php diff --git a/src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemControllerTest.php new file mode 100644 index 000000000..8809138a2 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemControllerTest.php @@ -0,0 +1,36 @@ +getClientAuthenticated('admin', 'admin'); + + $crawler = $client->request('GET', '/fr/admin/news_item'); + self::assertResponseIsSuccessful('Testing /fr/admin/news_item'); + + $btnEdit = $crawler->filter('.btn-edit')?->first(); + + self::assertNotNull($btnEdit, 'check that there is at least one btn-edit on news item page'); + + $client->click($btnEdit->link()); + + self::assertResponseIsSuccessful(); + } + +} diff --git a/src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemRepositoryTest.php b/src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemRepositoryTest.php new file mode 100644 index 000000000..f0491b75a --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Dashboard/NewsItemRepositoryTest.php @@ -0,0 +1,50 @@ +newsItemRepository = self::$container->get(NewsItemRepository::class); + } + + public function testFindWithDateFilter(): void + { + $clock = new MockClock('2023-11-20'); + + $newsItemA = new NewsItem(); + $newsItemA->setTitle('With end date article'); + $newsItemA->setContent('blabla'); + $newsItemA->setStartDate(new \DateTime('2023-11-01')); + $newsItemA->setEndDate(new \DateTime('2023-11-15')); + + $newsItemB = new NewsItem(); + $newsItemB->setTitle('No end date article'); + $newsItemB->setContent('with blopblop'); + $newsItemB->setStartDate(new \DateTime('2023-11-02')); + + $newsItemC = new NewsItem(); + $newsItemC->setTitle('Null as end date article'); + $newsItemC->setContent('tralala'); + $newsItemC->setStartDate(new \DateTime('2023-11-03')); + $newsItemC->setEndDate(null); + + } + +} From f1df2d5165a4efc5f2bc51c040440c94fc03af8e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 29 Nov 2023 11:12:21 +0100 Subject: [PATCH 03/27] Update wrong translation key --- .../ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php index 88007a074..ab73932b5 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php @@ -59,7 +59,7 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface ]); } - $menu->addChild($this->translator->trans('news_history.menu'), [ + $menu->addChild($this->translator->trans('news.menu'), [ 'route' => 'chill_main_news_items_history', ]) ->setExtras([ From df16ca9a60cfaa97bc46037e4e389bacd0b2738d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 13:20:14 +0100 Subject: [PATCH 04/27] force bootstrap to be restricted to version 5.2 --- package.json | 12 ++++++------ .../Resources/public/module/bootstrap/_shared.scss | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8ef78d1c7..26c93e045 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "@ckeditor/ckeditor5-vue": "^4.0.1", "@symfony/webpack-encore": "^4.1.0", "@tsconfig/node14": "^1.0.1", + "@types/dompurify": "^3.0.5", "bindings": "^1.5.0", - "bootstrap": "^5.3.0", "chokidar": "^3.5.1", "fork-awesome": "^1.1.7", "jquery": "^3.6.0", @@ -31,10 +31,10 @@ "typescript": "^4.7.2", "vue-loader": "^17.0.0", "webpack": "^5.75.0", - "webpack-cli": "^5.0.1", - "@types/dompurify": "^3.0.5" + "webpack-cli": "^5.0.1" }, "dependencies": { + "bootstrap": "~5.2.0", "@fullcalendar/core": "^6.1.4", "@fullcalendar/daygrid": "^6.1.4", "@fullcalendar/interaction": "^6.1.4", @@ -43,9 +43,11 @@ "@fullcalendar/vue3": "^6.1.4", "@popperjs/core": "^2.9.2", "@types/leaflet": "^1.9.3", + "dompurify": "^3.0.6", "dropzone": "^5.7.6", "es6-promise": "^4.2.8", "leaflet": "^1.7.1", + "marked": "^9.1.5", "masonry-layout": "^4.2.2", "mime": "^3.0.0", "swagger-ui": "^4.15.5", @@ -54,9 +56,7 @@ "vue-i18n": "^9.1.6", "vue-multiselect": "3.0.0-alpha.2", "vue-toast-notification": "^2.0", - "vuex": "^4.0.0", - "dompurify": "^3.0.6", - "marked": "^9.1.5" + "vuex": "^4.0.0" }, "browserslist": [ "Firefox ESR" diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/_shared.scss b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/_shared.scss index feca44382..96da20779 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/_shared.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/module/bootstrap/_shared.scss @@ -11,7 +11,6 @@ // 3. Include remainder of required Bootstrap stylesheets @import "bootstrap/scss/variables"; -@import "bootstrap/scss/variables-dark"; // 4. Include any default map overrides here @import "custom/_maps"; From 8bbe094e708f597750cab19bcbc2cf21b3dde6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 13:20:35 +0100 Subject: [PATCH 05/27] fix error for props on AddressDetailsButton.vue --- .../AddressDetails/AddressDetailsButton.vue | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddressDetails/AddressDetailsButton.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddressDetails/AddressDetailsButton.vue index f5e914d27..9a1550d7d 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddressDetails/AddressDetailsButton.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddressDetails/AddressDetailsButton.vue @@ -15,18 +15,20 @@ import AddressModal from "./AddressModal.vue"; export interface AddressModalContentProps { address_id: number; - address_ref_status: AddressRefStatus | null; + address_ref_status: AddressRefStatus; } -const data = reactive<{ - loading: boolean, - working_address: Address | null, - working_ref_status: AddressRefStatus | null, -}>({ +interface AddressModalData { + loading: boolean, + working_address: Address | null, + working_ref_status: AddressRefStatus | null, +} + +const data: AddressModalData = reactive({ loading: false, working_address: null, working_ref_status: null, -}); +} as AddressModalData); const props = defineProps(); From 53d18c7748f09a4e3b6033366a19c1e09989d784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 13:22:51 +0100 Subject: [PATCH 06/27] Give a more obvious url for new/current api endpoint --- .../ChillMainBundle/Controller/NewsItemApiController.php | 6 +++--- src/Bundle/ChillMainBundle/chill.api.specs.yaml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php index 5224228a8..6df54c779 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php @@ -30,15 +30,15 @@ class NewsItemApiController /** * Get list of news items filtered on start and end date. * - * @Route("/api/1.0/main/news.json", methods={"get"}) + * @Route("/api/1.0/main/news/current.json", methods={"get"}) */ public function listCurrentNewsItems(): JsonResponse { $total = $this->newsItemRepository->countWithDateFilter(); $paginator = $this->paginatorFactory->create($total); $newsItems = $this->newsItemRepository->findWithDateFilter( - $limit = $paginator->getItemsPerPage(), - $offset = $paginator->getCurrentPage()->getFirstItemNumber() + $paginator->getItemsPerPage(), + $paginator->getCurrentPage()->getFirstItemNumber() ); return new JsonResponse($this->serializer->serialize( diff --git a/src/Bundle/ChillMainBundle/chill.api.specs.yaml b/src/Bundle/ChillMainBundle/chill.api.specs.yaml index 8edbd93f6..f37ee723d 100644 --- a/src/Bundle/ChillMainBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillMainBundle/chill.api.specs.yaml @@ -892,11 +892,11 @@ paths: 403: description: "Unauthorized" - /1.0/main/news.json: + /1.0/main/news/current.json: get: tags: - news items - summary: Returns a list of news items + summary: Returns a list of news items which are valid responses: 200: description: "ok" From 67876120710097fe0a9dc13893ba9d09560a91db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 13:28:50 +0100 Subject: [PATCH 07/27] Take into account case when there are no active news --- .../vuejs/HomepageWidget/DashboardWidgets/News.vue | 12 +++++++----- .../public/vuejs/HomepageWidget/MyCustoms.vue | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue index a33bebf5c..6f85a5678 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue @@ -1,5 +1,5 @@