瀏覽代碼

Switch hubs

reduction
Guillaume 4 年之前
父節點
當前提交
8834ee4495
共有 6 個文件被更改,包括 292 次插入1 次删除
  1. +24
    -1
      ShopBundle/Controller/Admin/AdminController.php
  2. +31
    -0
      ShopBundle/Controller/Admin/MerchantController.php
  3. +3
    -0
      ShopBundle/Resources/config/shop_routes.yaml
  4. +8
    -0
      ShopBundle/Resources/public/css/backend/custom.css
  5. +10
    -0
      ShopBundle/Resources/public/js/backend/custom.js
  6. +216
    -0
      ShopBundle/Resources/views/backend/default/layout.html.twig

+ 24
- 1
ShopBundle/Controller/Admin/AdminController.php 查看文件

@@ -3,11 +3,11 @@
namespace Lc\ShopBundle\Controller\Admin;

use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
use Lc\ShopBundle\Context\MerchantInterface;
use Symfony\Component\Security\Core\Security;

class AdminController extends EasyAdminController
{

protected $security;

public function __construct(Security $security)
@@ -15,6 +15,29 @@ class AdminController extends EasyAdminController
$this->security = $security;
}

public function renderTemplate($actionName, $templatePath, array $parameters = [])
{
$parameters = array_merge(
$parameters,
$this->getTwigExtraParameters()
) ;

return parent::renderTemplate($actionName, $templatePath, $parameters) ;
}

public function getTwigExtraParameters()
{
$repositoryMerchant = $this->getDoctrine()->getRepository(MerchantInterface::class);
$merchants = $repositoryMerchant->findAll() ;

$user = $this->security->getUser() ;

return [
'merchants' => $merchants,
'current_merchant' => ($user && $user->getMerchant()) ? $user->getMerchant() : null,
] ;
}

public function updateEntity($entity)
{
$this->setUpdated($entity);

+ 31
- 0
ShopBundle/Controller/Admin/MerchantController.php 查看文件

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

namespace Lc\ShopBundle\Controller\Admin;

use Lc\ShopBundle\Context\MerchantInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

class MerchantController extends AdminController
{

public function switchMerchantAction(Request $request): RedirectResponse
{
$em = $this->getDoctrine()->getManager();
$idMerchant = $request->request->get('id_merchant') ;
$merchant = $this->getDoctrine()
->getRepository(MerchantInterface::class)
->find($idMerchant);

if($merchant) {
$user = $this->security->getUser() ;
$user->setMerchant($merchant) ;
$em->persist($user);
$em->flush() ;
}

return $this->redirect('admin/dashboard') ;
}

}


+ 3
- 0
ShopBundle/Resources/config/shop_routes.yaml 查看文件

@@ -1 +1,4 @@

switch_merchant:
path: /switch-merchant
controller: Lc\ShopBundle\Controller\Admin\MerchantController::switchMerchantAction

+ 8
- 0
ShopBundle/Resources/public/css/backend/custom.css 查看文件

@@ -0,0 +1,8 @@

#switch-merchant {
width: 200px ;
}

#switch-merchant select {
width: 100% ;
}

+ 10
- 0
ShopBundle/Resources/public/js/backend/custom.js 查看文件

@@ -0,0 +1,10 @@

jQuery(document).ready(function() {
custom_switch_merchants() ;
}) ;

function custom_switch_merchants() {
$('#switch-merchant select').change(function() {
$('#switch-merchant form').submit() ;
}) ;
}

+ 216
- 0
ShopBundle/Resources/views/backend/default/layout.html.twig 查看文件

@@ -0,0 +1,216 @@

<!DOCTYPE html>
<html lang="{{ app.request.locale|split('_')|first|default('en') }}" dir="{{ easyadmin_config('design.rtl') ? 'rtl' : 'ltr' }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="robots" content="noindex, nofollow, noarchive, nosnippet, noodp, noimageindex, notranslate, nocache" />
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<meta name="generator" content="EasyAdmin" />

