Skip to content

Commit

Permalink
feat(Chroot): Display node chroot on mainNodeTree instead of its chil…
Browse files Browse the repository at this point in the history
…dren
  • Loading branch information
ambroisemaupate committed Sep 5, 2023
1 parent f6de0ee commit b9e2f7a
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 76 deletions.
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Repository/NodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public function findByReverseNodeAndFieldAndTranslation(
public function findAllOffspringIdByNode(Node $node): array
{
$theOffsprings = [];
$in = [$node->getId()];
$in = \array_filter([(int) $node->getId()]);

do {
$theOffsprings = array_merge($theOffsprings, $in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ public function __construct(
private Security $security,
private HandlerFactoryInterface $handlerFactory,
private CacheItemPoolInterface $cache
)
{
) {
}

protected function supports(string $attribute, $subject): bool
{
if (\in_array($attribute, [
if (
\in_array($attribute, [
self::CREATE_AT_ROOT,
self::READ_AT_ROOT,
self::EMPTY_TRASH,
])) {
])
) {
return true;
}

if (!\in_array($attribute, [
if (
!\in_array($attribute, [
self::CREATE,
self::DUPLICATE,
self::READ,
Expand All @@ -63,7 +65,8 @@ protected function supports(string $attribute, $subject): bool
self::EDIT_STATUS,
self::EDIT_ATTRIBUTE,
self::DELETE
])) {
])
) {
return false;
}

Expand All @@ -87,7 +90,7 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
$subject = $subject->getNode();
}

return match($attribute) {
return match ($attribute) {
self::CREATE => $this->canCreate($subject, $user),
self::DUPLICATE => $this->canDuplicate($subject, $user),
self::CREATE_AT_ROOT => $this->canCreateAtRoot($user),
Expand Down
2 changes: 1 addition & 1 deletion lib/Rozier/src/AjaxControllers/AjaxNodeTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getTreeAction(Request $request): JsonResponse
$parent = $this->nodeChrootResolver->getChroot($this->getUser());
}

$nodeTree = $this->treeWidgetFactory->createNodeTree($parent, $translation);
$nodeTree = $this->treeWidgetFactory->createRootNodeTree($parent, $translation);
$this->assignation['mainNodeTree'] = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
use RZ\Roadiz\CoreBundle\Entity\NodesSourcesDocuments;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\SearchEngine\GlobalNodeSourceSearchHandler;
use RZ\Roadiz\CoreBundle\Security\Authorization\Voter\NodeVoter;
use RZ\Roadiz\Documents\UrlGenerators\DocumentUrlGeneratorInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Security\Core\Security;

class AjaxSearchNodesSourcesController extends AbstractAjaxController
{
public const RESULT_COUNT = 8;
private DocumentUrlGeneratorInterface $documentUrlGenerator;
public const RESULT_COUNT = 10;

public function __construct(DocumentUrlGeneratorInterface $documentUrlGenerator)
{
$this->documentUrlGenerator = $documentUrlGenerator;
public function __construct(
private DocumentUrlGeneratorInterface $documentUrlGenerator,
private Security $security
) {
}

/**
* Handle AJAX edition requests for Node
* such as coming from nodetree widgets.
* such as coming from node-tree widgets.
*
* @param Request $request
*
Expand All @@ -43,7 +45,7 @@ public function searchAction(Request $request): Response
$searchHandler = new GlobalNodeSourceSearchHandler($this->em());
$searchHandler->setDisplayNonPublishedNodes(true);

/** @var array<mixed> $nodesSources */
/** @var array $nodesSources */
$nodesSources = $searchHandler->getNodeSourcesBySearchTerm(
$request->get('searchTerms'),
static::RESULT_COUNT
Expand All @@ -60,6 +62,7 @@ public function searchAction(Request $request): Response
foreach ($nodesSources as $source) {
if (
$source instanceof NodesSources &&
$this->security->isGranted(NodeVoter::READ, $source) &&
!key_exists($source->getNode()->getId(), $responseArray['data'])
) {
$responseArray['data'][$source->getNode()->getId()] = $this->getNodeSourceData($source);
Expand Down
42 changes: 22 additions & 20 deletions lib/Rozier/src/Resources/views/nodes/breadcrumb.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@
{% apply spaceless %}
<ul class="uk-breadcrumb content-breadcrumb node-breadcrumb">
{% for parent in source|parents(null, true)|reverse %}
{% set title = parent.title|default(parent.node.nodeName) %}
{% if is_granted('READ', parent) %}
{% set title = parent.title|default(parent.node.nodeName) %}

{% if parent.node.isHidingChildren %}
{% if parent.translation %}
{% set url = path('nodesTreePage', { nodeId: parent.node.id, translationId: parent.translation.id }) %}
{% if parent.node.isHidingChildren %}
{% if parent.translation %}
{% set url = path('nodesTreePage', { nodeId: parent.node.id, translationId: parent.translation.id }) %}
{% else %}
{% set url = path('nodesTreePage', { nodeId: parent.node.id }) %}
{% endif %}
{% else %}
{% set url = path('nodesTreePage', { nodeId: parent.node.id }) %}
{% set url = path('nodesEditSourcePage', {
nodeId: parent.node.id,
translationId: parent.translation.id
}) %}
{% endif %}
{% else %}
{% set url = path('nodesEditSourcePage', {
nodeId: parent.node.id,
translationId: parent.translation.id
}) %}
{% endif %}

<li class="node-breadcrumb-item">
<a class="node-breadcrumb-link" href="{{ url }}">
{% if parent.node.isHome %}
<i class="uk-icon-rz-breadcrumb-home"></i>
{% else %}
{{ title|u.truncate(25, '[…]', true) }}
{% endif %}
</a>
</li>
<li class="node-breadcrumb-item">
<a class="node-breadcrumb-link" href="{{ url }}">
{% if parent.node.isHome %}
<i class="uk-icon-rz-breadcrumb-home"></i>
{% else %}
{{ title|u.truncate(25, '[…]', true) }}
{% endif %}
</a>
</li>
{% endif %}
{% endfor %}
<li class="node-breadcrumb-item uk-active"><span>{{ currentTitle|u.truncate(25, '[…]', true) }}</span></li>
</ul>
Expand Down
21 changes: 18 additions & 3 deletions lib/Rozier/src/Resources/views/panels/tree_panel.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@
{% if tabCount > 1 %}
<ul id="tree-menu" class="uk-tab">
{% if is_granted('ROLE_ACCESS_NODES')%}
<li id="tree-menu-tab-nodes" data-index="0" class="tabs"><a class="tab-link" href="#"><i class="uk-icon-rz-node-tree"></i><span class="label">{% trans %}nodes{% endtrans %}</span></a></li>
<li id="tree-menu-tab-nodes" data-index="0" class="tabs">
<a class="tab-link" href="#">
<i class="uk-icon-rz-node-tree"></i>
<span class="label">{% trans %}nodes{% endtrans %}</span>
</a>
</li>
{% endif %}
{% if is_granted('ROLE_ACCESS_TAGS')%}
<li id="tree-menu-tab-tags" data-index="1" class="tabs"><a class="tab-link" href="#"><i class="uk-icon-rz-tag-tree"></i><span class="label">{% trans %}tags{% endtrans %}</span></a></li>
<li id="tree-menu-tab-tags" data-index="1" class="tabs">
<a class="tab-link" href="#">
<i class="uk-icon-rz-tag-tree"></i>
<span class="label">{% trans %}tags{% endtrans %}</span>
</a>
</li>
{% endif %}
{% if is_granted('ROLE_ACCESS_DOCUMENTS')%}
<li id="tree-menu-tab-folders" data-index="2" class="tabs"><a class="tab-link" href="#"><i class="uk-icon-rz-folder-tree"></i><span class="label">{% trans %}folders{% endtrans %}</span></a></li>
<li id="tree-menu-tab-folders" data-index="2" class="tabs">
<a class="tab-link" href="#">
<i class="uk-icon-rz-folder-tree"></i>
<span class="label">{% trans %}folders{% endtrans %}</span>
</a>
</li>
{% endif %}
</ul>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{% set type = node.nodeType.name %}

{% set classes = [
type|lower,
'nodetree-element'
type|lower,
'nodetree-element'
] %}

{% set classes = classes|merge(['uk-nestable-item']) %}
Expand Down Expand Up @@ -52,7 +52,6 @@ type|lower,
{% endif %}
{% endif %}


<li data-node-id="{{ node.id }}" class="{{ classes|join(' ') }}">
{% if not mainNodeTree and not nodeTree.isStackTree %}
<span class="nodetree-list-item-color"></span>
Expand Down
4 changes: 2 additions & 2 deletions lib/Rozier/src/Widgets/AbstractWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
abstract class AbstractWidget
{
private RequestStack $requestStack;
private ManagerRegistry $managerRegistry;
protected RequestStack $requestStack;
protected ManagerRegistry $managerRegistry;
protected ?TranslationInterface $defaultTranslation = null;

/**
Expand Down
8 changes: 2 additions & 6 deletions lib/Rozier/src/Widgets/FolderTreeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Themes\Rozier\Widgets;

use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\Folder;
use Symfony\Component\HttpFoundation\RequestStack;
Expand All @@ -15,10 +14,7 @@
final class FolderTreeWidget extends AbstractWidget
{
protected ?Folder $parentFolder = null;
/**
* @var array<Folder>|Paginator<Folder>|null
*/
protected $folders = null;
protected ?iterable $folders = null;

/**
* @param RequestStack $requestStack
Expand Down Expand Up @@ -53,7 +49,7 @@ public function getRootFolder(): ?Folder
}

/**
* @return array<Folder>|Paginator<Folder>
* @return iterable<Folder>
*/
public function getFolders(): iterable
{
Expand Down
41 changes: 22 additions & 19 deletions lib/Rozier/src/Widgets/NodeTreeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Themes\Rozier\Widgets;

use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\Core\AbstractEntities\TranslationInterface;
use RZ\Roadiz\CoreBundle\Entity\Node;
Expand All @@ -19,34 +18,35 @@
final class NodeTreeWidget extends AbstractWidget
{
public const SESSION_ITEM_PER_PAGE = 'nodetree_item_per_page';
protected ?Node $parentNode = null;
/**
* @var array<Node>|Paginator<Node>|null
*/
protected $nodes = null;
protected ?Tag $tag = null;
protected ?TranslationInterface $translation = null;
protected bool $stackTree = false;
protected ?array $filters = null;
protected bool $canReorder = true;
protected array $additionalCriteria = [];
private ?Node $parentNode = null;
private ?iterable $nodes = null;
private ?Tag $tag = null;
private ?TranslationInterface $translation = null;
private bool $stackTree = false;
private ?array $filters = null;
private bool $canReorder = true;
private array $additionalCriteria = [];
private bool $includeRootNode;

/**
* @param RequestStack $requestStack
* @param ManagerRegistry $managerRegistry
* @param Node|null $parent Entry point of NodeTreeWidget, set null if it's root
* @param TranslationInterface|null $translation NodeTree translation
* @param bool $includeRootNode
*/
public function __construct(
RequestStack $requestStack,
ManagerRegistry $managerRegistry,
?Node $parent = null,
?TranslationInterface $translation = null
?TranslationInterface $translation = null,
bool $includeRootNode = false
) {
parent::__construct($requestStack, $managerRegistry);

$this->parentNode = $parent;
$this->translation = $translation;
$this->includeRootNode = $includeRootNode;
}

/**
Expand Down Expand Up @@ -78,13 +78,13 @@ public function isStackTree(): bool
}

/**
* @param bool $newstackTree
* @param bool $stackTree
*
* @return $this
*/
public function setStackTree(bool $newstackTree): NodeTreeWidget
public function setStackTree(bool $stackTree): NodeTreeWidget
{
$this->stackTree = (bool) $newstackTree;
$this->stackTree = $stackTree;

return $this;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ protected function getListManager(
/**
* @param Node|null $parent
* @param bool $subRequest Default: false
* @return array<int, Node>|Paginator<Node>
* @return iterable<Node>
*/
public function getChildrenNodes(Node $parent = null, bool $subRequest = false): iterable
{
Expand All @@ -219,7 +219,7 @@ public function getChildrenNodes(Node $parent = null, bool $subRequest = false):
/**
* @param Node|null $parent
* @param bool $subRequest Default: false
* @return array<int, Node>|Paginator<Node>
* @return iterable<Node>
*/
public function getReachableChildrenNodes(Node $parent = null, bool $subRequest = false): iterable
{
Expand Down Expand Up @@ -270,10 +270,13 @@ public function getAvailableTranslations(): array
}

/**
* @return array<int, Node>|Paginator<Node>
* @return iterable<Node>
*/
public function getNodes(): iterable
{
if ($this->includeRootNode && null !== $this->getRootNode()) {
return [$this->getRootNode()];
}
if (null === $this->nodes) {
$manager = $this->getRootListManager();
$this->nodes = $manager->getEntities();
Expand Down
10 changes: 3 additions & 7 deletions lib/Rozier/src/Widgets/TagTreeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Themes\Rozier\Widgets;

use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\Tag;
use RZ\Roadiz\CoreBundle\Repository\TagRepository;
Expand All @@ -16,10 +15,7 @@
final class TagTreeWidget extends AbstractWidget
{
protected ?Tag $parentTag = null;
/**
* @var array<Tag>|Paginator<Tag>|null
*/
protected $tags = null;
protected ?iterable $tags = null;
protected bool $canReorder = true;
protected bool $forceTranslation = false;

Expand Down Expand Up @@ -111,9 +107,9 @@ public function getRootTag(): ?Tag
}

/**
* @return array<Tag>|Paginator<Tag>|null
* @return iterable<Tag>
*/
public function getTags(): ?iterable
public function getTags(): iterable
{
if ($this->tags === null) {
$this->getTagTreeAssignationForParent();
Expand Down
Loading

0 comments on commit b9e2f7a

Please sign in to comment.