Browse Source

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/CaracoleBundle into develop

feature/ticket
Fab 3 years ago
parent
commit
2d1365ea4c
10 changed files with 177 additions and 11 deletions
  1. +2
    -1
      Controller/Dashboard/DashboardAdminController.php
  2. +3
    -3
      Controller/Section/SwitchSectionAdminController.php
  3. +11
    -3
      EventSubscriber/User/UserRolesEventSubscriber.php
  4. +60
    -0
      Form/Merchant/SwitchMerchantButtonAdminFormType.php
  5. +1
    -1
      Form/Section/SwitchSectionFormType.php
  6. +32
    -0
      Resources/assets/app/adminlte/common/common.scss
  7. +1
    -0
      Resources/assets/app/switchmerchant/app.switchmerchant.js
  8. +12
    -0
      Resources/assets/app/switchmerchant/switchmerchant_admin.js
  9. +41
    -3
      Resources/views/adminlte/layout.html.twig
  10. +14
    -0
      Twig/TwigExtension.php

+ 2
- 1
Controller/Dashboard/DashboardAdminController.php View File

{ {
$assets = parent::configureAssets(); // TODO: Change the autogenerated stub $assets = parent::configureAssets(); // TODO: Change the autogenerated stub


$assets->addWebpackEncoreEntry('common-switch-merchant') ;
$assets->addWebpackEncoreEntry('carac-common') ;
$assets->addWebpackEncoreEntry('carac-switch-merchant') ;


return $assets ; return $assets ;
} }

+ 3
- 3
Controller/Section/SwitchSectionAdminController.php View File

$em->update($section); $em->update($section);
$em->flush(); $em->flush();
} }

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

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

+ 11
- 3
EventSubscriber/User/UserRolesEventSubscriber.php View File

