Przeglądaj źródła

Merge branch 'develop' of https://forge.laclic.fr/Laclic/SovBundle into develop

ideas
Charly 3 lat temu
rodzic
commit
1321a34c24
20 zmienionych plików z 330 dodań i 46 usunięć
  1. +1
    -0
      Controller/Dashboard/DashboardAdminController.php
  2. +70
    -3
      Controller/Reminder/ReminderAdminController.php
  3. +2
    -6
      Controller/User/AccountAdminController.php
  4. +14
    -0
      Factory/Reminder/ReminderFactory.php
  5. +8
    -0
      Factory/Reminder/ReminderFactoryInterface.php
  6. +89
    -0
      Form/Reminder/ReminderAdminFormType.php
  7. +15
    -15
      Model/Reminder/ReminderModel.php
  8. +1
    -0
      Resources/assets/app/adminlte/common/common.scss
  9. +19
    -0
      Resources/assets/app/adminlte/common/scss/_common.scss
  10. +3
    -0
      Resources/assets/app/adminlte/reminder/app.reminder.js
  11. +21
    -0
      Resources/assets/app/adminlte/reminder/reminder.js
  12. +0
    -0
      Resources/assets/app/adminlte/reminder/reminder.scss
  13. +7
    -0
      Resources/config/routes.yaml
  14. +4
    -0
      Resources/translations/admin.fr.yaml
  15. +19
    -0
      Resources/views/admin/reminder/form_modal.html.twig
  16. +11
    -13
      Resources/views/adminlte/block/navbar_header.html.twig
  17. +20
    -0
      Resources/views/adminlte/crud/form_theme.html.twig
  18. +1
    -2
      Resources/views/adminlte/embed/modal.twig
  19. +2
    -0
      Resources/views/adminlte/layout.html.twig
  20. +23
    -7
      Twig/TwigExtension.php

+ 1
- 0
Controller/Dashboard/DashboardAdminController.php Wyświetl plik

@@ -43,6 +43,7 @@ class DashboardAdminController extends AbstractDashboardController
$assets->addWebpackEncoreEntry('adminlte-sort');
$assets->addWebpackEncoreEntry('adminlte-field-collection');
$assets->addWebpackEncoreEntry('adminlte-field-filemanager');
$assets->addWebpackEncoreEntry('adminlte-reminder');

return $assets;
}

+ 70
- 3
Controller/Reminder/ReminderAdminController.php Wyświetl plik

@@ -2,12 +2,79 @@

namespace Lc\SovBundle\Controller\Reminder;

use Lc\SovBundle\Controller\AbstractAdminController;
use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

abstract class ReminderAdminController extends AbstractAdminController
class ReminderAdminController extends AbstractController
{

protected $entityManager;
protected $reminderFactory;
protected $formFactory;
protected $urlGenerator;

public function __construct(
EntityManagerInterface $entityManager,
ReminderFactoryInterface $reminderFactory,
FormFactoryInterface $formFactory,
UrlGeneratorInterface $urlGenerator
) {
$this->entityManager = $entityManager;
$this->reminderFactory = $reminderFactory;
$this->formFactory = $formFactory;
$this->urlGenerator = $urlGenerator;
}

public function renderModal(Request $request): Response
{
$reminder = $this->reminderFactory->create(
[
'crudAction' => $request->get('crudAction'),
'crudControllerFqcn' => $request->get('crudControllerFqcn'),
'entityId' => $request->get('entityId'),
]
);
$form = $this->formFactory->create(
ReminderAdminFormType::class,
$reminder,
[
'action' => $this->urlGenerator->generate('sov_admin_reminder_new')
]
);

return $this->render(
'@LcSov/admin/reminder/form_modal.html.twig',
[
'form_reminder' => $form->createView()
]
);
}

public function new(Request $request)
{
$reminder = $this->reminderFactory->create();
$form = $this->formFactory->create(ReminderAdminFormType::class, $reminder);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$reminder = $form->getData();
$this->entityManager->persist($reminder);
$this->entityManager->flush();

$this->addFlash('success', 'Le pense-bête a bien été ajouté');
}

return $this->redirect($request->headers->get('referer'));
}

