Browse Source

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

feature/ticket
Fab 3 years ago
parent
commit
9fa502d7b1
14 changed files with 188 additions and 149 deletions
  1. +40
    -0
      Controller/Merchant/FavoriteMerchantController.php
  2. +11
    -4
      Controller/Merchant/SwitchMerchantController.php
  3. +1
    -0
      Controller/Setting/SettingAdminController.php
  4. +30
    -0
      Definition/MerchantSettingDefinition.php
  5. +0
    -60
      Form/Merchant/SwitchMerchantButtonAdminFormType.php
  6. +9
    -0
      Form/Merchant/SwitchMerchantFormType.php
  7. +14
    -15
      Form/Setting/BaseSettingType.php
  8. +16
    -23
      Resources/assets/app/adminlte/common/common.scss
  9. +8
    -2
      Resources/assets/app/switchmerchant/switchmerchant_admin.js
  10. +29
    -17
      Resources/assets/app/switchmerchant/switchmerchant_admin.scss
  11. +4
    -0
      Resources/config/routes.yaml
  12. +11
    -0
      Resources/translations/admin.fr.yaml
  13. +13
    -13
      Resources/views/adminlte/layout.html.twig
  14. +2
    -15
      Twig/TwigExtension.php

+ 40
- 0
Controller/Merchant/FavoriteMerchantController.php View File

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

namespace Lc\CaracoleBundle\Controller\Merchant;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;

class FavoriteMerchantController extends AbstractController
{
public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $em)
{
$user = $security->getUser() ;

if($user) {
$form = $this->createForm(SwitchMerchantFormType::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$merchant = $form->get('merchant')->getData();

if ($merchant) {
$user->setFavoriteMerchant($merchant) ;
$em->update($user) ;
$em->flush() ;

$url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL).'admin';

if ($url) {
return $this->redirect($url);
}
}
}
}
}
}

+ 11
- 4
Controller/Merchant/SwitchMerchantController.php View File

@@ -2,14 +2,16 @@

namespace Lc\CaracoleBundle\Controller\Merchant;

use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class SwitchMerchantController extends AbstractController
{

public function switchMerchant(Request $request)
public function switchMerchant(Request $request, MerchantRepository $merchantRepository)
{
$form = $this->createForm(SwitchMerchantFormType::class);
$form->handleRequest($request);
@@ -19,10 +21,10 @@ class SwitchMerchantController extends AbstractController
$context = $form->get('context')->getData();

if ($merchant) {
$url = $merchant->getMerchantConfig('url');
$url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL);

if($context == 'admin') {
$url .= 'admin' ;
if ($context == 'admin') {
$url .= 'admin';
}

if ($url) {
@@ -31,4 +33,9 @@ class SwitchMerchantController extends AbstractController
}
}
}

public function visitMerchant()
{

}
}

+ 1
- 0
Controller/Setting/SettingAdminController.php View File

@@ -65,6 +65,7 @@ class SettingAdminController extends AbstractController
$entity = $resolver->getCurrent();

if ($entity) {

$form = $this->createForm($formClass, $entity);

$form->handleRequest($request);

+ 30
- 0
Definition/MerchantSettingDefinition.php View File

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

namespace Lc\CaracoleBundle\Definition;


class MerchantSettingDefinition extends AbstractSettingDefinition implements MerchantSettingDefinitionInterface
{
const CATEGORY_GENERAL = 'general';

const SETTING_URL = 'url';

public function __construct()
{
$this
->addSettingText(
[
'name' => self::SETTING_URL,
'category' => self::CATEGORY_GENERAL,
]
) ;
}

public function getCategories()
{
return [
self::CATEGORY_GENERAL,
];
}

}

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

@@ -1,60 +0,0 @@
<?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(),
]
);
}

}

+ 9
- 0
Form/Merchant/SwitchMerchantFormType.php View File

@@ -10,6 +10,7 @@ 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\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

@@ -45,6 +46,14 @@ class SwitchMerchantFormType extends AbstractType
'data' => $options['context']
]
);

$builder->add(
'submit',
SubmitType::class,
[
'label' => $this->translatorAdmin->transAction('favorite')
]
);
}

