Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Grid Functionality #206

Merged
merged 23 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions config/grid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false


Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearchInterface:
class: Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearch


Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapperInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Mapper\ColumnMapper

Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridService

Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnService

Pimcore\Bundle\StudioBackendBundle\Grid\Service\ColumnDefinitionLoaderInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnDefinitionLoader

Pimcore\Bundle\StudioBackendBundle\Grid\Service\ColumnResolverLoaderInterface:
class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnResolverLoader

#
# Column Definitions
#

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\IntegerDefinition:
tags: [ 'pimcore.studio_backend.grid_column_definition' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\StringDefinition:
tags: [ 'pimcore.studio_backend.grid_column_definition' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\DatetimeDefinition:
tags: [ 'pimcore.studio_backend.grid_column_definition' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\ImageDefinition:
tags: [ 'pimcore.studio_backend.grid_column_definition' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\FileSizeDefinition:
tags: [ 'pimcore.studio_backend.grid_column_definition' ]

#
# Column Resolver
#

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\StringResolver:
tags: [ 'pimcore.studio_backend.grid_column_resolver' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\IntegerResolver:
tags: [ 'pimcore.studio_backend.grid_column_resolver' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\FileSizeResolver:
tags: [ 'pimcore.studio_backend.grid_column_resolver' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\DatetimeResolver:
tags: [ 'pimcore.studio_backend.grid_column_resolver' ]

Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\ImageResolver:
tags: [ 'pimcore.studio_backend.grid_column_resolver' ]
74 changes: 74 additions & 0 deletions src/Asset/Controller/Grid/Configuration/GetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Grid\Configuration;

use OpenApi\Attributes\Get;
use OpenApi\Attributes\JsonContent;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class GetController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly GridServiceInterface $gridService,
) {
parent::__construct($serializer);
}

/**
* @throws NotFoundException|SearchException
*/
#[Route('/assets/grid/configuration', name: 'pimcore_studio_api_get_asset_grid_configuration', methods: ['GET'])]
#[IsGranted(UserPermissions::ASSETS->value)]
#[Get(
path: self::API_PATH . '/assets/grid/configuration',
operationId: 'getAssetGridConfiguration',
description: 'Get assets grid configuration',
summary: 'Get default assets grid configuration',
tags: [Tags::Grid->name]
)]
#[SuccessResponse(
description: 'Grid configuration',
content: new JsonContent(
ref: Configuration::class
)
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
])]
public function getAssetGridConfiguration(): JsonResponse
{
return $this->jsonResponse($this->gridService->getAssetGridConfiguration());
}
}
77 changes: 77 additions & 0 deletions src/Asset/Controller/Grid/GetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Grid;

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Property\GridCollection;
use Pimcore\Bundle\StudioBackendBundle\Grid\Attributes\Request\GridRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class GetController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly GridServiceInterface $gridService,
) {
parent::__construct($serializer);
}

/**
* @throws InvalidArgumentException
*/
#[Route('/assets/grid', name: 'pimcore_studio_api_get_asset_grid', methods: ['POST'])]
#[IsGranted(UserPermissions::ASSETS->value)]
#[Post(
path: self::API_PATH . '/assets/grid',
operationId: 'getAssetGrid',
description: 'Get assets for grid',
summary: 'Get assets for grid',
tags: [Tags::Grid->name]
)]
#[GridRequestBody]
#[SuccessResponse(
description: 'Grid data',
content: new CollectionJson(
collection: new GridCollection()
)
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
])]
public function getAssetGrid(#[MapRequestPayload] GridParameter $gridParameter): JsonResponse
{
return $this->jsonResponse($this->gridService->getAssetGrid($gridParameter));
}
}
49 changes: 49 additions & 0 deletions src/DataIndex/Grid/GridSearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\AssetSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResult;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter;
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface;
use Pimcore\Model\User;

/**
* @internal
*/
final readonly class GridSearch implements GridSearchInterface
{
public function __construct(
private SecurityServiceInterface $securityService,
private AssetSearchServiceInterface $assetSearchService,
) {
}

public function searchAssets(GridParameter $gridParameter): AssetSearchResult
{
// TODO Try to repurpose filter concept from data-index
$search = new AssetSearch();
/** @var User $user */
$user = $this->securityService->getCurrentUser();
$search->setUser($user);
$search->addModifier(new ParentIdFilter($gridParameter->getFolderId()));

return $this->assetSearchService->search($search);
}
}
28 changes: 28 additions & 0 deletions src/DataIndex/Grid/GridSearchInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResult;
use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter;

/**
* @internal
*/
interface GridSearchInterface
{
public function searchAssets(GridParameter $gridParameter): AssetSearchResult;
}
49 changes: 49 additions & 0 deletions src/DependencyInjection/CompilerPass/GridColumnDefinitionPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass;

use Pimcore\Bundle\StudioBackendBundle\Exception\MustImplementInterfaceException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnDefinitionLoader;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\MustImplementInterfaceTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
final readonly class GridColumnDefinitionPass implements CompilerPassInterface
{
use MustImplementInterfaceTrait;

/**
* @throws MustImplementInterfaceException
*/
public function process(ContainerBuilder $container): void
{
$taggedServices = array_keys(
[
... $container->findTaggedServiceIds(TaggedIteratorColumnDefinitionLoader::COLUMN_DEFINITION_TAG),

]
);

foreach ($taggedServices as $environmentType) {
$this->checkInterface($environmentType, ColumnDefinitionInterface::class);
}
}
}
49 changes: 49 additions & 0 deletions src/DependencyInjection/CompilerPass/GridColumnResolverPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DependencyInjection\CompilerPass;

use Pimcore\Bundle\StudioBackendBundle\Exception\MustImplementInterfaceException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\Loader\TaggedIteratorColumnResolverLoader;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\MustImplementInterfaceTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
final readonly class GridColumnResolverPass implements CompilerPassInterface
{
use MustImplementInterfaceTrait;

/**
* @throws MustImplementInterfaceException
*/
public function process(ContainerBuilder $container): void
{
$taggedServices = array_keys(
[
... $container->findTaggedServiceIds(TaggedIteratorColumnResolverLoader::COLUMN_RESOLVER_TAG),

]
);

foreach ($taggedServices as $environmentType) {
$this->checkInterface($environmentType, ColumnResolverInterface::class);
}
}
}
Loading
Loading