Change how imported nodes are recognized

Since configurations are cached this cannot be done by using
a flag. Instead the rendering and path aggregation are now able
to distinguish nodes themselves.
This commit is contained in:
Johannes Meyer 2019-02-25 13:58:18 +01:00
parent 40538c51ce
commit eaf5b85538
9 changed files with 48 additions and 43 deletions

View file

@ -46,7 +46,7 @@ class NodeController extends Controller
if ($importedConfig->hasNode($name)) { if ($importedConfig->hasNode($name)) {
$node = $importedConfig->getNode($name); $node = $importedConfig->getNode($name);
$nativePaths = $node->getPaths(); $nativePaths = $node->getPaths($config);
do { do {
$path = array_pop($nativePaths); $path = array_pop($nativePaths);
@ -55,7 +55,7 @@ class NodeController extends Controller
array_pop($path); // Remove the monitored node array_pop($path); // Remove the monitored node
$immediateParentName = array_pop($path); // The directly affected process $immediateParentName = array_pop($path); // The directly affected process
$importedPath = array_slice($path, $importedNodePos + 1); $importedPath = array_slice($path, $importedNodePos + 1);
foreach ($importedNode->getPaths() as $targetPath) { foreach ($importedNode->getPaths($config) as $targetPath) {
if ($targetPath[count($targetPath) - 1] === $immediateParentName) { if ($targetPath[count($targetPath) - 1] === $immediateParentName) {
array_pop($targetPath); array_pop($targetPath);
$parent = $importedNode; $parent = $importedNode;

View file

@ -88,7 +88,7 @@ class ProcessController extends Controller
$renderer = $this->prepareRenderer($bp, $node); $renderer = $this->prepareRenderer($bp, $node);
if (! $this->showFullscreen && ($node === null || ! $node->getBpConfig()->isImported())) { if (! $this->showFullscreen && ($node === null || ! $renderer->rendersImportedNode())) {
if ($this->params->get('unlocked')) { if ($this->params->get('unlocked')) {
$renderer->unlock(); $renderer->unlock();
} }
@ -141,7 +141,7 @@ class ProcessController extends Controller
if (! ($this->showFullscreen || $this->view->compact)) { if (! ($this->showFullscreen || $this->view->compact)) {
$controls->add($this->getProcessTabs($bp, $renderer)); $controls->add($this->getProcessTabs($bp, $renderer));
} }
$controls->add(Breadcrumb::create($renderer)); $controls->add(Breadcrumb::create(clone $renderer));
if (! $this->showFullscreen && ! $this->view->compact) { if (! $this->showFullscreen && ! $this->view->compact) {
$controls->add( $controls->add(
new RenderedProcessActionBar($bp, $renderer, $this->Auth(), $this->url()) new RenderedProcessActionBar($bp, $renderer, $this->Auth(), $this->url())

View file

@ -88,13 +88,6 @@ class BpConfig
*/ */
protected $root_nodes = array(); protected $root_nodes = array();
/**
* Whether this configuration has been imported
*
* @var bool
*/
protected $imported = false;
/** /**
* Imported nodes * Imported nodes
* *
@ -561,17 +554,6 @@ class BpConfig
return $missing; return $missing;
} }
public function setImported($state = true)
{
$this->imported = (bool) $state;
return $this;
}
public function isImported()
{
return $this->imported;
}
public function createImportedNode($config, $name = null) public function createImportedNode($config, $name = null)
{ {
$params = (object) array('configName' => $config); $params = (object) array('configName' => $config);
@ -594,7 +576,6 @@ class BpConfig
{ {
if (! isset($this->importedConfigs[$name])) { if (! isset($this->importedConfigs[$name])) {
$import = $this->storage()->loadProcess($name); $import = $this->storage()->loadProcess($name);
$import->setImported();
if ($this->usesSoftStates()) { if ($this->usesSoftStates()) {
$import->useSoftStates(); $import->useSoftStates();

View file

@ -339,20 +339,29 @@ abstract class Node
} }
/** /**
* @param BpConfig $rootConfig
*
* @return array * @return array
*/ */
public function getPaths() public function getPaths($rootConfig = null)
{ {
$differentConfig = false;
if ($rootConfig === null) {
$rootConfig = $this->getBpConfig();
} else {
$differentConfig = $this->getBpConfig()->getName() !== $rootConfig->getName();
}
$paths = []; $paths = [];
foreach ($this->parents as $parent) { foreach ($this->parents as $parent) {
foreach ($parent->getPaths() as $path) { foreach ($parent->getPaths($rootConfig) as $path) {
$path[] = $this->getIdentifier(); $path[] = $differentConfig ? $this->getIdentifier() : $this->getName();
$paths[] = $path; $paths[] = $path;
} }
} }
if (! $this instanceof ImportedNode && $this->getBpConfig()->hasRootNode($this->getName())) { if (! $this instanceof ImportedNode && $this->getBpConfig()->hasRootNode($this->getName())) {
$paths[] = [$this->getIdentifier()]; $paths[] = [$differentConfig ? $this->getIdentifier() : $this->getName()];
} }
return $paths; return $paths;
@ -410,12 +419,7 @@ abstract class Node
public function getIdentifier() public function getIdentifier()
{ {
$prefix = ''; return '@' . $this->getBpConfig()->getName() . ':' . $this->getName();
if ($this->getBpConfig()->isImported()) {
$prefix = '@' . $this->getBpConfig()->getName() . ':';
}
return $prefix . $this->getName();
} }
public function __toString() public function __toString()

View file

@ -46,10 +46,12 @@ class Breadcrumb extends BaseHtmlElement
$path = $renderer->getCurrentPath(); $path = $renderer->getCurrentPath();
$parts = array(); $parts = array();
while ($node = array_pop($path)) { while ($nodeName = array_pop($path)) {
$node = $bp->getNode($nodeName);
$renderer->setParentNode($node);
array_unshift( array_unshift(
$parts, $parts,
static::renderNode($bp->getNode($node), $path, $renderer) static::renderNode($node, $path, $renderer)
); );
} }
$breadcrumb->add($parts); $breadcrumb->add($parts);

View file

@ -74,6 +74,17 @@ abstract class Renderer extends HtmlDocument
return $this->parent !== null; return $this->parent !== null;
} }
public function rendersImportedNode()
{
return $this->parent !== null && $this->parent->getBpConfig()->getName() !== $this->config->getName();
}
public function setParentNode(BpNode $node)
{
$this->parent = $node;
return $this;
}
/** /**
* @return BpNode * @return BpNode
*/ */
@ -213,8 +224,11 @@ abstract class Renderer extends HtmlDocument
{ {
$path = $this->getPath(); $path = $this->getPath();
if ($this->rendersSubNode()) { if ($this->rendersSubNode()) {
$path[] = $this->parent->getIdentifier(); $path[] = $this->rendersImportedNode()
? $this->parent->getIdentifier()
: $this->parent->getName();
} }
return $path; return $path;
} }

View file

@ -121,7 +121,12 @@ class NodeTile extends BaseHtmlElement
$url = $this->renderer->getBaseUrl(); $url = $this->renderer->getBaseUrl();
$p = $url->getParams(); $p = $url->getParams();
$p->set('node', $node->getIdentifier()); if ($this->renderer->rendersImportedNode()) {
$p->set('node', $node->getIdentifier());
} else {
$p->set('node', $node->getName());
}
if (! empty($this->path)) { if (! empty($this->path)) {
$p->addValues('path', $this->path); $p->addValues('path', $this->path);
} }

View file

@ -177,15 +177,14 @@ class TreeRenderer extends Renderer
$div->add($this->createInfoAction($node)); $div->add($this->createInfoAction($node));
} }
if (! $this->isLocked() && $node->getBpConfig()->getName() === $this->getBusinessProcess()->getName()) { $differentConfig = $node->getBpConfig()->getName() !== $this->getBusinessProcess()->getName();
if (! $this->isLocked() && !$differentConfig) {
$div->add($this->getActionIcons($bp, $node)); $div->add($this->getActionIcons($bp, $node));
} }
$ul = Html::tag('ul', [ $ul = Html::tag('ul', [
'class' => ['bp', 'sortable'], 'class' => ['bp', 'sortable'],
'data-sortable-disabled' => ( 'data-sortable-disabled' => ($this->isLocked() || $differentConfig) ? 'true' : 'false',
$this->isLocked() || $node->getBpConfig()->getName() !== $this->getBusinessProcess()->getName()
) ? 'true' : 'false',
'data-sortable-invert-swap' => 'true', 'data-sortable-invert-swap' => 'true',
'data-sortable-data-id-attr' => 'id', 'data-sortable-data-id-attr' => 'id',
'data-sortable-draggable' => '.movable', 'data-sortable-draggable' => '.movable',
@ -206,7 +205,7 @@ class TreeRenderer extends Renderer
]); ]);
$li->add($ul); $li->add($ul);
$path[] = $node->getIdentifier(); $path[] = $differentConfig ? $node->getIdentifier() : $node->getName();
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));

View file

@ -58,7 +58,7 @@ class RenderedProcessActionBar extends ActionBar
$hasChanges = $config->hasSimulations() || $config->hasBeenChanged(); $hasChanges = $config->hasSimulations() || $config->hasBeenChanged();
if ($renderer->isLocked()) { if ($renderer->isLocked()) {
if (! $renderer->wantsRootNodes() && $renderer->getParentNode()->getBpConfig()->isImported()) { if (! $renderer->wantsRootNodes() && $renderer->rendersImportedNode()) {
$span = Html::tag('span', [ $span = Html::tag('span', [
'class' => 'disabled', 'class' => 'disabled',
'title' => mt( 'title' => mt(