Преглед изворни кода

Switch merchant et section

feature/ticket
Guillaume пре 3 година
родитељ
комит
50ce4eb410
11 измењених фајлова са 178 додато и 4 уклоњено
  1. +1
    -1
      Controller/Merchant/SwitchMerchantController.php
  2. +39
    -0
      Controller/Section/SwitchSectionAdminController.php
  3. +1
    -1
      Form/Merchant/SwitchMerchantFormType.php
  4. +81
    -0
      Form/Section/SwitchSectionFormType.php
  5. +2
    -0
      Resources/assets/app/adminlte/common/app.common.js
  6. +0
    -0
      Resources/assets/app/adminlte/common/common.scss
  7. +1
    -0
      Resources/assets/app/switchmerchant/app.switchmerchant.js
  8. +25
    -0
      Resources/assets/app/switchmerchant/switchmerchant_admin.scss
  9. +4
    -0
      Resources/config/routes.yaml
  10. +8
    -2
      Resources/views/adminlte/layout.html.twig
  11. +16
    -0
      Twig/TwigExtension.php

+ 1
- 1
Controller/Merchant/SwitchMerchantController.php Прегледај датотеку

@@ -18,7 +18,7 @@ class SwitchMerchantController extends AbstractController
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$merchant = $form->get('merchants')->getData();
$merchant = $form->get('merchant')->getData();
$context = $form->get('context')->getData();

if ($merchant) {

+ 39
- 0
Controller/Section/SwitchSectionAdminController.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Controller\Section;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class SwitchSectionAdminController extends AbstractController
{

public function switchSection(
Request $request,
EntityManagerInterface $em,
MerchantResolver $merchantResolver,
SectionRepository $sectionRepository
) {
$form = $this->createForm(SwitchSectionFormType::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$idSection = $form->get('id_section')->getData();
$section = $sectionRepository->find($idSection);
$userMerchant = $merchantResolver->getUserMerchant();

if ($section && $userMerchant) {
$userMerchant->setCurrentAdminSection($section);
$em->update($section);
$em->flush();
}

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

+ 1
- 1
Form/Merchant/SwitchMerchantFormType.php Прегледај датотеку

@@ -29,7 +29,7 @@ class SwitchMerchantFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'merchants',
'merchant',
EntityType::class,
[
'class' => $this->em->getEntityName(MerchantInterface::class),

+ 81
- 0
Form/Section/SwitchSectionFormType.php Прегледај датотеку

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

namespace Lc\CaracoleBundle\Form\Section;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
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\ButtonType;
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;

class SwitchSectionFormType extends AbstractType
{
protected $em;
protected $translatorAdmin;
protected $sectionResolver;

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

public function buildForm(FormBuilderInterface $builder, array $options)
{
$section = $options['section'];
$currentSection = $this->sectionResolver->getCurrent();

$builder->add(
'id_section',
HiddenType::class,
[
'data' => $section ? $section->getId() : null
]
);

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

$builder->add(
'submit',
SubmitType::class,
[
'label' => $section ? $section->getTitle() : '',
'attr' => [
'class' => $classButton,
'style' => $styleButton,
]
]
);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'section' => null,
]
);
}

}

+ 2
- 0
Resources/assets/app/adminlte/common/app.common.js Прегледај датотеку

@@ -0,0 +1,2 @@

import './common.scss' ;

+ 0
- 0
Resources/assets/app/adminlte/common/common.scss Прегледај датотеку


+ 1
- 0
Resources/assets/app/switchmerchant/app.switchmerchant.js Прегледај датотеку

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

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




+ 25
- 0
Resources/assets/app/switchmerchant/switchmerchant_admin.scss Прегледај датотеку

@@ -0,0 +1,25 @@

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

.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 ;
}
}
}
}

+ 4
- 0
Resources/config/routes.yaml Прегледај датотеку

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

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


+ 8
- 2
Resources/views/adminlte/layout.html.twig Прегледај датотеку

@@ -7,13 +7,19 @@
<ul class="navbar-nav">
{% for section in carac_get_sections() %}
<li class="nav-item d-none d-sm-inline-block">
<a href="#" class="nav-link">{{ section.title }}</a>
{% set form_switch_section = carac_get_form_switch_section(section) %}
{% form_theme form_switch_section '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_section) }}
{{ form(form_switch_section) }}
{{ form_end(form_switch_section) }}
</li>
{% endfor %}
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i>
{% set form_switch_merchant = carac_get_form_switch_merchant('admin') %}
{% 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) }}

+ 16
- 0
Twig/TwigExtension.php Прегледај датотеку

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

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\SovBundle\Translation\TranslatorAdmin;
@@ -42,6 +43,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_section', [$this, 'getFormSwitchSection']),
);
}

@@ -68,4 +70,18 @@ class TwigExtension extends AbstractExtension
);
return $form->createView();
}

public function getFormSwitchSection($section)
{
$form = $this->formFactory->create(
SwitchSectionFormType::class,
null,
[
'action' => $this->urlGenerator->generate('carac_switch_section'),
'attr' => ['class' => 'switch-section'],
'section' => $section,
]
);
return $form->createView();
}
}

Loading…
Откажи
Сачувај