Browse Source

Fonction shortcut + actionDefinition et correcftif

develop
Fab 3 years ago
parent
commit
21f3e6b2ec
10 changed files with 119 additions and 58 deletions
  1. +64
    -44
      Controller/AbstractAdminController.php
  2. +3
    -2
      Controller/Ticket/TicketAdminController.php
  3. +18
    -0
      Definition/ActionDefinition.php
  4. +2
    -2
      Form/Common/FiltersFormType.php
  5. +1
    -1
      Resources/assets/app/adminlte/field/collection/app.collection.js
  6. +1
    -2
      Resources/assets/app/adminlte/main/init.js
  7. +2
    -2
      Resources/assets/app/adminlte/sort/app.sort.js
  8. +1
    -3
      Resources/assets/functions/widgets.js
  9. +1
    -1
      Resources/views/adminlte/crud/detail.html.twig
  10. +26
    -1
      Twig/TwigExtension.php

+ 64
- 44
Controller/AbstractAdminController.php View File

@@ -36,7 +36,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Controller\Order\OrderShopAdminController;
use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Container\ComponentContainer;
use Lc\SovBundle\Container\File\FileContainer;
@@ -50,6 +49,7 @@ use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Definition\ActionDefinition;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
@@ -60,18 +60,14 @@ use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Form\Common\FiltersFormType;
use Lc\SovBundle\Form\Common\PositionType;
use Lc\SovBundle\Notification\MailMailjetNotification;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;


@@ -103,6 +99,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
UserContainer::class => UserContainer::class,
SiteSettingContainer::class => SiteSettingContainer::class,
MailMailjetNotification::class => MailMailjetNotification::class,
SettingSolver::class => SettingSolver::class
]
);
}
@@ -119,14 +116,15 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) {
$responseParameters->set('fields', $this->configureFields('index'));

if ($this->filtersForm === null) {
//TODO supprimer ce code rapport au filtre dans les index
/*if ($this->filtersForm === null) {
die('nncncd');
//TODO delete under code
$options['fields'] = $responseParameters->get('fields');
$options['entity_class'] = $this->getEntityFqcn();
$options['entity_name'] = $responseParameters->get('entity')->getName();
$this->filtersForm = $this->createForm(FiltersFormType::class, null, $options);
}
}*/
$responseParameters->set('filters_form', $this->filtersForm);
}

@@ -317,7 +315,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::INDEX)
->setAction(ActionDefinition::INDEX)
->generateUrl();
$this->addFlashTranslator('success', 'sorted');

