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 18, 2024
1 parent 518090e commit ae3b36a
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 @@ -276,6 +277,8 @@ public function parentsAction(): void

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

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

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

Expand Down Expand Up @@ -339,6 +342,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 @@ -33,6 +33,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 @@ -104,7 +105,7 @@ public function indexAction(): void
$this->setAutorefreshInterval(10);
}

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

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

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

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

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

Expand Down Expand Up @@ -211,6 +214,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 @@ -248,7 +253,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 ae3b36a

Please sign in to comment.