/**

+ 14
- 15
Form/Setting/BaseSettingType.php View File

@@ -24,27 +24,27 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
abstract class BaseSettingType extends AbstractType
{
protected $em;
protected $merchantSetup;
protected $sectionSetup;
protected $merchantSettingDefinition;
protected $sectionSettingDefinition;

public function __construct(
EntityManagerInterface $entityManager,
MerchantSettingDefinitionInterface $merchantSetup,
SectionSettingDefinitionInterface $sectionSetup
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition
) {
$this->em = $entityManager;
$this->merchantSetup = $merchantSetup;
$this->sectionSetup = $sectionSetup;
$this->merchantSettingDefinition = $merchantSettingDefinition;
$this->sectionSettingDefinition = $sectionSettingDefinition;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$merchantSetup = $this->merchantSetup;
$sectionSetup = $this->sectionSetup;
$merchantSettingDefinition = $this->merchantSettingDefinition;
$sectionSettingDefinition = $this->sectionSettingDefinition;

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($merchantSetup, $sectionSetup) {
function (FormEvent $event) use ($merchantSettingDefinition, $sectionSettingDefinition) {
$form = $event->getForm();

$settingEntity = $event->getData();
@@ -57,18 +57,17 @@ abstract class BaseSettingType extends AbstractType
$setup = null ;
if($settingEntity instanceof MerchantSettingInterface) {
$transCategory = 'merchant' ;
$setup = $merchantSetup ;
$settingDefinition = $merchantSettingDefinition ;
}
elseif($settingEntity instanceof SectionSettingInterface) {
$transCategory = 'section' ;
$setup = $sectionSetup ;
$settingDefinition = $sectionSettingDefinition ;
}
$label = 'setting_definition.'.$transCategory.'.settings.'.$settingName ;

if($setup) {
$setting = $setup->getSettingByName($settingName);
$settingType = $setup->getSettingType($settingName);

if($settingDefinition) {
$setting = $settingDefinition->getSettingByName($settingName);
$settingType = $settingDefinition->getSettingType($settingName);

if ($settingType == 'text') {
$form->add(

+ 16
- 23
Resources/assets/app/adminlte/common/common.scss View File

@@ -1,32 +1,25 @@

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

nav.navbar.carac {
background-color: white ;
padding-top: 0px ;
padding-bottom: 0px ;
border-width: 2px;
ul.left {
position: relative;
top: 16px;

ul.left {
position: relative ;
top: 16px ;
li {
form.switch-section {
button {
border-radius: 7px 7px 0px 0px;

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

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

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

}
}

+ 8
- 2
Resources/assets/app/switchmerchant/switchmerchant_admin.js View File

@@ -4,9 +4,15 @@ $(document).ready(function() {
}) ;

function initSwitchMerchantAdmin() {
let idMerchant = $('#switch_merchant_form_merchant').val() ;
let nameVisitMerchantSessionStorage = 'visit_merchant_'+idMerchant ;
let $modalSwitchMerchant = $('#carac-modal-switch-merchant') ;

if($modalSwitchMerchant.length) {
//$('#carac-modal-switch-merchant').modal('show') ;
if($modalSwitchMerchant.length && !sessionStorage.getItem(nameVisitMerchantSessionStorage)) {
$('#carac-modal-switch-merchant').modal('show') ;
}

$('#carac-button-visit-merchant').click(function() {
sessionStorage.setItem(nameVisitMerchantSessionStorage, true);
}) ;
}

+ 29
- 17
Resources/assets/app/switchmerchant/switchmerchant_admin.scss View File

@@ -1,25 +1,37 @@

body.admin {
.nav-switch-merchant {
width: 220px ;
text-align: right ;
// switch dans la navbar
.nav-switch-merchant {
width: 220px ;
text-align: right ;

.fa {
position: relative;
top: -4px;
right: 7px;
.fa {
position: relative;
top: -4px;
right: 7px;
}

form.switch-merchant {
display: inline-block ;
width: 180px ;
position: relative ;
top: 7px ;
text-align: left ;

label, .select2-selection__clear {
display: none ;
}

form.switch-merchant {
display: inline-block ;
width: 180px ;
position: relative ;
top: 7px ;
text-align: left ;
button {
display: none ;
}
}
}

label, .select2-selection__clear {
display: none ;
}
// modal
#carac-modal-switch-merchant {
form.switch-merchant {
.form-group:first-child {
display: none ;
}
}
}

+ 4
- 0
Resources/config/routes.yaml View File

@@ -2,6 +2,10 @@ carac_switch_merchant:
path: /switch-merchant
controller: Lc\CaracoleBundle\Controller\Merchant\SwitchMerchantController::switchMerchant

carac_favorite_merchant:
path: /favorite-merchant
controller: Lc\CaracoleBundle\Controller\Merchant\FavoriteMerchantController::favoriteMerchant

carac_switch_section:
path: /switch-section
controller: Lc\CaracoleBundle\Controller\Section\SwitchSectionAdminController::switchSection

+ 11
- 0
Resources/translations/admin.fr.yaml View File

@@ -12,6 +12,17 @@ menu:
flash_message:
settings_saved: Paramètres mis à jour

action:
favorite: Définir comme favoris

setting_definition:
merchant:
categories:
general: Général
settings:
url: URL absolue


entity:
default:
fields:

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

@@ -36,31 +36,31 @@
{% set merchant_current = merchant_resolver.getCurrent() %}

{% if(user.favoriteMerchant != merchant_current) %}
{# modal affichée uniquement si la sessionStorage.visit_merchant n'est pas défini (js) #}
{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% block id %}carac-modal-switch-merchant{% endblock %}
{% block size %}modal-lg{% endblock %}
{% block title %}
Switch merchant
Bienvenue sur le marchand <i>{{ merchant_current.getTitle() }}</i>
{% 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>
<p>Vous n'êtes pas sur votre marchand par favoris.</p>
{% endif %}
<p>Vous pouvez soit définir le marchand <strong>{{ merchant_current.getTitle() }}</strong>
comme marchand favoris ou simplement indiquer que vous visitez ce marchand pour aujourd'hui.</p>
{% 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>
{% set form_switch_merchant = carac_get_form_switch_merchant('admin', 'carac_favorite_merchant') %}
{% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }}
{{ form_end(form_switch_merchant) }}
<button id="carac-button-visit-merchant" type="button" class="btn btn-default"
data-dismiss="modal">Visiter</button>
{% endblock %}
{% endembed %}
{% endif %}

+ 2
- 15
Twig/TwigExtension.php View File

@@ -44,7 +44,6 @@ 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']),
);
}
@@ -59,13 +58,13 @@ class TwigExtension extends AbstractExtension
return $this->merchantRepository->findAll();
}

public function getFormSwitchMerchant($context = 'front')
public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_switch_merchant')
{
$form = $this->formFactory->create(
SwitchMerchantFormType::class,
null,
[
'action' => $this->urlGenerator->generate('carac_switch_merchant'),
'action' => $this->urlGenerator->generate($actionRoute),
'attr' => ['class' => 'switch-merchant'],
'context' => $context
]
@@ -73,18 +72,6 @@ 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(

Loading…
Cancel
Save