Skip to content

Commit

Permalink
RedundancyGroupListItem: Remove plugin output from caption
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 28, 2024
1 parent e82398e commit 2467f30
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 101 deletions.
94 changes: 6 additions & 88 deletions library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

namespace Icinga\Module\Icingadb\Widget\ItemList;

use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Database;
use Icinga\Module\Icingadb\Common\ListItemCommonLayout;
use Icinga\Module\Icingadb\Model\RedundancyGroup;
use Icinga\Module\Icingadb\Model\RedundancyGroupSummary;
use Icinga\Module\Icingadb\Model\RedundancyGroupState;
use Icinga\Module\Icingadb\Util\PluginOutput;
use Icinga\Module\Icingadb\Widget\PluginOutputContainer;
use Icinga\Module\Icingadb\Widget\DependencyNodeStatistics;
use ipl\Html\BaseHtmlElement;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\StateBall;
use ipl\Html\HtmlElement;
Expand All @@ -30,36 +26,13 @@
class RedundancyGroupListItem extends StateListItem
{
use ListItemCommonLayout;
use Auth;
use Database;

protected $defaultAttributes = ['class' => ['list-item', 'redundancy-group-list-item']];

/** @var RedundancyGroupSummary Objects state summary */
protected $summary;

/** @var RedundancyGroupState */
protected $state;

/** @var bool Whether the redundancy group has been handled */
protected $isHandled = false;

protected function init(): void
{
parent::init();

$this->summary = RedundancyGroupSummary::on($this->getDb())
->filter(Filter::equal('id', $this->item->id))
->first();

$this->isHandled = $this->state->failed
&& (
$this->summary->nodes_problem_handled
|| $this->summary->nodes_unknown_handled
|| $this->summary->nodes_warning_handled
);
}

protected function getStateBallSize(): string
{
return StateBall::SIZE_LARGE;
Expand All @@ -81,71 +54,16 @@ protected function createSubject(): BaseHtmlElement

protected function assembleVisual(BaseHtmlElement $visual): void
{
$stateBall = new StateBall($this->state->getStateText(), $this->getStateBallSize());
if ($this->isHandled) {
$stateBall->getAttributes()->add('class', 'handled');
}

$visual->addHtml($stateBall);
$visual->addHtml(new StateBall($this->state->getStateText(), $this->getStateBallSize()));
}

protected function assembleCaption(BaseHtmlElement $caption): void
{
$members = RedundancyGroup::on($this->getDb())
->columns([
'id' => 'id',
'nodes_output' => new Expression(
'CASE WHEN redundancy_group_from_to_service.id IS NOT NULL'
. ' THEN redundancy_group_from_to_service_state.output'
. ' ELSE redundancy_group_from_to_host_state.output END'
),
'nodes_long_output' => new Expression(
'CASE WHEN redundancy_group_from_to_service.id IS NOT NULL'
. ' THEN redundancy_group_from_to_service_state.long_output'
. ' ELSE redundancy_group_from_to_host_state.long_output END'
),
'nodes_checkcommand_name' => new Expression(
'CASE WHEN redundancy_group_from_to_service.id IS NOT NULL'
. ' THEN redundancy_group_from_to_service.checkcommand_name'
. ' ELSE redundancy_group_from_to_host.checkcommand_name END'
),
'nodes_last_state_change' => new Expression(
'CASE WHEN redundancy_group_from_to_service.id IS NOT NULL'
. ' THEN redundancy_group_from_to_service_state.last_state_change'
. ' ELSE redundancy_group_from_to_host_state.last_state_change END'
),
'nodes_severity' => new Expression(
'CASE WHEN redundancy_group_from_to_service.id IS NOT NULL'
. ' THEN redundancy_group_from_to_service_state.severity'
. ' ELSE redundancy_group_from_to_host_state.severity END'
)
])
->with([
'from',
'from.to.host',
'from.to.host.state',
'from.to.service',
'from.to.service.state'
])
->filter(Filter::equal('id', $this->item->id))
->orderBy([
'nodes_severity',
'nodes_last_state_change',
], SORT_DESC);

$this->applyRestrictions($members);

/** @var RedundancyGroup $data */
$data = $members->first();

if ($data) {
$caption->addHtml(new PluginOutputContainer(
(new PluginOutput($data->nodes_output . "\n" . $data->nodes_long_output))
->setCommandName($data->nodes_checkcommand_name)
));
}

$caption->addHtml(new DependencyNodeStatistics($this->summary));
$caption->addHtml(new DependencyNodeStatistics(
RedundancyGroupSummary::on($this->getDb())
->filter(Filter::equal('id', $this->item->id))
->first()
));
}

protected function assembleTitle(BaseHtmlElement $title): void
Expand Down
14 changes: 1 addition & 13 deletions public/css/list/redundancy-group-list-item.less
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
.redundancy-group-list-item {
.caption {
display: flex;
align-items: baseline;

.plugin-output {
// Allows the plugin output width to grow or shrink based on the width of object statistics
flex: 1 1 auto;
// Since caption is not -webkit-box anymore, its line-clamp rule will not be inherited
// and hence applied here directly
.line-clamp(2);
}

.object-statistics {
// Prevents the wrapping effect caused by changing caption to a flexbox
flex: 0 0 auto;
justify-content: end;
}
}
}

0 comments on commit 2467f30

Please sign in to comment.