-
-
Notifications
You must be signed in to change notification settings - Fork 144
FEATURE: switch to backend-calculated parent node links (needed for Event Sourced CR) #2178
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
Changes from all commits
14a54ff
96fda15
1ca2917
dbe6f43
6fdf14d
55c71d1
4be1aa0
eb0d140
a8e3cd8
52942df
900165d
7a05e21
fed0112
f0f8318
89426a5
544f240
38f2ad0
473291e
e59b0ca
5cb50c3
3c0fa62
0096b3e
ef38b5c
14ef051
341357c
5313ffb
39bb719
913afb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ | |
* source code. | ||
*/ | ||
|
||
use Neos\ContentRepository\Domain\NodeType\NodeTypeConstraintFactory; | ||
use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this file, we implement everything against the TraversableNodeInterface instead of NodeInterface; so that we use the forward-compatible API already. |
||
use Neos\ContentRepository\Exception\NodeException; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Property\PropertyMapper; | ||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
|
@@ -42,6 +45,12 @@ class NeosUiDefaultNodesOperation extends AbstractOperation | |
*/ | ||
protected $propertyMapper; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var NodeTypeConstraintFactory | ||
*/ | ||
protected $nodeTypeConstraintFactory; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
|
@@ -50,7 +59,7 @@ class NeosUiDefaultNodesOperation extends AbstractOperation | |
*/ | ||
public function canEvaluate($context) | ||
{ | ||
return isset($context[0]) && ($context[0] instanceof NodeInterface); | ||
return isset($context[0]) && ($context[0] instanceof TraversableNodeInterface); | ||
} | ||
|
||
/** | ||
|
@@ -62,38 +71,48 @@ public function canEvaluate($context) | |
*/ | ||
public function evaluate(FlowQuery $flowQuery, array $arguments) | ||
{ | ||
/** @var TraversableNodeInterface $siteNode */ | ||
/** @var TraversableNodeInterface $documentNode */ | ||
list($siteNode, $documentNode) = $flowQuery->getContext(); | ||
/** @var TraversableNodeInterface $toggledNodes */ | ||
list($baseNodeType, $loadingDepth, $toggledNodes, $clipboardNodesContextPaths) = $arguments; | ||
|
||
// Collect all parents of documentNode up to siteNode | ||
$parents = []; | ||
$currentNode = $documentNode->getParent(); | ||
$currentNode = null; | ||
try { | ||
$currentNode = $documentNode->findParentNode(); | ||
} catch (NodeException $ignored) { | ||
// parent does not exist | ||
} | ||
if ($currentNode) { | ||
$parentNodeIsUnderneathSiteNode = strpos($currentNode->getPath(), $siteNode->getPath()) === 0; | ||
while ($currentNode !== $siteNode && $parentNodeIsUnderneathSiteNode) { | ||
$parents[] = $currentNode->getContextPath(); | ||
$currentNode = $currentNode->getParent(); | ||
$parentNodeIsUnderneathSiteNode = strpos((string)$currentNode->findNodePath(), (string)$siteNode->findNodePath()) === 0; | ||
while ((string)$currentNode->getNodeAggregateIdentifier() !== (string)$siteNode->getNodeAggregateIdentifier() && $parentNodeIsUnderneathSiteNode) { | ||
$parents[] = (string)$currentNode->getNodeAggregateIdentifier(); | ||
$currentNode = $currentNode->findParentNode(); | ||
} | ||
} | ||
|
||
$nodes = [$siteNode]; | ||
$gatherNodesRecursively = function (&$nodes, $baseNode, $level = 0) use (&$gatherNodesRecursively, $baseNodeType, $loadingDepth, $toggledNodes, $parents) { | ||
$nodes = [ | ||
((string)$siteNode->getNodeAggregateIdentifier()) => $siteNode | ||
]; | ||
$gatherNodesRecursively = function (&$nodes, TraversableNodeInterface $baseNode, $level = 0) use (&$gatherNodesRecursively, $baseNodeType, $loadingDepth, $toggledNodes, $parents) { | ||
if ( | ||
$level < $loadingDepth || // load all nodes within loadingDepth | ||
$loadingDepth === 0 || // unlimited loadingDepth | ||
in_array($baseNode->getContextPath(), $toggledNodes) || // load toggled nodes | ||
in_array($baseNode->getContextPath(), $parents) // load children of all parents of documentNode | ||
in_array((string)$baseNode->getNodeAggregateIdentifier(), $toggledNodes) || // load toggled nodes | ||
in_array((string)$baseNode->getNodeAggregateIdentifier(), $parents) // load children of all parents of documentNode | ||
) { | ||
foreach ($baseNode->getChildNodes($baseNodeType) as $childNode) { | ||
$nodes[] = $childNode; | ||
foreach ($baseNode->findChildNodes($this->nodeTypeConstraintFactory->parseFilterString($baseNodeType)) as $childNode) { | ||
$nodes[(string)$childNode->getNodeAggregateIdentifier()] = $childNode; | ||
$gatherNodesRecursively($nodes, $childNode, $level + 1); | ||
} | ||
} | ||
}; | ||
$gatherNodesRecursively($nodes, $siteNode); | ||
|
||
if (!in_array($documentNode, $nodes)) { | ||
$nodes[] = $documentNode; | ||
if (!isset($nodes[(string)$documentNode->getNodeAggregateIdentifier()])) { | ||
$nodes[(string)$documentNode->getNodeAggregateIdentifier()] = $documentNode; | ||
} | ||
|
||
foreach ($clipboardNodesContextPaths as $clipboardNodeContextPath) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,24 +21,6 @@ export const getAllowedNodeTypesTakingAutoCreatedIntoAccount = (baseNode: Node, | |
return nodeTypesRegistry.getAllowedChildNodeTypes(baseNode.nodeType); | ||
}; | ||
|
||
// | ||
// Helper function to get parent contextPath from current contextPath | ||
// | ||
export const parentNodeContextPath = (contextPath: NodeContextPath) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. basically, we remove this method and all transitive usages. |
||
if (typeof contextPath !== 'string') { | ||
console.error('`contextPath` must be a string!'); // tslint:disable-line | ||
return null; | ||
} | ||
const [path, context] = contextPath.split('@'); | ||
|
||
if (path.length === 0) { | ||
// We are at top level; so there is no parent anymore! | ||
return null; | ||
} | ||
|
||
return `${path.substr(0, path.lastIndexOf('/'))}@${context}`; | ||
}; | ||
|
||
// | ||
// Helper function to check if the node is collapsed | ||
// | ||
|
@@ -60,9 +42,9 @@ export const calculateNewFocusedNodes = (selectionMode: SelectionModeTypes, cont | |
return [contextPath]; | ||
} else if (selectionMode === SelectionModeTypes.RANGE_SELECT) { | ||
const lastSelectedNodeContextPath = focusedNodesContextPaths[focusedNodesContextPaths.length - 1]; | ||
const maybeParentNodeContextPath = parentNodeContextPath(lastSelectedNodeContextPath); | ||
if (maybeParentNodeContextPath) { | ||
const parentNode = getNodeOrThrow(nodesByContextPath, maybeParentNodeContextPath); | ||
const lastSelectedNode = nodesByContextPath[lastSelectedNodeContextPath]; | ||
if (lastSelectedNode && lastSelectedNode.parent) { | ||
const parentNode = getNodeOrThrow(nodesByContextPath, lastSelectedNode.parent); | ||
const tempSelection: string[] = []; | ||
let startSelectionFlag = false; | ||
// if both start and end nodes are within children, then we can do range select | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not really have anything to do with the core of the change; but we were missing a way to reset feedbacks beforehand.