From 09f823ac0874decc545a7f9fa6bfe97db619af8f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 13 Nov 2023 14:06:05 +0100 Subject: [PATCH] process review --- .../ChillMainExtension.php | 42 ---------- .../Entity/DashboardConfigItem.php | 4 +- .../ChillMainBundle/Entity/NewsItem.php | 78 ++----------------- .../Repository/NewsItemRepository.php | 10 ++- .../HomepageWidget/DashboardWidgets/News.vue | 13 ++-- .../public/vuejs/HomepageWidget/MyCustoms.vue | 4 +- .../Resources/public/vuejs/_js/i18n.ts | 3 +- .../views/Admin/indexDashboard.html.twig | 2 +- .../Resources/views/NewsItem/index.html.twig | 6 +- .../migrations/Version20231108141141.php | 2 +- .../translations/messages.fr.yml | 12 +++ 11 files changed, 43 insertions(+), 133 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 7cb84b14d..1621471b8 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -791,48 +791,6 @@ class ChillMainExtension extends Extension implements ], ], ], - /* [ - 'class' => \Chill\MainBundle\Entity\DashboardConfigItem::class, - 'controller' => \Chill\MainBundle\Controller\DashboardApiController::class, - 'name' => 'dashboard-config-item', - 'base_path' => '/api/1.0/main/dashboard-config-item', - 'base_role' => 'ROLE_USER', - 'actions' => [ - '_index' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - '_entity' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - ], - ], - [ - 'class' => \Chill\MainBundle\Entity\NewsItem::class, - 'controller' => \Chill\MainBundle\Controller\NewsItemApiController::class, - 'name' => 'news-items', - 'base_path' => '/api/1.0/main/news', - 'base_role' => 'ROLE_USER', - 'actions' => [ - '_index' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - '_entity' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - ], - ],*/ ], ]); } diff --git a/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php b/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php index 122202f96..5ad1107c5 100644 --- a/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php +++ b/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php @@ -54,10 +54,10 @@ class DashboardConfigItem /** * @ORM\ManyToOne(targetEntity=User::class) */ - private User $user; + private ?User $user = null; /** - * @ORM\Column(type="json") + * @ORM\Column(type="json" "jsonb"=true, options={"default": "[]"}) * * @Serializer\Groups({"dashboardConfigItem:read"}) */ diff --git a/src/Bundle/ChillMainBundle/Entity/NewsItem.php b/src/Bundle/ChillMainBundle/Entity/NewsItem.php index 10eca8f54..6ca58afd1 100644 --- a/src/Bundle/ChillMainBundle/Entity/NewsItem.php +++ b/src/Bundle/ChillMainBundle/Entity/NewsItem.php @@ -12,7 +12,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; +use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -24,6 +26,10 @@ use Symfony\Component\Validator\Constraints as Assert; */ class NewsItem implements TrackCreationInterface, TrackUpdateInterface { + use TrackCreationTrait; + + use TrackUpdateTrait; + /** * @ORM\Id * @@ -71,78 +77,6 @@ class NewsItem implements TrackCreationInterface, TrackUpdateInterface */ private ?\DateTimeImmutable $endDate = null; - /** - * @ORM\Column(type="datetime_immutable", nullable=true) - */ - private ?\DateTimeInterface $createdAt = null; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - * - * @ORM\JoinColumn(nullable=true) - */ - private ?User $createdBy = null; - - /** - * @ORM\Column(type="datetime_immutable", nullable=true) - */ - private ?\DateTimeInterface $updatedAt = null; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - * - * @ORM\JoinColumn(nullable=true) - */ - private ?User $updatedBy = null; - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function getCreatedBy(): ?User - { - return $this->createdBy; - } - - public function getUpdatedAt(): ?\DateTimeInterface - { - return $this->updatedAt; - } - - public function getUpdatedBy(): ?User - { - return $this->updatedBy; - } - - public function setCreatedAt(\DateTimeInterface $datetime): self - { - $this->createdAt = $datetime; - - return $this; - } - - public function setCreatedBy(User $user): self - { - $this->createdBy = $user; - - return $this; - } - - public function setUpdatedAt(\DateTimeInterface $datetime): self - { - $this->updatedAt = $datetime; - - return $this; - } - - public function setUpdatedBy(User $user): self - { - $this->updatedBy = $user; - - return $this; - } - public function getTitle(): string { return $this->title; diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index bb2128b25..042c052c5 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -16,12 +16,13 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectRepository; +use Symfony\Component\Clock\ClockInterface; class NewsItemRepository implements ObjectRepository { private readonly EntityRepository $repository; - public function __construct(EntityManagerInterface $entityManager) + public function __construct(EntityManagerInterface $entityManager, private ClockInterface $clock) { $this->repository = $entityManager->getRepository(NewsItem::class); } @@ -58,6 +59,9 @@ class NewsItemRepository implements ObjectRepository public function findWithDateFilter() { + dump($this->buildQueryWithDateFilter() + ->getQuery() + ->getResult()); return $this->buildQueryWithDateFilter() ->getQuery() ->getResult(); @@ -73,13 +77,13 @@ class NewsItemRepository implements ObjectRepository public function buildQueryWithDateFilter(): QueryBuilder { - $now = new \DateTime('now'); + $now = $this->clock->now(); $qb = $this->createQueryBuilder('n'); $qb ->where( $qb->expr()->andX( - $qb->expr()->gte('n.startDate', ':now'), + $qb->expr()->lte('n.startDate', ':now'), $qb->expr()->orX( $qb->expr()->lt('n.endDate', ':now'), $qb->expr()->isNull('n.endDate') 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 272a57e9b..e11338c4a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue @@ -5,8 +5,8 @@
  • {{ item.title }}

    -
    - Read more +
    + {{ $t('widget.news.readMore') }}
    @@ -64,9 +64,9 @@ const convertMarkdownToHtml = (markdown: string): string => { return DOMPurify.sanitize(rawHtml) }; -const truncateMarkdownContent = (content: string, maxLength = 100): string => { - const htmlContent = convertMarkdownToHtml(content); - return truncateContent(htmlContent, maxLength); +const prepareContent = (content: string, maxLength = 100): string => { + const truncatedContent = truncateContent(content, maxLength); + return convertMarkdownToHtml(truncatedContent); }; const formatDate = (datetime: { date: string }): string => { @@ -76,9 +76,10 @@ const formatDate = (datetime: { date: string }): string => { onMounted(() => { makeFetch('GET', '/api/1.0/main/news.json') .then((response: {results: NewsItem[]}) => { + // console.log('news articles', response.results) newsItems.value = response.results }) - .catch((error) => { + .catch((error: string) => { console.error('Error fetching news items', error); }) }) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue index 5df7fb787..65bed73ef 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue @@ -41,7 +41,7 @@
    - +
    @@ -76,7 +76,7 @@ export default { mounted() { const elem = document.querySelector('#dashboards'); const masonry = new Masonry(elem, {}); - //Fetch the dashboard items configured for user. Currently response is still hardcoded and no user id passed. + //Fetch the dashboard items configured for user. Currently response is still hardcoded makeFetch('GET', '/api/1.0/main/dashboard-config-item.json') .then((response) => { this.dashboardItems = response; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts index c43586915..54e136e08 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts @@ -54,7 +54,8 @@ const messages = { }, widget: { news: { - title: "Actualités" + title: "Actualités", + readMore: "Lire la suite" } } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig index 6f79e3d2a..8049f3430 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig @@ -8,6 +8,6 @@ {% block layout_wvm_content %} {% block admin_content %} -

    {{ 'News configuration' |trans }}

    +

    {{ 'News configuration' | trans }}

    {% endblock %} {% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig index 25c1555fb..307073496 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig @@ -4,8 +4,8 @@ {% embed '@ChillMain/CRUD/_index.html.twig' %} {% block table_entities_thead_tr %} {{ 'Title'|trans }} - {{ 'news.startdate'|trans }} - {{ 'news.enddate'|trans }} + {{ 'dashboard.news.startDate'|trans }} + {{ 'dashboard.news.endDate'|trans }} {% endblock %} {% block table_entities_tbody %} {% for entity in entities %} @@ -15,7 +15,7 @@ {% if entity.endDate is not null %} {{ entity.endDate|date }} {% else %} - Pas de date de fin + {{ 'dashboard.news.noDate'|trans }} {% endif %}
      diff --git a/src/Bundle/ChillMainBundle/migrations/Version20231108141141.php b/src/Bundle/ChillMainBundle/migrations/Version20231108141141.php index d081a9e94..d4fe9b561 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20231108141141.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20231108141141.php @@ -28,7 +28,7 @@ final class Version20231108141141 extends AbstractMigration { $this->addSql('CREATE SEQUENCE chill_main_dashboard_config_item_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('CREATE SEQUENCE chill_main_news_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE chill_main_dashboard_config_item (id INT NOT NULL, user_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, position VARCHAR(255) NOT NULL, metadata JSON NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE chill_main_dashboard_config_item (id INT NOT NULL, user_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, position VARCHAR(255) NOT NULL, metadata JSONB DEFAULT \'{}\'::jsonb, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_CF59DFD6A76ED395 ON chill_main_dashboard_config_item (user_id)'); $this->addSql('CREATE TABLE chill_main_news (id INT NOT NULL, title TEXT NOT NULL, content TEXT NOT NULL, startDate DATE NOT NULL, endDate DATE DEFAULT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updatedAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, createdBy_id INT DEFAULT NULL, updatedBy_id INT DEFAULT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_96922AFB3174800F ON chill_main_news (createdBy_id)'); diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 28615bc75..a3b772081 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -431,6 +431,12 @@ crud: add_new: Ajouter un centre title_new: Nouveau centre title_edit: Modifier un centre + news_item: + index: + title: Liste des actualités + add_new: Créer une nouvelle actualité + title_new: Nouvelle actualité + title_edit: Modifier une actualité No entities: Aucun élément @@ -672,3 +678,9 @@ admin: undefined: non défini user: Utilisateur scope: Service + +dashboard: + news: + noDate: Pas de date de fin + startDate: Date de début + endDate: Date de fin