$view):
- $url = $this->url('toplevelview/show', array('name' => $name));
+ $url = $this->url('toplevelview/show', ['name' => $name]);
?>
= $view->getMeta('name') ?>
diff --git a/application/views/scripts/show/actions.phtml b/application/views/scripts/show/actions.phtml
index a94a438..b3e231a 100644
--- a/application/views/scripts/show/actions.phtml
+++ b/application/views/scripts/show/actions.phtml
@@ -7,49 +7,49 @@
echo $this->qlink(
$this->translate('Source'),
'toplevelview/show/source',
- array('name' => $view->getName()),
- array(
+ ['name' => $view->getName()],
+ [
'class' => 'action-link',
'icon' => 'doc-text',
'data-base-target' => '_next'
- )
+ ]
);
echo $this->qlink(
$this->translate('Fullscreen'),
'toplevelview/show',
- array(
+ [
'name' => $view->getName(),
'view' => 'compact',
'showFullscreen' => true
- ),
- array(
- 'class' => 'action-link',
- 'icon' => 'resize-full',
+ ],
+ [
+ 'class' => 'action-link',
+ 'icon' => 'resize-full',
'target' => '_blank'
- )
+ ]
);
if ($this->hasPermission('toplevelview/edit')) {
echo $this->qlink(
$this->translate('Edit'),
'toplevelview/edit',
- array('name' => $view->getName()),
- array(
+ ['name' => $view->getName()],
+ [
'class' => 'action-link',
'icon' => 'edit',
'data-base-target' => '_next'
- )
+ ]
);
echo $this->qlink(
$this->translate('Clone'),
'toplevelview/edit/clone',
- array('name' => $view->getName()),
- array(
+ ['name' => $view->getName()],
+ [
'class' => 'action-link',
'icon' => 'rewind',
'data-base-target' => '_next'
- )
+ ]
);
}
}
diff --git a/application/views/scripts/show/index.phtml b/application/views/scripts/show/index.phtml
index 811aeca..b2d6970 100644
--- a/application/views/scripts/show/index.phtml
+++ b/application/views/scripts/show/index.phtml
@@ -1,8 +1,6 @@
getTree();
if (! $this->compact):
diff --git a/application/views/scripts/show/tree.phtml b/application/views/scripts/show/tree.phtml
index ed503a3..7c622d0 100644
--- a/application/views/scripts/show/tree.phtml
+++ b/application/views/scripts/show/tree.phtml
@@ -1,8 +1,6 @@
getTree();
diff --git a/application/views/scripts/text/index.phtml b/application/views/scripts/text/index.phtml
index 3aaf6d0..7396bf6 100644
--- a/application/views/scripts/text/index.phtml
+++ b/application/views/scripts/text/index.phtml
@@ -1,5 +1,4 @@
compact):
?>
diff --git a/library/Toplevelview/Model/View.php b/library/Toplevelview/Model/View.php
index bb3d90b..2a65516 100644
--- a/library/Toplevelview/Model/View.php
+++ b/library/Toplevelview/Model/View.php
@@ -200,17 +200,6 @@ public function getTextChecksum(): string
return $this->textChecksum;
}
- /**
- * setFormat sets the format for this View
- * @param string $format Format for this view (e.g. 'yml')
- * @return $this
- */
- public function setFormat($format)
- {
- $this->format = $format;
- return $this;
- }
-
/**
* getFormat returns the View's format
*/
diff --git a/library/Toplevelview/Tree/TLVStatus.php b/library/Toplevelview/Tree/TLVStatus.php
index 4ef43e5..a39f033 100644
--- a/library/Toplevelview/Tree/TLVStatus.php
+++ b/library/Toplevelview/Tree/TLVStatus.php
@@ -8,7 +8,10 @@
*/
class TLVStatus
{
- protected $properties = array(
+ /**
+ * Properties track each tree nodes Icinga states
+ */
+ protected $properties = [
'critical_unhandled' => null,
'critical_handled' => null,
'warning_unhandled' => null,
@@ -20,9 +23,12 @@ class TLVStatus
'ok' => null,
'missing' => null,
'total' => null,
- );
+ ];
- protected static $statusPriority = array(
+ /**
+ * statusPriority decribes the priority from worst to best
+ */
+ protected static $statusPriority = [
'critical_unhandled',
'warning_unhandled',
'unknown_unhandled',
@@ -32,10 +38,16 @@ class TLVStatus
'ok',
'downtime_handled',
'missing',
- );
+ ];
- protected $meta = array();
+ /**
+ * meta tracks get overall count of hosts and services if this status object
+ */
+ protected $meta = [];
+ /**
+ * merge merges another TLVStatus object's properties into this object
+ */
public function merge(TLVStatus $status)
{
$properties = $status->getProperties();
@@ -49,22 +61,42 @@ public function merge(TLVStatus $status)
return $this;
}
+ /**
+ * get returns the given key's value from the properties
+ *
+ * @param string $key key of the property
+ */
public function get($key)
{
return $this->properties[$key];
}
+ /**
+ * set sets the given key/value in the properties
+ *
+ * @param string $key key of the property
+ * @param int $value value to set to property to
+ */
public function set($key, $value)
{
$this->properties[$key] = (int) $value;
return $this;
}
+ /**
+ * getProperties returns all properties
+ */
public function getProperties()
{
return $this->properties;
}
+ /**
+ * add adds the given value (integer) to the given property
+ *
+ * @param string $key key of the property
+ * @param int $value value to add to the property
+ */
public function add($key, $value = 1)
{
if ($this->properties[$key] === null) {
@@ -74,6 +106,9 @@ public function add($key, $value = 1)
return $this;
}
+ /**
+ * zero sets all properties to zero (0)
+ */
public function zero()
{
foreach (array_keys($this->properties) as $key) {
@@ -82,7 +117,13 @@ public function zero()
return $this;
}
- public function getOverall()
+ /**
+ * getOverall returns the worst state of this TLVStatus,
+ * given the statusPriority.
+ *
+ * @return string
+ */
+ public function getOverall(): string
{
foreach (static::$statusPriority as $key) {
if ($this->properties[$key] !== null && $this->properties[$key] > 0) {
@@ -92,11 +133,18 @@ public function getOverall()
return 'missing';
}
+ /**
+ * cssFriendly transforms the given key to be CSS friendly,
+ * meaning using spaces between the state and the handled indicator
+ */
protected function cssFriendly($key): string
{
return str_replace('_', ' ', $key);
}
+ /**
+ * getMeta returns the given key's value from the metadata
+ */
public function getMeta($key)
{
if (array_key_exists($key, $this->meta)) {
@@ -106,11 +154,9 @@ public function getMeta($key)
}
}
- public function getAllMeta()
- {
- return $this->meta;
- }
-
+ /**
+ * setMeta sets the given key/value in the metadata
+ */
public function setMeta($key, $value)
{
$this->meta[$key] = $value;
diff --git a/library/Toplevelview/Tree/TLVTree.php b/library/Toplevelview/Tree/TLVTree.php
index 012e9be..fc6ebd6 100644
--- a/library/Toplevelview/Tree/TLVTree.php
+++ b/library/Toplevelview/Tree/TLVTree.php
@@ -69,7 +69,7 @@ public function getById($id)
return $currentNode;
}
- public function getViewName(): string
+ public function getViewName(): ?string
{
return $this->viewName;
}
@@ -80,7 +80,7 @@ public function setViewName(string $name)
return $this;
}
- public function getViewChecksum(): string
+ public function getViewChecksum(): ?string
{
return $this->viewChecksum;
}
diff --git a/library/Toplevelview/Tree/TLVTreeNode.php b/library/Toplevelview/Tree/TLVTreeNode.php
index 395bfee..bd2ec28 100644
--- a/library/Toplevelview/Tree/TLVTreeNode.php
+++ b/library/Toplevelview/Tree/TLVTreeNode.php
@@ -70,12 +70,12 @@ class TLVTreeNode extends TreeNode
*
* @var array
*/
- protected static $typeMap = array(
+ protected static $typeMap = [
'host' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVHostNode',
'service' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVServiceNode',
'hostgroup' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVHostGroupNode',
'servicegroup' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVServiceGroupNode',
- );
+ ];
/**
* Mapping keys to a type
@@ -84,12 +84,12 @@ class TLVTreeNode extends TreeNode
*
* @var array
*/
- protected static $typeKeyMap = array(
- 'service' => array('host', 'service'),
+ protected static $typeKeyMap = [
+ 'service' => ['host', 'service'],
'host' => 'host',
'hostgroup' => 'hostgroup',
'servicegroup' => 'servicegroup',
- );
+ ];
/**
* @param $array
@@ -116,7 +116,7 @@ public static function fromArray($array, TLVTreeNode $parent = null, TLVTree $ro
if (! array_key_exists('type', $array)) {
foreach (self::$typeKeyMap as $type => $keys) {
if (! is_array($keys)) {
- $keys = array($keys);
+ $keys = [$keys];
}
$matched = false;
foreach ($keys as $k) {
diff --git a/library/Toplevelview/Util/Str.php b/library/Toplevelview/Util/Str.php
index ce93041..0560bb2 100644
--- a/library/Toplevelview/Util/Str.php
+++ b/library/Toplevelview/Util/Str.php
@@ -32,4 +32,20 @@ public static function limit($str, $len = 25, $end = '...'): string
// and add the given end to it.
return mb_strimwidth($str, 0, $len, '', 'UTF-8') . $end;
}
+
+ /**
+ * Transforms the title badge title "warning_unhandled" to "Warning Unhandled"
+ *
+ * @param string $identifier
+ *
+ * @return string
+ */
+ public static function prettyTitle($identifier): string
+ {
+ $s = '';
+ foreach (explode('_', $identifier) as $p) {
+ $s .= ' ' . ucfirst($p);
+ }
+ return trim($s);
+ }
}
diff --git a/test/php/library/Toplevelview/Tree/TLVStatusTest.php b/test/php/library/Toplevelview/Tree/TLVStatusTest.php
index 0f976ca..6cc0ba2 100644
--- a/test/php/library/Toplevelview/Tree/TLVStatusTest.php
+++ b/test/php/library/Toplevelview/Tree/TLVStatusTest.php
@@ -27,11 +27,21 @@ public function testGetOverall()
$this->assertSame(0, $t->get('missing'));
}
+ public function testGetOverallWithMissing()
+ {
+ $t = new TLVStatus();
+ $this->assertSame('missing', $t->getOverall());
+ }
+
public function testGetterSetter()
{
$t = new TLVStatus();
$t->set('missing', 123);
$this->assertSame(123, $t->get('missing'));
+
+ $t->setMeta('hosts_total', 321);
+ $this->assertSame(321, $t->getMeta('hosts_total'));
+ $this->assertSame(null, $t->getMeta('services_total'));
}
public function testMerge()
diff --git a/test/php/library/Toplevelview/Util/StrTest.php b/test/php/library/Toplevelview/Util/StrTest.php
index cb3fe6b..6106115 100644
--- a/test/php/library/Toplevelview/Util/StrTest.php
+++ b/test/php/library/Toplevelview/Util/StrTest.php
@@ -41,4 +41,14 @@ public function testLimitWithLongerStringAndSpecificEnd()
Str::limit('Кто это читает, тот дурак', 1, ' (🦔🦔🦔)')
);
}
+
+ public function testPrettyPrint()
+ {
+ $this->assertSame('Critical Unhandled', Str::prettyTitle('critical_unhandled'));
+ $this->assertSame('Warning Handled', Str::prettyTitle('warning_handled'));
+ $this->assertSame('Foo Bar', Str::prettyTitle('foo_bar'));
+ $this->assertSame('XXX YYY', Str::prettyTitle('XXX_YYY'));
+ $this->assertSame('', Str::prettyTitle(''));
+ $this->assertSame('Ok', Str::prettyTitle('ok'));
+ }
}