Skip to content

Commit

Permalink
IBX-4125: Optimized Dashboard tabs (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 authored Dec 1, 2022
1 parent c0ae32d commit 94b3384
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 169 deletions.
23 changes: 14 additions & 9 deletions src/bundle/Resources/config/services/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,44 @@ services:
parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab
public: false
arguments:
$contentSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\ContentSubtreeQueryType'
$contentLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType'
tags:
- { name: ezplatform.tab, group: dashboard-my }

EzSystems\EzPlatformAdminUi\Tab\Dashboard\MyMediaTab:
EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneContentTab:
parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab
public: false
arguments:
$mediaSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\MediaSubtreeQueryType'
$contentLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType'
tags:
- { name: ezplatform.tab, group: dashboard-my }
- { name: ezplatform.tab, group: dashboard-everyone }

EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneMediaTab:
EzSystems\EzPlatformAdminUi\Tab\Dashboard\MyMediaTab:
parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab
public: false
arguments:
$mediaSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\MediaSubtreeQueryType'
$mediaLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType'
tags:
- { name: ezplatform.tab, group: dashboard-everyone }
- { name: ezplatform.tab, group: dashboard-my }

EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneContentTab:
EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneMediaTab:
parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab
public: false
arguments:
$contentSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\ContentSubtreeQueryType'
$mediaLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType'
tags:
- { name: ezplatform.tab, group: dashboard-everyone }

EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper:
deprecated: 'Service "%service_id%" is deprecated. Use "Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper" instead'
parent: EzSystems\EzPlatformAdminUi\Search\AbstractPagerContentToDataMapper
autowire: true
public: false

Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper:
autowire: true
public: false

ezplatform.adminui.dashboard.me:
parent: EzSystems\EzPlatformAdminUi\Component\TwigComponent
arguments:
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/query_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ services:

EzSystems\EzPlatformAdminUi\QueryType\ContentSubtreeQueryType: ~

Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType: ~

EzSystems\EzPlatformAdminUi\QueryType\MediaSubtreeQueryType: ~

Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType: ~

EzSystems\EzPlatformAdminUi\QueryType\SearchQueryType:
deprecated: 'Service "%service_id%" is deprecated since 3.1 and will be removed in 3.2. Use "Ibexa\Platform\Search\QueryType\SearchQueryType" instead'
arguments:
Expand Down
24 changes: 24 additions & 0 deletions src/lib/QueryType/ContentLocationSubtreeQueryType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\QueryType;

use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreePath;

final class ContentLocationSubtreeQueryType extends LocationSubtreeQueryType
{
public static function getName(): string
{
return 'IbexaAdminUi:ContentLocationSubtree';
}

protected function getSubtreePathFromConfiguration(): string
{
return $this->configResolver->getParameter(SubtreePath::CONTENT_SUBTREE_PATH);
}
}
75 changes: 75 additions & 0 deletions src/lib/QueryType/LocationSubtreeQueryType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\QueryType;

use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use eZ\Publish\Core\QueryType\OptionsResolverBasedQueryType;
use eZ\Publish\Core\QueryType\QueryType;
use Symfony\Component\OptionsResolver\OptionsResolver;

abstract class LocationSubtreeQueryType extends OptionsResolverBasedQueryType implements QueryType
{
protected const OWNED_OPTION_NAME = 'owned';
protected const SUBTREE_OPTION_NAME = 'subtree';

/** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
protected $configResolver;

/** @var \eZ\Publish\API\Repository\PermissionResolver */
private $permissionResolver;

public function __construct(
ConfigResolverInterface $configResolver,
PermissionResolver $permissionResolver
) {
$this->configResolver = $configResolver;
$this->permissionResolver = $permissionResolver;
}

public function doGetQuery(array $parameters): LocationQuery
{
$subtreeCriterion = new Query\Criterion\Subtree($parameters[self::SUBTREE_OPTION_NAME]);

$ownerId = $parameters[self::OWNED_OPTION_NAME]
? $this->permissionResolver->getCurrentUserReference()->getUserId()
: null;

if ($ownerId !== null) {
$filter = new Query\Criterion\LogicalAnd([
$subtreeCriterion,
new Query\Criterion\UserMetadata(
Query\Criterion\UserMetadata::OWNER,
Query\Criterion\Operator::EQ,
$ownerId
),
]);
} else {
$filter = $subtreeCriterion;
}

return new LocationQuery([
'filter' => $filter,
'sortClauses' => [new Query\SortClause\DateModified(Query::SORT_DESC)],
]);
}

protected function configureOptions(OptionsResolver $optionsResolver): void
{
$optionsResolver->setDefined([self::SUBTREE_OPTION_NAME, self::OWNED_OPTION_NAME]);
$optionsResolver->setAllowedTypes(self::SUBTREE_OPTION_NAME, 'string');
$optionsResolver->setAllowedTypes(self::OWNED_OPTION_NAME, 'bool');
$optionsResolver->setDefault(self::SUBTREE_OPTION_NAME, $this->getSubtreePathFromConfiguration());
$optionsResolver->setDefault(self::OWNED_OPTION_NAME, false);
}

abstract protected function getSubtreePathFromConfiguration(): string;
}
24 changes: 24 additions & 0 deletions src/lib/QueryType/MediaLocationSubtreeQueryType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\QueryType;

use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\SubtreePath;

final class MediaLocationSubtreeQueryType extends LocationSubtreeQueryType
{
public static function getName(): string
{
return 'IbexaAdminUi:MediaLocationSubtree';
}

protected function getSubtreePathFromConfiguration(): string
{
return $this->configResolver->getParameter(SubtreePath::MEDIA_SUBTREE_PATH);
}
}
42 changes: 42 additions & 0 deletions src/lib/Tab/Dashboard/AbstractContentTab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Tab\Dashboard;

use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\Core\QueryType\QueryType;
use EzSystems\EzPlatformAdminUi\Tab\AbstractTab;
use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

abstract class AbstractContentTab extends AbstractTab implements OrderedTabInterface
{
/** @var \Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper */
protected $pagerLocationToDataMapper;

/** @var \eZ\Publish\API\Repository\SearchService */
protected $searchService;

/** @var \Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType */
protected $contentLocationSubtreeQueryType;

public function __construct(
Environment $twig,
TranslatorInterface $translator,
PagerLocationToDataMapper $pagerLocationToDataMapper,
SearchService $searchService,
QueryType $contentLocationSubtreeQueryType
) {
parent::__construct($twig, $translator);

$this->pagerLocationToDataMapper = $pagerLocationToDataMapper;
$this->searchService = $searchService;
$this->contentLocationSubtreeQueryType = $contentLocationSubtreeQueryType;
}
}
42 changes: 42 additions & 0 deletions src/lib/Tab/Dashboard/AbstractMediaTab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Tab\Dashboard;

use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\Core\QueryType\QueryType;
use EzSystems\EzPlatformAdminUi\Tab\AbstractTab;
use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

abstract class AbstractMediaTab extends AbstractTab implements OrderedTabInterface
{
/** @var \Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper */
protected $pagerLocationToDataMapper;

/** @var \eZ\Publish\API\Repository\SearchService */
protected $searchService;

/** @var \Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType */
protected $mediaLocationSubtreeQueryType;

public function __construct(
Environment $twig,
TranslatorInterface $translator,
PagerLocationToDataMapper $pagerLocationToDataMapper,
SearchService $searchService,
QueryType $mediaLocationSubtreeQueryType
) {
parent::__construct($twig, $translator);

$this->pagerLocationToDataMapper = $pagerLocationToDataMapper;
$this->searchService = $searchService;
$this->mediaLocationSubtreeQueryType = $mediaLocationSubtreeQueryType;
}
}
49 changes: 9 additions & 40 deletions src/lib/Tab/Dashboard/EveryoneContentTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,13 @@

namespace EzSystems\EzPlatformAdminUi\Tab\Dashboard;

use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter;
use eZ\Publish\Core\QueryType\QueryType;
use EzSystems\EzPlatformAdminUi\Tab\AbstractTab;
use eZ\Publish\Core\Pagination\Pagerfanta\LocationSearchAdapter;
use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface;
use Ibexa\AdminUi\Tab\Dashboard\AbstractContentTab;
use Pagerfanta\Pagerfanta;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

class EveryoneContentTab extends AbstractTab implements OrderedTabInterface
class EveryoneContentTab extends AbstractContentTab implements OrderedTabInterface
{
/** @var \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper */
protected $pagerContentToDataMapper;

/** @var \eZ\Publish\API\Repository\SearchService */
protected $searchService;

/** @var \eZ\Publish\Core\QueryType\QueryType */
private $contentSubtreeQueryType;

/**
* @param \Twig\Environment $twig
* @param \Symfony\Contracts\Translation\TranslatorInterface $translator
* @param \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper $pagerContentToDataMapper
* @param \eZ\Publish\API\Repository\SearchService $searchService
* @param \eZ\Publish\Core\QueryType\QueryType $contentSubtreeQueryType
*/
public function __construct(
Environment $twig,
TranslatorInterface $translator,
PagerContentToDataMapper $pagerContentToDataMapper,
SearchService $searchService,
QueryType $contentSubtreeQueryType
) {
parent::__construct($twig, $translator);

$this->pagerContentToDataMapper = $pagerContentToDataMapper;
$this->searchService = $searchService;
$this->contentSubtreeQueryType = $contentSubtreeQueryType;
}

public function getIdentifier(): string
{
return 'everyone-content';
Expand All @@ -65,23 +31,26 @@ public function getOrder(): int
return 100;
}

/**
* @inheritdoc
*/
public function renderView(array $parameters): string
{
/** @todo Handle pagination */
$page = 1;
$limit = 10;

$pager = new Pagerfanta(
new ContentSearchAdapter(
$this->contentSubtreeQueryType->getQuery(),
new LocationSearchAdapter(
$this->contentLocationSubtreeQueryType->getQuery(),
$this->searchService
)
);
$pager->setMaxPerPage($limit);
$pager->setCurrentPage($page);

return $this->twig->render('@ezdesign/ui/dashboard/tab/all_content.html.twig', [
'data' => $this->pagerContentToDataMapper->map($pager),
'data' => $this->pagerLocationToDataMapper->map($pager, true),
]);
}
}
Loading

0 comments on commit 94b3384

Please sign in to comment.