Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkrovitch committed Oct 26, 2023
1 parent 08bb0ee commit 94f170e
Show file tree
Hide file tree
Showing 119 changed files with 1,496 additions and 783 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/c8e28654-44c7-46f3-9450-497e37bda3d0/mini.png)](https://insight.sensiolabs.com/projects/c8e28654-44c7-46f3-9450-497e37bda3d0)
[![Total Downloads](https://poser.pugx.org/lag/adminbundle/downloads)](https://packagist.org/packages/lag/adminbundle)

# TODO
- validation groups
- serialization
- set nullable resource arrays to add difference between empty set array and not set array
- check validation php attributes of metadata
- batch actions

# AdminBundle
The AdminBundle let you create a **flexible** and **robust backoffice** on any Symfony application, with simple `yaml` configuration.

Expand Down
1 change: 1 addition & 0 deletions assets/scss/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import "partials/list";
@import "partials/login";
@import "partials/header";
@import "partials/table";
7 changes: 7 additions & 0 deletions assets/scss/partials/_table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.admin-table.table {
@for $i from 1 through 3 {
.column-button-#{$i} {
min-width: $i * 130px;
}
}
}
39 changes: 5 additions & 34 deletions config/services/controllers.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,21 @@
services:
LAG\AdminBundle\Controller\Security\Login:
arguments:
$formFactory: '@form.factory'
$environment: '@twig'
$authenticationUtils: '@security.authentication_utils'
tags: ['controller.service_arguments']

LAG\AdminBundle\Controller\Index:
arguments:
$uriVariablesExtractor: '@lag_admin.request_uri_variables_extractor'
$contextProvider: '@lag_admin.request.context_provider'
$dataProvider: '@lag_admin.state.data_provider'
$formFactory: '@form.factory'
$gridFactory: '@lag_admin.grid.factory'
$environment: '@twig'
tags: ['controller.service_arguments']

LAG\AdminBundle\Controller\Create:
arguments:
$uriVariablesExtractor: '@lag_admin.request_uri_variables_extractor'
$contextProvider: '@lag_admin.request.context_provider'
$dataProvider: '@lag_admin.state.data_provider'
$dataProcessor: '@lag_admin.state.data_processor'
$formFactory: '@form.factory'
$environment: '@twig'
$urlGenerator: '@lag_admin.routing.url_generator'
tags: [ 'controller.service_arguments' ]

LAG\AdminBundle\Controller\Update:
LAG\AdminBundle\Controller\Resource\ResourceController:
arguments:
$uriVariablesExtractor: '@lag_admin.request_uri_variables_extractor'
$contextProvider: '@lag_admin.request.context_provider'
$dataProvider: '@lag_admin.state.data_provider'
$dataProcessor: '@lag_admin.state.data_processor'
$formFactory: '@form.factory'
$environment: '@twig'
$urlGenerator: '@lag_admin.routing.url_generator'
$responseHandler: '@RedirectionHandler'
tags: ['controller.service_arguments']

LAG\AdminBundle\Controller\Delete:
LAG\AdminBundle\Controller\Resource\ResourceCollectionController:
arguments:
$uriVariablesExtractor: '@lag_admin.request_uri_variables_extractor'
$contextProvider: '@lag_admin.request.context_provider'
$dataProvider: '@lag_admin.state.data_provider'
$dataProcessor: '@lag_admin.state.data_processor'
$formFactory: '@form.factory'
$gridFactory: '@lag_admin.grid.factory'
$environment: '@twig'
$urlGenerator: '@lag_admin.routing.url_generator'
tags: [ 'controller.service_arguments' ]
tags: ['controller.service_arguments']
27 changes: 18 additions & 9 deletions config/services/event_listeners.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
services:
lag_admin.resource.dispatcher: '@LAG\AdminBundle\Event\Dispatcher\ResourceEventDispatcher'

# Resource listeners
LAG\AdminBundle\EventListener\Resource\ResourceCreateListener:
arguments:
$routeNameGenerator: '@lag_admin.routing.route_name_generator'
$applicationConfiguration: '@lag_admin.application'
tags:
- { name: kernel.event_listener, event: lag_admin.resource.create, priority: 255 }
- {name: kernel.event_listener, event: lag_admin.resource.create, priority: 255}

LAG\AdminBundle\EventListener\Resource\ResourceCreatedListener:
arguments:
$routeNameGenerator: '@lag_admin.routing.route_name_generator'
tags:
- { name: kernel.event_listener, event: lag_admin.resource.created, priority: 255 }
- {name: kernel.event_listener, event: lag_admin.resource.created, priority: 255}

# Operation listeners
LAG\AdminBundle\EventListener\Operation\OperationCreateListener:
LAG\AdminBundle\EventListener\Operation\DefaultOperationListener:
tags:
- { name: kernel.event_listener, event: lag_admin.operation.create, priority: 255 }
- {name: kernel.event_listener, event: lag_admin.operation.create, priority: 255}

LAG\AdminBundle\EventListener\Operation\OperationPathListener:
tags:
- { name: kernel.event_listener, event: lag_admin.operation.create, priority: -255 }
- {name: kernel.event_listener, event: lag_admin.operation.create, priority: -255}

# Security listeners
LAG\AdminBundle\EventListener\Security\RequestListener:
LAG\AdminBundle\EventListener\Security\OperationPermissionListener:
arguments:
$resourceContext: '@lag_admin.resource.context'
$security: '@security.helper'
tags:
- { name: kernel.event_listener, event: kernel.controller_arguments, priority: 0 }
- {name: kernel.event_listener, event: kernel.request}

# Data listeners
LAG\AdminBundle\EventListener\Data\TimestampableListener:
tags:
- { name: kernel.event_listener, event: lag_admin.data.process, priority: 255 }
- {name: kernel.event_listener, event: lag_admin.data.process, priority: 255}

LAG\AdminBundle\EventListener\Data\SlugListener:
arguments:
$generator: '@lag_admin.slug.generator'
$mapping: '@LAG\AdminBundle\Slug\Mapping\SlugMapping'
tags:
- { name: kernel.event_listener, event: lag_admin.data.process, priority: 255 }
- {name: kernel.event_listener, event: lag_admin.data.process, priority: 255}

# Dispatcher
LAG\AdminBundle\Event\Dispatcher\ResourceEventDispatcherInterface: '@LAG\AdminBundle\Event\Dispatcher\ResourceEventDispatcher'
LAG\AdminBundle\Event\Dispatcher\ResourceEventDispatcher:
arguments:
$eventDispatcher: '@event_dispatcher'
6 changes: 6 additions & 0 deletions config/services/forms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ services:

LAG\AdminBundle\Form\Type\Image\ImageType:
tags: [ 'form.type' ]

LAG\AdminBundle\Form\Type\Image\ImageChoiceType:
arguments:
$transformer: '@LAG\AdminBundle\Form\Transformer\ImageFileToArrayTransformer'
tags: [ 'form.type' ]

LAG\AdminBundle\Form\Type\Resource\ResourceChoiceType:
arguments:
$registry: '@lag_admin.resource.registry'
$dataProvider: '@lag_admin.state.data_provider'

### Form Extensions ###
LAG\AdminBundle\Form\Extension\CollectionTypeExtension:
tags: ['form.type_extension']
Expand Down
6 changes: 3 additions & 3 deletions config/services/knp_menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ services:
$routeNameGenerator: '@lag_admin.routing.route_name_generator'
$eventDispatcher: '@event_dispatcher'
tags:
- { name: knp_menu.menu_builder, method: build, alias: contextual }
- {name: knp_menu.menu_builder, method: build, alias: contextual}

LAG\AdminBundle\Bridge\KnpMenu\Builder\UserMenuBuilder:
arguments:
$factory: '@knp_menu.factory'
$eventDispatcher: '@event_dispatcher'
tags:
- { name: knp_menu.menu_builder, method: build, alias: user }
- {name: knp_menu.menu_builder, method: build, alias: user}

LAG\AdminBundle\Bridge\KnpMenu\Builder\ResourceMenuBuilder:
arguments:
Expand All @@ -24,4 +24,4 @@ services:
$routeNameGenerator: '@lag_admin.routing.route_name_generator'
$eventDispatcher: '@event_dispatcher'
tags:
- { name: knp_menu.menu_builder, method: build, alias: resource }
- {name: knp_menu.menu_builder, method: build, alias: resource}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ services:
arguments:
$registry: '@doctrine'
tags:
- { name: lag_admin.data_provider, identifier: doctrine }
- {name: lag_admin.data_provider, identifier: doctrine, priority: 0}

# Data providers
LAG\AdminBundle\Bridge\Doctrine\ORM\State\ORMDataProcessor:
arguments:
$registry: '@doctrine'
tags:
- { name: lag_admin.data_processor, identifier: doctrine }
- {name: lag_admin.data_processor, identifier: doctrine, priority: 0}

# Event listeners
LAG\AdminBundle\Bridge\Doctrine\ORM\EventListener\ResourceCreateListener:
arguments:
$propertyFactory: '@lag_admin.orm.property_factory'
tags:
- { name: kernel.event_listener, event: lag_admin.resource.create, priority: 200 }
- {name: kernel.event_listener, event: lag_admin.resource.create, priority: 200}

LAG\AdminBundle\Bridge\Doctrine\ORM\EventListener\OperationCreateListener:
arguments:
$filterFactory: '@lag_admin.filter.factory'
tags:
- { name: kernel.event_listener, event: lag_admin.operation.create, priority: 256 }
- {name: kernel.event_listener, event: lag_admin.operation.create, priority: 256}

# Property provider
lag_admin.orm.property_factory: '@LAG\AdminBundle\Bridge\Doctrine\ORM\Metadata\MetadataPropertyFactoryInterface'
Expand Down
28 changes: 26 additions & 2 deletions config/services/request.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
services:
# Controller parameter resolvers
LAG\AdminBundle\Request\Resolver\ResourceValueResolver:
arguments:
$resourceContext: '@lag_admin.resource.context'
tags:
- { name: controller.argument_value_resolver, priority: 255 }
- {name: controller.argument_value_resolver, priority: 255}

lag_admin.request.parameters_extractor: '@LAG\AdminBundle\Request\Extractor\ParametersExtractorInterface'
LAG\AdminBundle\Request\Extractor\ParametersExtractorInterface:
Expand All @@ -13,6 +14,29 @@ services:
LAG\AdminBundle\Request\Uri\UriVariablesExtractorInterface:
class: LAG\AdminBundle\Request\Uri\UriVariablesExtractor

# Request context resolvers
lag_admin.request.context_provider: '@LAG\AdminBundle\Request\Context\ContextProviderInterface'
LAG\AdminBundle\Request\Context\ContextProviderInterface:
class: LAG\AdminBundle\Request\Context\ContextProvider
class: LAG\AdminBundle\Request\Context\CompositeContextProvider
arguments:
$contextProviders: !tagged_iterator lag_admin.request_context_provider

LAG\AdminBundle\Request\Context\SortingContextProvider:
tags:
- {name: lag_admin.request_context_provider, priority: 255}

LAG\AdminBundle\Request\Context\AjaxContextProvider:
tags:
- {name: lag_admin.request_context_provider, priority: 255}

LAG\AdminBundle\Request\Context\FilterContextProvider:
arguments:
$formFactory: '@form.factory'
tags:
- {name: lag_admin.request_context_provider, priority: 255}

# Redirection handler
LAG\AdminBundle\Response\Handler\ResponseHandlerInterface:
class: LAG\AdminBundle\Response\Handler\ResponseHandler
arguments:
$urlGenerator: '@LAG\AdminBundle\Routing\UrlGenerator\UrlGenerator'
2 changes: 1 addition & 1 deletion config/services/routing.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
LAG\AdminBundle\Routing\Loader\RoutingLoader:
LAG\AdminBundle\Routing\Loader\ResourceRoutingLoader:
arguments:
$pathGenerator: '@lag_admin.routing.path_generator'
$resourceRegistry: '@lag_admin.resource.registry'
Expand Down
6 changes: 3 additions & 3 deletions config/services/security.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
lag_admin.security.helper: '@LAG\AdminBundle\Security\Helper\SecurityHelper'
LAG\AdminBundle\Security\Helper\SecurityHelper:
# Voters
LAG\AdminBundle\Security\Voter\OperationPermissionVoter:
arguments:
$security: '@security.helper'
$registry: '@lag_admin.resource.registry'
tags: ['security.voter']
2 changes: 1 addition & 1 deletion config/services/slug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:

LAG\AdminBundle\Slug\Generator\SimpleSlugGenerator:
tags:
- { name: lag_admin.slug_generator, generator: default}
- {name: lag_admin.slug_generator, generator: default}

# Mapping
LAG\AdminBundle\Slug\Mapping\SlugMappingInterface: '@LAG\AdminBundle\Slug\Mapping\SlugMapping'
Expand Down
26 changes: 15 additions & 11 deletions config/services/state.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
services:
lag_admin.state.data_provider: '@LAG\AdminBundle\State\DataProviderInterface'
LAG\AdminBundle\State\DataProviderInterface:
class: LAG\AdminBundle\State\CompositeDataProvider
lag_admin.state.data_provider: '@LAG\AdminBundle\State\Provider\DataProviderInterface'
lag_admin.state.data_processor: '@LAG\AdminBundle\State\Processor\DataProcessorInterface'

# Data providers
LAG\AdminBundle\State\Provider\DataProviderInterface:
class: LAG\AdminBundle\State\Provider\CompositeDataProvider
arguments:
$providers: !tagged_iterator lag_admin.data_provider

lag_admin.state.data_processor: '@LAG\AdminBundle\State\DataProcessorInterface'
LAG\AdminBundle\State\DataProcessorInterface:
class: LAG\AdminBundle\State\CompositeDataProcessor
LAG\AdminBundle\State\Provider\JsonDataProviderDecorator:
decorates: lag_admin.state.data_provider
arguments:
$processors: !tagged_iterator lag_admin.data_processor
$decorated: '@.inner'
$serializer: '@serializer'

LAG\AdminBundle\State\EventDataProcessor:
decorates: 'lag_admin.state.data_processor'
# Data processors
LAG\AdminBundle\State\Processor\DataProcessorInterface:
class: LAG\AdminBundle\State\Processor\CompositeDataProcessor
arguments:
$decorated: '@.inner'
$eventDispatcher: '@event_dispatcher'
$processors: !tagged_iterator lag_admin.data_processor
$eventDispatcher: '@lag_admin.resource.dispatcher'
12 changes: 11 additions & 1 deletion public/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/admin.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Bridge/Doctrine/ORM/Metadata/MetadataPropertyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace LAG\AdminBundle\Bridge\Doctrine\ORM\Metadata;

use LAG\AdminBundle\Metadata\Property\Boolean;
use LAG\AdminBundle\Metadata\Property\Collection;
use LAG\AdminBundle\Metadata\Property\Count;
use LAG\AdminBundle\Metadata\Property\Date;
use LAG\AdminBundle\Metadata\Property\Text;
use function Symfony\Component\String\u;

class MetadataPropertyFactory implements MetadataPropertyFactoryInterface
{
Expand All @@ -32,6 +34,8 @@ public function createProperties(string $resourceClass): array
$properties[$fieldName] = new Date($fieldName);
} elseif ($fieldType === 'boolean') {
$properties[$fieldName] = new Boolean($fieldName);
} elseif (u($fieldType)->containsAny(['array', 'json'])) {
$properties[$fieldName] = new Collection($fieldName);
} else {
$properties[$fieldName] = new Text($fieldName);
}
Expand Down
16 changes: 14 additions & 2 deletions src/Bridge/Doctrine/ORM/QueryBuilder/QueryBuilderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ public function addOrderBy(array $orderBy): self
}
} else {
if ($this->metadata->hasField($propertyPath->toString())) {
$this->queryBuilder->addOrderBy($propertyPath->prepend($this->rootAlias.'.')->toString(), $order);
$this->queryBuilder->addOrderBy(
$propertyPath->prepend($this->rootAlias . '.')->toString(),
$order
);
}

if ($this->metadata->isSingleValuedAssociation($propertyPath->toString())) {
$joinProperty = $propertyPath->prepend('.')->prepend($this->rootAlias)->toString();

if (!$this->hasJoin($propertyPath->toString())) {
$this->queryBuilder->innerJoin($joinProperty, $propertyPath->toString());
}
// TODO wip order by join
}
}
}
Expand Down Expand Up @@ -139,7 +151,7 @@ private function hasJoin(string $joinAlias): bool
{
$dqlPart = $this->queryBuilder->getDQLPart('join');

foreach ($dqlPart as $rootAlias => $joins) {
foreach ($dqlPart as $joins) {
/** @var Join $join */
foreach ($joins as $join) {
if ($join->getAlias() === $joinAlias.'_resource') {
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/ORM/State/ORMDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use LAG\AdminBundle\Metadata\Delete;
use LAG\AdminBundle\Metadata\OperationInterface;
use LAG\AdminBundle\Metadata\Update;
use LAG\AdminBundle\State\DataProcessorInterface;
use LAG\AdminBundle\State\Processor\DataProcessorInterface;

class ORMDataProcessor implements DataProcessorInterface
{
Expand Down
Loading

0 comments on commit 94f170e

Please sign in to comment.