Skip to content

Commit

Permalink
StateBadges: Prepend base table name to state filters
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Nov 12, 2021
1 parent 4f156b7 commit 8b7e83f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
23 changes: 20 additions & 3 deletions library/Icingadb/Common/StateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ abstract class StateBadges extends BaseHtmlElement
/** @var object $item */
protected $item;

/** @var string */
protected $type;

/** @var string Prefix */
protected $prefix;

Expand All @@ -37,6 +40,7 @@ abstract class StateBadges extends BaseHtmlElement
public function __construct($item)
{
$this->item = $item;
$this->type = $this->getType();
$this->prefix = $this->getPrefix();
$this->url = $this->getBaseUrl();
}
Expand All @@ -48,6 +52,13 @@ public function __construct($item)
*/
abstract protected function getBaseUrl(): Url;

/**
* Get the type of the items
*
* @return string
*/
abstract protected function getType(): string;

/**
* Get the prefix for accessing state information
*
Expand Down Expand Up @@ -125,7 +136,7 @@ protected function createBadge(string $state)
if (isset($this->item->$key) && $this->item->$key) {
return Html::tag('li', $this->createLink(
new StateBadge($this->item->$key, $state),
['state.soft_state' => $this->getStateInt($state)]
[$this->type . '.state.soft_state' => $this->getStateInt($state)]
));
}

Expand All @@ -148,14 +159,20 @@ protected function createGroup(string $state)
if (isset($this->item->$unhandledKey) && $this->item->$unhandledKey) {
$content[] = Html::tag('li', $this->createLink(
new StateBadge($this->item->$unhandledKey, $state),
['state.soft_state' => $this->getStateInt($state), 'state.is_handled' => 'n']
[
$this->type . '.state.soft_state' => $this->getStateInt($state),
$this->type . '.state.is_handled' => 'n'
]
));
}

if (isset($this->item->$handledKey) && $this->item->$handledKey) {
$content[] = Html::tag('li', $this->createLink(
new StateBadge($this->item->$handledKey, $state, true),
['state.soft_state' => $this->getStateInt($state), 'state.is_handled' => 'y']
[
$this->type . '.state.soft_state' => $this->getStateInt($state),
$this->type . '.state.is_handled' => 'y'
]
));
}

Expand Down
5 changes: 5 additions & 0 deletions library/Icingadb/Widget/HostStateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ protected function getBaseUrl(): Url
return Links::hosts();
}

protected function getType(): string
{
return 'host';
}

protected function getPrefix(): string
{
return 'hosts';
Expand Down
5 changes: 5 additions & 0 deletions library/Icingadb/Widget/ServiceStateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ protected function getBaseUrl(): Url
return Links::services();
}

protected function getType(): string
{
return 'service';
}

protected function getPrefix(): string
{
return 'services';
Expand Down

0 comments on commit 8b7e83f

Please sign in to comment.