@@ -7,9 +7,11 @@ use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||
use Lc\CaracoleBundle\Resolver\SectionResolver; | |||
use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface; | |||
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType; | |||
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\Form\FormFactoryInterface; | |||
use Symfony\Component\HttpFoundation\JsonResponse; | |||
use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\HttpFoundation\Response; | |||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |||
@@ -20,6 +22,7 @@ class ReminderAdminController extends AbstractController | |||
protected EntityManagerInterface $entityManager; | |||
protected ReminderFactoryInterface $reminderFactory; | |||
protected ReminderRepositoryQueryInterface $reminderRepositoryQuery; | |||
protected FormFactoryInterface $formFactory; | |||
protected UrlGeneratorInterface $urlGenerator; | |||
protected MerchantResolver $merchantResolver; | |||
@@ -29,6 +32,7 @@ class ReminderAdminController extends AbstractController | |||
public function __construct( | |||
EntityManagerInterface $entityManager, | |||
ReminderFactoryInterface $reminderFactory, | |||
ReminderRepositoryQueryInterface $reminderRepositoryQuery, | |||
FormFactoryInterface $formFactory, | |||
UrlGeneratorInterface $urlGenerator, | |||
MerchantResolver $merchantResolver, | |||
@@ -37,6 +41,7 @@ class ReminderAdminController extends AbstractController | |||
) { | |||
$this->entityManager = $entityManager; | |||
$this->reminderFactory = $reminderFactory; | |||
$this->reminderRepositoryQuery = $reminderRepositoryQuery; | |||
$this->formFactory = $formFactory; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->merchantResolver = $merchantResolver; | |||
@@ -49,19 +54,30 @@ class ReminderAdminController extends AbstractController | |||
*/ | |||
public function renderModal(Request $request): Response | |||
{ | |||
$crudAction = $request->get('crudAction'); | |||
$crudControllerFqcn = $request->get('crudControllerFqcn'); | |||
$entityId = $request->get('entityId'); | |||
$reminder = $this->createEntity($crudAction, $crudControllerFqcn, $entityId); | |||
$id = $request->get('id'); | |||
if($id) { | |||
$reminder = $this->reminderRepositoryQuery->getRepository()->find($id); | |||
$action = $this->urlGenerator->generate( | |||
$this->parameterBag->get('app.reminder.route_edit'), | |||
['id' => $id] | |||
); | |||
} | |||
else { | |||
$crudAction = $request->get('crudAction'); | |||
$crudControllerFqcn = $request->get('crudControllerFqcn'); | |||
$entityId = $request->get('entityId') ? $request->get('entityId') : null ; | |||
$reminder = $this->createEntity($crudAction, $crudControllerFqcn, $entityId); | |||
$action = $this->urlGenerator->generate( | |||
$this->parameterBag->get('app.reminder.route_new') | |||
); | |||
} | |||
$form = $this->formFactory->create( | |||
ReminderAdminFormType::class, | |||
$reminder, | |||
[ | |||
'action' => $this->urlGenerator->generate( | |||
$this->parameterBag->get('app.reminder.route_new') | |||
) | |||
'action' => $action | |||
] | |||
); | |||
@@ -94,56 +110,51 @@ class ReminderAdminController extends AbstractController | |||
return $this->redirect($request->headers->get('referer')); | |||
} | |||
public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null) | |||
/** | |||
* @Route("/admin/reminder/edit/{id}", name="sov_admin_reminder_edit") | |||
*/ | |||
public function edit(Request $request) | |||
{ | |||
return $this->reminderFactory->create($crudAction, $crudControllerFqcn, $entityId); | |||
} | |||
$id = $request->get('id'); | |||
$reminder = $this->reminderRepositoryQuery->getRepository()->find($id); | |||
$form = $this->formFactory->create(ReminderAdminFormType::class, $reminder); | |||
$form->handleRequest($request); | |||
/* | |||
public function renderTemplate($actionName, $templatePath, array $parameters = []) | |||
{ | |||
if ($this->request->isXmlHttpRequest() && ($actionName == 'new' || $actionName == 'edit')) { | |||
$response['flashMessages'] = $this->utils->getFlashMessages(); | |||
if ($form->isSubmitted() && $form->isValid()) { | |||
$reminder = $form->getData(); | |||
$this->entityManager->update($reminder); | |||
$this->entityManager->flush(); | |||
$response['data'] = $this->render('@LcShop/backend/default/modal/edit_reminder.twig', $parameters)->getContent(); | |||
return new Response(json_encode($response)); | |||
} else { | |||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||
$this->addFlash('success', 'Le pense-bête a bien été mis à jour'); | |||
} | |||
return $this->redirect($request->headers->get('referer')); | |||
} | |||
protected function redirectToReferrer() | |||
/** | |||
* @Route("/admin/reminder/done", name="sov_admin_reminder_done") | |||
*/ | |||
public function done(Request $request): JsonResponse | |||
{ | |||
$action = $this->request->query->get('action'); | |||
if ($action == 'new') { | |||
$this->utils->addFlash('success', 'success.reminder.add'); | |||
} elseif ($action == 'edit') { | |||
$this->utils->addFlash('success', 'success.reminder.edit'); | |||
} elseif ($action == ' setReminderDone') { | |||
$this->utils->addFlash('success', 'success.reminder.done'); | |||
} | |||
$id = $request->get('id'); | |||
$reminder = $this->reminderRepositoryQuery->getRepository()->find($id); | |||
$done = $request->get('done'); | |||
if ($this->request->isXmlHttpRequest()) { | |||
$response['flashMessages'] = $this->utils->getFlashMessages(); | |||
return new Response(json_encode($response)); | |||
} else { | |||
return parent::redirectToReferrer(); | |||
if($done == 'true') { | |||
$reminder->setDone(true); | |||
} | |||
else { | |||
$reminder->setDone(false); | |||
} | |||
$this->entityManager->update($reminder); | |||
$this->entityManager->flush(); | |||
return new JsonResponse(['success' => true]); | |||
} | |||
public function setReminderDoneAction() | |||
public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null) | |||
{ | |||
$id = $this->request->query->get('id'); | |||
$done = $this->request->query->get('done'); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$reminder = $easyadmin['item']; | |||
$reminder->setDone($done); | |||
$this->em->persist($reminder); | |||
$this->em->flush(); | |||
return $this->redirectToReferrer(); | |||
}*/ | |||
return $this->reminderFactory->create($crudAction, $crudControllerFqcn, $entityId); | |||
} | |||
} |
@@ -89,5 +89,6 @@ abstract class AbstractRepositoryQuery | |||
return $data; | |||
} | |||
} | |||
@@ -12,10 +12,36 @@ class ReminderRepositoryQuery extends AbstractRepositoryQuery implements Reminde | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
public function filterDone() | |||
public function filterBase($params = []) | |||
{ | |||
$this->filterDone(); | |||
if(array_key_exists('user', $params)) { | |||
$this->filterUser($params['user']); | |||
} | |||
if(array_key_exists('crudAction', $params)) { | |||
$this->filterCrudAction($params['crudAction']); | |||
} | |||
if(array_key_exists('crudControllerFqcn', $params)) { | |||
$this->filterCrudControllerFqcn($params['crudControllerFqcn']); | |||
} | |||
if(array_key_exists('entityId', $params)) { | |||
$this->filterEntityId($params['entityId']); | |||
} | |||
$this->orderDefault(); | |||
return $this; | |||
} | |||
public function filterDone($done = false) | |||
{ | |||
return $this | |||
->andWhere('.done = 0'); | |||
->andWhere('.done = :done') | |||
->setParameter(':done', $done); | |||
} | |||
public function filterUser($user) | |||
@@ -28,6 +54,45 @@ class ReminderRepositoryQuery extends AbstractRepositoryQuery implements Reminde | |||
->groupBy('.id'); | |||
} | |||
public function filterCrudAction($crudAction) | |||
{ | |||
if(is_null($crudAction)) { | |||
return $this | |||
->andWhere('.crudControllerFqcn IS NULL'); | |||
} | |||
else { | |||
return $this | |||
->andWhere('.crudAction = :crudAction') | |||
->setParameter(':crudAction', $crudAction); | |||
} | |||
} | |||
public function filterCrudControllerFqcn($crudControllerFqcn) | |||
{ | |||
if(is_null($crudControllerFqcn)) { | |||
return $this | |||
->andWhere('.crudControllerFqcn IS NULL'); | |||
} | |||
else { | |||
return $this | |||
->andWhere('.crudControllerFqcn = :crudControllerFqcn') | |||
->setParameter(':crudControllerFqcn', $crudControllerFqcn); | |||
} | |||
} | |||
public function filterEntityId($entityId) | |||
{ | |||
if(is_null($entityId)) { | |||
return $this | |||
->andWhere('.entityId IS NULL'); | |||
} | |||
else { | |||
return $this | |||
->andWhere('.entityId = :entityId') | |||
->setParameter(':entityId', $entityId); | |||
} | |||
} | |||
public function orderDefault() | |||
{ | |||
return $this |
@@ -11,32 +11,14 @@ class ReminderStore implements ReminderStoreInterface | |||
$this->query = $query; | |||
} | |||
public function getByUser($user) | |||
public function get($params = []) | |||
{ | |||
$query = $this->query->create(); | |||
return $query | |||
->filterDone() | |||
->filterUser($user) | |||
->orderDefault() | |||
->find(); | |||
$query->filterBase($params) ; | |||
return $query->find(); | |||
} | |||
/*public function getFoo($query = null) | |||
{ | |||
if (!$query) { | |||
$query = $this->query->create(); | |||
} | |||
return $query | |||
->useCustomFilters() | |||
->andWhere('.description = :description') | |||
->setParameter(':description', 'ahah') | |||
->findOne(); | |||
}*/ | |||
/* | |||
public function findByUser($user) | |||
{ | |||
$qb = $this->createQueryBuilder('e') | |||
@@ -71,7 +53,5 @@ class ReminderStore implements ReminderStoreInterface | |||
$qb->groupBy('e.id'); | |||
return $qb->getQuery()->getResult(); | |||
} | |||
*/ | |||
}*/ | |||
} |
@@ -11,6 +11,7 @@ function initReminder() { | |||
crudAction: $(this).data('crud-action'), | |||
crudControllerFqcn: $(this).data('crud-controller-fqcn'), | |||
entityId: $(this).data('entity-id'), | |||
id: $(this).data('id'), | |||
}, function(html) { | |||
$(selectorModal).remove() ; | |||
$('body').append(html) ; | |||
@@ -18,4 +19,13 @@ function initReminder() { | |||
}); | |||
return false ; | |||
}) ; | |||
$('.checkbox-reminder').click(function() { | |||
$.post($(this).data('url'), { | |||
id: $(this).data('id'), | |||
done: $(this).is(':checked') | |||
}, function(data) { | |||
Notification.add('success', 'Pense-bête mis à jour'); | |||
}, 'json'); | |||
}) ; | |||
} |
@@ -4,6 +4,11 @@ div#reminders { | |||
li { | |||
div.text { | |||
padding-left: 30px ; | |||
.badge-date { | |||
margin-left: 0px; | |||
margin-right: 6px; | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,85 @@ | |||
{% if reminders %} | |||
<div class="col-sm-12"> | |||
<div id="reminders" class="card card-outline card-danger"> | |||
<ul class="todo-list"> | |||
{% for reminder in reminders %} | |||
<li> | |||
<label class="big form-check-label"> | |||
<input type="checkbox" name="" value="1" | |||
class="form-check-input checkbox-reminder" | |||
data-url="{{ path('sov_admin_reminder_done') }}" data-id="{{ reminder.id }}"/> | |||
<span class="checkmark"></span> | |||
</label> | |||
<div class="text"> | |||
{% if reminder.dateReminder %} | |||
<small class="badge badge-info badge-date"> | |||
<i class="far fa-clock"></i> | |||
{{ reminder.dateReminder|date('d/m/Y') }} | |||
</small> | |||
{% endif %} | |||
{{ reminder.title }} | |||
</div> | |||
<div class="tools"> | |||
<a href="#" class="btn-sm btn-success" data-toggle="modal" | |||
data-target="#modal-reminder-{{ reminder.id }}"> | |||
<i class="fas fa-eye"></i> | |||
</a> | |||
<a href="{{ path(sov_parameter('app.reminder.route_render_modal')) }}" | |||
class="btn-sm btn-info btn-reminder" data-id="{{ reminder.id }}"> | |||
<i class="fas fa-edit"></i> | |||
</a> | |||
</div> | |||
{% embed '@LcSov/adminlte/embed/modal.twig' %} | |||
{% block id %}modal-reminder-{{ reminder.id }}{% endblock %} | |||
{% block title %} | |||
Pense-bête #{{ reminder.id }} | |||
{% endblock %} | |||
{% block body %} | |||
<div class="row"> | |||
<div class="col-1 align-center"> | |||
<i class="fa fa-thumbtack"></i> | |||
</div> | |||
<div class="col-11"> | |||
<h5><strong>{{ reminder.title }}</strong></h5> | |||
</div> | |||
{% if reminder.dateReminder %} | |||
<div class="col-1 align-center"> | |||
<i class="fa fa-calendar"></i> | |||
</div> | |||
<div class="col-11"> | |||
<p>{{ reminder.dateReminder|date('d/m/Y') }}</p> | |||
</div> | |||
{% endif %} | |||
{% if reminder.description %} | |||
<div class="col-1 align-center"> | |||
<i class="fa fa-align-left"></i> | |||
</div> | |||
<div class="col-11"> | |||
<p>{{ reminder.description|nl2br }}</p> | |||
</div> | |||
{% endif %} | |||
{# {% if reminder.relatedPage %} | |||
<div class="col-1 align-center"> | |||
<i class="fa fa-link"></i> | |||
</div> | |||
<div class="col-11"> | |||
<a href="{{ path('easyadmin', {"action" : reminder.entityAction, 'entity' : reminder.entityName, 'id': reminder.entityId }) }}">{{ reminder.relatedPage }}</a> | |||
</div> | |||
{% endif %} #} | |||
</div> | |||
{% endblock %} | |||
{% block footer %} | |||
<button type="button" class="btn btn-default float-right" data-dismiss="modal">Fermer | |||
</button> | |||
{% endblock %} | |||
{% endembed %} | |||
</li> | |||
{% endfor %} | |||
</ul> | |||
</div> | |||
</div> | |||
{% endif %} |
@@ -39,7 +39,7 @@ | |||
</li> | |||
<li class="nav-item"> | |||
<a href="{{ path(sov_parameter('app.reminder.route_render_modal')) }}" class="btn btn-sm btn-outline-info btn-reminder" data-crud-action="{{ ea.request.query.get('crudAction') }}" data-crud-controller-fqcn="{{ ea.request.query.get('crudControllerFqcn') }}"> | |||
<a href="{{ path(sov_parameter('app.reminder.route_render_modal')) }}" class="btn btn-sm btn-outline-info btn-reminder" data-crud-action="{{ ea.request.query.get('crudAction') }}" data-crud-controller-fqcn="{{ ea.request.query.get('crudControllerFqcn') }}" data-entity-id="{{ ea.request.query.get('entityId') }}"> | |||
<i class="action-icon fa fa-plus"></i> | |||
Pense-bête | |||
</a> |
@@ -105,35 +105,21 @@ | |||
<div class="container-fluid"> | |||
<div class="row mb-2"> | |||
{% set reminders = sov_get_reminders() %} | |||
{% if reminders %} | |||
<div class="col-sm-12"> | |||
<div id="reminders" class="card card-outline card-danger"> | |||
<ul class="todo-list"> | |||
{% for reminder in reminders %} | |||
<li> | |||
<label class="big form-check-label"> | |||
<input type="checkbox" name="" value="1" class="form-check-input checkbox-valid-reminder" data-url="/admin/?action=setReminderDone&entity=Reminder&id=90"> | |||
<span class="checkmark"></span> | |||
</label> | |||
<div class="text"> | |||
{{ reminder.description }} | |||
</div> | |||
<div class="tools"> | |||
<button type="button" class="btn-sm btn-success" data-toggle="modal" data-target="#modal-reminder-91"> | |||
<i class="fas fa-eye"></i> | |||
</button> | |||
<button type="button" class="btn-sm btn-info btn-edit-reminder" data-url="/admin/?action=edit&entity=Reminder&id=91"> | |||
<i class="fas fa-edit"></i> | |||
</button> | |||
</div> | |||
</li> | |||
{% endfor %} | |||
</ul> | |||
</div> | |||
</div> | |||
{% set params_reminders = {crudAction: null, crudControllerFqcn: null, entityId: null} %} | |||
{% if ea is defined and ea %} | |||
{% if ea.crud is defined and ea.crud %} | |||
{% set params_reminders = params_reminders|merge({crudAction: ea.crud.currentAction}) %} | |||
{% set params_reminders = params_reminders|merge({crudControllerFqcn: ea.crud.controllerFqcn}) %} | |||
{% endif %} | |||
{% if ea.request.query.get('entityId') and ea.entity is defined and ea.entity.instance is defined %} | |||
{% set params_reminders = params_reminders|merge({entityId: ea.entity.instance.id}) %} | |||
{% endif %} | |||
{% endif %} | |||
{% block reminders %} | |||
{% set reminders = sov_reminders(params_reminders) %} | |||
{% include '@LcSov/admin/reminder/block.html.twig' %} | |||
{% endblock %} | |||
{% set has_help_message = (ea.crud.helpMessage ?? '') is not empty %} | |||
{% block content_header %} |
@@ -2,7 +2,8 @@ | |||
namespace Lc\SovBundle\Twig; | |||
use Lc\SovBundle\Repository\Reminder\ReminderStore; | |||
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; | |||
use Lc\SovBundle\Repository\Reminder\ReminderStoreInterface; | |||
use Symfony\Component\Security\Core\Security; | |||
use Twig\Extension\AbstractExtension; | |||
use Twig\TwigFunction; | |||
@@ -10,11 +11,11 @@ use Twig\TwigFunction; | |||
class StoreTwigExtension extends AbstractExtension | |||
{ | |||
protected Security $security; | |||
protected ReminderStore $reminderStore; | |||
protected ReminderStoreInterface $reminderStore; | |||
public function __construct( | |||
Security $security, | |||
ReminderStore $reminderStore | |||
ReminderStoreInterface $reminderStore | |||
) { | |||
$this->security = $security; | |||
$this->reminderStore = $reminderStore; | |||
@@ -23,7 +24,7 @@ class StoreTwigExtension extends AbstractExtension | |||
public function getFunctions() | |||
{ | |||
return [ | |||
new TwigFunction('sov_get_reminders', [$this, 'getReminders']), | |||
new TwigFunction('sov_reminders', [$this, 'getReminders']), | |||
]; | |||
} | |||
@@ -32,9 +33,13 @@ class StoreTwigExtension extends AbstractExtension | |||
return []; | |||
} | |||
public function getReminders() | |||
public function getReminders($params) | |||
{ | |||
return $this->reminderStore->getByUser($this->security->getUser()); | |||
return $this->reminderStore->get(array_merge( | |||
[ | |||
'user' => $this->security->getUser() | |||
], $params) | |||
); | |||
} | |||
} |