TileRenderer: Make the navigation through imported nodes fluent

This commit is contained in:
Johannes Meyer 2019-02-21 11:45:45 +01:00
parent f0162278d6
commit c19854d05c
5 changed files with 29 additions and 52 deletions

View file

@ -53,6 +53,11 @@ class ImportedNode extends BpNode
return $this->nodeName; return $this->nodeName;
} }
public function getIdentifier()
{
return $this->getName();
}
public function getBpConfig() public function getBpConfig()
{ {
if ($this->bp === null) { if ($this->bp === null) {

View file

@ -343,18 +343,18 @@ abstract class Node
*/ */
public function getPaths() public function getPaths()
{ {
if ($this->getBpConfig()->hasRootNode($this->getName())) { $paths = [];
return array(array($this->getName()));
}
$paths = array();
foreach ($this->parents as $parent) { foreach ($this->parents as $parent) {
foreach ($parent->getPaths() as $path) { foreach ($parent->getPaths() as $path) {
$path[] = $this->getName(); $path[] = $this->getIdentifier();
$paths[] = $path; $paths[] = $path;
} }
} }
if (! $this instanceof ImportedNode && $this->getBpConfig()->hasRootNode($this->getName())) {
$paths[] = [$this->getIdentifier()];
}
return $paths; return $paths;
} }
@ -408,6 +408,16 @@ abstract class Node
return $this->name; return $this->name;
} }
public function getIdentifier()
{
$prefix = '';
if ($this->getBpConfig()->isImported()) {
$prefix = '@' . $this->getBpConfig()->getName() . ':';
}
return $prefix . $this->getName();
}
public function __toString() public function __toString()
{ {
return $this->getName(); return $this->getName();

View file

@ -194,7 +194,7 @@ abstract class Renderer extends HtmlDocument
} }
/** /**
* @return string|null * @return array
*/ */
public function getPath() public function getPath()
{ {
@ -205,7 +205,7 @@ abstract class Renderer extends HtmlDocument
{ {
$path = $this->getPath(); $path = $this->getPath();
if ($this->rendersSubNode()) { if ($this->rendersSubNode()) {
$path[] = (string) $this->parent; $path[] = $this->parent->getIdentifier();
} }
return $path; return $path;
} }

View file

@ -117,21 +117,12 @@ class NodeTile extends BaseHtmlElement
protected function buildBaseNodeUrl(Node $node) protected function buildBaseNodeUrl(Node $node)
{ {
$path = $this->path; $url = $this->renderer->getBaseUrl();
$renderer = $this->renderer;
$params = [
'config' => $node->getBpConfig()->getName(),
'node' => $node instanceof ImportedNode
? $node->getNodeName()
: $this->name
];
$url = $renderer->getBaseUrl();
$p = $url->getParams(); $p = $url->getParams();
$p->mergeValues($params); $p->set('node', $node->getIdentifier());
if (! empty($path) && !$node instanceof ImportedNode) { if (! empty($this->path)) {
$p->addValues('path', $path); $p->addValues('path', $this->path);
} }
return $url; return $url;
@ -142,31 +133,6 @@ class NodeTile extends BaseHtmlElement
return $this->buildBaseNodeUrl($node); return $this->buildBaseNodeUrl($node);
} }
protected function makeMonitoredNodeUrl(MonitoredNode $node)
{
$path = $this->path;
$name = $this->name; // TODO: ??
$renderer = $this->renderer;
$bp = $renderer->getBusinessProcess();
$params = array(
'config' => $bp->getName()
);
if ($name !== null) {
$params['node'] = $node->getName();
}
$url = $renderer->getBaseUrl();
$p = $url->getParams();
$p->mergeValues($params);
if (! empty($path)) {
$p->addValues('path', $path);
}
return $url;
}
/** /**
* @return BaseHtmlElement * @return BaseHtmlElement
*/ */
@ -180,12 +146,8 @@ class NodeTile extends BaseHtmlElement
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname()); $link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
} else { } else {
$link = Html::tag('a', ['href' => $url], $node->getAlias()); $link = Html::tag('a', ['href' => $url], $node->getAlias());
if ($node->getBpConfig()->getName() !== $this->renderer->getBusinessProcess()->getName()) {
$link->getAttributes()->add('data-base-target', '_next');
} else {
$link->getAttributes()->add('data-base-target', '_self'); $link->getAttributes()->add('data-base-target', '_self');
} }
}
return $link; return $link;
} }

View file

@ -198,7 +198,7 @@ class TreeRenderer extends Renderer
]); ]);
$li->add($ul); $li->add($ul);
$path[] = (string) $node; $path[] = $node->getIdentifier();
foreach ($node->getChildren() as $name => $child) { foreach ($node->getChildren() as $name => $child) {
if ($child instanceof BpNode) { if ($child instanceof BpNode) {
$ul->add($this->renderNode($bp, $child, $path)); $ul->add($this->renderNode($bp, $child, $path));