Skip to content

Commit

Permalink
Add csv/json export support for parents and children tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Dec 16, 2024
1 parent f4861b7 commit 9ab8072
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
13 changes: 9 additions & 4 deletions application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use ipl\Web\Control\SortControl;
use ipl\Web\Url;
use ipl\Web\Widget\Tabs;
use Generator;

class HostController extends Controller
{
Expand Down Expand Up @@ -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..

Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -234,7 +235,7 @@ public function servicesAction(): \Generator
$this->setAutorefreshInterval(10);
}

public function parentsAction(): void
public function parentsAction(): Generator
{
$nodesQuery = $this->fetchNodes(true);

Expand Down Expand Up @@ -275,6 +276,8 @@ public function parentsAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand All @@ -293,7 +296,7 @@ public function parentsAction(): void
$this->setAutorefreshInterval(10);
}

public function childrenAction(): void
public function childrenAction(): Generator
{
$nodesQuery = $this->fetchNodes();

Expand Down Expand Up @@ -337,6 +340,8 @@ public function childrenAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand Down
11 changes: 8 additions & 3 deletions application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use ipl\Web\Control\SortControl;
use ipl\Web\Url;
use ipl\Web\Widget\Tabs;
use Generator;

class ServiceController extends Controller
{
Expand Down Expand Up @@ -100,7 +101,7 @@ public function indexAction(): void
$this->setAutorefreshInterval(10);
}

public function parentsAction(): void
public function parentsAction(): Generator
{
$nodesQuery = $this->fetchNodes(true);

Expand Down Expand Up @@ -142,6 +143,8 @@ public function parentsAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand All @@ -160,7 +163,7 @@ public function parentsAction(): void
$this->setAutorefreshInterval(10);
}

public function childrenAction(): void
public function childrenAction(): Generator
{
$nodesQuery = $this->fetchNodes();

Expand Down Expand Up @@ -205,6 +208,8 @@ public function childrenAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand Down Expand Up @@ -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..

Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Data/CsvResultSetUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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__);
Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Data/JsonResultSetUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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__);
Expand Down

0 comments on commit 9ab8072

Please sign in to comment.