<title>{% block page_title %}{{ block('content_title')|striptags|raw }}{% endblock %}</title>

{% block head_stylesheets %}
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/app.css') }}">
{% endblock %}

{% block head_custom_stylesheets %}
{% for css_asset in easyadmin_config('design.assets.css') %}
<link rel="stylesheet" href="{{ asset(css_asset) }}">
{% endfor %}
{% endblock head_custom_stylesheets %}

{% if easyadmin_config('design.brand_color') != 'hsl(230, 55%, 60%)' %}
<style>
:root { --color-primary: {{ easyadmin_config('design.brand_color') }}; }
</style>
{% endif %}

{% block head_favicon %}
{% set favicon = easyadmin_config('design.assets.favicon') %}
<link rel="icon" type="{{ favicon.mime_type }}" href="{{ asset(favicon.path) }}" />
{% endblock %}

{% block head_javascript %}
<script src="{{ asset('bundles/easyadmin/app.js') }}"></script>
{% endblock head_javascript %}

{% if easyadmin_config('design.rtl') %}
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/app.rtl.css') }}">
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/app-custom-rtl.css') }}">
{% endif %}
</head>

{% block body %}
<body id="{% block body_id %}{% endblock %}" class="easyadmin {% block body_class %}{% endblock %}">
<script>
document.body.classList.add(
'easyadmin-content-width-' + (localStorage.getItem('easyadmin/content/width') || 'normal'),
'easyadmin-sidebar-width-' + (localStorage.getItem('easyadmin/sidebar/width') || 'normal')
);
</script>

{% block wrapper_wrapper %}
<div class="wrapper">
{% block wrapper %}
<header class="main-header">
{% block header %}
<nav class="navbar" role="navigation">
<button id="navigation-toggler" type="button" aria-label="Toggle navigation">
<i class="fa fa-fw fa-bars"></i>
</button>

<div id="header-logo">
{% block header_logo %}
<a class="logo {{ easyadmin_config('site_name')|length > 14 ? 'logo-long' }}" title="{{ easyadmin_config('site_name')|striptags }}" href="{{ path('easyadmin') }}">
{{ easyadmin_config('site_name')|raw }}
</a>
{% endblock header_logo %}
</div>
</nav>


<div id="switch-merchant">
{% if is_granted('ROLE_ADMIN') %}
<form action="{{ path('switch_merchant') }}" method="post">
<select class="form-control" name="id_merchant">
{% for merchant in merchants %}
<option value="{{merchant.id}}" {% if current_merchant and current_merchant.id == merchant.id %}selected="selected"{% endif %}>{{merchant.title}}</option>
{% endfor %}
</select>
</form>
{% else %}
{% if current_merchant %}
{{ current_merchant.title }}
{% endif %}
{% endif %}
</div>

{% set _user_name = easyadmin_read_property(app.user, easyadmin_config('user.name_property_path'))|default('user.unnamed'|trans(domain = 'EasyAdminBundle')) %}
{% set _logout_path = easyadmin_logout_path() %}
{% set _user_has_logout = _logout_path is not empty %}
{% set _user_is_impersonated = is_granted('ROLE_PREVIOUS_ADMIN') %}
{% set _user_menu_content %}
<div class="popover-content-section user-details {{ _user_has_logout or _user_is_impersonated ? 'user-has-actions' }}">
<p class="small text-muted mb-0">{{ 'user.logged_in_as'|trans(domain = 'EasyAdminBundle') }}</p>
<p class="user-details-name">
{% if app.user|default(false) == false %}
{{ 'user.anonymous'|trans(domain = 'EasyAdminBundle') }}
{% else %}
{{ _user_name }}
{% endif %}
</p>
</div>