/*
public function renderTemplate($actionName, $templatePath, array $parameters = [])
{
if ($this->request->isXmlHttpRequest() && ($actionName == 'new' || $actionName == 'edit')) {
@@ -52,5 +119,5 @@ abstract class ReminderAdminController extends AbstractAdminController
$this->em->persist($reminder);
$this->em->flush();
return $this->redirectToReferrer();
}
}*/
}

+ 2
- 6
Controller/User/AccountAdminController.php Wyświetl plik

@@ -2,17 +2,13 @@

namespace Lc\SovBundle\Controller\User;

use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Form\User\ChangePasswordFormType;
use Lc\SovBundle\Form\User\ProfileFormType;
use Lc\SovBundle\Form\User\UserMerchantFormType;
use Lc\SovBundle\Model\User\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Translation\TranslatableMessage;

@@ -50,7 +46,7 @@ class AccountAdminController extends AbstractController
);
}

public function changePassword(Request $request, UserPasswordHasherInterface $passwordEncoder): Response
public function changePassword(Request $request, UserPasswordEncoderInterface $passwordEncoder): Response
{
$user = $this->getUser();
$form = $this->createForm(ChangePasswordFormType::class, $user);
@@ -62,7 +58,7 @@ class AccountAdminController extends AbstractController

$plainPassword = $form->get('plain_password')->getData();

$user->setPassword($passwordEncoder->hashPassword($user, $plainPassword));
$user->setPassword($passwordEncoder->encodePassword($user, $plainPassword));

$this->em->update($user);
$this->em->flush();

+ 14
- 0
Factory/Reminder/ReminderFactory.php Wyświetl plik

@@ -0,0 +1,14 @@
<?php

namespace Lc\SovBundle\Factory\Reminder;

use Lc\SovBundle\Factory\AbstractFactory;
use Lc\SovBundle\Model\Reminder\ReminderInterface;

class ReminderFactory extends AbstractFactory implements ReminderFactoryInterface
{
public function getEntityClass()
{
return ReminderInterface::class;
}
}

+ 8
- 0
Factory/Reminder/ReminderFactoryInterface.php Wyświetl plik

@@ -0,0 +1,8 @@
<?php

namespace Lc\SovBundle\Factory\Reminder;

interface ReminderFactoryInterface
{

}

+ 89
- 0
Form/Reminder/ReminderAdminFormType.php Wyświetl plik

@@ -0,0 +1,89 @@
<?php

namespace Lc\SovBundle\Form\Reminder;

use Lc\SovBundle\Model\Reminder\ReminderInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ReminderAdminFormType extends AbstractType
{
protected $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$userClass = $this->entityManager->getEntityName(UserInterface::class);
$userRepo = $this->entityManager->getRepository(UserInterface::class);
$builder
->add('title', TextType::class, ['label' => 'Titre'])
->add(
'description',
TextareaType::class,
array(
'required' => false
)
)
->add(
'crudAction',
HiddenType::class,
array(
'required' => false
)
)
->add(
'crudControllerFqcn',
HiddenType::class,
array(
'required' => false
)
)
->add(
'entityId',
HiddenType::class,
array(
'required' => false
)
)
->add(
'users',
EntityType::class,
array(
'class' => $userClass,
'choices' => $userRepo->findByRole('ROLE_ADMIN'),
'required' => false,
'multiple' => true,
'expanded' => false
)
)
->add(
'dateReminder',
DateType::class,
array(
'required' => false,
'widget' => 'single_text',
)
);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => $this->entityManager->getEntityName(ReminderInterface::class)
]
);
}
}

+ 15
- 15
Model/Reminder/ReminderModel.php Wyświetl plik

