From 68f7fd11656736e7184e1d1eaa189a1da3dab090 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Thu, 20 Jun 2024 13:08:05 +0200 Subject: [PATCH] Fix active list item handling --- library/Notifications/Common/Links.php | 36 +++++++++++++++---- .../Widget/ItemList/ContactGroupList.php | 7 ++++ .../Widget/ItemList/ContactGroupListItem.php | 4 ++- .../Widget/ItemList/ContactList.php | 7 ++++ .../Widget/ItemList/ContactListItem.php | 4 ++- .../Widget/ItemList/EventList.php | 4 +++ .../Widget/ItemList/EventListItem.php | 3 ++ .../Widget/ItemList/EventRuleList.php | 7 ++++ .../Widget/ItemList/EventRuleListItem.php | 3 +- .../Widget/ItemList/IncidentList.php | 4 +++ .../Widget/ItemList/IncidentListItem.php | 3 ++ .../Widget/ItemList/ScheduleList.php | 7 ++++ .../Widget/ItemList/ScheduleListItem.php | 3 +- 13 files changed, 82 insertions(+), 10 deletions(-) diff --git a/library/Notifications/Common/Links.php b/library/Notifications/Common/Links.php index fbdd03e5..d611afcd 100644 --- a/library/Notifications/Common/Links.php +++ b/library/Notifications/Common/Links.php @@ -11,8 +11,12 @@ */ abstract class Links { - public static function event(int $id): Url + public static function event(?int $id = null): Url { + if ($id === null) { + return Url::fromPath('notifications/event'); + } + return Url::fromPath('notifications/event', ['id' => $id]); } @@ -26,8 +30,12 @@ public static function incidents(): Url return Url::fromPath('notifications/incidents'); } - public static function incident(int $id): Url + public static function incident(?int $id = null): Url { + if ($id === null) { + return Url::fromPath('notifications/incident'); + } + return Url::fromPath('notifications/incident', ['id' => $id]); } @@ -36,8 +44,12 @@ public static function contacts(): Url return Url::fromPath('notifications/contacts'); } - public static function contact(int $id): Url + public static function contact(?int $id = null): Url { + if ($id === null) { + return Url::fromPath('notifications/contact'); + } + return Url::fromPath('notifications/contact', ['id' => $id]); } @@ -46,8 +58,12 @@ public static function eventRules(): Url return Url::fromPath('notifications/event-rules'); } - public static function eventRule(int $id): Url + public static function eventRule(?int $id = null): Url { + if ($id === null) { + return Url::fromPath('notifications/event-rule'); + } + return Url::fromPath('notifications/event-rule', ['id' => $id]); } @@ -56,8 +72,12 @@ public static function schedules(): Url return Url::fromPath('notifications/schedules'); } - public static function schedule(int $id): Url + public static function schedule(?int $id = null): Url { + if ($id === null) { + return Url::fromPath('notifications/schedule'); + } + return Url::fromPath('notifications/schedule', ['id' => $id]); } @@ -86,8 +106,12 @@ public static function contactGroupsSuggestMember(): Url return Url::fromPath('notifications/contact-groups/suggest-member'); } - public static function contactGroup(int $id): Url + public static function contactGroup(?int $id = null): Url { + if ($id === null) { + return Url::fromPath('notifications/contact-group'); + } + return Url::fromPath('notifications/contact-group', ['id' => $id]); } diff --git a/library/Notifications/Widget/ItemList/ContactGroupList.php b/library/Notifications/Widget/ItemList/ContactGroupList.php index 99fc351e..a7c23aa8 100644 --- a/library/Notifications/Widget/ItemList/ContactGroupList.php +++ b/library/Notifications/Widget/ItemList/ContactGroupList.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use ipl\Web\Common\BaseItemList; class ContactGroupList extends BaseItemList @@ -14,4 +15,10 @@ protected function getItemClass(): string { return ContactGroupListItem::class; } + + protected function init(): void + { + $this->getAttributes() + ->set('data-icinga-detail-url', (string) Links::contactGroup()); + } } diff --git a/library/Notifications/Widget/ItemList/ContactGroupListItem.php b/library/Notifications/Widget/ItemList/ContactGroupListItem.php index e792e066..b2194c3d 100644 --- a/library/Notifications/Widget/ItemList/ContactGroupListItem.php +++ b/library/Notifications/Widget/ItemList/ContactGroupListItem.php @@ -23,7 +23,9 @@ class ContactGroupListItem extends BaseListItem protected function init(): void { - $this->getAttributes()->set('data-action-item', true); + $this->getAttributes() + ->set('data-action-item', true) + ->set('data-icinga-detail-filter', Links::contactGroup($this->item->id)->getQueryString()); } protected function assembleVisual(BaseHtmlElement $visual): void diff --git a/library/Notifications/Widget/ItemList/ContactList.php b/library/Notifications/Widget/ItemList/ContactList.php index 7735a115..aafa1b3f 100644 --- a/library/Notifications/Widget/ItemList/ContactList.php +++ b/library/Notifications/Widget/ItemList/ContactList.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use ipl\Web\Common\BaseItemList; class ContactList extends BaseItemList @@ -14,4 +15,10 @@ protected function getItemClass(): string { return ContactListItem::class; } + + protected function init(): void + { + $this->getAttributes() + ->set('data-icinga-detail-url', (string) Links::contact()); + } } diff --git a/library/Notifications/Widget/ItemList/ContactListItem.php b/library/Notifications/Widget/ItemList/ContactListItem.php index e80d6026..00dc3eb0 100644 --- a/library/Notifications/Widget/ItemList/ContactListItem.php +++ b/library/Notifications/Widget/ItemList/ContactListItem.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use Icinga\Module\Notifications\Model\Contact; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; @@ -28,7 +29,8 @@ class ContactListItem extends BaseListItem protected function init(): void { $this->getAttributes() - ->set('data-action-item', true); + ->set('data-action-item', true) + ->set('data-icinga-detail-filter', Links::contactGroup($this->item->id)->getQueryString()); } protected function assembleVisual(BaseHtmlElement $visual): void diff --git a/library/Notifications/Widget/ItemList/EventList.php b/library/Notifications/Widget/ItemList/EventList.php index 96d3b9a6..551cd500 100644 --- a/library/Notifications/Widget/ItemList/EventList.php +++ b/library/Notifications/Widget/ItemList/EventList.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use Icinga\Module\Notifications\Common\LoadMore; use Icinga\Module\Notifications\Common\NoSubjectLink; use Icinga\Module\Notifications\Hook\ObjectsRendererHook; @@ -37,6 +38,9 @@ protected function init(): void $this->on(self::ON_ASSEMBLED, function () { ObjectsRendererHook::load(); }); + + $this->getAttributes() + ->set('data-icinga-detail-url', (string) Links::event()); } protected function getItemClass(): string diff --git a/library/Notifications/Widget/ItemList/EventListItem.php b/library/Notifications/Widget/ItemList/EventListItem.php index 2da23be7..bb96c62a 100644 --- a/library/Notifications/Widget/ItemList/EventListItem.php +++ b/library/Notifications/Widget/ItemList/EventListItem.php @@ -47,6 +47,9 @@ protected function init(): void $this->getAttributes() ->set('data-action-item', true); } + + $this->getAttributes() + ->set('data-icinga-detail-filter', Links::event($this->item->id)->getQueryString()); } protected function assembleVisual(BaseHtmlElement $visual): void diff --git a/library/Notifications/Widget/ItemList/EventRuleList.php b/library/Notifications/Widget/ItemList/EventRuleList.php index 533448fc..ce8b6711 100644 --- a/library/Notifications/Widget/ItemList/EventRuleList.php +++ b/library/Notifications/Widget/ItemList/EventRuleList.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use Icinga\Module\Notifications\Common\LoadMore; use ipl\Web\Common\BaseItemList; @@ -17,4 +18,10 @@ protected function getItemClass(): string { return EventRuleListItem::class; } + + protected function init(): void + { + $this->getAttributes() + ->set('data-icinga-detail-url', (string) Links::eventRule()); + } } diff --git a/library/Notifications/Widget/ItemList/EventRuleListItem.php b/library/Notifications/Widget/ItemList/EventRuleListItem.php index cb4127a0..a173866c 100644 --- a/library/Notifications/Widget/ItemList/EventRuleListItem.php +++ b/library/Notifications/Widget/ItemList/EventRuleListItem.php @@ -28,7 +28,8 @@ class EventRuleListItem extends BaseListItem protected function init(): void { $this->getAttributes() - ->set('data-action-item', true); + ->set('data-action-item', true) + ->set('data-icinga-detail-filter', Links::eventRule($this->item->id)->getQueryString()); } protected function assembleVisual(BaseHtmlElement $visual): void diff --git a/library/Notifications/Widget/ItemList/IncidentList.php b/library/Notifications/Widget/ItemList/IncidentList.php index ba66e37a..9091038a 100644 --- a/library/Notifications/Widget/ItemList/IncidentList.php +++ b/library/Notifications/Widget/ItemList/IncidentList.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use Icinga\Module\Notifications\Hook\ObjectsRendererHook; use Icinga\Module\Notifications\Model\Incident; use ipl\Web\Common\BaseItemList; @@ -24,6 +25,9 @@ protected function init(): void $this->on(self::ON_ASSEMBLED, function () { ObjectsRendererHook::load(); }); + + $this->getAttributes() + ->set('data-icinga-detail-url', (string) Links::incident()); } protected function getItemClass(): string diff --git a/library/Notifications/Widget/ItemList/IncidentListItem.php b/library/Notifications/Widget/ItemList/IncidentListItem.php index acf1bc9a..319df961 100644 --- a/library/Notifications/Widget/ItemList/IncidentListItem.php +++ b/library/Notifications/Widget/ItemList/IncidentListItem.php @@ -41,6 +41,9 @@ protected function init(): void $this->getAttributes() ->set('data-action-item', true); } + + $this->getAttributes() + ->set('data-icinga-detail-filter', Links::incident($this->item->id)->getQueryString()); } protected function assembleVisual(BaseHtmlElement $visual): void diff --git a/library/Notifications/Widget/ItemList/ScheduleList.php b/library/Notifications/Widget/ItemList/ScheduleList.php index 983143c8..db014165 100644 --- a/library/Notifications/Widget/ItemList/ScheduleList.php +++ b/library/Notifications/Widget/ItemList/ScheduleList.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Links; use ipl\Web\Common\BaseItemList; class ScheduleList extends BaseItemList @@ -14,4 +15,10 @@ protected function getItemClass(): string { return ScheduleListItem::class; } + + protected function init(): void + { + $this->getAttributes() + ->set('data-icinga-detail-url', (string) Links::schedule()); + } } diff --git a/library/Notifications/Widget/ItemList/ScheduleListItem.php b/library/Notifications/Widget/ItemList/ScheduleListItem.php index 24e9f9d8..f4862ce2 100644 --- a/library/Notifications/Widget/ItemList/ScheduleListItem.php +++ b/library/Notifications/Widget/ItemList/ScheduleListItem.php @@ -24,7 +24,8 @@ class ScheduleListItem extends BaseListItem protected function init(): void { $this->getAttributes() - ->set('data-action-item', true); + ->set('data-action-item', true) + ->set('data-icinga-detail-filter', Links::schedule($this->item->id)->getQueryString()); } protected function assembleTitle(BaseHtmlElement $title): void