{% block user_menu %}
{% if _user_has_logout or _user_is_impersonated %}
<div class="popover-content-section user-menu">
{% if _user_has_logout %}
<a class="user-action user-action-logout" href="{{ _logout_path }}">{{ 'user.signout'|trans(domain = 'EasyAdminBundle') }}</a>
{% endif %}
{% if _user_is_impersonated %}
<a class="user-action user-action-exit-impersonation" href="?_switch_user=_exit">{{ 'user.exit_impersonation'|trans(domain = 'EasyAdminBundle') }}</a>
{% endif %}
</div>
{% endif %}
{% endblock user_menu %}
{% endset %}

<div class="content-top navbar-custom-menu">
{% block header_custom_menu %}
<div class="user user-menu-wrapper {{ _user_is_impersonated ? 'user-is-impersonated' }}" data-toggle="popover" data-placement="bottom" data-container=".user-menu-wrapper" data-content="{{ _user_menu_content|e('html_attr') }}" data-html="true">
{% if easyadmin_config('user.display_avatar') %}
{% set _avatar_image_path = easyadmin_read_property(app.user, easyadmin_config('user.avatar_property_path')) %}
{% if null == _avatar_image_path %}
<i class="fa fa-fw {{ app.user is not null ? 'fa-user-circle' : 'fa-user-times' }} user-avatar"></i>
{% else %}
<img class="user-avatar" src="{{ _avatar_image_path }}" />
{% endif %}
{% endif %}
{% if easyadmin_config('user.display_name') %}
<span class="user-name">{{ _user_name }}</span>
{% endif %}
</div>
{% endblock header_custom_menu %}
</div>
{% endblock header %}
</header>

<aside class="main-sidebar">
{% block sidebar %}
<section class="sidebar">
{% block main_menu_wrapper %}
{{ include([
_entity_config is defined ? _entity_config.templates.menu,
easyadmin_config('design.templates.menu'),
'@EasyAdmin/default/menu.html.twig'
]) }}
{% endblock main_menu_wrapper %}
</section>

{% endblock sidebar %}
</aside>

<div class="content-wrapper">
{% block flash_messages %}
{{ include(_entity_config is defined ? _entity_config.templates.flash_messages : '@EasyAdmin/default/flash_messages.html.twig') }}
{% endblock flash_messages %}

<div id="sidebar-resizer-handler" class="resizer-handler resizer-handler-left"></div>

{% block content %}
<div class="content">
{% block content_header_wrapper %}
{% set _has_content_help = _entity_config is defined and _entity_config[app.request.query.get('action')]['help']|default(false) %}
<section class="content-header {{ _has_content_help ? 'has-content-help' }}">
{% block content_header %}
<div class="d-flex flex-row justify-content-between align-content-center w-100">
<div class="content-header-title">
<h1 class="title">{% block content_title %}{% endblock %}</h1>
</div>

{% block global_actions_wrapper %}
<div class="global-actions">{% block global_actions %}{% endblock %}</div>
{% endblock %}
</div>

{% block content_help %}
{% if _entity_config is defined and _entity_config[app.request.query.get('action')]['help']|default(false) %}
<div class="content-header-help">
{{ _entity_config[app.request.query.get('action')]['help']|trans(domain = _entity_config.translation_domain)|raw }}
</div>
{% endif %}
{% endblock content_help %}
{% endblock content_header %}
</section>
{% endblock content_header_wrapper %}

<section id="main" class="content-body">
{% block main %}{% endblock %}
</section>

{% block content_footer_wrapper %}
<section class="content-footer">
{% block content_footer %}{% endblock %}
</section>
{% endblock %}
</div>
{% endblock content %}

<div id="content-resizer-handler" class="resizer-handler resizer-handler-right"></div>
</div>
{% endblock wrapper %}
</div>
{% endblock wrapper_wrapper %}

{% block body_javascript %}{% endblock body_javascript %}

{% block body_custom_javascript %}
{% for js_asset in easyadmin_config('design.assets.js') %}
<script src="{{ asset(js_asset) }}"></script>
{% endfor %}
{% endblock body_custom_javascript %}

</body>
{% endblock body %}
</html>

Loading…
取消
儲存