Properly handle display values when performing other actions than moving nodes

This commit is contained in:
Johannes Meyer 2019-01-15 09:35:57 +01:00
parent f022c0f101
commit bc03569765
5 changed files with 37 additions and 6 deletions

View file

@ -122,15 +122,20 @@ class AddNodeForm extends QuickForm
)
));
$display = 1;
if ($this->bp->getMetadata()->isManuallyOrdered() && !$this->bp->isEmpty()) {
$rootNodes = $this->bp->getRootNodes();
$display = end($rootNodes)->getDisplay() + 1;
}
$this->addElement('select', 'display', array(
'label' => $this->translate('Visualization'),
'required' => true,
'description' => $this->translate(
'Where to show this process'
),
'value' => $this->hasParentNode() ? '0' : '1',
'value' => $this->hasParentNode() ? '0' : "$display",
'multiOptions' => array(
'1' => $this->translate('Toplevel Process'),
"$display" => $this->translate('Toplevel Process'),
'0' => $this->translate('Subprocess only'),
)
));

View file

@ -126,15 +126,16 @@ class EditNodeForm extends QuickForm
)
));
$display = $this->getNode()->getDisplay() ?: 1;
$this->addElement('select', 'display', array(
'label' => $this->translate('Visualization'),
'required' => true,
'description' => $this->translate(
'Where to show this process'
),
'value' => $this->hasParentNode() ? '0' : '1',
'value' => $display,
'multiOptions' => array(
'1' => $this->translate('Toplevel Process'),
"$display" => $this->translate('Toplevel Process'),
'0' => $this->translate('Subprocess only'),
)
));

View file

@ -73,14 +73,20 @@ class ProcessForm extends QuickForm
)
));
if ($this->node !== null) {
$display = $this->node->getDisplay() ?: 1;
} else {
$display = 1;
}
$this->addElement('select', 'display', array(
'label' => $this->translate('Visualization'),
'required' => true,
'description' => $this->translate(
'Where to show this process'
),
'value' => $display,
'multiOptions' => array(
'1' => $this->translate('Toplevel Process'),
"$display" => $this->translate('Toplevel Process'),
'0' => $this->translate('Subprocess only'),
)
));
@ -97,7 +103,6 @@ class ProcessForm extends QuickForm
$this->getElement('alias')->setValue($node->getAlias());
}
$this->getElement('operator')->setValue($node->getOperator());
$this->getElement('display')->setValue($node->getDisplay());
if ($node->hasInfoUrl()) {
$this->getElement('url')->setValue($node->getInfoUrl());
}

View file

@ -112,6 +112,15 @@ class NodeCreateAction extends NodeAction
$node->$func($val);
}
if ($node->getDisplay() > 1) {
$i = $node->getDisplay();
foreach ($config->getRootNodes() as $_ => $rootNode) {
if ($rootNode->getDisplay() >= $node->getDisplay()) {
$rootNode->setDisplay(++$i);
}
}
}
$config->addNode($name, $node);
return $node;

View file

@ -66,7 +66,18 @@ class NodeRemoveAction extends NodeAction
$name = $this->getNodeName();
$parentName = $this->getParentName();
if ($parentName === null) {
$oldDisplay = $config->getBpNode($name)->getDisplay();
$config->removeNode($name);
if ($config->getMetadata()->isManuallyOrdered()) {
foreach ($config->getRootNodes() as $_ => $node) {
$nodeDisplay = $node->getDisplay();
if ($nodeDisplay > $oldDisplay) {
$node->setDisplay($node->getDisplay() - 1);
} elseif ($nodeDisplay === $oldDisplay) {
break; // Stop immediately to not make things worse ;)
}
}
}
} else {
$node = $config->getNode($name);
$parent = $config->getBpNode($parentName);