Skip to content

Commit 6d10307

Browse files
authored
[Custom Reports] Add the group field to the config list (#1751)
* add the possibility to group tree nodes for custom reports * chore: split service
1 parent 3573b63 commit 6d10307

21 files changed

Lines changed: 633 additions & 261 deletions

config/prepend/bundle_custom_reports.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ services:
3636
Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CsvServiceInterface:
3737
class: Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CsvService
3838

39+
Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface:
40+
class: Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigService
41+
3942
Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface:
4043
class: Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportService
4144

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Attribute\Response\Property;
15+
16+
use OpenApi\Attributes\Items;
17+
use OpenApi\Attributes\Property;
18+
use OpenApi\Attributes\Schema;
19+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportTreeConfigNode;
20+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportTreeNodeFolder;
21+
22+
/**
23+
* @internal
24+
*/
25+
final class AnyOfCustomReportNodes extends Property
26+
{
27+
public function __construct()
28+
{
29+
parent::__construct(
30+
'items',
31+
title: 'items',
32+
type: 'array',
33+
items: new Items(
34+
anyOf: array_map(static function ($class) {
35+
return new Schema(ref: $class);
36+
}, [CustomReportTreeConfigNode::class, CustomReportTreeNodeFolder::class])
37+
)
38+
);
39+
}
40+
}

src/Bundle/CustomReport/Controller/Config/AddController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use OpenApi\Attributes\Post;
1818
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportAdd;
1919
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportDetails;
20-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
2121
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2222
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
2323
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
@@ -42,7 +42,7 @@ final class AddController extends AbstractApiController
4242

4343
public function __construct(
4444
SerializerInterface $serializer,
45-
private readonly CustomReportServiceInterface $customReportService,
45+
private readonly CustomReportConfigServiceInterface $customReportConfigService,
4646
) {
4747
parent::__construct($serializer);
4848
}
@@ -75,6 +75,6 @@ public function addCustomReport(
7575
#[MapRequestPayload] CustomReportAdd $parameters
7676
): JsonResponse {
7777

78-
return $this->jsonResponse($this->customReportService->createCustomReport($parameters));
78+
return $this->jsonResponse($this->customReportConfigService->createCustomReport($parameters));
7979
}
8080
}

src/Bundle/CustomReport/Controller/Config/CloneController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\NameParameter;
1919
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportClone;
2020
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportDetails;
21-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
21+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
2222
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2323
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
2424
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
@@ -44,7 +44,7 @@ final class CloneController extends AbstractApiController
4444

4545
public function __construct(
4646
SerializerInterface $serializer,
47-
private readonly CustomReportServiceInterface $customReportService,
47+
private readonly CustomReportConfigServiceInterface $customReportConfigService,
4848
) {
4949
parent::__construct($serializer);
5050
}
@@ -79,6 +79,6 @@ public function cloneCustomReport(
7979
#[MapRequestPayload] CustomReportClone $parameters
8080
): JsonResponse {
8181

82-
return $this->jsonResponse($this->customReportService->cloneCustomReport($name, $parameters));
82+
return $this->jsonResponse($this->customReportConfigService->cloneCustomReport($name, $parameters));
8383
}
8484
}

src/Bundle/CustomReport/Controller/Config/DeleteController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use OpenApi\Attributes\Delete;
1717
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\NameParameter;
18-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
18+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
1919
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2020
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
2121
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
@@ -38,7 +38,7 @@ final class DeleteController extends AbstractApiController
3838

3939
public function __construct(
4040
SerializerInterface $serializer,
41-
private readonly CustomReportServiceInterface $customReportService,
41+
private readonly CustomReportConfigServiceInterface $customReportConfigService,
4242
) {
4343
parent::__construct($serializer);
4444
}
@@ -69,7 +69,7 @@ public function __construct(
6969
])]
7070
public function deleteCustomReport(string $name): Response
7171
{
72-
$this->customReportService->deleteCustomReport($name);
72+
$this->customReportConfigService->deleteCustomReport($name);
7373

7474
return new Response();
7575
}

src/Bundle/CustomReport/Controller/Config/GetController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use OpenApi\Attributes\JsonContent;
1919
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\NameParameter;
2020
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportDetails;
21-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
21+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
2222
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2323
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
2424
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
@@ -41,7 +41,7 @@ final class GetController extends AbstractApiController
4141

4242
public function __construct(
4343
SerializerInterface $serializer,
44-
private readonly CustomReportServiceInterface $customReportService
44+
private readonly CustomReportConfigServiceInterface $customReportConfigService
4545
) {
4646
parent::__construct($serializer);
4747
}
@@ -80,7 +80,7 @@ public function getByName(string $name): JsonResponse
8080
);
8181

8282
return $this->jsonResponse(
83-
$this->customReportService->getCustomReportDetails($name)
83+
$this->customReportConfigService->getCustomReportDetails($name)
8484
);
8585
}
8686
}

src/Bundle/CustomReport/Controller/Config/TreeController.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
namespace Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Controller\Config;
1515

1616
use OpenApi\Attributes\Get;
17-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportTreeConfigNode;
18-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
17+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Attribute\Response\Property\AnyOfCustomReportNodes;
18+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\MappedParameter\TreeParameter;
19+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
1920
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
20-
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidQueryTypeException;
21-
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Content\ItemsJson;
22-
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter;
23-
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\BoolParameter;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
2423
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
2524
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
2625
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
2726
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\CustomReportPermissions;
2827
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
2928
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
3029
use Symfony\Component\HttpFoundation\JsonResponse;
30+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
3131
use Symfony\Component\Routing\Attribute\Route;
3232
use Symfony\Component\Security\Http\Attribute\IsGranted;
3333
use Symfony\Component\Serializer\SerializerInterface;
@@ -44,14 +44,11 @@ final class TreeController extends AbstractApiController
4444

