Sfoglia il codice sorgente

Merge branch 'develop'

master
Guillaume 3 anni fa
parent
commit
8218fae54f
7 ha cambiato i file con 63 aggiunte e 36 eliminazioni
  1. +0
    -1
      Controller/AbstractAdminController.php
  2. +7
    -17
      Definition/Field/Ticket/TicketFieldDefinition.php
  3. +1
    -1
      Definition/Field/User/UserFieldDefinition.php
  4. +32
    -0
      EventListener/ExceptionListener.php
  5. +18
    -17
      Field/Filter/FilterManager.php
  6. +1
    -0
      Resources/assets/functions/widgets.js
  7. +4
    -0
      Resources/config/services.yaml

+ 0
- 1
Controller/AbstractAdminController.php Vedi File

@@ -396,7 +396,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$filterManager = $this->get(FilterManager::class);

$this->filtersForm->handleRequest($searchDto->getRequest());

$this->isRepositoryQueryFiltered = $filterManager->handleFiltersForm($repositoryQuery, $this->filtersForm, $fields, $entityDto);
return $repositoryQuery;
}

+ 7
- 17
Definition/Field/Ticket/TicketFieldDefinition.php Vedi File

@@ -58,34 +58,24 @@ class TicketFieldDefinition extends AbstractFieldDefinition
{
return [
'id' => IdField::new('id')
->setSortable(true)
->hideOnForm(),
->setSortable(true),
'createdAt' => DateTimeField::new('createdAt')
->setSortable(true)
->hideOnForm(),
->setSortable(true),
'visitorFirstname' => TextField::new('visitorFirstname')
->setTemplatePath('@LcSov/admin/ticket/field/firstname.html.twig')
->setCustomOption('filter_fqcn', TicketFirstnameFilter::class)
->setSortable(true)
->hideOnForm(),
->setCustomOption('filter_fqcn', TicketFirstnameFilter::class),
'visitorLastname' => TextField::new('visitorLastname')
->setTemplatePath('@LcSov/admin/ticket/field/lastname.html.twig')
->setCustomOption('filter_fqcn', TicketLastnameFilter::class)
->setSortable(true)
->hideOnForm(),
->setCustomOption('filter_fqcn', TicketLastnameFilter::class),
'visitorEmail' => TextField::new('visitorEmail')
->setTemplatePath('@LcSov/admin/ticket/field/email.html.twig')
->setCustomOption('filter_fqcn', TicketEmailFilter::class)
->setSortable(true)
->hideOnForm(),
'user' => AssociationField::new('user')
->hideOnIndex(),
->setCustomOption('filter_fqcn', TicketEmailFilter::class),
'user' => AssociationField::new('user'),
'subject' => TextField::new('subject')
->setSortable(true),
'updatedAt' => DateTimeField::new('updatedAt')
->setTemplatePath('@LcSov/admin/ticket/field/lastmessage.html.twig')
->setSortable(true)
->hideOnForm(),
->setSortable(true),
'type' => ChoiceField::new('type')
->autocomplete()
->setSortable(true)

+ 1
- 1
Definition/Field/User/UserFieldDefinition.php Vedi File

@@ -61,7 +61,7 @@ class UserFieldDefinition extends AbstractFieldDefinition
public function configureFields(): array
{
return [
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'id' => IntegerField::new('id')->setSortable(true),
'gender' => ChoiceField::new('gender')->setChoices(
$this->translatorAdmin->transChoices(UserSolver::getGenderChoices(), 'User', 'gender')
)

+ 32
- 0
EventListener/ExceptionListener.php Vedi File

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

namespace Lc\SovBundle\EventListener;

use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

class ExceptionListener
{

public function __construct(
SessionInterface $session
) {
$this->session = $session;
}

public function onKernelException(ExceptionEvent $event)
{
// You get the exception object from the received event
$exception = $event->getThrowable();

// On détecte une erreur interne (500), on remove les sessions qui servent de filtre dans l'admin
if ($exception instanceof HttpExceptionInterface != true) {
foreach ($this->session->all() as $key => $s) {
if (str_contains($key, "_filter")) {
$this->session->remove($key);
}
}
}
}
}

+ 18
- 17
Field/Filter/FilterManager.php Vedi File

@@ -36,17 +36,23 @@ class FilterManager

use FilterTrait;

public function __construct(SessionInterface $session, EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin)
{
public function __construct(
SessionInterface $session,
EntityManagerInterface $entityManager,
TranslatorAdmin $translatorAdmin
) {
$this->session = $session;
$this->em = $entityManager;
$this->translatorAdmin = $translatorAdmin;
}


public function handleFiltersForm(RepositoryQueryInterface $repositoryQuery, Form $filtersForm, $fields, EntityDto $entityDto):bool
{

public function handleFiltersForm(
RepositoryQueryInterface $repositoryQuery,
Form $filtersForm,
$fields,
EntityDto $entityDto
): bool {
foreach ($fields as $field) {
$filteredValue = array();
if ($field instanceof FieldInterface) {
@@ -56,8 +62,8 @@ class FilterManager
}
if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) {
if ($filtersForm->has($this->getFieldPropertySnake($fieldDto->getProperty()))) {
if ($fieldDto->getFormType() === DateTimeType::class || $fieldDto->getFormType() === DateType::class) {
if ($fieldDto->getFormType() === DateTimeType::class || $fieldDto->getFormType(
) === DateType::class) {
$filteredValue['dateStart'] = $this->getFilteredValue(
$filtersForm,
$entityDto->getFqcn(),
@@ -70,7 +76,7 @@ class FilterManager
$fieldDto->getProperty(),
'dateEnd'
);
if($filteredValue['dateStart'] || $filteredValue['dateEnd']){
if ($filteredValue['dateStart'] || $filteredValue['dateEnd']) {
$this->isFiltered = true;
}
} else {
@@ -79,7 +85,7 @@ class FilterManager
$entityDto->getFqcn(),
$fieldDto->getProperty()
);
if($filteredValue['value'] ){
if ($filteredValue['value']) {
$this->isFiltered = true;
}
}
@@ -100,9 +106,7 @@ class FilterManager

$customFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']);
} else {

switch ($fieldDto->getFormType()) {

case CheckboxType::class:
$checkboxFilter = new CheckboxFilter();
$checkboxFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']);
@@ -140,15 +144,13 @@ class FilterManager
}

public function getFilteredValue(
Form $filtersForm,
Form $filtersForm,
string $entityFqcn,
string $field,
string $dateExtraField = null
)
{
) {
$field = $this->getFieldPropertySnake($field);
$sessionParam = $entityFqcn . $field . $dateExtraField;

$sessionParam = "_filter/" . $entityFqcn . $field . $dateExtraField;
$formField = $this->getFormField($filtersForm, $field, $dateExtraField);

$value = $formField->getData();
@@ -185,7 +187,6 @@ class FilterManager

return $value;
}

}

public function getFormField(Form $filtersForm, string $field, string $extraField = null): Form

+ 1
- 0
Resources/assets/functions/widgets.js Vedi File

@@ -32,6 +32,7 @@ export class SovWidgets {
var event = new Event('change');
e.target.dispatchEvent(event);
});
SovTools.log(myselect);

return myselect;
}

+ 4
- 0
Resources/config/services.yaml Vedi File

@@ -35,3 +35,7 @@ services:
Lc\SovBundle\Maker\:
resource: '../../Maker/'
tags: [ 'maker.command' ]

Lc\SovBundle\EventListener\ExceptionListener:
tags:
- { name: kernel.event_listener, event: kernel.exception }

Loading…
Annulla
Salva