Browse Source

Finalisation app product & reduction

feature/symfony6.1
Fab 3 years ago
parent
commit
2da9fd1228
15 changed files with 121 additions and 31 deletions
  1. +29
    -16
      Controller/AbstractAdminController.php
  2. +17
    -2
      Definition/Field/AbstractFieldDefinition.php
  3. +3
    -1
      Definition/Field/User/UserFieldDefinition.php
  4. +1
    -1
      Field/BooleanField.php
  5. +1
    -1
      Model/User/UserModel.php
  6. +13
    -0
      Repository/User/GroupUserRepositoryQuery.php
  7. +1
    -0
      Repository/User/GroupUserStore.php
  8. +16
    -0
      Repository/User/UserRepositoryQuery.php
  9. +10
    -0
      Resources/assets/app/adminlte/index/index.scss
  10. +1
    -2
      Resources/assets/app/adminlte/sort/sort.js
  11. +12
    -0
      Resources/views/adminlte/crud/field/association.html.twig
  12. +3
    -6
      Resources/views/adminlte/crud/field/toggle.html.twig
  13. +6
    -0
      Resources/views/adminlte/crud/form_theme.html.twig
  14. +1
    -1
      Resources/views/adminlte/crud/index.html.twig
  15. +7
    -1
      Resources/views/adminlte/crud/sort.html.twig

+ 29
- 16
Controller/AbstractAdminController.php View File