4545
public function __construct(
4646
SerializerInterface $serializer,
47-
private readonly CustomReportServiceInterface $customReportService,
47+
private readonly CustomReportConfigServiceInterface $customReportConfigService,
4848
) {
4949
parent::__construct($serializer);
5050
}
5151

52-
/**
53-
* @throws InvalidQueryTypeException
54-
*/
5552
#[Route(self::ROUTE, name: 'pimcore_studio_api_custom_reports_tree_config', methods: ['GET'])]
5653
#[IsGranted(CustomReportPermissions::REPORTS_CONFIG->value)]
5754
#[Get(
@@ -61,18 +58,23 @@ public function __construct(
6158
summary: 'custom_reports_config_get_tree_summary',
6259
tags: [Tags::BundleCustomReports->value]
6360
)]
64-
#[PageParameter]
65-
#[PageSizeParameter]
61+
#[BoolParameter(
62+
'withGroup',
63+
description: 'Whether to group the results by report group.',
64+
required: false,
65+
example: false
66+
)]
6667
#[SuccessResponse(
67-
description: 'custom_reports_get_tree_success_response',
68-
content: new ItemsJson(CustomReportTreeConfigNode::class)
68+
description: 'custom_reports_config_get_tree_success_response',
69+
content: new CollectionJson(new AnyOfCustomReportNodes())
6970
)]
7071
#[DefaultResponses([
7172
HttpResponseCodes::UNAUTHORIZED,
7273
])]
73-
public function getCustomReports(): JsonResponse
74-
{
75-
$items = $this->customReportService->getCustomReportConfigTree();
74+
public function getCustomReports(
75+
#[MapQueryString] TreeParameter $parameters = new TreeParameter()
76+
): JsonResponse {
77+
$items = $this->customReportConfigService->getCustomReportConfigTree($parameters->isWithGroup());
7678

7779
return $this->getPaginatedCollection($this->serializer, $items, count($items));
7880
}

src/Bundle/CustomReport/Controller/Config/UpdateController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use OpenApi\Attributes\Put;
1818
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportDetails;
1919
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportUpdate;
20-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
2121
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2222
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
2323
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
@@ -43,7 +43,7 @@ final class UpdateController extends AbstractApiController
4343

4444
public function __construct(
4545
SerializerInterface $serializer,
46-
private readonly CustomReportServiceInterface $customReportService
46+
private readonly CustomReportConfigServiceInterface $customReportConfigService
4747
) {
4848
parent::__construct($serializer);
4949
}
@@ -79,6 +79,6 @@ public function updateCustomReport(
7979
string $name,
8080
#[MapRequestPayload] CustomReportUpdate $parameters
8181
): JsonResponse {
82-
return $this->jsonResponse($this->customReportService->updateCustomReport($name, $parameters));
82+
return $this->jsonResponse($this->customReportConfigService->updateCustomReport($name, $parameters));
8383
}
8484
}

src/Bundle/CustomReport/Controller/TreeController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515

1616
use OpenApi\Attributes\Get;
1717
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportTreeNode;
18-
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportServiceInterface;
18+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Service\CustomReportConfigServiceInterface;
1919
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
2020
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidQueryTypeException;
2121
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Content\ItemsJson;
22-
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter;
23-
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter;
2422
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
2523
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
2624
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
@@ -44,7 +42,7 @@ final class TreeController extends AbstractApiController
4442

4543
public function __construct(
4644
SerializerInterface $serializer,
47-
private readonly CustomReportServiceInterface $customReportService,
45+
private readonly CustomReportConfigServiceInterface $customReportConfigService,
4846
) {
4947
parent::__construct($serializer);
5048
}
@@ -61,8 +59,6 @@ public function __construct(
6159
summary: 'custom_reports_get_tree_summary',
6260
tags: [Tags::BundleCustomReports->value]
6361
)]
64-
#[PageParameter]
65-
#[PageSizeParameter]
6662
#[SuccessResponse(
6763
description: 'custom_reports_collection_success_response',
6864
content: new ItemsJson(CustomReportTreeNode::class)
@@ -72,7 +68,7 @@ public function __construct(
7268
])]
7369
public function getCustomReports(): JsonResponse
7470
{
75-
$items = $this->customReportService->getCustomReportTree();
71+
$items = $this->customReportConfigService->getCustomReportTree();
7672

7773
return $this->getPaginatedCollection($this->serializer, $items, count($items));
7874
}

src/Bundle/CustomReport/Event/TreeConfigNodeEvent.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@
1414
namespace Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Event;
1515

1616
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportTreeConfigNode;
17+
use Pimcore\Bundle\StudioBackendBundle\Bundle\CustomReport\Schema\CustomReportTreeNodeFolder;
1718
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
1819

1920
final class TreeConfigNodeEvent extends AbstractPreResponseEvent
2021
{
21-
public const EVENT_NAME = 'pre_response.custom_report_tree_config_node';
22+
public const string EVENT_NAME = 'pre_response.custom_report_tree_config_node';
2223

2324
public function __construct(
24-
private readonly CustomReportTreeConfigNode $treeConfigNode
25+
private readonly CustomReportTreeConfigNode|CustomReportTreeNodeFolder $treeConfigNode
2526
) {
2627
parent::__construct($this->treeConfigNode);
2728
}
2829

29-
/**
30-
* Use this to get additional infos out of the response object
31-
*/
32-
public function getTreeConfigNode(): CustomReportTreeConfigNode
30+
public function getTreeConfigNode(): CustomReportTreeConfigNode|CustomReportTreeNodeFolder
3331
{
3432
return $this->treeConfigNode;
3533
}

0 commit comments

Comments
 (0)