2021-08-16 11:43:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Widget;
|
|
|
|
|
|
|
|
use gipfl\Translation\TranslationHelper;
|
|
|
|
use gipfl\Web\Widget\Hint;
|
2021-08-23 09:01:03 +02:00
|
|
|
use Icinga\Authentication\Auth;
|
2022-02-06 19:09:30 +01:00
|
|
|
use Icinga\Exception\NotFoundError;
|
2021-08-16 11:43:09 +02:00
|
|
|
use Icinga\Module\Director\Db\Branch\Branch;
|
2021-10-05 19:13:57 +02:00
|
|
|
use Icinga\Module\Director\Db\Branch\BranchedObject;
|
2021-08-16 11:43:09 +02:00
|
|
|
use ipl\Html\Html;
|
|
|
|
use ipl\Html\HtmlDocument;
|
|
|
|
|
2021-10-05 19:13:57 +02:00
|
|
|
class BranchedObjectHint extends HtmlDocument
|
2021-08-16 11:43:09 +02:00
|
|
|
{
|
|
|
|
use TranslationHelper;
|
|
|
|
|
2022-12-16 14:16:02 +01:00
|
|
|
public function __construct(Branch $branch, Auth $auth, BranchedObject $object = null, $hasPreferredBranch = false)
|
2021-08-16 11:43:09 +02:00
|
|
|
{
|
|
|
|
if (! $branch->isBranch()) {
|
2022-12-16 14:16:02 +01:00
|
|
|
if ($hasPreferredBranch) {
|
|
|
|
$main = true;
|
|
|
|
$hintMethod = 'warning';
|
|
|
|
$link = $this->translate('the main configuration branch');
|
|
|
|
$deployHint = ' ' . $this->translate('This will be part of the next deployment');
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-23 09:01:03 +02:00
|
|
|
} else {
|
2022-12-16 14:16:02 +01:00
|
|
|
$main = false;
|
|
|
|
$hintMethod = 'info';
|
|
|
|
$deployHint = ' ' . $this->translate('This will not be part of any deployment, unless being merged');
|
|
|
|
$hook = Branch::requireHook();
|
|
|
|
$name = $branch->getName();
|
|
|
|
if (substr($name, 0, 1) === '/') {
|
|
|
|
$label = $this->translate('this configuration branch');
|
|
|
|
} else {
|
|
|
|
$label = $name;
|
|
|
|
}
|
|
|
|
$link = $hook->linkToBranch($branch, $auth, $label);
|
2021-08-23 09:01:03 +02:00
|
|
|
}
|
2022-12-16 14:16:02 +01:00
|
|
|
|
2022-09-20 12:03:46 +02:00
|
|
|
if ($object === null) {
|
2022-12-16 14:16:02 +01:00
|
|
|
$this->add(Hint::$hintMethod(Html::sprintf($this->translate(
|
|
|
|
'This object will be created in %s.'
|
|
|
|
) . $deployHint, $link)));
|
2022-09-20 12:03:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-08-23 09:01:03 +02:00
|
|
|
|
2021-10-05 19:13:57 +02:00
|
|
|
if (! $object->hasBeenTouchedByBranch()) {
|
2022-12-16 14:16:02 +01:00
|
|
|
$this->add(Hint::$hintMethod(Html::sprintf($this->translate(
|
|
|
|
'Your changes are going to be stored in %s.'
|
|
|
|
) . $deployHint, $link)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($main) {
|
2021-08-16 11:43:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-05 19:13:57 +02:00
|
|
|
if ($object->hasBeenDeletedByBranch()) {
|
2022-02-06 19:09:30 +01:00
|
|
|
throw new NotFoundError('No such object available');
|
|
|
|
// Alternative, requires hiding other actions:
|
|
|
|
// $this->add(Hint::info(Html::sprintf(
|
|
|
|
// $this->translate('This object has been deleted in %s'),
|
|
|
|
// $link
|
|
|
|
// )));
|
2021-10-05 19:13:57 +02:00
|
|
|
} elseif ($object->hasBeenCreatedByBranch()) {
|
2021-08-16 11:43:09 +02:00
|
|
|
$this->add(Hint::info(Html::sprintf(
|
2021-10-05 19:13:57 +02:00
|
|
|
$this->translate('This object has been created in %s'),
|
2021-08-23 09:01:03 +02:00
|
|
|
$link
|
2021-08-16 11:43:09 +02:00
|
|
|
)));
|
|
|
|
} else {
|
|
|
|
$this->add(Hint::info(Html::sprintf(
|
2021-10-05 19:13:57 +02:00
|
|
|
$this->translate('This object has modifications visible only in %s'),
|
|
|
|
// TODO: Also link to object modifications
|
|
|
|
// $hook->linkToBranchedObject($this->translate('modifications'), $branch, $object, $auth),
|
2021-08-23 09:01:03 +02:00
|
|
|
$link
|
2021-08-16 11:43:09 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|