mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-06 07:49:53 +00:00
Improve layout of the history page
This commit is contained in:
parent
684f1a3015
commit
e2efb267f5
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Controller;
|
namespace Chill\MainBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\NewsItem;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Repository\NewsItemRepository;
|
use Chill\MainBundle\Repository\NewsItemRepository;
|
||||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
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\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class NewsItemHistoryController extends AbstractController
|
class NewsItemHistoryController extends AbstractController
|
||||||
{
|
{
|
||||||
@ -26,42 +28,41 @@ class NewsItemHistoryController extends AbstractController
|
|||||||
private readonly NewsItemRepository $newsItemRepository,
|
private readonly NewsItemRepository $newsItemRepository,
|
||||||
private readonly PaginatorFactory $paginatorFactory,
|
private readonly PaginatorFactory $paginatorFactory,
|
||||||
private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
|
private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
|
||||||
|
private readonly Environment $environment,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/{_locale}/news-items/history", name="chill_main_news_items_history")
|
* @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());
|
$total = $this->newsItemRepository->countAllFilteredBySearchTerm($filter->getQueryString());
|
||||||
$newsItems = $this->newsItemRepository->findAllFilteredBySearchTerm($filter->getQueryString());
|
$newsItems = $this->newsItemRepository->findAllFilteredBySearchTerm($filter->getQueryString());
|
||||||
|
|
||||||
$pagination = $this->paginatorFactory->create($total);
|
$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,
|
'entities' => $newsItems,
|
||||||
'paginator' => $pagination,
|
'paginator' => $pagination,
|
||||||
'filter_order' => $filter,
|
'filter_order' => $filter,
|
||||||
]);
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/{_locale}/news-items/{id}", name="chill_main_single_news_item")
|
* @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 new Response($this->environment->render(
|
||||||
|
|
||||||
return $this->render(
|
|
||||||
'@ChillMain/NewsItem/show.html.twig',
|
'@ChillMain/NewsItem/show.html.twig',
|
||||||
[
|
[
|
||||||
'entity' => $newsItem,
|
'entity' => $newsItem,
|
||||||
]
|
]
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildFilterOrder($includeFilterByUser = true, $includeMissionType = false): FilterOrderHelper
|
private function buildFilterOrder(): FilterOrderHelper
|
||||||
{
|
{
|
||||||
$filterBuilder = $this->filterOrderHelperFactory
|
$filterBuilder = $this->filterOrderHelperFactory
|
||||||
->create(self::class)
|
->create(self::class)
|
||||||
|
@ -57,11 +57,14 @@ class NewsItemRepository implements ObjectRepository
|
|||||||
return NewsItem::class;
|
return NewsItem::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildBaseQuery(
|
private function buildBaseQuery(
|
||||||
string $pattern = null
|
string $pattern = null
|
||||||
): QueryBuilder {
|
): QueryBuilder {
|
||||||
$qb = $this->createQueryBuilder('n');
|
$qb = $this->createQueryBuilder('n');
|
||||||
|
|
||||||
|
$qb->where('n.startDate <= :now');
|
||||||
|
$qb->setParameter('now', $this->clock->now());
|
||||||
|
|
||||||
if (null !== $pattern && '' !== $pattern) {
|
if (null !== $pattern && '' !== $pattern) {
|
||||||
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(n.title))', 'LOWER(UNACCENT(:pattern))'))
|
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(n.title))', 'LOWER(UNACCENT(:pattern))'))
|
||||||
->orWhere($qb->expr()->like('LOWER(UNACCENT(n.content))', '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)
|
public function findAllFilteredBySearchTerm(string $pattern = null)
|
||||||
{
|
{
|
||||||
$qb = $this->buildBaseQuery($pattern);
|
$qb = $this->buildBaseQuery($pattern);
|
||||||
$qb->addOrderBy('n.startDate', 'DESC')
|
$qb
|
||||||
|
->addOrderBy('n.startDate', 'DESC')
|
||||||
->addOrderBy('n.id', 'DESC');
|
->addOrderBy('n.id', 'DESC');
|
||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
|
@ -21,54 +21,38 @@
|
|||||||
{% for entity in entities %}
|
{% for entity in entities %}
|
||||||
|
|
||||||
<div class="item-bloc">
|
<div class="item-bloc">
|
||||||
<div class="item-row wrap-header">
|
<div class="item-row">
|
||||||
|
<h3>
|
||||||
<div class="item-col">
|
{{ entity.title }}
|
||||||
<h3>
|
</h3>
|
||||||
{{ entity.title }}
|
</div>
|
||||||
</h3>
|
<div class="item-row">
|
||||||
<div>
|
<p>
|
||||||
{% if entity.startDate %}
|
{% if entity.startDate %}
|
||||||
<span>{{ entity.startDate|format_date('long') }}</span>
|
<span>{{ entity.startDate|format_date('long') }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if entity.endDate %}
|
{% if entity.endDate %}
|
||||||
<span> - {{ entity.endDate|format_date('long') }}</span>
|
<span> - {{ entity.endDate|format_date('long') }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="item-col" style="justify-content: flex-end;">
|
<div class="item-row separator">
|
||||||
<div class="box">
|
<div>
|
||||||
<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 }}
|
||||||
{# <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>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ chill_pagination(paginator) }}
|
{{ 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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -3,19 +3,22 @@
|
|||||||
{% block title 'news.show_details'|trans %}
|
{% block title 'news.show_details'|trans %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ entity.title }}</h1>
|
<div class="col-md-10">
|
||||||
|
<h1>{{ entity.title }}</h1>
|
||||||
|
|
||||||
<div class="flex-table">
|
<div>
|
||||||
<div class="item-row">
|
<span>{{ entity.startDate|format_date('long') }}</span>
|
||||||
<div>
|
{% if entity.endDate is not null %}
|
||||||
<span>{{ entity.startDate|format_date('long') }}</span>
|
<span> - {{ entity.endDate|format_date('long') }}</span>
|
||||||
{% if entity.endDate is not null %}
|
{% endif %}
|
||||||
<span> - {{ entity.endDate|format_date('long') }}</span>
|
</div>
|
||||||
{% endif %}
|
<div>
|
||||||
</div>
|
{{ entity.content|chill_markdown_to_html }}
|
||||||
</div>
|
</div>
|
||||||
<div class="item-row separator">
|
<ul class="record_actions sticky-form-buttons">
|
||||||
{{ entity.content|chill_markdown_to_html }}
|
<li class="cancel">
|
||||||
</div>
|
<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>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user