Improve layout of the history page

This commit is contained in:
Julien Fastré 2023-11-29 20:52:12 +01:00
parent 684f1a3015
commit e2efb267f5
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 58 additions and 66 deletions

View File

@ -11,6 +11,7 @@ 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;
@ -19,6 +20,7 @@ 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
{
@ -26,42 +28,41 @@ class NewsItemHistoryController extends AbstractController
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);
$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)

View File

@ -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))'))
@ -74,7 +77,8 @@ class NewsItemRepository implements ObjectRepository
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();

View File

@ -21,54 +21,38 @@
{% for entity in entities %}
<div class="item-bloc">
<div class="item-row wrap-header">
<div class="item-col">
<h3>
{{ entity.title }}
</h3>
<div>
{% if entity.startDate %}
<span>{{ entity.startDate|format_date('long') }}</span>
{% endif %}
{% if entity.endDate %}
<span> - {{ entity.endDate|format_date('long') }}</span>
{% endif %}
</div>
</div>
<div class="item-col" style="justify-content: flex-end;">
<div class="box">
<div>
{# <blockquote class="chill-user-quote">#}
{{ entity.content|u.truncate(350, '…', false)|chill_markdown_to_html }}
{# {% if entity.content|length > 350 %}#}
{# <a href="{{ chill_path_add_return_path('chill_main_news_items_history', {'news_item_id': entity.id}) }}">{{ 'news.read_more'|trans }}</a>#}
{# {% endif %}#}
{# </blockquote>#}
<div class="action">
<ul class="record_actions">
<li>
<a href="{{ chill_path_add_return_path('chill_main_single_news_item', { 'id': entity.id } ) }}" class="btn btn-show btn-mini"></a>
</li>
</ul>
</div>
</div>
</div>
<div class="item-row">
<h3>
{{ entity.title }}
</h3>
</div>
<div class="item-row">
<p>
{% if entity.startDate %}
<span>{{ entity.startDate|format_date('long') }}</span>
{% endif %}
{% if entity.endDate %}
<span> - {{ entity.endDate|format_date('long') }}</span>
{% endif %}
</p>
</div>
<div class="item-row separator">
<div>
{{ entity.content|u.truncate(350, '… [' ~ ('news.read_more'|trans) ~ '](' ~ chill_path_add_return_path('chill_main_single_news_item', { 'id': entity.id } ) ~ ')', false)|chill_markdown_to_html }}
</div>
</div>
<div class="item-row">
<ul class="record_actions">
<li>
<a href="{{ chill_path_add_return_path('chill_main_single_news_item', { 'id': entity.id } ) }}" class="btn btn-show btn-mini"></a>
</li>
</ul>
</div>
</div>
{% endfor %}
</div>
{{ chill_pagination(paginator) }}
<ul class="record_actions sticky-form-buttons">
<li>
<a href="{{ chill_path_add_return_path('chill_crud_aside_activity_new') }}" class="btn btn-create">
{{ 'Create'|trans }}
</a>
</li>
</ul>
{% endif %}
</div>
{% endblock %}

View File

@ -3,19 +3,22 @@
{% block title 'news.show_details'|trans %}
{% block content %}
<h1>{{ entity.title }}</h1>
<div class="col-md-10">
<h1>{{ entity.title }}</h1>
<div class="flex-table">
<div class="item-row">
<div>
<span>{{ entity.startDate|format_date('long') }}</span>
{% if entity.endDate is not null %}
<span> - {{ entity.endDate|format_date('long') }}</span>
{% endif %}
</div>
</div>
<div class="item-row separator">
{{ entity.content|chill_markdown_to_html }}
</div>
<div>
<span>{{ entity.startDate|format_date('long') }}</span>
{% if entity.endDate is not null %}
<span> - {{ entity.endDate|format_date('long') }}</span>
{% endif %}
</div>
<div>
{{ entity.content|chill_markdown_to_html }}
</div>
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a href="{{ chill_return_path_or('chill_main_news_items_history') }}" class="btn btn-cancel">{{ 'Back to the list'|trans|chill_return_path_label }}</a>
</li>
</ul>
</div>
{% endblock %}