Browse Source

Reminder

develop
Guillaume 3 years ago
parent
commit
77efd196f6
10 changed files with 255 additions and 107 deletions
  1. +58
    -47
      Controller/Reminder/ReminderAdminController.php
  2. +1
    -0
      Repository/AbstractRepositoryQuery.php
  3. +67
    -2
      Repository/Reminder/ReminderRepositoryQuery.php
  4. +4
    -24
      Repository/Reminder/ReminderStore.php
  5. +10
    -0
      Resources/assets/app/admin/reminder/reminder.js
  6. +5
    -0
      Resources/assets/app/admin/reminder/reminder.scss
  7. +85
    -0
      Resources/views/admin/reminder/block.html.twig
  8. +1
    -1
      Resources/views/adminlte/block/navbar_header.html.twig
  9. +13
    -27
      Resources/views/adminlte/layout.html.twig
  10. +11
    -6
      Twig/StoreTwigExtension.php

+ 58
- 47
Controller/Reminder/ReminderAdminController.php View File

use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface; use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType; use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;


protected EntityManagerInterface $entityManager; protected EntityManagerInterface $entityManager;
protected ReminderFactoryInterface $reminderFactory; protected ReminderFactoryInterface $reminderFactory;
protected ReminderRepositoryQueryInterface $reminderRepositoryQuery;
protected FormFactoryInterface $formFactory; protected FormFactoryInterface $formFactory;
protected UrlGeneratorInterface $urlGenerator; protected UrlGeneratorInterface $urlGenerator;
protected MerchantResolver $merchantResolver; protected MerchantResolver $merchantResolver;
public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
ReminderFactoryInterface $reminderFactory, ReminderFactoryInterface $reminderFactory,
ReminderRepositoryQueryInterface $reminderRepositoryQuery,
FormFactoryInterface $formFactory, FormFactoryInterface $formFactory,
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
MerchantResolver $merchantResolver, MerchantResolver $merchantResolver,
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->reminderFactory = $reminderFactory; $this->reminderFactory = $reminderFactory;
$this->reminderRepositoryQuery = $reminderRepositoryQuery;
$this->formFactory = $formFactory; $this->formFactory = $formFactory;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->merchantResolver = $merchantResolver; $this->merchantResolver = $merchantResolver;
*/ */
public function renderModal(Request $request): Response 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( $form = $this->formFactory->create(
ReminderAdminFormType::class, ReminderAdminFormType::class,
$reminder, $reminder,
[ [
'action' => $this->urlGenerator->generate(
$this->parameterBag->get('app.reminder.route_new')
)
'action' => $action
] ]
); );


return $this->redirect($request->headers->get('referer')); 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);
}
} }

+ 1
- 0
Repository/AbstractRepositoryQuery.php View File



return $data; return $data;
} }

} }



+ 67
- 2
Repository/Reminder/ReminderRepositoryQuery.php View File

parent::__construct($repository, 'r', $paginator); 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 return $this
->andWhere('.done = 0');
->andWhere('.done = :done')
->setParameter(':done', $done);
} }


public function filterUser($user) public function filterUser($user)
->groupBy('.id'); ->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() public function orderDefault()
{ {
return $this return $this

+ 4
- 24
Repository/Reminder/ReminderStore.php View File

$this->query = $query; $this->query = $query;
} }


public function getByUser($user)
public function get($params = [])
{ {
$query = $this->query->create(); $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) public function findByUser($user)
{ {
$qb = $this->createQueryBuilder('e') $qb = $this->createQueryBuilder('e')
$qb->groupBy('e.id'); $qb->groupBy('e.id');


return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
}

*/
}*/
} }

+ 10
- 0
Resources/assets/app/admin/reminder/reminder.js View File

crudAction: $(this).data('crud-action'), crudAction: $(this).data('crud-action'),
crudControllerFqcn: $(this).data('crud-controller-fqcn'), crudControllerFqcn: $(this).data('crud-controller-fqcn'),
entityId: $(this).data('entity-id'), entityId: $(this).data('entity-id'),
id: $(this).data('id'),
}, function(html) { }, function(html) {
$(selectorModal).remove() ; $(selectorModal).remove() ;
$('body').append(html) ; $('body').append(html) ;
}); });
return false ; 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');
}) ;
} }

+ 5
- 0
Resources/assets/app/admin/reminder/reminder.scss View File

li { li {
div.text { div.text {
padding-left: 30px ; padding-left: 30px ;

.badge-date {
margin-left: 0px;
margin-right: 6px;
}
} }
} }
} }

+ 85
- 0
Resources/views/admin/reminder/block.html.twig View File


{% 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>&nbsp;
<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 %}

+ 1
- 1
Resources/views/adminlte/block/navbar_header.html.twig View File

</li> </li>


<li class="nav-item"> <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> <i class="action-icon fa fa-plus"></i>
Pense-bête Pense-bête
</a> </a>

+ 13
- 27
Resources/views/adminlte/layout.html.twig View File

<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <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&amp;entity=Reminder&amp;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&amp;entity=Reminder&amp;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 %} {% 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 %} {% set has_help_message = (ea.crud.helpMessage ?? '') is not empty %}
{% block content_header %} {% block content_header %}

+ 11
- 6
Twig/StoreTwigExtension.php View File



namespace Lc\SovBundle\Twig; 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 Symfony\Component\Security\Core\Security;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFunction; use Twig\TwigFunction;
class StoreTwigExtension extends AbstractExtension class StoreTwigExtension extends AbstractExtension
{ {
protected Security $security; protected Security $security;
protected ReminderStore $reminderStore;
protected ReminderStoreInterface $reminderStore;


public function __construct( public function __construct(
Security $security, Security $security,
ReminderStore $reminderStore
ReminderStoreInterface $reminderStore
) { ) {
$this->security = $security; $this->security = $security;
$this->reminderStore = $reminderStore; $this->reminderStore = $reminderStore;
public function getFunctions() public function getFunctions()
{ {
return [ return [
new TwigFunction('sov_get_reminders', [$this, 'getReminders']),
new TwigFunction('sov_reminders', [$this, 'getReminders']),
]; ];
} }


return []; 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)
);
} }


} }

Loading…
Cancel
Save