@@ -17,7 +17,7 @@ abstract class ReminderModel extends AbstractLightEntity implements ReminderInte
/**
* temporary fields (do not delete)
*/
public $relatedPage;
protected $relatedPage;

/**
* @ORM\Column(type="string", length=255)
@@ -30,19 +30,19 @@ abstract class ReminderModel extends AbstractLightEntity implements ReminderInte
protected $description;

/**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="string", length=64, nullable=true)
*/
protected $entityName;
protected $crudAction;

/**
* @ORM\Column(type="integer", nullable=true)
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $entityId;
protected $crudControllerFqcn;

/**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="integer", nullable=true)
*/
protected $entityAction;
protected $entityId;

/**
* @ORM\ManyToMany(targetEntity="Lc\SovBundle\Model\User\UserInterface")
@@ -90,26 +90,26 @@ abstract class ReminderModel extends AbstractLightEntity implements ReminderInte
return $this;
}

public function getEntityName(): ?string
public function getCrudAction(): ?string
{
return $this->entityName;
return $this->crudAction;
}

public function setEntityName(?string $entityName): self
public function setCrudAction(?string $crudAction): self
{
$this->entityName = $entityName;
$this->crudAction = $crudAction;

return $this;
}

public function getEntityAction(): ?string
public function getCrudControllerFqcn(): ?string
{
return $this->entityAction;
return $this->crudControllerFqcn;
}

public function setEntityAction(?string $entityAction): self
public function setCrudControllerFqcn(?string $crudControllerFqcn): self
{
$this->entityAction = $entityAction;
$this->crudControllerFqcn = $crudControllerFqcn;

return $this;
}

+ 1
- 0
Resources/assets/app/adminlte/common/common.scss Wyświetl plik

@@ -1,6 +1,7 @@

@import "adminlte-css";
@import "fontawesome-css";
@import 'scss/common';
@import 'scss/form/checkboxradio';
@import 'scss/form/footer';
@import 'scss/card';

+ 19
- 0
Resources/assets/app/adminlte/common/scss/_common.scss Wyświetl plik

@@ -0,0 +1,19 @@

nav.main-header {
ul.navbar-nav {
li.nav-item-user-menu {
.dropdown-menu {
position: absolute ;
z-index: 1000 ;
}
}

li.nav-item {
margin-left: 10px;

.btn {
margin-top: 7px;
}
}
}
}

+ 3
- 0
Resources/assets/app/adminlte/reminder/app.reminder.js Wyświetl plik

@@ -0,0 +1,3 @@

import './reminder.js'
import './reminder.scss'

+ 21
- 0
Resources/assets/app/adminlte/reminder/reminder.js Wyświetl plik

@@ -0,0 +1,21 @@


$(document).ready(function() {
initReminder() ;
}) ;

function initReminder() {
var selectorModal = '#modal-reminder' ;
$('.btn-reminder').click(function() {
$.post($(this).attr('href'), {
crudAction: $(this).data('crud-action'),
crudControllerFqcn: $(this).data('crud-controller-fqcn'),
entityId: $(this).data('entity-id'),
}, function(html) {
$(selectorModal).remove() ;
$('body').append(html) ;
$(selectorModal).modal('show') ;
});
return false ;
}) ;
}

+ 0
- 0
Resources/assets/app/adminlte/reminder/reminder.scss Wyświetl plik


+ 7
- 0
Resources/config/routes.yaml Wyświetl plik

@@ -30,3 +30,10 @@ sov_admin_create_ticket:
path: /admin/ticket/create
controller: Lc\SovBundle\Controller\Ticket\TicketAdminController::create

sov_admin_reminder_render_modal:
path: /admin/reminder/modal
controller: Lc\SovBundle\Controller\Reminder\ReminderAdminController::renderModal

sov_admin_reminder_new:
path: /admin/reminder/new
controller: Lc\SovBundle\Controller\Reminder\ReminderAdminController::new

+ 4
- 0
Resources/translations/admin.fr.yaml Wyświetl plik

@@ -63,6 +63,10 @@ entity:
label_plurial: Bulletins d'informations
fields:
isMain: Principale
Reminder:
fields:
users: Utilisateurs
dateReminder: Date limite
Ticket:
label: Ticket
label_plurial: Tickets

+ 19
- 0
Resources/views/admin/reminder/form_modal.html.twig Wyświetl plik

@@ -0,0 +1,19 @@

{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% form_theme form_reminder '@LcSov/adminlte/crud/form_theme.html.twig' %}
{% block id %}modal-reminder{% endblock %}
{% block title %}Ajouter un pense-bête{% endblock %}
{% block form_start %}
{{ form_start(form_reminder) }}
{% endblock %}
{% block body %}
{{ form(form_reminder) }}
{% endblock %}
{% block footer %}
<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
<input type="submit" class="btn btn-primary btn-save" value="Ajouter" />
{% endblock %}
{% block form_end %}
{{ form_end(form_reminder) }}
{% endblock %}
{% endembed %}

+ 11
- 13
Resources/views/adminlte/block/navbar_header.html.twig Wyświetl plik

@@ -7,22 +7,13 @@
</ul>

<ul class="navbar-nav ml-auto">
<li class="nav-item">
<li class="nav-item nav-item-user-menu">
{% block user_menu %}
<div class="btn-group">
<button class="btn btn-block dropdown-toggle" data-toggle="dropdown"
<button class="btn btn-sm btn-default btn-block dropdown-toggle" data-toggle="dropdown"
data-placement="bottom">
<i class="fa fa-user-alt"></i>
<span class="user-name">{{ ea.user is null ? 'user.anonymous'|trans(domain = 'EasyAdminBundle') : ea.userMenu.name }}</span>
{# <br /><small>
{% if is_granted('ROLE_SUPER_ADMIN') %}
<span class="mt-1 small text-muted">Superadmin</span>
{% elseif is_granted('ROLE_ADMIN') %}
<span class="mt-1 small text-muted">Admin</span>
{% else %}
<span class="mt-1 small text-muted">NC</span>
{% endif %}
</small> #}
</button>
{% if ea.userMenu.items|length > 0 %}
<div class="dropdown-menu">
@@ -46,10 +37,17 @@
</div>
{% endblock user_menu %}
</li>
<!-- Messages Dropdown Menu -->

<li class="nav-item">
<a href="{{ path('sov_admin_reminder_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') }}">
<i class="action-icon fa fa-plus"></i>
Pense-bête
</a>
</li>
<li class="nav-item">
<a href="{{ path(homepage_route()) }}" class="btn btn-block btn-outline-success" target="_blank"
<a href="{{ path(homepage_route()) }}" class="btn btn-sm btn-block btn-outline-success" target="_blank"
rel="noreferrer">
<i class="action-icon fa fa-eye"></i>
Afficher le site
</a>
</li>

+ 20
- 0
Resources/views/adminlte/crud/form_theme.html.twig Wyświetl plik

@@ -1,6 +1,26 @@
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{% use '@EasyAdmin/crud/form_theme.html.twig' %}

{% block form_start %}
{% if form.vars.errors|length > 0 and 'ea_crud' in form.vars.block_prefixes|default([]) %}
{{ form_errors(form) }}
{% endif %}

{%- do form.setMethodRendered() -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
{%- endif -%}

<input type="hidden" name="referrer" value="{% if ea is defined %}{{ ea.request.query.get('referrer') }}{% endif %}">
{% endblock form_start %}

{% block form_row %}
{% set row_attr = row_attr|merge({
class: row_attr.class|default('') ~ ' form-group'

+ 1
- 2
Resources/views/adminlte/embed/modal.twig Wyświetl plik

@@ -1,4 +1,4 @@
<div class="modal fade show" id="{% block id %}{% endblock %}">
<div class="modal show" id="{% block id %}{% endblock %}">
<div class="modal-dialog {% block size %}{% endblock %}">
{% block form_start %}{% endblock %}
<div class="modal-content">
@@ -22,6 +22,5 @@
{% endblock %}
</div>
{% block form_end %}{% endblock %}
<!-- /.modal-content -->
</div>
</div>

+ 2
- 0
Resources/views/adminlte/layout.html.twig Wyświetl plik

@@ -197,6 +197,8 @@
{% endif %}
{% endif %}



{% block append_body %}{% endblock %}

</body>

+ 23
- 7
Twig/TwigExtension.php Wyświetl plik

@@ -3,10 +3,12 @@
namespace Lc\SovBundle\Twig;

use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use Lc\SovBundle\Factory\Reminder\ReminderFactory;
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -25,6 +27,8 @@ class TwigExtension extends AbstractExtension
protected $router;
protected $translator;
protected $translatorAdmin;
protected $formFactory;
protected $reminderFactory;

public function __construct(
KernelInterface $kernel,
@@ -34,7 +38,9 @@ class TwigExtension extends AbstractExtension
RequestStack $requestStack,
UrlGeneratorInterface $router,
TranslatorInterface $translator,
TranslatorAdmin $translatorAdmin
TranslatorAdmin $translatorAdmin,
FormFactoryInterface $formFactory,
ReminderFactory $reminderFactory
) {
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
@@ -44,6 +50,8 @@ class TwigExtension extends AbstractExtension
$this->router = $router;
$this->translator = $translator;
$this->translatorAdmin = $translatorAdmin;
$this->formFactory = $formFactory;
$this->reminderFactory = $reminderFactory;
}

public function getFunctions()
@@ -52,7 +60,8 @@ class TwigExtension extends AbstractExtension
new TwigFunction('lc_liip', [$this, 'lcLiip']),
new TwigFunction('homepage_route', [$this, 'homepageRoute']),
new TwigFunction('page_by_dev_alias', [$this, 'getPageByDevAlias']),
new TwigFunction('translated_urls', [$this, 'getTranslatedUrls'])
new TwigFunction('translated_urls', [$this, 'getTranslatedUrls']),
new TwigFunction('sov_get_form_reminder', [$this, 'getFormReminder']),
);
}

@@ -82,17 +91,17 @@ class TwigExtension extends AbstractExtension

public function lcTransAdminField($fieldName, $entityClass)
{
return $this->translatorAdmin->transField($fieldName, $entityClass) ;
return $this->translatorAdmin->transField($fieldName, $entityClass);
}

public function lcTransAdminHelp($fieldName, $entityClass)
{
return $this->translatorAdmin->transHelp($fieldName, $entityClass) ;
return $this->translatorAdmin->transHelp($fieldName, $entityClass);
}

public function lcTransAdminPanel($panelName, $entityClass)
{
return $this->translatorAdmin->transPanel($panelName, $entityClass) ;
return $this->translatorAdmin->transPanel($panelName, $entityClass);
}

public function lcTransAdminMenu($menuName)
@@ -107,7 +116,7 @@ class TwigExtension extends AbstractExtension

public function lcTransAdminTitle($pageName, $entityClass = null, $params = [])
{
return $this->translatorAdmin->transTitle($pageName, $entityClass, $params) ;
return $this->translatorAdmin->transTitle($pageName, $entityClass, $params);
}

public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg')
@@ -158,4 +167,11 @@ class TwigExtension extends AbstractExtension
return $this->parameterBag->get('lc_sov.homepage_route');
}

public function getFormReminder()
{
$reminder = $this->reminderFactory->create();
$formReminder = $this->formFactory->create(ReminderAdminFormType::class, $reminder);
return $formReminder->createView();
}

}

Ładowanie…
Anuluj
Zapisz