use Lc\CaracoleBundle\Model\User\UserMerchantInterface; use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver; use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver; use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent; use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
$token = $this->tokenStorage->getToken(); $token = $this->tokenStorage->getToken();
$sessionUser = $token->getUser(); $sessionUser = $token->getUser();
if($sessionUser instanceof UserInterface) { if($sessionUser instanceof UserInterface) {
$roles = $this->merchantResolver->getUserMerchant($sessionUser)->getRoles();


if($roles != $sessionUser->getRoles()) {
$userMerchant = $this->merchantResolver->getUserMerchant($sessionUser) ;

if($userMerchant) {
$roles = $userMerchant->getRoles();
}
else {
$roles = [RolesDefinition::ROLE_USER] ;
}

if ($roles != $sessionUser->getRoles()) {
$sessionUser->setRoles($roles); $sessionUser->setRoles($roles);
$this->em->update($sessionUser); $this->em->update($sessionUser);
$this->em->flush(); $this->em->flush();
); );
$this->security->setToken($token); $this->security->setToken($token);
} }

} }
/* /*
// This check can be just `is_object` like in symfony core // This check can be just `is_object` like in symfony core

+ 60
- 0
Form/Merchant/SwitchMerchantButtonAdminFormType.php View File

<?php

namespace Lc\CaracoleBundle\Form\Merchant;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class SwitchMerchantButtonAdminFormType extends AbstractType
{
protected $em;
protected $translatorAdmin;
protected $merchantResolver;

public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin, MerchantResolver $merchantResolver)
{
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
$this->merchantResolver = $merchantResolver;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'merchant',
HiddenType::class,
[
'data' => $options['merchant']
]
);

$builder->add(
'context',
HiddenType::class,
[
'data' => 'admin'
]
);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'merchant' => $this->merchantResolver->getCurrent(),
]
);
}

}

+ 1
- 1
Form/Section/SwitchSectionFormType.php View File

$classButton = 'btn-section'; $classButton = 'btn-section';
if ($section == $currentSection) { if ($section == $currentSection) {
$classButton .= ' btn-section-current'; $classButton .= ' btn-section-current';
$styleButton = 'background-color: ' . $currentSection->getColor() . ';';
$styleButton = 'color: white; background-color: ' . $currentSection->getColor() . ';';
} }


$builder->add( $builder->add(

+ 32
- 0
Resources/assets/app/adminlte/common/common.scss View File


body.admin {

nav.navbar.carac {
background-color: white ;
padding-top: 0px ;
padding-bottom: 0px ;
border-width: 2px;

ul.left {
position: relative ;
top: 16px ;

li {
form.switch-section {
button {
border-radius: 7px 7px 0px 0px ;

&:hover {
color: gray ;
}
}
}
}
}
}

.content-header {
padding-top: 20px ;
}

}

+ 1
- 0
Resources/assets/app/switchmerchant/app.switchmerchant.js View File



import './switchmerchant.js' ; import './switchmerchant.js' ;
import './switchmerchant_admin.js' ;
import './switchmerchant_admin.scss' ; import './switchmerchant_admin.scss' ;





+ 12
- 0
Resources/assets/app/switchmerchant/switchmerchant_admin.js View File


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

function initSwitchMerchantAdmin() {
let $modalSwitchMerchant = $('#carac-modal-switch-merchant') ;

if($modalSwitchMerchant.length) {
//$('#carac-modal-switch-merchant').modal('show') ;
}
}

+ 41
- 3
Resources/views/adminlte/layout.html.twig View File

{% block navbar_header %} {% block navbar_header %}
{{ parent() }} {{ parent() }}


<nav class="navbar navbar-expand navbar-light main-header">
<ul class="navbar-nav">
{% set section_current = section_resolver.getCurrent() %}

<nav class="carac navbar navbar-expand navbar-light main-header" style="border-color: {{ section_current.color }};">
<ul class="navbar-nav left">
{% for section in carac_get_sections() %} {% for section in carac_get_sections() %}
<li class="nav-item d-none d-sm-inline-block"> <li class="nav-item d-none d-sm-inline-block">
{% set form_switch_section = carac_get_form_switch_section(section) %} {% set form_switch_section = carac_get_form_switch_section(section) %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<ul class="navbar-nav ml-auto">
<ul class="navbar-nav ml-auto right">
<li class="nav-item nav-switch-merchant"> <li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i> <i class="fa fa-store"></i>
{% set form_switch_merchant = carac_get_form_switch_merchant('admin') %} {% set form_switch_merchant = carac_get_form_switch_merchant('admin') %}
</li> </li>
</ul> </ul>
</nav> </nav>
{% endblock %}

{% block append_body %}
{# modal switch merchant #}
{% set user = app.user %}
{% set merchant_current = merchant_resolver.getCurrent() %}

{% if(user.favoriteMerchant != merchant_current) %}
{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% block id %}carac-modal-switch-merchant{% endblock %}
{% block title %}
Switch merchant
{% endblock %}
{% block body %}
{% if not user.favoriteMerchant %}
<p>Vous n'avez pas de marchand favoris.</p>
{% endif %}
{% if user.favoriteMerchant and user.favoriteMerchant != merchant_current %}
<p>Vous n'êtes pas sur votre marchand par défaut.</p>
{% endif %}
{% endblock %}
{% block footer %}
{% set form_switch_merchant_button = carac_get_form_switch_merchant_button() %}
{% form_theme form_switch_merchant_button '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant_button) }}
{{ form(form_switch_merchant_button) }}
{{ form_end(form_switch_merchant_button) }}


<button type="button" class="btn btn-primary"
data-dismiss="modal">{{ 'action.switch_merchant'|trans }}</button>
<button type="button" class="btn btn-default"
data-dismiss="modal">{{ 'action.visit'|trans }}</button>
{% endblock %}
{% endembed %}
{% endif %}
{% endblock %} {% endblock %}

+ 14
- 0
Twig/TwigExtension.php View File

namespace Lc\CaracoleBundle\Twig; namespace Lc\CaracoleBundle\Twig;


use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType; use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
return array( return array(
new TwigFunction('carac_get_sections', [$this, 'getSections']), new TwigFunction('carac_get_sections', [$this, 'getSections']),
new TwigFunction('carac_get_form_switch_merchant', [$this, 'getFormSwitchMerchant']), new TwigFunction('carac_get_form_switch_merchant', [$this, 'getFormSwitchMerchant']),
new TwigFunction('carac_get_form_switch_merchant_button', [$this, 'getFormSwitchMerchantButton']),
new TwigFunction('carac_get_form_switch_section', [$this, 'getFormSwitchSection']), new TwigFunction('carac_get_form_switch_section', [$this, 'getFormSwitchSection']),
); );
} }
return $form->createView(); return $form->createView();
} }


public function getFormSwitchMerchantButton()
{
$form = $this->formFactory->create(
SwitchMerchantButtonAdminFormType::class,
null,
[
'action' => $this->urlGenerator->generate('carac_switch_merchant'),
]
);
return $form->createView();
}

public function getFormSwitchSection($section) public function getFormSwitchSection($section)
{ {
$form = $this->formFactory->create( $form = $this->formFactory->create(

Loading…
Cancel
Save