From 1cd03462d8339283dde1b9c4d9ff492746f54958 Mon Sep 17 00:00:00 2001 From: Bastian Lederer Date: Mon, 9 Mar 2026 10:26:32 +0100 Subject: [PATCH] Add `ServiceItemTable::setColumnChooserUrl()` Use the setter to set the url for the ColumnChooser --- application/controllers/HostsController.php | 3 ++- application/controllers/ServicesController.php | 3 ++- .../Icingadb/Widget/ItemTable/HostItemTable.php | 5 ----- .../Widget/ItemTable/ServiceItemTable.php | 5 ----- .../Icingadb/Widget/ItemTable/StateItemTable.php | 16 ++++++++++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index 8e091068..0a6bae37 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -114,7 +114,8 @@ class HostsController extends Controller $continueWith = $this->createContinueWith(Links::hostsDetails(), $searchBar, $results->hasResult()); if ($viewModeSwitcher->getViewMode() === 'tabular') { $hostList = (new HostItemTable($results, HostItemTable::applyColumnMetaData($hosts, $columns))) - ->setSort($sortControl->getSort()); + ->setSort($sortControl->getSort()) + ->setColumnChooserUrl(Url::fromPath('icingadb/hosts/columnControl')); } else { $hostList = (new ObjectList($results)) ->setViewMode($viewModeSwitcher->getViewMode()); diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 5a55f52c..27a74523 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -127,7 +127,8 @@ class ServicesController extends Controller if ($viewModeSwitcher->getViewMode() === 'tabular') { $serviceList = (new ServiceItemTable($results, ServiceItemTable::applyColumnMetaData($services, $columns))) - ->setSort($sortControl->getSort()); + ->setSort($sortControl->getSort()) + ->setColumnChooserUrl(Url::fromPath('icingadb/services/columnControl')); } else { $serviceList = (new ObjectList($results)) ->setViewMode($viewModeSwitcher->getViewMode()); diff --git a/library/Icingadb/Widget/ItemTable/HostItemTable.php b/library/Icingadb/Widget/ItemTable/HostItemTable.php index 26df6093..9c8020a7 100644 --- a/library/Icingadb/Widget/ItemTable/HostItemTable.php +++ b/library/Icingadb/Widget/ItemTable/HostItemTable.php @@ -29,9 +29,4 @@ class HostItemTable extends StateItemTable { return 'host.state.severity'; } - - protected function getControllerPath(): string - { - return 'hosts'; - } } diff --git a/library/Icingadb/Widget/ItemTable/ServiceItemTable.php b/library/Icingadb/Widget/ItemTable/ServiceItemTable.php index 3b3cc235..a495585b 100644 --- a/library/Icingadb/Widget/ItemTable/ServiceItemTable.php +++ b/library/Icingadb/Widget/ItemTable/ServiceItemTable.php @@ -29,9 +29,4 @@ class ServiceItemTable extends StateItemTable { return 'service.state.severity'; } - - protected function getControllerPath(): string - { - return 'services'; - } } diff --git a/library/Icingadb/Widget/ItemTable/StateItemTable.php b/library/Icingadb/Widget/ItemTable/StateItemTable.php index 57af5b38..d1621d50 100644 --- a/library/Icingadb/Widget/ItemTable/StateItemTable.php +++ b/library/Icingadb/Widget/ItemTable/StateItemTable.php @@ -46,6 +46,9 @@ abstract class StateItemTable extends BaseHtmlElement /** @var ?ValidHtml Message to show if the list is empty */ protected $emptyStateMessage; + /** @var ?Url The url for the column chooser modal */ + protected ?Url $columnChooserUrl = null; + /** * Create a new item table * @@ -127,12 +130,17 @@ abstract class StateItemTable extends BaseHtmlElement return $this; } + public function setColumnChooserUrl(Url $url): static + { + $this->columnChooserUrl = $url; + + return $this; + } + abstract protected function getItemClass(): string; abstract protected function getVisualColumn(): string; - abstract protected function getControllerPath(): string; - protected function createColumnChooserOpener(): ValidHtml { return new HtmlElement( @@ -140,7 +148,7 @@ abstract class StateItemTable extends BaseHtmlElement new Attributes(['class' => 'column-chooser-opener']), (new ActionLink( new Ball('xs'), - Url::fromPath("icingadb/{$this->getControllerPath()}/columnControl")->setParam( + $this->columnChooserUrl->setParam( 'columns', implode(',', array_keys($this->columns)) ) @@ -236,7 +244,7 @@ abstract class StateItemTable extends BaseHtmlElement $headerRow->addHtml($headerCell); } - if ($headerCell !== null) { + if (! empty($this->columns) && $this->columnChooserUrl !== null) { $headerCell->addHtml($this->createColumnChooserOpener()) ->getAttribute('class') ->addValue('last-th');