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

#253 [Grid] Differentiate between ColumnConfiguration and ColumnData #259

Merged
merged 9 commits into from
Jul 16, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ Swagger-ui is available at `/studio/api/docs` and the OpenApi Specification is a
## Documentation Overview

- [Installation](./doc/01_Installation.md)

- [Grid](./doc/03_Grid.md)
13 changes: 13 additions & 0 deletions doc/03_Grid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Grid

On the request level we have three main components for the grid: `Column`, `ColumnConfiguration` and `ColumnData`.

## Column
A column is a single column in the grid. It has a name, type and a locale. It is used to get the data for the column.
in addition, it has a configuration which can be used to configure the column, like the direction of the sorting

## ColumnConfiguration
A column configuration represents how the column should behave, for example if it should be sort-able or editable.

## ColumnData
A column data is the actual data for a column. It has a reference to the column and the actual data.
8 changes: 6 additions & 2 deletions src/Asset/Attributes/Request/CsvExportRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constants\Csv;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;

/**
* @internal
Expand All @@ -36,7 +36,11 @@ public function __construct()
content: new JsonContent(
properties: [
new Property(property: 'assets', type: 'array', items: new Items(type: 'integer'), example: [83]),
new Property(property: 'gridConfig', ref: Configuration::class),
new Property(
property: 'gridConfig',
type: 'array',
items: new Items(ref: Column::class)
),
new Property(property: 'settings', properties: [
new Property(property: Csv::SETTINGS_DELIMITER->value, type: 'string', example: ';'),
new Property(
Expand Down
11 changes: 9 additions & 2 deletions src/Asset/Controller/Grid/Configuration/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Grid\Configuration;

use OpenApi\Attributes\Get;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
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\Schema\ColumnConfiguration;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
Expand Down Expand Up @@ -60,7 +62,12 @@ public function __construct(
#[SuccessResponse(
description: 'Grid configuration',
content: new JsonContent(
ref: Configuration::class
properties: [
new Property(
property: 'columns',
type: 'array',
items: new Items(ref: ColumnConfiguration::class),
)],
)
)]
#[DefaultResponses([
Expand Down
1 change: 1 addition & 0 deletions src/Asset/Controller/Grid/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function __construct(
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND,
HttpResponseCodes::BAD_REQUEST,
])]
public function getAssetGrid(#[MapRequestPayload] GridParameter $gridParameter): JsonResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public function __invoke(CsvCreationMessage $message): void
}

$settings = $this->extractConfigFieldFromJobStepConfig($message, 'settings');
$configuration = $this->gridService->getConfigurationFromArray(
$columnCollection = $this->gridService->getConfigurationFromArray(
$this->extractConfigFieldFromJobStepConfig($message, 'configuration')
);

$csv = $this->csvService->getCsvFile($jobRun->getId(), $configuration, $settings);
$csv = $this->csvService->getCsvFile($jobRun->getId(), $columnCollection, $settings);

if (!$csv) {
$this->abort($this->getAbortData(
Expand All @@ -125,7 +125,7 @@ public function __invoke(CsvCreationMessage $message): void
}

$assetData = $this->gridService->getGridValuesForElement(
$configuration,
$columnCollection,
$asset,
ElementTypes::TYPE_ASSET
);
Expand Down
10 changes: 5 additions & 5 deletions src/Asset/Service/ExecutionEngine/CsvService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\EnvironmentException;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Config;
use Pimcore\Bundle\StudioBackendBundle\ExecutionEngine\Util\Jobs;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection\ColumnCollection;
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\StorageDirectories;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\TempFilePathTrait;
Expand Down Expand Up @@ -80,14 +80,14 @@ public function generateCsvFile(ExportAssetParameter $exportAssetParameter): str
return $this->getTempFilePath($jobRun->getId(), self::CSV_FILE_PATH);
}

public function getCsvFile(int $id, Configuration $configuration, array $settings): string
public function getCsvFile(int $id, ColumnCollection $columnCollection, array $settings): string
{
$storage = $this->storageResolver->get(StorageDirectories::TEMP->value);
$file = $this->getTempFileName($id, self::CSV_FILE_NAME);

try {
if (!$storage->fileExists($file)) {
$headers = $this->getHeaders($configuration, $settings);
$headers = $this->getHeaders($columnCollection, $settings);
$storage->write(
$file,
implode($settings[Csv::SETTINGS_DELIMITER->value] ?? ',', $headers). Csv::NEW_LINE->value
Expand Down Expand Up @@ -125,15 +125,15 @@ private function encodeFunc(?string $value): string
return '"' . $value . '"';
}

private function getHeaders(Configuration $configuration, array $settings): array
private function getHeaders(ColumnCollection $columnCollection, array $settings): array
{
$header = $settings[Csv::SETTINGS_HEADER->value] ?? Csv::SETTINGS_HEADER_NO_HEADER->value;
if ($header === Csv::SETTINGS_HEADER_NO_HEADER->value) {
return [];
}

return $this->gridService->getColumnKeys(
$configuration,
$columnCollection,
$header === Csv::SETTINGS_HEADER_NAME->value
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Asset/Service/ExecutionEngine/CsvServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine;

use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ExportAssetParameter;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Configuration;
use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Collection\ColumnCollection;

/**
* @internal
Expand All @@ -28,7 +28,7 @@ interface CsvServiceInterface

public const CSV_FILE_PATH = PIMCORE_SYSTEM_TEMP_DIRECTORY . '/' . self::CSV_FILE_NAME;

public function getCsvFile(int $id, Configuration $configuration, array $settings): string;
public function getCsvFile(int $id, ColumnCollection $columnCollection, array $settings): string;

public function addData(string $filePath, string $delimiter, array $data): void;

Expand Down
14 changes: 4 additions & 10 deletions src/Grid/Attributes/Request/GridRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ public function __construct()
parent::__construct(
required: true,
content: new JsonContent(
required: ['folderId', 'gridConfig'],
required: ['folderId', 'columns'],
properties: [
new SingleInteger(propertyName: 'folderId'),
new Property(
property: 'gridConfig',
properties: [
new Property(
property: 'columns',
type: 'array',
items: new Items(ref: Column::class)
),
],
type: 'object'
property: 'columns',
type: 'array',
items: new Items(ref: Column::class)
),
],
type: 'object',
Expand Down
14 changes: 7 additions & 7 deletions src/Grid/Column/Collector/MetaDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\FrontendType;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration;
use Pimcore\Bundle\StudioBackendBundle\MetaData\Repository\MetaDataRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes;
use function array_key_exists;
Expand All @@ -42,9 +42,9 @@ public function getCollectorName(): string
/**
* @param ColumnDefinitionInterface[] $availableColumnDefinitions
*
* @return Column[]
* @return ColumnConfiguration[]
*/
public function getColumnDefinitions(array $availableColumnDefinitions): array
public function getColumnConfigurations(array $availableColumnDefinitions): array
{
return array_merge(
$this->getDefaultMetaData(),
Expand All @@ -54,14 +54,14 @@ public function getColumnDefinitions(array $availableColumnDefinitions): array

/**
*
* @return Column[]
* @return ColumnConfiguration[]
*/
private function getDefaultMetaData(): array
{
$defaultMetadata = ['title', 'alt', 'copyright'];
$columns = [];
foreach ($defaultMetadata as $metadata) {
$columns[] = new Column(
$columns[] = new ColumnConfiguration(
key: $metadata,
group: 'default_metadata',
sortable: true,
Expand All @@ -80,7 +80,7 @@ private function getDefaultMetaData(): array
/**
* @param ColumnDefinitionInterface[] $availableColumnDefinitions
*
* @return Column[]
* @return ColumnConfiguration[]
*/
private function getPredefinedMetaData(array $availableColumnDefinitions): array
{
Expand All @@ -93,7 +93,7 @@ private function getPredefinedMetaData(array $availableColumnDefinitions): array
continue;
}

$columns[] = new Column(
$columns[] = new ColumnConfiguration(
key: $item->getName(),
group: 'predefined_metadata',
sortable: $availableColumnDefinitions[$type]->isSortable(),
Expand Down
8 changes: 4 additions & 4 deletions src/Grid/Column/Collector/SystemFieldCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes;
use function array_key_exists;
Expand All @@ -41,9 +41,9 @@ public function getCollectorName(): string
/**
* @param ColumnDefinitionInterface[] $availableColumnDefinitions
*
* @return Column[]
* @return ColumnConfiguration[]
*/
public function getColumnDefinitions(array $availableColumnDefinitions): array
public function getColumnConfigurations(array $availableColumnDefinitions): array
{
$systemColumns = $this->systemColumnService->getSystemColumnsForAssets();
$columns = [];
Expand All @@ -53,7 +53,7 @@ public function getColumnDefinitions(array $availableColumnDefinitions): array
continue;
}

$column = new Column(
$column = new ColumnConfiguration(
key: $columnKey,
group: $this->getCollectorName(),
sortable: $availableColumnDefinitions[$type]->isSortable(),
Expand Down
6 changes: 3 additions & 3 deletions src/Grid/Column/ColumnCollectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column;

use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration;

interface ColumnCollectorInterface
{
Expand All @@ -25,9 +25,9 @@ public function getCollectorName(): string;
/**
* @param ColumnDefinitionInterface[] $availableColumnDefinitions
*
* @return Column[]
* @return ColumnConfiguration[]
*/
public function getColumnDefinitions(array $availableColumnDefinitions): array;
public function getColumnConfigurations(array $availableColumnDefinitions): array;

public function supportedElementTypes(): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
namespace Pimcore\Bundle\StudioBackendBundle\Grid\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration;

final class GridColumnDefinitionEvent extends AbstractPreResponseEvent
final class GridColumnConfigurationEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.grid_column_definition';
public const EVENT_NAME = 'pre_response.grid_column_configuration';

public function __construct(
private readonly Column $column
private readonly ColumnConfiguration $column
) {
parent::__construct($column);
}

/**
* Use this to get additional infos out of the response object
*/
public function getConfiguration(): Column
public function getConfiguration(): ColumnConfiguration
{
return $this->column;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Grid/MappedParameter/GridParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{
public function __construct(
private int $folderId,
private array $gridConfig,
private array $columns,
) {
}

Expand All @@ -32,8 +32,8 @@ public function getFolderId(): int
return $this->folderId;
}

public function getGridConfig(): array
public function getColumns(): array
{
return $this->gridConfig;
return $this->columns;
}
}
Loading
Loading