From a76399f15f812d8eeb30f431cb5a6210e67edfb2 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 22 Apr 2024 17:29:04 +0200 Subject: [PATCH] Move source icon in incident detail to the header --- application/controllers/EventController.php | 2 +- .../controllers/IncidentsController.php | 2 +- .../Widget/Detail/IncidentDetail.php | 1 - .../ItemList/IncidentHistoryListItem.php | 6 ----- .../Widget/ItemList/IncidentListItem.php | 25 ++++++++++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/application/controllers/EventController.php b/application/controllers/EventController.php index 55a873e0d..f3ae1e8d1 100644 --- a/application/controllers/EventController.php +++ b/application/controllers/EventController.php @@ -25,7 +25,7 @@ public function indexAction(): void $id = $this->params->getRequired('id'); $query = Event::on(Database::get()) - ->with(['object', 'object.source', 'incident', 'incident.object']) + ->with(['object', 'object.source', 'incident', 'incident.object', 'incident.object.source']) ->withColumns(['object.id_tags', 'incident.object.id_tags']) ->filter(Filter::equal('event.id', $id)); diff --git a/application/controllers/IncidentsController.php b/application/controllers/IncidentsController.php index 082a4f6a5..a0a50a776 100644 --- a/application/controllers/IncidentsController.php +++ b/application/controllers/IncidentsController.php @@ -29,7 +29,7 @@ public function indexAction(): void $this->addTitleTab(t('Incidents')); $incidents = Incident::on(Database::get()) - ->with('object') + ->with(['object', 'object.source']) ->withColumns('object.id_tags'); $limitControl = $this->createLimitControl(); diff --git a/library/Notifications/Widget/Detail/IncidentDetail.php b/library/Notifications/Widget/Detail/IncidentDetail.php index 949cefae4..ac747b594 100644 --- a/library/Notifications/Widget/Detail/IncidentDetail.php +++ b/library/Notifications/Widget/Detail/IncidentDetail.php @@ -97,7 +97,6 @@ protected function createHistory() ->with([ 'event', 'incident.object', - 'incident.object.source', 'contact', 'rule', 'rule_escalation', diff --git a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php index cc1876b7e..5bc6078a8 100644 --- a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php @@ -9,7 +9,6 @@ use Icinga\Module\Notifications\Model\Event; use Icinga\Module\Notifications\Model\IncidentHistory; use Icinga\Module\Notifications\Model\Objects; -use Icinga\Module\Notifications\Widget\SourceIcon; use ipl\Html\BaseHtmlElement; use ipl\Web\Widget\IcingaIcon; use ipl\Web\Common\BaseListItem; @@ -76,11 +75,6 @@ protected function assembleHeader(BaseHtmlElement $header): void } $header->addHtml($this->createCaption()); - if ($this->item->type === 'opened' || $this->item->type === 'incident_severity_changed') { - $header->add( - (new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($this->item->incident->object->source->getIcon()) - ); - } $header->add(new TimeAgo($this->item->time->getTimestamp())); } diff --git a/library/Notifications/Widget/ItemList/IncidentListItem.php b/library/Notifications/Widget/ItemList/IncidentListItem.php index 57df92ca1..cacd0c6cd 100644 --- a/library/Notifications/Widget/ItemList/IncidentListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentListItem.php @@ -8,8 +8,12 @@ use Icinga\Module\Notifications\Common\Links; use Icinga\Module\Notifications\Model\Incident; use Icinga\Module\Notifications\Model\Objects; +use Icinga\Module\Notifications\Model\Source; +use Icinga\Module\Notifications\Widget\SourceIcon; +use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; +use ipl\Html\HtmlElement; use ipl\Web\Common\BaseListItem; use ipl\Web\Widget\Icon; use ipl\Web\Widget\Link; @@ -73,19 +77,22 @@ protected function assembleTitle(BaseHtmlElement $title): void protected function assembleHeader(BaseHtmlElement $header): void { $header->add($this->createTitle()); + $meta = new HtmlElement('span', Attributes::create(['class' => 'meta'])); + + /** @var Source $source */ + $source = $this->item->object->source; + $meta->addHtml((new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($source->getIcon())); if ($this->item->recovered_at !== null) { - $header->add(Html::tag( - 'span', - ['class' => 'meta'], - [ - 'closed ', - new TimeAgo($this->item->recovered_at->getTimestamp()) - ] - )); + $meta->add([ + 'closed ', + new TimeAgo($this->item->recovered_at->getTimestamp()) + ]); } else { - $header->add(new TimeSince($this->item->started_at->getTimestamp())); + $meta->addHtml(new TimeSince($this->item->started_at->getTimestamp())); } + + $header->addHtml($meta); } protected function getSeverityIcon(): string