From 138579b9eb53f275c95da153bc7b628218a0cbac Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 22 Apr 2024 17:29:04 +0200 Subject: [PATCH 1/4] 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 55a873e0..f3ae1e8d 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 082a4f6a..a0a50a77 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 e3fff80b..21965067 100644 --- a/library/Notifications/Widget/Detail/IncidentDetail.php +++ b/library/Notifications/Widget/Detail/IncidentDetail.php @@ -95,7 +95,6 @@ protected function createHistory() new IncidentHistoryList( $this->incident->incident_history ->with([ - 'incident.object.source', 'contact', 'rule', 'rule_escalation', diff --git a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php index 21f70579..a4177aa8 100644 --- a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php @@ -8,7 +8,6 @@ use Icinga\Module\Notifications\Model\Event; use Icinga\Module\Notifications\Model\IncidentHistory; use Icinga\Module\Notifications\Widget\IconBall; -use Icinga\Module\Notifications\Widget\SourceIcon; use ipl\Html\BaseHtmlElement; use ipl\Web\Common\BaseListItem; use ipl\Web\Widget\Icon; @@ -50,11 +49,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 57df92ca..cacd0c6c 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 From 8e62c5e22b248537e42b38fdfb4fc30762da7879 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 6 May 2024 11:00:09 +0200 Subject: [PATCH 2/4] Improve source icon placement in incident and event list --- public/css/common.less | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/css/common.less b/public/css/common.less index 9f704c66..bfb850f3 100644 --- a/public/css/common.less +++ b/public/css/common.less @@ -95,3 +95,11 @@ .full-width .add-new-component { margin: 0 0 1em 1em; } + +.event-list .list-item, +.incident-list .list-item { + .meta .source-icon { + margin-left: auto; + margin-right: 0.5em; + } +} \ No newline at end of file From 7d96409c42b14cdc6851f62575130697a27b1cce Mon Sep 17 00:00:00 2001 From: raviks789 Date: Fri, 3 May 2024 11:08:44 +0200 Subject: [PATCH 3/4] IncidentListItem: Translate text in `meta` --- .../Notifications/Widget/ItemList/IncidentListItem.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/Notifications/Widget/ItemList/IncidentListItem.php b/library/Notifications/Widget/ItemList/IncidentListItem.php index cacd0c6c..8e94ff30 100644 --- a/library/Notifications/Widget/ItemList/IncidentListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentListItem.php @@ -12,8 +12,10 @@ use Icinga\Module\Notifications\Widget\SourceIcon; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; +use ipl\Html\FormattedString; use ipl\Html\Html; use ipl\Html\HtmlElement; +use ipl\I18n\Translation; use ipl\Web\Common\BaseListItem; use ipl\Web\Widget\Icon; use ipl\Web\Widget\Link; @@ -25,6 +27,8 @@ */ class IncidentListItem extends BaseListItem { + use Translation; + /** @var Incident The associated list item */ protected $item; @@ -84,10 +88,10 @@ protected function assembleHeader(BaseHtmlElement $header): void $meta->addHtml((new SourceIcon(SourceIcon::SIZE_BIG))->addHtml($source->getIcon())); if ($this->item->recovered_at !== null) { - $meta->add([ - 'closed ', + $meta->addHtml(FormattedString::create( + $this->translate('closed %s', '(incident) ... '), new TimeAgo($this->item->recovered_at->getTimestamp()) - ]); + )); } else { $meta->addHtml(new TimeSince($this->item->started_at->getTimestamp())); } From e3fad979fc82425d260364e7639fe8e295c2bdd8 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Fri, 3 May 2024 11:30:53 +0200 Subject: [PATCH 4/4] Add correct class documentation --- .../Notifications/Widget/ItemList/IncidentHistoryListItem.php | 2 +- library/Notifications/Widget/ItemList/IncidentListItem.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php index a4177aa8..c4b5635b 100644 --- a/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentHistoryListItem.php @@ -14,7 +14,7 @@ use ipl\Web\Widget\TimeAgo; /** - * Event item of an event list. Represents one database row. + * Incident history item of an incident history list. Represents one database row. */ class IncidentHistoryListItem extends BaseListItem { diff --git a/library/Notifications/Widget/ItemList/IncidentListItem.php b/library/Notifications/Widget/ItemList/IncidentListItem.php index 8e94ff30..4d7e3689 100644 --- a/library/Notifications/Widget/ItemList/IncidentListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentListItem.php @@ -23,7 +23,7 @@ use ipl\Web\Widget\TimeSince; /** - * Event item of an event list. Represents one database row. + * Incident item of an incident list. Represents one database row. */ class IncidentListItem extends BaseListItem {