mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 14:50:11 -05:00
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:
parent
40538c51ce
commit
eaf5b85538
9 changed files with 48 additions and 43 deletions
|
|
@ -46,7 +46,7 @@ class NodeController extends Controller
|
|||
|
||||
if ($importedConfig->hasNode($name)) {
|
||||
$node = $importedConfig->getNode($name);
|
||||
$nativePaths = $node->getPaths();
|
||||
$nativePaths = $node->getPaths($config);
|
||||
|
||||
do {
|
||||
$path = array_pop($nativePaths);
|
||||
|
|
@ -55,7 +55,7 @@ class NodeController extends Controller
|
|||
array_pop($path); // Remove the monitored node
|
||||
$immediateParentName = array_pop($path); // The directly affected process
|
||||
$importedPath = array_slice($path, $importedNodePos + 1);
|
||||
foreach ($importedNode->getPaths() as $targetPath) {
|
||||
foreach ($importedNode->getPaths($config) as $targetPath) {
|
||||
if ($targetPath[count($targetPath) - 1] === $immediateParentName) {
|
||||
array_pop($targetPath);
|
||||
$parent = $importedNode;
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class ProcessController extends Controller
|
|||
|
||||
$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')) {
|
||||
$renderer->unlock();
|
||||
}
|
||||
|
|
@ -141,7 +141,7 @@ class ProcessController extends Controller
|
|||
if (! ($this->showFullscreen || $this->view->compact)) {
|
||||
$controls->add($this->getProcessTabs($bp, $renderer));
|
||||
}
|
||||
$controls->add(Breadcrumb::create($renderer));
|
||||
$controls->add(Breadcrumb::create(clone $renderer));
|
||||
if (! $this->showFullscreen && ! $this->view->compact) {
|
||||
$controls->add(
|
||||
new RenderedProcessActionBar($bp, $renderer, $this->Auth(), $this->url())
|
||||
|
|
|
|||
|
|
@ -88,13 +88,6 @@ class BpConfig
|
|||
*/
|
||||
protected $root_nodes = array();
|
||||
|
||||
/**
|
||||
* Whether this configuration has been imported
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $imported = false;
|
||||
|
||||
/**
|
||||
* Imported nodes
|
||||
*
|
||||
|
|
@ -561,17 +554,6 @@ class BpConfig
|
|||
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)
|
||||
{
|
||||
$params = (object) array('configName' => $config);
|
||||
|
|
@ -594,7 +576,6 @@ class BpConfig
|
|||
{
|
||||
if (! isset($this->importedConfigs[$name])) {
|
||||
$import = $this->storage()->loadProcess($name);
|
||||
$import->setImported();
|
||||
|
||||
if ($this->usesSoftStates()) {
|
||||
$import->useSoftStates();
|
||||
|
|
|
|||
|
|
@ -339,20 +339,29 @@ abstract class Node
|
|||
}
|
||||
|
||||
/**
|
||||
* @param BpConfig $rootConfig
|
||||
*
|
||||
* @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 = [];
|
||||
foreach ($this->parents as $parent) {
|
||||
foreach ($parent->getPaths() as $path) {
|
||||
$path[] = $this->getIdentifier();
|
||||
foreach ($parent->getPaths($rootConfig) as $path) {
|
||||
$path[] = $differentConfig ? $this->getIdentifier() : $this->getName();
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this instanceof ImportedNode && $this->getBpConfig()->hasRootNode($this->getName())) {
|
||||
$paths[] = [$this->getIdentifier()];
|
||||
$paths[] = [$differentConfig ? $this->getIdentifier() : $this->getName()];
|
||||
}
|
||||
|
||||
return $paths;
|
||||
|
|
@ -410,12 +419,7 @@ abstract class Node
|
|||
|
||||
public function getIdentifier()
|
||||
{
|
||||
$prefix = '';
|
||||
if ($this->getBpConfig()->isImported()) {
|
||||
$prefix = '@' . $this->getBpConfig()->getName() . ':';
|
||||
}
|
||||
|
||||
return $prefix . $this->getName();
|
||||
return '@' . $this->getBpConfig()->getName() . ':' . $this->getName();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
|
|
|||
|
|
@ -46,10 +46,12 @@ class Breadcrumb extends BaseHtmlElement
|
|||
$path = $renderer->getCurrentPath();
|
||||
|
||||
$parts = array();
|
||||
while ($node = array_pop($path)) {
|
||||
while ($nodeName = array_pop($path)) {
|
||||
$node = $bp->getNode($nodeName);
|
||||
$renderer->setParentNode($node);
|
||||
array_unshift(
|
||||
$parts,
|
||||
static::renderNode($bp->getNode($node), $path, $renderer)
|
||||
static::renderNode($node, $path, $renderer)
|
||||
);
|
||||
}
|
||||
$breadcrumb->add($parts);
|
||||
|
|
|
|||
|
|
@ -74,6 +74,17 @@ abstract class Renderer extends HtmlDocument
|
|||
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
|
||||
*/
|
||||
|
|
@ -213,8 +224,11 @@ abstract class Renderer extends HtmlDocument
|
|||
{
|
||||
$path = $this->getPath();
|
||||
if ($this->rendersSubNode()) {
|
||||
$path[] = $this->parent->getIdentifier();
|
||||
$path[] = $this->rendersImportedNode()
|
||||
? $this->parent->getIdentifier()
|
||||
: $this->parent->getName();
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,12 @@ class NodeTile extends BaseHtmlElement
|
|||
$url = $this->renderer->getBaseUrl();
|
||||
|
||||
$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)) {
|
||||
$p->addValues('path', $this->path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,15 +177,14 @@ class TreeRenderer extends Renderer
|
|||
$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));
|
||||
}
|
||||
|
||||
$ul = Html::tag('ul', [
|
||||
'class' => ['bp', 'sortable'],
|
||||
'data-sortable-disabled' => (
|
||||
$this->isLocked() || $node->getBpConfig()->getName() !== $this->getBusinessProcess()->getName()
|
||||
) ? 'true' : 'false',
|
||||
'data-sortable-disabled' => ($this->isLocked() || $differentConfig) ? 'true' : 'false',
|
||||
'data-sortable-invert-swap' => 'true',
|
||||
'data-sortable-data-id-attr' => 'id',
|
||||
'data-sortable-draggable' => '.movable',
|
||||
|
|
@ -206,7 +205,7 @@ class TreeRenderer extends Renderer
|
|||
]);
|
||||
$li->add($ul);
|
||||
|
||||
$path[] = $node->getIdentifier();
|
||||
$path[] = $differentConfig ? $node->getIdentifier() : $node->getName();
|
||||
foreach ($node->getChildren() as $name => $child) {
|
||||
if ($child instanceof BpNode) {
|
||||
$ul->add($this->renderNode($bp, $child, $path));
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class RenderedProcessActionBar extends ActionBar
|
|||
$hasChanges = $config->hasSimulations() || $config->hasBeenChanged();
|
||||
|
||||
if ($renderer->isLocked()) {
|
||||
if (! $renderer->wantsRootNodes() && $renderer->getParentNode()->getBpConfig()->isImported()) {
|
||||
if (! $renderer->wantsRootNodes() && $renderer->rendersImportedNode()) {
|
||||
$span = Html::tag('span', [
|
||||
'class' => 'disabled',
|
||||
'title' => mt(
|
||||
|
|
|
|||
Loading…
Reference in a new issue