From 6fb2e4be92c41a853fb55738ec9fb3ec06972465 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 25 Nov 2024 15:15:48 +0100 Subject: [PATCH] Add `csv/json` export support for parents and children tab --- application/controllers/HostController.php | 13 +++++++++---- application/controllers/ServiceController.php | 11 ++++++++--- library/Icingadb/Data/CsvResultSetUtils.php | 4 +++- library/Icingadb/Data/JsonResultSetUtils.php | 4 +++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 37fb307c9..2a2a1c949 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -38,6 +38,7 @@ use ipl\Web\Control\SortControl; use ipl\Web\Url; use ipl\Web\Widget\Tabs; +use Generator; class HostController extends Controller { @@ -114,7 +115,7 @@ public function sourceAction(): void )); } - public function historyAction(): \Generator + public function historyAction(): Generator { $compact = $this->view->compact; // TODO: Find a less-legacy way.. @@ -185,7 +186,7 @@ public function historyAction(): \Generator } } - public function servicesAction(): \Generator + public function servicesAction(): Generator { if ($this->host->state->is_overdue) { $this->controls->addAttributes(['class' => 'overdue']); @@ -234,7 +235,7 @@ public function servicesAction(): \Generator $this->setAutorefreshInterval(10); } - public function parentsAction(): void + public function parentsAction(): Generator { $nodesQuery = $this->fetchNodes(true); @@ -275,6 +276,8 @@ public function parentsAction(): void $nodesQuery->filter($filter); + yield $this->export($nodesQuery); + $this->addControl($paginationControl); $this->addControl($sortControl); $this->addControl($limitControl); @@ -293,7 +296,7 @@ public function parentsAction(): void $this->setAutorefreshInterval(10); } - public function childrenAction(): void + public function childrenAction(): Generator { $nodesQuery = $this->fetchNodes(); @@ -337,6 +340,8 @@ public function childrenAction(): void $nodesQuery->filter($filter); + yield $this->export($nodesQuery); + $this->addControl($paginationControl); $this->addControl($sortControl); $this->addControl($limitControl); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index e3f0384ff..c959fe614 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -32,6 +32,7 @@ use ipl\Web\Control\SortControl; use ipl\Web\Url; use ipl\Web\Widget\Tabs; +use Generator; class ServiceController extends Controller { @@ -100,7 +101,7 @@ public function indexAction(): void $this->setAutorefreshInterval(10); } - public function parentsAction(): void + public function parentsAction(): Generator { $nodesQuery = $this->fetchNodes(true); @@ -142,6 +143,8 @@ public function parentsAction(): void $nodesQuery->filter($filter); + yield $this->export($nodesQuery); + $this->addControl($paginationControl); $this->addControl($sortControl); $this->addControl($limitControl); @@ -160,7 +163,7 @@ public function parentsAction(): void $this->setAutorefreshInterval(10); } - public function childrenAction(): void + public function childrenAction(): Generator { $nodesQuery = $this->fetchNodes(); @@ -205,6 +208,8 @@ public function childrenAction(): void $nodesQuery->filter($filter); + yield $this->export($nodesQuery); + $this->addControl($paginationControl); $this->addControl($sortControl); $this->addControl($limitControl); @@ -242,7 +247,7 @@ public function sourceAction(): void )); } - public function historyAction(): \Generator + public function historyAction(): Generator { $compact = $this->view->compact; // TODO: Find a less-legacy way.. diff --git a/library/Icingadb/Data/CsvResultSetUtils.php b/library/Icingadb/Data/CsvResultSetUtils.php index 61995d3a2..862260cc8 100644 --- a/library/Icingadb/Data/CsvResultSetUtils.php +++ b/library/Icingadb/Data/CsvResultSetUtils.php @@ -6,6 +6,7 @@ use DateTime; use DateTimeZone; +use Icinga\Module\Icingadb\Model\DependencyNode; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; use ipl\Orm\Model; @@ -67,7 +68,8 @@ protected function extractKeysAndValues(Model $model, string $path = ''): array public static function stream(Query $query): void { - if ($query->getModel() instanceof Host || $query->getModel() instanceof Service) { + $model = $query->getModel(); + if ($model instanceof Host || $model instanceof Service || $model instanceof DependencyNode) { $query->setResultSetClass(VolatileCsvResults::class); } else { $query->setResultSetClass(__CLASS__); diff --git a/library/Icingadb/Data/JsonResultSetUtils.php b/library/Icingadb/Data/JsonResultSetUtils.php index 8b8857122..dc78fe094 100644 --- a/library/Icingadb/Data/JsonResultSetUtils.php +++ b/library/Icingadb/Data/JsonResultSetUtils.php @@ -6,6 +6,7 @@ use DateTime; use DateTimeZone; +use Icinga\Module\Icingadb\Model\DependencyNode; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; use Icinga\Util\Json; @@ -61,7 +62,8 @@ protected function createObject(Model $model): array public static function stream(Query $query): void { - if ($query->getModel() instanceof Host || $query->getModel() instanceof Service) { + $model = $query->getModel(); + if ($model instanceof Host || $model instanceof Service || $model instanceof DependencyNode) { $query->setResultSetClass(VolatileJsonResults::class); } else { $query->setResultSetClass(__CLASS__);