summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Widget
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/Web/Widget')
-rw-r--r--library/Director/Web/Widget/ActivityLogInfo.php46
-rw-r--r--library/Director/Web/Widget/AdditionalTableActions.php5
-rw-r--r--library/Director/Web/Widget/BranchedObjectHint.php48
-rw-r--r--library/Director/Web/Widget/BranchedObjectsHint.php7
-rw-r--r--library/Director/Web/Widget/DeploymentInfo.php27
-rw-r--r--library/Director/Web/Widget/IcingaObjectInspection.php2
6 files changed, 99 insertions, 36 deletions
diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php
index 8454b26..2b64fd4 100644
--- a/library/Director/Web/Widget/ActivityLogInfo.php
+++ b/library/Director/Web/Widget/ActivityLogInfo.php
@@ -3,7 +3,10 @@
namespace Icinga\Module\Director\Web\Widget;
use gipfl\Json\JsonString;
+use Icinga\Module\Director\Data\FieldReferenceLoader;
+use Icinga\Module\Director\DirectorObject\Automation\BasketSnapshotFieldResolver;
use Icinga\Module\Director\Objects\DirectorActivityLog;
+use Icinga\Module\Director\Web\Form\IcingaObjectFieldLoader;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use Icinga\Date\DateFormatter;
@@ -83,8 +86,7 @@ class ActivityLogInfo extends HtmlDocument
/** @var Url $url */
$url = $url->without('checksum')->without('show');
$div = Html::tag('div', [
- 'class' => 'pagination-control',
- 'style' => 'float: right; width: 5em'
+ 'class' => ['pagination-control', 'activity-log-control'],
]);
$ul = Html::tag('ul', ['class' => 'nav tab-nav']);
@@ -434,11 +436,30 @@ class ActivityLogInfo extends HtmlDocument
{
if ($object instanceof IcingaService) {
return $this->previewService($object);
+ } elseif ($object instanceof IcingaServiceSet) {
+ return $this->previewServiceSet($object);
} else {
return $object->toSingleIcingaConfig();
}
}
+ /**
+ * Render service set to be previewed
+ *
+ * @param IcingaServiceSet $object
+ *
+ * @return IcingaConfig
+ */
+ protected function previewServiceSet(IcingaServiceSet $object)
+ {
+ $config = $object->toSingleIcingaConfig();
+ foreach ($object->getCachedServices() as $service) {
+ $service->renderToConfig($config);
+ }
+
+ return $config;
+ }
+
protected function previewService(IcingaService $service)
{
if (($set = $service->get('service_set')) !== null) {
@@ -625,10 +646,27 @@ class ActivityLogInfo extends HtmlDocument
$newProps['object_type'] = $props->object_type;
}
- return IcingaObject::createByType(
+ $object = IcingaObject::createByType(
$type,
$newProps,
$this->db
- )->setProperties((array) $props);
+ );
+
+ if ($type === 'icinga_service_set' && isset($props->services)) {
+ $services = [];
+ foreach ($props->services as $service) {
+ $services[$service->object_name] = IcingaObject::createByType(
+ 'icinga_service',
+ (array) $service,
+ $this->db
+ );
+ }
+
+ /** @var IcingaServiceSet $object */
+ $object->setCachedServices($services);
+ unset($props->services);
+ }
+
+ return $object->setProperties((array) $props);
}
}
diff --git a/library/Director/Web/Widget/AdditionalTableActions.php b/library/Director/Web/Widget/AdditionalTableActions.php
index 978f399..7495189 100644
--- a/library/Director/Web/Widget/AdditionalTableActions.php
+++ b/library/Director/Web/Widget/AdditionalTableActions.php
@@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Web\Widget;
+use Icinga\Module\Director\Auth\Permission;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use gipfl\IcingaWeb2\Icon;
@@ -35,10 +36,10 @@ class AdditionalTableActions
public function appendTo(HtmlDocument $parent)
{
$links = [];
- if ($this->hasPermission('director/admin')) {
+ if ($this->hasPermission(Permission::ADMIN)) {
$links[] = $this->createDownloadJsonLink();
}
- if ($this->hasPermission('director/showsql')) {
+ if ($this->hasPermission(Permission::SHOW_SQL)) {
$links[] = $this->createShowSqlToggle();
}
diff --git a/library/Director/Web/Widget/BranchedObjectHint.php b/library/Director/Web/Widget/BranchedObjectHint.php
index ec16094..c50f923 100644
--- a/library/Director/Web/Widget/BranchedObjectHint.php
+++ b/library/Director/Web/Widget/BranchedObjectHint.php
@@ -15,33 +15,45 @@ class BranchedObjectHint extends HtmlDocument
{
use TranslationHelper;
- public function __construct(Branch $branch, Auth $auth, BranchedObject $object = null)
+ public function __construct(Branch $branch, Auth $auth, BranchedObject $object = null, $hasPreferredBranch = false)
{
if (! $branch->isBranch()) {
- return;
- }
- $hook = Branch::requireHook();
-
- $name = $branch->getName();
- if (substr($name, 0, 1) === '/') {
- $label = $this->translate('this configuration branch');
+ 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;
+ }
} else {
- $label = $name;
+ $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);
}
- $link = $hook->linkToBranch($branch, $auth, $label);
+
if ($object === null) {
- $this->add(Hint::info(Html::sprintf($this->translate(
- 'This object will be created in %s. It will not be part of any deployment'
- . ' unless being merged'
- ), $link)));
+ $this->add(Hint::$hintMethod(Html::sprintf($this->translate(
+ 'This object will be created in %s.'
+ ) . $deployHint, $link)));
return;
}
if (! $object->hasBeenTouchedByBranch()) {
- $this->add(Hint::info(Html::sprintf($this->translate(
- 'Your changes will be stored in %s. The\'ll not be part of any deployment'
- . ' unless being merged'
- ), $link)));
+ $this->add(Hint::$hintMethod(Html::sprintf($this->translate(
+ 'Your changes are going to be stored in %s.'
+ ) . $deployHint, $link)));
+ return;
+ }
+ if ($main) {
return;
}
diff --git a/library/Director/Web/Widget/BranchedObjectsHint.php b/library/Director/Web/Widget/BranchedObjectsHint.php
index d689178..3f00f9e 100644
--- a/library/Director/Web/Widget/BranchedObjectsHint.php
+++ b/library/Director/Web/Widget/BranchedObjectsHint.php
@@ -13,9 +13,14 @@ class BranchedObjectsHint extends HtmlDocument
{
use TranslationHelper;
- public function __construct(Branch $branch, Auth $auth)
+ public function __construct(Branch $branch, Auth $auth, $hasPreferredBranch = false)
{
if (! $branch->isBranch()) {
+ if ($hasPreferredBranch) {
+ $this->add(Hint::warning($this->translate(
+ "You're currently in the master branch, your changes will make part of the next Deployment"
+ )));
+ }
return;
}
$hook = Branch::requireHook();
diff --git a/library/Director/Web/Widget/DeploymentInfo.php b/library/Director/Web/Widget/DeploymentInfo.php
index 110200f..1f87abc 100644
--- a/library/Director/Web/Widget/DeploymentInfo.php
+++ b/library/Director/Web/Widget/DeploymentInfo.php
@@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Web\Widget;
+use Icinga\Module\Director\Auth\Permission;
use ipl\Html\HtmlDocument;
use Icinga\Authentication\Auth;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
@@ -55,7 +56,7 @@ class DeploymentInfo extends HtmlDocument
'url' => $request->getUrl()
))->activate('deployment');
- if ($dep->config_checksum !== null && $auth->hasPermission('director/showconfig')) {
+ if ($dep->config_checksum !== null && $auth->hasPermission(Permission::SHOW_CONFIG)) {
$tabs->add('config', array(
'label' => $this->translate('Config'),
'url' => 'director/config/files',
@@ -72,7 +73,8 @@ class DeploymentInfo extends HtmlDocument
protected function createInfoTable()
{
$dep = $this->deployment;
- $table = new NameValueTable();
+ $table = (new NameValueTable())
+ ->addAttributes(['class' => 'deployment-details']);
$table->addNameValuePairs([
$this->translate('Deployment time') => $dep->start_time,
$this->translate('Sent to') => $dep->peer_identity,
@@ -135,16 +137,21 @@ class DeploymentInfo extends HtmlDocument
} else {
return [$this->translate('Unknown, failed to collect related information'), new Icon('help')];
}
- } elseif ($dep->startup_succeeded === 'y') {
- return $this->colored('green', [$this->translate('Succeeded'), new Icon('ok')]);
} else {
- return $this->colored('red', [$this->translate('Failed'), new Icon('cancel')]);
- }
- }
+ $div = Html::tag('div')->setSeparator(' ');
- protected function colored($color, array $content)
- {
- return Html::tag('div', ['style' => "color: $color;"], $content)->setSeparator(' ');
+ if ($dep->startup_succeeded === 'y') {
+ $div
+ ->addAttributes(['class' => 'succeeded'])
+ ->add([$this->translate('Succeeded'), new Icon('ok')]);
+ } else {
+ $div
+ ->addAttributes(['class' => 'failed'])
+ ->add([$this->translate('Failed'), new Icon('cancel')]);
+ }
+
+ return $div;
+ }
}
public function render()
diff --git a/library/Director/Web/Widget/IcingaObjectInspection.php b/library/Director/Web/Widget/IcingaObjectInspection.php
index 61f3567..d9cf69d 100644
--- a/library/Director/Web/Widget/IcingaObjectInspection.php
+++ b/library/Director/Web/Widget/IcingaObjectInspection.php
@@ -205,7 +205,7 @@ class IcingaObjectInspection extends BaseHtmlElement
$this->add(Html::tag('p')->add(Html::sprintf(
'The configuration for this object has been rendered by Icinga'
. ' Director %s to %s',
- DateFormatter::timeAgo(strtotime($deployment->start_time, false)),
+ DateFormatter::timeAgo(strtotime($deployment->start_time)),
$this->linkToSourceLocation($deployment, $source)
)));
}