From d34ce1b5858253d0c1a4b4418f9aed6a3eac3e1b Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Tue, 25 May 2021 15:20:32 +0200 Subject: [PATCH] backports murph-skeleton --- assets/css/admin.scss | 21 ++++++++-- config/packages/app.yaml | 13 ++++++ core/Controller/Site/NodeAdminController.php | 5 +++ core/DependencyInjection/Configuration.php | 13 ++++++ core/Form/Site/NodeType.php | 18 ++++++--- core/Site/ControllerConfiguration.php | 38 ++++++++++++++++++ core/Site/ControllerLocator.php | 42 ++++++++++++++++++++ core/Site/PageLocator.php | 2 +- 8 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 core/Site/ControllerConfiguration.php create mode 100644 core/Site/ControllerLocator.php diff --git a/assets/css/admin.scss b/assets/css/admin.scss index e3cd170..49c5041 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -12,7 +12,6 @@ $pagination-bg: #ffffff !default; $pagination-active-color: #ffffff !default; $pagination-active-bg: #343a40 !default; -@import "~simplemde/dist/simplemde.min.css"; @import "~choices.js/src/styles/choices.scss"; @import "~bootstrap/scss/bootstrap.scss"; @import "~@fortawesome/fontawesome-free/css/all.css"; @@ -96,9 +95,9 @@ body { padding-right: 25px; } -.thead-light { +.table .thead-light { a, th { - color: #333333; + color: map-get($theme-colors, 'dark-blue'); } } @@ -112,8 +111,21 @@ tr.table-primary-light { white-space: nowrap; } +.table tr { + td { + transition: border 500ms ease-out; + border-bottom: 1px solid #dee2e6; + } + + &:hover { + td { + border-bottom: 1px solid #a8aaac; + } + } +} + .bg-dark-blue { - background: #242b3b; + background: map-get($theme-colors, 'dark-blue'); color: #fff; .nav-item-label { @@ -132,6 +144,7 @@ tr.table-primary-light { } } + .sidebar { width: 260px; display: inline-block; diff --git a/config/packages/app.yaml b/config/packages/app.yaml index b69f16e..dd0caab 100644 --- a/config/packages/app.yaml +++ b/config/packages/app.yaml @@ -2,6 +2,19 @@ core: site: name: "Blog" logo: "build/images/core/logo.svg" + controllers: + - {name: 'PostController::posts', action: 'App\Controller\Blog\PostController::posts'} + - {name: 'CategoryController::categories', action: 'App\Controller\Blog\CategoryController::categories'} + - {name: 'PostController::category', action: 'App\Controller\Blog\PostController::category'} + - {name: 'PostController::search', action: 'App\Controller\Blog\PostController::search'} + - {name: 'LinkController:links', action: 'App\Controller\LinkController:links'} + - {name: 'ContactController::contact', action: 'App\Controller\ContactController::contact'} + - {name: 'PostController::post', action: 'App\Controller\Blog\PostController::post'} + - {name: '\Blog\PostController::rss', action: 'App\Controller\Blog\PostController::rss'} + - {name: 'BotController::formWithoutJavascript', action: 'App\Controller\BotController::formWithoutJavascript'} + - {name: 'LinkController:rss', action: 'App\Controller\LinkController:rss'} + - {name: 'PostController::jsonApi', action: 'App\Controller\Blog\PostController::jsonApi'} + - {name: 'TextController:text', action: 'App\Controller\TextController:text'} pages: App\Entity\Page\SimplePage: name: 'Page de contenu' diff --git a/core/Controller/Site/NodeAdminController.php b/core/Controller/Site/NodeAdminController.php index 940c2ea..d6dc8df 100644 --- a/core/Controller/Site/NodeAdminController.php +++ b/core/Controller/Site/NodeAdminController.php @@ -20,6 +20,7 @@ use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use App\Core\Site\ControllerLocator; /** * @Route("/admin/site/node") @@ -36,11 +37,13 @@ class NodeAdminController extends AdminController EntityManager $entityManager, NodeRepository $nodeRepository, PageLocator $pageLocator, + ControllerLocator $controllerLocator, Request $request ): Response { $entity = $factory->create($node->getMenu()); $form = $this->createForm(EntityType::class, $entity, [ 'pages' => $pageLocator->getPages(), + 'controllers' => $controllerLocator->getControllers(), 'navigation' => $node->getMenu()->getNavigation(), ]); @@ -105,10 +108,12 @@ class NodeAdminController extends AdminController EntityManager $entityManager, PageFactory $pageFactory, PageLocator $pageLocator, + ControllerLocator $controllerLocator, Request $request ): Response { $form = $this->createForm(EntityType::class, $entity, [ 'pages' => $pageLocator->getPages(), + 'controllers' => $controllerLocator->getControllers(), 'navigation' => $entity->getMenu()->getNavigation(), ]); diff --git a/core/DependencyInjection/Configuration.php b/core/DependencyInjection/Configuration.php index 199223b..62a1e83 100644 --- a/core/DependencyInjection/Configuration.php +++ b/core/DependencyInjection/Configuration.php @@ -23,6 +23,18 @@ class Configuration implements ConfigurationInterface ->isRequired() ->cannotBeEmpty() ->end() + ->arrayNode('controllers') + ->prototype('array') + ->children() + ->scalarNode('name') + ->cannotBeEmpty() + ->end() + ->scalarNode('action') + ->cannotBeEmpty() + ->end() + ->end() + ->end() + ->end() ->arrayNode('pages') ->prototype('array') ->children() @@ -42,6 +54,7 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->end() + ->end() ->end() ->end() ->end() diff --git a/core/Form/Site/NodeType.php b/core/Form/Site/NodeType.php index 7998567..ed00e97 100644 --- a/core/Form/Site/NodeType.php +++ b/core/Form/Site/NodeType.php @@ -89,15 +89,20 @@ class NodeType extends AbstractType $builder->add( 'controller', - TextType::class, + ChoiceType::class, [ 'label' => 'Controller', 'required' => false, - 'help' => 'Leave blank to use the default one. Example: App\\Controller\\FooController::barAction', - 'attr' => [ - ], - 'constraints' => [ - ], + 'help' => 'Leave blank to use the default one', + 'choices' => call_user_func(function () use ($options) { + $choices = []; + + foreach ($options['controllers'] as $controller) { + $choices[$controller->getName()] = $controller->getAction(); + } + + return $choices; + }), ] ); @@ -259,6 +264,7 @@ class NodeType extends AbstractType $resolver->setDefaults([ 'data_class' => Node::class, 'pages' => [], + 'controllers' => [], 'navigation' => null, ]); } diff --git a/core/Site/ControllerConfiguration.php b/core/Site/ControllerConfiguration.php new file mode 100644 index 0000000..0e00d49 --- /dev/null +++ b/core/Site/ControllerConfiguration.php @@ -0,0 +1,38 @@ + + */ +class ControllerConfiguration +{ + protected string $name; + protected string $action; + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + + public function getName(): string + { + return $this->name; + } + + public function setAction(string $action): self + { + $this->action = $action; + + return $this; + } + + public function getAction(): string + { + return $this->action; + } +} diff --git a/core/Site/ControllerLocator.php b/core/Site/ControllerLocator.php new file mode 100644 index 0000000..5956ca7 --- /dev/null +++ b/core/Site/ControllerLocator.php @@ -0,0 +1,42 @@ + + */ +class ControllerLocator +{ + protected array $params; + protected array $controllers = []; + + public function __construct(ParameterBagInterface $bag) + { + $this->params = $bag->get('core'); + $this->loadControllers(); + } + + public function getControllers(): array + { + return $this->controllers; + } + + protected function loadControllers(): void + { + $params = $this->params['site']['controllers'] ?? []; + + foreach ($params as $conf) { + $controllerConfiguration = new ControllerConfiguration(); + $controllerConfiguration + ->setName($conf['name']) + ->setAction($conf['action']) + ; + + $this->controllers[$conf['action']] = $controllerConfiguration; + } + } +} diff --git a/core/Site/PageLocator.php b/core/Site/PageLocator.php index bd08636..7780470 100644 --- a/core/Site/PageLocator.php +++ b/core/Site/PageLocator.php @@ -12,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class PageLocator { protected array $params; - protected array $pages; + protected array $pages = []; public function __construct(ParameterBagInterface $bag) {