use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface; use Lc\SovBundle\Doctrine\Extension\SeoInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface; use Lc\SovBundle\Doctrine\Extension\SortableInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\TranslatableInterface; use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
use Lc\SovBundle\Doctrine\Extension\TreeInterface; use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Field\CollectionField; use Lc\SovBundle\Field\CollectionField;
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) {
$responseParameters->set('fields', $this->configureFields('index')); $responseParameters->set('fields', $this->configureFields('index'));


//TODO supprimer ce code rapport au filtre dans les index
/*if ($this->filtersForm === null) {
die('nncncd');

$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);
if(isset($this->filtersForm)) {
$responseParameters->set('filters_form', $this->filtersForm);
}
} }


$responseParameters->set('translation_entity_name', $this->getTranslationEntityName()); $responseParameters->set('translation_entity_name', $this->getTranslationEntityName());
} }
} }


protected function getRequestCrudAction() :string{
return $this->getRequestStack()->getCurrentRequest()->get('crudAction');
}

public function configureCrud(Crud $crud): Crud public function configureCrud(Crud $crud): Crud
{ {
$crud = parent::configureCrud($crud); $crud = parent::configureCrud($crud);

$this->setMaxResults($crud);
if($this->getRequestCrudAction() === ActionDefinition::SORT) {
$crud->setPaginatorPageSize(9999);
}else {
$this->setMaxResults($crud);
}


$crud->setFormOptions(['translation_entity_name' => $this->getTranslationEntityName()]); $crud->setFormOptions(['translation_entity_name' => $this->getTranslationEntityName()]);


$fields, $fields,
$context->getEntity() $context->getEntity()
); );
$queryBuilder = $this->createIndexQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);

$queryBuilder = $this->createSortQueryBuilder($context->getSearch(), $context->getEntity(), $fields, $filters);
$paginator = $this->get(PaginatorFactory::class)->create($queryBuilder); $paginator = $this->get(PaginatorFactory::class)->create($queryBuilder);


$entities = $this->get(EntityFactory::class)->createCollection($context->getEntity(), $paginator->getResults()); $entities = $this->get(EntityFactory::class)->createCollection($context->getEntity(), $paginator->getResults());
$repositoryQuery->filterIsParent(); $repositoryQuery->filterIsParent();
} }
} }
if ($this->isInstanceOf(StatusInterface::class)) {
$repositoryQuery->filterIsOnlineAndOffline();
}


$this->filtersForm = $this->createForm( $this->filtersForm = $this->createForm(
FiltersFormType::class, FiltersFormType::class,
return $repositoryQuery; return $repositoryQuery;
} }



public function createSortRepositoryQuery(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): RepositoryQueryInterface {
return $this->createIndexRepositoryQuery($searchDto,$entityDto, $fields, $filters);
}
public function createIndexQueryBuilder( public function createIndexQueryBuilder(
SearchDto $searchDto, SearchDto $searchDto,
EntityDto $entityDto, EntityDto $entityDto,
FieldCollection $fields, FieldCollection $fields,
FilterCollection $filters FilterCollection $filters
): QueryBuilder { ): QueryBuilder {
$queryBuilder = $this->createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);

return $queryBuilder;
$repositoryQuery = $this->createSortRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
} }


public function edit(AdminContext $context) public function edit(AdminContext $context)

+ 17
- 2
Definition/Field/AbstractFieldDefinition.php View File

namespace Lc\SovBundle\Definition\Field; namespace Lc\SovBundle\Definition\Field;


use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
->hideOnIndex(), ->hideOnIndex(),
'devAlias' => TextField::new('devAlias')->hideOnIndex(), 'devAlias' => TextField::new('devAlias')->hideOnIndex(),
'status' => StatusField::new('status')->setSortable(true), 'status' => StatusField::new('status')->setSortable(true),
'createdAt' => DateTimeField::new('createdAt')->setSortable(true),
'updatedAt' => DateTimeField::new('updatedAt')->setSortable(true),
]; ];
} }


throw new \Exception($method . ' n\'existe pas '); throw new \Exception($method . ' n\'existe pas ');
} }


$fieldPanel = FormField::addPanel($panel);
$method = 'panel'.ucfirst($panel).'CustomOptions';
if(method_exists($this, $method)) {
foreach ($this->$method() as $customOptionKey => $customOptionValue){
$fieldPanel->setCustomOption($customOptionKey, $customOptionValue);
}

}

return array_merge( return array_merge(
['panel_' . $panel => FormField::addPanel($panel)],
[
'panel_' . $panel => $fieldPanel

],
$this->buildFieldArray($panelFieldArray) $this->buildFieldArray($panelFieldArray)
); );
} }


}
}

+ 3
- 1
Definition/Field/User/UserFieldDefinition.php View File

'firstname' => TextField::new('firstname')->setSortable(true), 'firstname' => TextField::new('firstname')->setSortable(true),
'email' => TextField::new('email')->setSortable(true), 'email' => TextField::new('email')->setSortable(true),
'phone' => TextField::new('phone')->setSortable(true), 'phone' => TextField::new('phone')->setSortable(true),
'birthdate' => DateField::new('birthdate')->setSortable(true),
'birthdate' => DateField::new('birthdate')
->setFormTypeOption('required', false)
->setSortable(true),
'groupUsers' => AssociationField::new('groupUsers')->setSortable(true), 'groupUsers' => AssociationField::new('groupUsers')->setSortable(true),
'ticketTypesNotification' => ChoiceField::new('ticketTypesNotification') 'ticketTypesNotification' => ChoiceField::new('ticketTypesNotification')
->setSortable(true) ->setSortable(true)

+ 1
- 1
Field/BooleanField.php View File

return (new self()) return (new self())
->setProperty($propertyName) ->setProperty($propertyName)
->setLabel($label) ->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/boolean.html.twig')
->setTemplatePath('@LcSov/adminlte/crud/field/toggle.html.twig')
->setFormType(CheckboxType::class); ->setFormType(CheckboxType::class);
} }



+ 1
- 1
Model/User/UserModel.php View File

return $this->birthdate; return $this->birthdate;
} }


public function setBirthdate(\DateTimeInterface $birthdate): self
public function setBirthdate(?\DateTimeInterface $birthdate): self
{ {
$this->birthdate = $birthdate; $this->birthdate = $birthdate;



+ 13
- 0
Repository/User/GroupUserRepositoryQuery.php View File

{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

protected $isJoinUsers = false;

public function joinUsers(): self
{

if (!$this->isJoinUsers) {
$this->isJoinUsers = true;
return $this
->innerJoin('.users', 'user');
}
return $this;
}
} }

+ 1
- 0
Repository/User/GroupUserStore.php View File



public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->joinUsers();
return $query; return $query;
} }
} }

+ 16
- 0
Repository/User/UserRepositoryQuery.php View File

parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }


protected $isJoinGroupUsers = false;

public function joinGroupUsers($addSelect = true): self
{
if (!$this->isJoinGroupUsers) {
$this->isJoinGroupUsers = true;

$this->innerJoin('.groupUsers', 'groupUser');
if($addSelect){
$this->addSelect('groupUser');
}
}
return $this;
}


public function filterByNewsletter(Newsletter $newsletter): self public function filterByNewsletter(Newsletter $newsletter): self
{ {
return $this return $this

+ 10
- 0
Resources/assets/app/adminlte/index/index.scss View File

white-space: normal; white-space: normal;
} }
} }


table.fixedHeader-floating{margin-top: 0px !important;}
table th.sorting_asc, table th.sorting_desc{border-top:2px solid var(--success);}
.card-body table th.filtered{border-top:2px solid var(--primary);}
/*.card-body table.lc-table-list th{border-top:3px solid var(--success);}*/
table th.filtered{border-top:2px solid var(--primary);}
.card-body table th.sorted, table th.sorting_asc, table th.sorting_desc{border-top:2px solid var(--success);}
.card-body table th.sorted.filtered{border-top:0px; position: relative;}
.card-body table th.sorted.filtered:after{ content: ''; height: 2px; position: absolute; left: 0; width: 100%; right: 0; top: -1px; background: linear-gradient(to right, var(--success) 0%, var(--success) 50%, var(--primary) 50%, var(--primary) 100%);}

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



// Replace '__name__' in the prototype's HTML to // Replace '__name__' in the prototype's HTML to
$(li).find('div:last-child').remove(); $(li).find('div:last-child').remove();

$(li).append(newForm);
$(li).find('td:first').append('<div class="hidden">'+newForm+'</div>');
$(li).find('#form_entities_' + index + '_id').val($(li).data('id')); $(li).find('#form_entities_' + index + '_id').val($(li).data('id'));
/* if ($('.sov-sortable').data('parent-position') !== '') { /* if ($('.sov-sortable').data('parent-position') !== '') {
//Ajout d'un 0 initial pour les nuémros <10 //Ajout d'un 0 initial pour les nuémros <10

+ 12
- 0
Resources/views/adminlte/crud/field/association.html.twig View File

{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
{% if 'toMany' == field.customOptions.get('associationType') %}
<span class="badge badge-secondary">{{ field.formattedValue }}</span>
{% else %}
{% if field.customOption('crudControllerFqcn') is not null and field.value is not null%}
<a href="{{ ea_url_short(field.customOption('crudControllerFqcn'), 'edit', field.value.id) }}">{{ field.formattedValue }}</a>
{% else %}
{{ field.formattedValue }}
{% endif %}
{% endif %}

+ 3
- 6
Resources/views/adminlte/crud/field/toggle.html.twig View File

{% set id_toggle = 'toggle-'~item.id~'-'~property_name %} {% set id_toggle = 'toggle-'~item.id~'-'~property_name %}


{% block toggle %} {% block toggle %}
<div class="custom-control custom-switch custom-switch-on-success custom-switch-off-default"
<div class="custom-control custom-switch custom-switch-on-success custom-switch-off-default" data-toggle="tooltip" title="{{ field.getCustomOption('toggle_label') ? field.label : field.property|sov_trans_admin_field(entity.instance) }}"
data-url="{{ ea_url({crudAction: 'edit', entityId: item.id, fieldName: property_name }) }}"> data-url="{{ ea_url({crudAction: 'edit', entityId: item.id, fieldName: property_name }) }}">
<input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}>
<label class="custom-control-label" for="{{ id_toggle }}">
{% block label %}
{{ field.getCustomOption('toggle_label') ? field.label : field.property|sov_trans_admin_field(entity.instance) }}
{% endblock label %}
<input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}>
<label class="custom-control-label" for="{{ id_toggle }}" >
</label> </label>
</div> </div>
{% endblock toggle %} {% endblock toggle %}

+ 6
- 0
Resources/views/adminlte/crud/form_theme.html.twig View File

{% block class %}{{ loop.first ? 'active' }}{% endblock %} {% block class %}{{ loop.first ? 'active' }}{% endblock %}
{% block id %}{{ panel_name }}{% endblock %} {% block id %}{{ panel_name }}{% endblock %}
{% block content %} {% block content %}
{% if panel_config['prepend_content_path'] is defined %}
{% include panel_config['prepend_content_path'] %}
{% endif %}
{% for field in form|filter(field => 'hidden' not in field.vars.block_prefixes and field.vars.ea_crud_form.form_panel == panel_name) %} {% for field in form|filter(field => 'hidden' not in field.vars.block_prefixes and field.vars.ea_crud_form.form_panel == panel_name) %}
{% if not field.vars.ea_crud_form.form_tab or field.vars.ea_crud_form.form_tab == tab_name %} {% if not field.vars.ea_crud_form.form_tab or field.vars.ea_crud_form.form_tab == tab_name %}
{{ form_row(field) }} {{ form_row(field) }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if panel_config['append_content_path'] is defined %}
{% include panel_config['append_content_path'] %}
{% endif %}
{% endblock %} {% endblock %}
{% endembed %} {% endembed %}
{% else %} {% else %}

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

{% endblock %} {% endblock %}
{% block card_body_wrapper %} {% block card_body_wrapper %}
<div class="card-body"> <div class="card-body">
<div class="table-responsive">
<div class="">
<table class="table table-bordered table-hover table-striped"> <table class="table table-bordered table-hover table-striped">
<thead> <thead>
{% block table_head %} {% block table_head %}

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

{% set is_sorting_field = ea.search.isSortingField(field.property) %} {% set is_sorting_field = ea.search.isSortingField(field.property) %}
<th class="{{ is_sorting_field ? 'sorted' }} {{ field.isVirtual ? 'field-virtual' }} {% if field.textAlign %}text-{{ field.textAlign }}{% endif %}" <th class="{{ is_sorting_field ? 'sorted' }} {{ field.isVirtual ? 'field-virtual' }} {% if field.textAlign %}text-{{ field.textAlign }}{% endif %}"
dir="{{ ea.i18n.textDirection }}"> dir="{{ ea.i18n.textDirection }}">
<span>{{ field.label ? field.label|raw : field.getProperty|raw }}</span>
<span>
{% if field.label is not null %}
{{ field.label|raw }}
{% else %}
{{ field.getProperty|sov_trans_admin_field_index(translation_entity_name) }}
{% endif %}
</span>
</th> </th>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

Loading…
Cancel
Save