diff --git a/package.json b/package.json index 34f1c8ed0..26c93e045 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "@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", @@ -35,6 +34,7 @@ "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", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index aa519e376..223c74b56 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,7 @@ - + diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php index 5224228a8..786a7e0f1 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php @@ -22,23 +22,24 @@ use Symfony\Component\Serializer\SerializerInterface; class NewsItemApiController { public function __construct( - private NewsItemRepository $newsItemRepository, - private SerializerInterface $serializer, - private PaginatorFactory $paginatorFactory - ) {} + private readonly NewsItemRepository $newsItemRepository, + private readonly SerializerInterface $serializer, + private readonly PaginatorFactory $paginatorFactory + ) { + } /** * 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(); + $total = $this->newsItemRepository->countCurrentNews(); $paginator = $this->paginatorFactory->create($total); - $newsItems = $this->newsItemRepository->findWithDateFilter( - $limit = $paginator->getItemsPerPage(), - $offset = $paginator->getCurrentPage()->getFirstItemNumber() + $newsItems = $this->newsItemRepository->findCurrentNews( + $paginator->getItemsPerPage(), + $paginator->getCurrentPage()->getFirstItemNumber() ); return new JsonResponse($this->serializer->serialize( diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php index 8c645828b..cf1f4922b 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php @@ -11,57 +11,58 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; +use Chill\MainBundle\Entity\NewsItem; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\NewsItemRepository; use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Twig\Environment; -class NewsItemHistoryController extends AbstractController +final readonly class NewsItemHistoryController { public function __construct( private readonly NewsItemRepository $newsItemRepository, private readonly PaginatorFactory $paginatorFactory, private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory, - ) {} + private readonly Environment $environment, + ) { + } /** * @Route("/{_locale}/news-items/history", name="chill_main_news_items_history") */ - public function listAction(Request $request): Response + public function list(): Response { - $filter = $this->buildFilterOrder(false); - $total = $this->newsItemRepository->countAllFilteredByUser($filter->getQueryString()); - $newsItems = $this->newsItemRepository->findAllFilteredByUser($filter->getQueryString()); + $filter = $this->buildFilterOrder(); + $total = $this->newsItemRepository->countAllFilteredBySearchTerm($filter->getQueryString()); + $newsItems = $this->newsItemRepository->findAllFilteredBySearchTerm($filter->getQueryString()); $pagination = $this->paginatorFactory->create($total); - return $this->render('@ChillMain/NewsItem/news_items_history.html.twig', [ + return new Response($this->environment->render('@ChillMain/NewsItem/news_items_history.html.twig', [ 'entities' => $newsItems, 'paginator' => $pagination, 'filter_order' => $filter, - ]); + ])); } /** * @Route("/{_locale}/news-items/{id}", name="chill_main_single_news_item") */ - public function showSingleItem(int $id, Request $request): Response + public function showSingleItem(NewsItem $newsItem, Request $request): Response { - $newsItem = $this->newsItemRepository->findOneBy(['id' => $id]); - - return $this->render( + return new Response($this->environment->render( '@ChillMain/NewsItem/show.html.twig', [ 'entity' => $newsItem, ] - ); + )); } - private function buildFilterOrder($includeFilterByUser = true, $includeMissionType = false): FilterOrderHelper + private function buildFilterOrder(): FilterOrderHelper { $filterBuilder = $this->filterOrderHelperFactory ->create(self::class) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 63cfb94c4..b88439314 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -562,10 +562,18 @@ class ChillMainExtension extends Extension implements 'role' => 'ROLE_ADMIN', 'template' => '@ChillMain/NewsItem/new.html.twig', ], + 'view' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillMain/NewsItem/view_admin.html.twig', + ], 'edit' => [ 'role' => 'ROLE_ADMIN', 'template' => '@ChillMain/NewsItem/edit.html.twig', ], + 'delete' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillMain/NewsItem/delete.html.twig', + ], ], ], ], diff --git a/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php b/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php index 5ad1107c5..ed9cc07bf 100644 --- a/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php +++ b/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php @@ -57,7 +57,7 @@ class DashboardConfigItem private ?User $user = null; /** - * @ORM\Column(type="json" "jsonb"=true, options={"default": "[]"}) + * @ORM\Column(type="json", options={"default": "[]", "jsonb": true}) * * @Serializer\Groups({"dashboardConfigItem:read"}) */ diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index 88b597647..2e517970c 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -22,7 +22,7 @@ class NewsItemRepository implements ObjectRepository { private readonly EntityRepository $repository; - public function __construct(EntityManagerInterface $entityManager, private ClockInterface $clock) + public function __construct(EntityManagerInterface $entityManager, private readonly ClockInterface $clock) { $this->repository = $entityManager->getRepository(NewsItem::class); } @@ -57,11 +57,14 @@ class NewsItemRepository implements ObjectRepository return NewsItem::class; } - public function buildBaseQuery( + private function buildBaseQuery( string $pattern = null ): QueryBuilder { $qb = $this->createQueryBuilder('n'); + $qb->where('n.startDate <= :now'); + $qb->setParameter('now', $this->clock->now()); + if (null !== $pattern && '' !== $pattern) { $qb->andWhere($qb->expr()->like('LOWER(UNACCENT(n.title))', 'LOWER(UNACCENT(:pattern))')) ->orWhere($qb->expr()->like('LOWER(UNACCENT(n.content))', 'LOWER(UNACCENT(:pattern))')) @@ -71,24 +74,28 @@ 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') + $qb + ->addOrderBy('n.startDate', 'DESC') ->addOrderBy('n.id', 'DESC'); return $qb->getQuery()->getResult(); } - public function findWithDateFilter($limit = null, $offset = null) + /** + * @return list + */ + public function findCurrentNews(int $limit = null, int $offset = null): array { - $qb = $this->buildQueryWithDateFilter(); + $qb = $this->buildQueryCurrentNews(); - if ($limit) { + if (null !== $limit) { $qb->setMaxResults($limit); } - if ($offset) { + if (null !== $offset) { $qb->setFirstResult($offset); } @@ -97,7 +104,7 @@ class NewsItemRepository implements ObjectRepository ->getResult(); } - public function countAllFilteredByUser(string $pattern = null) + public function countAllFilteredBySearchTerm(string $pattern = null) { $qb = $this->buildBaseQuery($pattern); @@ -107,15 +114,15 @@ class NewsItemRepository implements ObjectRepository ->getSingleScalarResult(); } - public function countWithDateFilter() + public function countCurrentNews() { - return $this->buildQueryWithDateFilter() + return $this->buildQueryCurrentNews() ->select('COUNT(n)') ->getQuery() ->getSingleScalarResult(); } - public function buildQueryWithDateFilter(): QueryBuilder + private function buildQueryCurrentNews(): QueryBuilder { $now = $this->clock->now(); 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"; diff --git a/src/Bundle/ChillMainBundle/Resources/public/types.ts b/src/Bundle/ChillMainBundle/Resources/public/types.ts index 79dae2695..2e33b8248 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/types.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/types.ts @@ -165,6 +165,6 @@ export interface NewsItemType { id: number; title: string; content: string; - startdate: { date: DateTime }; - enddate: { date: DateTime | null} + startDate: DateTime; + endDate: DateTime | null; } 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 @@