@@ -370,7 +368,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$em->flush();

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::EDIT)
->setAction(ActionDefinition::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();

@@ -497,8 +495,8 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->handleSortableEntityActions($actions);
$this->handleTreeEntityActions($actions);

/*$actions->reorder(Crud::PAGE_EDIT, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_CONTINUE, Action::DELETE]);
$actions->reorder(Crud::PAGE_NEW, [Action::INDEX, Action::SAVE_AND_RETURN, Action::SAVE_AND_ADD_ANOTHER]);*/
/*$actions->reorder(Crud::PAGE_EDIT, [ActionDefinition::INDEX, ActionDefinition::SAVE_AND_RETURN, ActionDefinition::SAVE_AND_CONTINUE, ActionDefinition::DELETE]);
$actions->reorder(Crud::PAGE_NEW, [ActionDefinition::INDEX, ActionDefinition::SAVE_AND_RETURN, ActionDefinition::SAVE_AND_ADD_ANOTHER]);*/

return $actions;
}
@@ -506,12 +504,12 @@ abstract class AbstractAdminController extends EaAbstractCrudController
public function getDuplicateAction(): Action
{
$duplicateAction = Action::new(
'duplicate',
$this->get(TranslatorAdmin::class)->transAction('duplicate'),
ActionDefinition::DUPLICATE,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicate')
->setLabel($this->get(TranslatorAdmin::class)->transAction('duplicate'))
->linkToCrudAction(ActionDefinition::DUPLICATE)
->setLabel($this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE))
->setCssClass('in-dropdown text-info action-confirm');

return $duplicateAction;
@@ -524,7 +522,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::NEW,
ActionDefinition::NEW,
[
'icon' => 'plus',
'label' => $this->get(TranslatorAdmin::class)->transAction('create'),
@@ -535,7 +533,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::EDIT,
ActionDefinition::EDIT,
[
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
@@ -550,7 +548,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::DETAIL,
ActionDefinition::DETAIL,
[
'icon' => 'eye',
'add_class' => 'btn btn-sm btn-success',
@@ -565,7 +563,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::DELETE,
ActionDefinition::DELETE,
[
'icon' => 'trash',
'dropdown' => true,
@@ -576,7 +574,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_INDEX,
Action::BATCH_DELETE,
ActionDefinition::BATCH_DELETE,
[
'class' => 'btn btn-sm btn-danger',
'icon' => 'trash',
@@ -588,14 +586,14 @@ abstract class AbstractAdminController extends EaAbstractCrudController

public function buildEditActions(Actions $actions): void
{
$actions->add(Crud::PAGE_EDIT, Action::INDEX);
$actions->add(Crud::PAGE_EDIT, Action::DELETE);
$actions->add(Crud::PAGE_EDIT, ActionDefinition::INDEX);
$actions->add(Crud::PAGE_EDIT, ActionDefinition::DELETE);


$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
ActionDefinition::SAVE_AND_RETURN,
[
'add_class' => 'float-right ',
'icon' => 'check',
@@ -606,7 +604,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
ActionDefinition::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
@@ -618,7 +616,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_CONTINUE,
ActionDefinition::SAVE_AND_CONTINUE,
[
'class' => 'btn btn-info float-right action-save-continue',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_continue'),
@@ -628,7 +626,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::DELETE,
ActionDefinition::DELETE,
[
'icon' => 'trash',
'class' => 'btn btn-outline-danger action-delete',
@@ -643,12 +641,12 @@ abstract class AbstractAdminController extends EaAbstractCrudController

public function buildNewActions(Actions $actions): void
{
$actions->add(Crud::PAGE_NEW, Action::INDEX);
$actions->add(Crud::PAGE_NEW, ActionDefinition::INDEX);

$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_RETURN,
ActionDefinition::SAVE_AND_RETURN,
[
'add_class' => 'float-right',
'icon' => 'check',
@@ -659,7 +657,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::INDEX,
ActionDefinition::INDEX,
[
'icon' => 'chevron-left',
'class' => 'btn btn-link',
@@ -670,7 +668,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
$this->actionUpdate(
$actions,
Crud::PAGE_EDIT,
Action::SAVE_AND_ADD_ANOTHER,
ActionDefinition::SAVE_AND_ADD_ANOTHER,
[
'class' => 'btn btn-info float-right',
'label' => $this->get(TranslatorAdmin::class)->transAction('save_and_add_another'),
@@ -683,7 +681,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if ($this->isInstanceOf(TranslatableInterface::class)) {
$actions->update(
Crud::PAGE_INDEX,
Action::EDIT,
ActionDefinition::EDIT,
function (Action $action) {
$action->setTemplatePath('@LcSov/adminlte/crud/action/translatable.html.twig');

@@ -696,8 +694,8 @@ abstract class AbstractAdminController extends EaAbstractCrudController
public function handleSortableEntityActions(Actions $actions): void
{
if ($this->isInstanceOf(SortableInterface::class)) {
$sortAction = Action::new('sort', $this->get(TranslatorAdmin::class)->transAction('sort'), 'fa fa-sort')
->linkToCrudAction('sort')
$sortAction = Action::new(ActionDefinition::SORT, $this->get(TranslatorAdmin::class)->transAction(ActionDefinition::SORT), 'fa fa-sort')
->linkToCrudAction(ActionDefinition::SORT)
->setCssClass('btn btn-sm btn-success')
->createAsGlobalAction();

@@ -710,22 +708,22 @@ abstract class AbstractAdminController extends EaAbstractCrudController
{
if ($this->isInstanceOf(TreeInterface::class)) {
$indexChildAction = Action::new(
'index_children',
$this->get(TranslatorAdmin::class)->transAction('index_children'),
ActionDefinition::INDEX_CHILDREN,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::INDEX_CHILDREN),
'fa fa-list'
)
->linkToCrudAction(Action::INDEX)
->linkToCrudAction(ActionDefinition::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');

$backParentAction = Action::new(
'index_parent',
$this->get(TranslatorAdmin::class)->transAction('index_parent'),
ActionDefinition::INDEX_PARENT,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::INDEX_PARENT),
'fa fa-chevron-left'
)
->linkToCrudAction(Action::INDEX)
->linkToCrudAction(ActionDefinition::INDEX)
->setCssClass('btn btn-sm btn-info')
->createAsGlobalAction();

@@ -784,7 +782,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
/** @var CrudControllerInterface $controller */
$controller = $this->get(ControllerFactory::class)->getCrudControllerInstance(
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
Action::INDEX,
ActionDefinition::INDEX,
$context->getRequest()
);
/** @var FieldDto $field */
@@ -813,7 +811,9 @@ abstract class AbstractAdminController extends EaAbstractCrudController
public function createCustomForm($class, $action, $controller, $entity, $dataInOption = true, $options = array())
{
if ($dataInOption) {
$options['data'] = $entity;
$data = $entity;
}else{
$data = null;
}

$options['action'] = $this->get(AdminUrlGenerator::class)
@@ -822,7 +822,27 @@ abstract class AbstractAdminController extends EaAbstractCrudController
->setEntityId($entity->getId())
->generateUrl();

return $this->createForm($class, null, $options);
return $this->createForm($class, $data, $options);
}

public function generateEaUrl(string $controller =null, string $action=null, int $entityId=null, array $extraParam = array()): string
{
$adminUrlGenerator = $this->get(AdminUrlGenerator::class);
if ($controller) {
$adminUrlGenerator->setController($controller);
}
if ($action) {
$adminUrlGenerator->setAction($action);
}
if ($entityId) {
$adminUrlGenerator->setEntityId($entityId);
}
if($extraParam){
foreach ($extraParam as $key=>$value) {
$adminUrlGenerator->set($key, $value);
}
}
return $adminUrlGenerator->generateUrl();
}

}

+ 3
- 2
Controller/Ticket/TicketAdminController.php View File

@@ -16,6 +16,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Definition\ActionDefinition;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketFactoryInterface;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
@@ -91,8 +92,8 @@ class TicketAdminController extends AbstractAdminController
public function configureActions(Actions $actions): Actions
{
$actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->remove(Crud::PAGE_INDEX, Action::EDIT);
->add(Crud::PAGE_INDEX, ActionDefinition::DETAIL)
->remove(Crud::PAGE_INDEX, ActionDefinition::EDIT);

return parent::configureActions($actions);
}

+ 18
- 0
Definition/ActionDefinition.php View File

@@ -0,0 +1,18 @@
<?php
namespace Lc\SovBundle\Definition;

class ActionDefinition {
public const BATCH_DELETE = 'batchDelete';
public const DELETE = 'delete';
public const DETAIL = 'detail';
public const EDIT = 'edit';
public const INDEX = 'index';
public const NEW = 'new';
public const DUPLICATE = 'duplicate';
public const SORT = 'sort';
public const INDEX_CHILDREN = 'index_children';
public const INDEX_PARENT = 'index_parent';
public const SAVE_AND_ADD_ANOTHER = 'saveAndAddAnother';
public const SAVE_AND_CONTINUE = 'saveAndContinue';
public const SAVE_AND_RETURN = 'saveAndReturn';
}

+ 2
- 2
Form/Common/FiltersFormType.php View File

@@ -53,7 +53,7 @@ class FiltersFormType extends AbstractType
$fieldDto = $field;
}
if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) {
dump($fieldDto);
switch ($fieldDto->getFormType()) {
case CheckboxType::class:
$checkboxFilter = new CheckboxFilter();
@@ -140,4 +140,4 @@ class FiltersFormType extends AbstractType
]
);
}
}
}

+ 1
- 1
Resources/assets/app/adminlte/field/collection/app.collection.js View File

@@ -1,5 +1,5 @@

import "jquery-ui"
import "jquery-ui-sortable"
import "./form.scss"



+ 1
- 2
Resources/assets/app/adminlte/main/init.js View File

@@ -12,7 +12,6 @@ window.addEventListener('load', (event) => {
/* Tooltip */
$('[data-toggle="tooltip"]').tooltip();

/* Select2 */
if ($('.form-select, .select2, select.form-control').length) {


@@ -84,4 +83,4 @@ window.addEventListener('load', (event) => {
SovWidgets.setAutoCompleteField();


});
});

+ 2
- 2
Resources/assets/app/adminlte/sort/app.sort.js View File

@@ -1,4 +1,4 @@

import 'jquery-ui'
import 'jquery-ui-sortable'
import './sort.js'
import './sort.scss'
import './sort.scss'

+ 1
- 3
Resources/assets/functions/widgets.js View File

@@ -92,12 +92,10 @@ export class SovWidgets {

static setAutoCompleteField() {
var autocompleteFields = $('[data-lc-autocomplete-url]');
SovTools.log($.fn);
autocompleteFields.each(function () {
var $this = $(this),
url = $this.data('lc-autocomplete-url');
SovTools.log($this);
SovTools.log(url);

$this.autoComplete({
//bootstrapVersion: 4,
//noResultsText: 'Aucun résultat n\'a été trouvé.',

+ 1
- 1
Resources/views/adminlte/crud/detail.html.twig View File

@@ -21,7 +21,7 @@
{% block main_prepend %}{% endblock %}
<div class="col-12" id="{% block detail_id %}{% endblock detail_id %}">
{% block card_wrapper %}
<div class="card card-table card-outline card-primary">
<div class="card card-outline card-primary">
{% block card_header_wrapper %}
<div class="card-header">
<div class="btn-list float-sm-right">

+ 26
- 1
Twig/TwigExtension.php View File

@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Twig;

use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Component\DateComponent;
use Lc\SovBundle\Component\FileComponent;
use Lc\SovBundle\Component\MetaComponent;
@@ -41,6 +42,7 @@ class TwigExtension extends AbstractExtension
protected MetaComponent $metaComponent;
protected DateComponent $dateComponent;
protected FileComponent $fileComponent;
protected AdminUrlGenerator $adminUrlGenerator;

public function __construct(
KernelInterface $kernel,
@@ -57,7 +59,8 @@ class TwigExtension extends AbstractExtension
StringComponent $stringComponent,
MetaComponent $metaComponent,
DateComponent $dateComponent,
FileComponent $fileComponent
FileComponent $fileComponent,
AdminUrlGenerator $adminUrlGenerator
) {
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
@@ -74,6 +77,7 @@ class TwigExtension extends AbstractExtension
$this->metaComponent = $metaComponent;
$this->dateComponent = $dateComponent;
$this->fileComponent = $fileComponent;
$this->adminUrlGenerator = $adminUrlGenerator;
}

public function getFunctions()
@@ -90,6 +94,7 @@ class TwigExtension extends AbstractExtension
new TwigFunction('sov_limit_text', [$this, 'limitText']),
new TwigFunction('day_by_number', [$this, 'getDayByNumber']),
new TwigFunction('user_current', [$this, 'getUserCurrent']),
new TwigFunction('ea_url_short', [$this, 'generateEaUrl']),
];
}

@@ -178,4 +183,24 @@ class TwigExtension extends AbstractExtension
return $this->security->getUser();
}

public function generateEaUrl(string $controller =null, string $action=null, int $entityId=null, array $extraParam = array()): string
{
$adminUrlGenerator = $this->adminUrlGenerator;
if ($controller) {
$adminUrlGenerator->setController($controller);
}
if ($action) {
$adminUrlGenerator->setAction($action);
}
if ($entityId) {
$adminUrlGenerator->setEntityId($entityId);
}
if($extraParam){
foreach ($extraParam as $key=>$value) {
$adminUrlGenerator->set($key, $value);
}
}
return $adminUrlGenerator->generateUrl();
}

}

Loading…
Cancel
Save