Skip to content

Commit

Permalink
Fix active list item handling
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Jun 26, 2024
1 parent ba627b4 commit 68f7fd1
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 10 deletions.
36 changes: 30 additions & 6 deletions library/Notifications/Common/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand All @@ -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]);
}

Expand All @@ -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]);
}

Expand All @@ -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]);
}

Expand All @@ -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]);
}

Expand Down Expand Up @@ -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]);
}

Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Widget/ItemList/ContactGroupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Widget/ItemList/ContactList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
4 changes: 3 additions & 1 deletion library/Notifications/Widget/ItemList/ContactListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions library/Notifications/Widget/ItemList/EventList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions library/Notifications/Widget/ItemList/EventListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Widget/ItemList/EventRuleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}
3 changes: 2 additions & 1 deletion library/Notifications/Widget/ItemList/EventRuleListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions library/Notifications/Widget/ItemList/IncidentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions library/Notifications/Widget/ItemList/IncidentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions library/Notifications/Widget/ItemList/ScheduleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
3 changes: 2 additions & 1 deletion library/Notifications/Widget/ItemList/ScheduleListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68f7fd1

Please sign in to comment.