浏览代码

Modal switch merchant

feature/ticket
Guillaume 3 年前
父节点
当前提交
b1f3ec2436
共有 10 个文件被更改,包括 177 次插入11 次删除
  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 查看文件

@@ -22,7 +22,8 @@ class DashboardAdminController extends SovDashboardController
{
$assets = parent::configureAssets(); // TODO: Change the autogenerated stub

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

return $assets ;
}

+ 3
- 3
Controller/Section/SwitchSectionAdminController.php 查看文件

@@ -31,9 +31,9 @@ class SwitchSectionAdminController extends AbstractController
$em->update($section);
$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 查看文件

@@ -9,6 +9,7 @@ use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Model\User\UserInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -60,9 +61,17 @@ class UserRolesEventSubscriber implements EventSubscriberInterface
$token = $this->tokenStorage->getToken();
$sessionUser = $token->getUser();
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);
$this->em->update($sessionUser);
$this->em->flush();
@@ -75,7 +84,6 @@ class UserRolesEventSubscriber implements EventSubscriberInterface
);
$this->security->setToken($token);
}

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

+ 60
- 0
Form/Merchant/SwitchMerchantButtonAdminFormType.php 查看文件

@@ -0,0 +1,60 @@
<?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 查看文件

@@ -50,7 +50,7 @@ class SwitchSectionFormType extends AbstractType
$classButton = 'btn-section';
if ($section == $currentSection) {
$classButton .= ' btn-section-current';
$styleButton = 'background-color: ' . $currentSection->getColor() . ';';
$styleButton = 'color: white; background-color: ' . $currentSection->getColor() . ';';
}

$builder->add(

+ 32
- 0
Resources/assets/app/adminlte/common/common.scss 查看文件

@@ -0,0 +1,32 @@

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 查看文件

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

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



+ 12
- 0
Resources/assets/app/switchmerchant/switchmerchant_admin.js 查看文件

@@ -0,0 +1,12 @@

$(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 查看文件

@@ -3,8 +3,10 @@
{% block navbar_header %}
{{ 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() %}
<li class="nav-item d-none d-sm-inline-block">
{% set form_switch_section = carac_get_form_switch_section(section) %}
@@ -15,7 +17,7 @@
</li>
{% endfor %}
</ul>
<ul class="navbar-nav ml-auto">
<ul class="navbar-nav ml-auto right">
<li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i>
{% set form_switch_merchant = carac_get_form_switch_merchant('admin') %}
@@ -26,4 +28,40 @@
</li>
</ul>
</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 %}

+ 14
- 0
Twig/TwigExtension.php 查看文件

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Twig;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
@@ -43,6 +44,7 @@ class TwigExtension extends AbstractExtension
return array(
new TwigFunction('carac_get_sections', [$this, 'getSections']),
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']),
);
}
@@ -71,6 +73,18 @@ class TwigExtension extends AbstractExtension
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)
{
$form = $this->formFactory->create(

正在加载...
取消
保存