mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
CommandController: branch support, argument table
This commit is contained in:
parent
2b62742362
commit
97b2f6c946
@ -3,6 +3,8 @@
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use gipfl\Web\Widget\Hint;
|
||||
use Icinga\Module\Director\Objects\IcingaCommandArgument;
|
||||
use Icinga\Module\Director\Web\Table\BranchedIcingaCommandArgumentTable;
|
||||
use ipl\Html\Html;
|
||||
use Icinga\Module\Director\Forms\IcingaCommandArgumentForm;
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
@ -22,9 +24,14 @@ class CommandController extends ObjectController
|
||||
parent::init();
|
||||
$o = $this->object;
|
||||
if ($o && ! $o->isExternal()) {
|
||||
if ($this->getBranch()->isBranch()) {
|
||||
$urlParams = ['uuid' => $o->getUniqueId()->toString()];
|
||||
} else {
|
||||
$urlParams = ['name' => $o->getObjectName()];
|
||||
}
|
||||
$this->tabs()->add('arguments', [
|
||||
'url' => 'director/command/arguments',
|
||||
'urlParams' => ['name' => $o->getObjectName()],
|
||||
'urlParams' => $urlParams,
|
||||
'label' => 'Arguments'
|
||||
]);
|
||||
}
|
||||
@ -83,16 +90,33 @@ class CommandController extends ObjectController
|
||||
$o = $this->object;
|
||||
$this->tabs()->activate('arguments');
|
||||
$this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName());
|
||||
$form = IcingaCommandArgumentForm::load()->setCommandObject($o);
|
||||
if ($id = $p->shift('argument_id')) {
|
||||
$form = (new IcingaCommandArgumentForm)
|
||||
->setBranch($this->getBranch())
|
||||
->setCommandObject($o);
|
||||
if ($argument = $p->shift('argument')) {
|
||||
$this->addBackLink('director/command/arguments', [
|
||||
'name' => $p->get('name')
|
||||
]);
|
||||
$form->loadObject($id);
|
||||
if ($this->branch->isBranch()) {
|
||||
$arguments = $o->arguments();
|
||||
$argument = $arguments->get($argument);
|
||||
// IcingaCommandArgument::create((array) $arguments->get($argument)->toFullPlainObject());
|
||||
// $argument->setBeingLoadedFromDb();
|
||||
} else {
|
||||
$argument = IcingaCommandArgument::load([
|
||||
'command_id' => $o->get('id'),
|
||||
'argument_name' => $argument
|
||||
], $this->db());
|
||||
}
|
||||
$form->setObject($argument);
|
||||
}
|
||||
$form->handleRequest();
|
||||
$this->content()->add([$form]);
|
||||
IcingaCommandArgumentTable::create($o)->renderTo($this);
|
||||
if ($this->branch->isBranch()) {
|
||||
(new BranchedIcingaCommandArgumentTable($o, $this->getBranch()))->renderTo($this);
|
||||
} else {
|
||||
(new IcingaCommandArgumentTable($o, $this->getBranch()))->renderTo($this);
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasBasketSupport()
|
||||
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use gipfl\IcingaWeb2\Data\SimpleQueryPaginationAdapter;
|
||||
use gipfl\IcingaWeb2\Table\QueryBasedTable;
|
||||
use Icinga\Data\DataArray\ArrayDatasource;
|
||||
use Icinga\Module\Director\Db\Branch\Branch;
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use gipfl\IcingaWeb2\Link;
|
||||
|
||||
class BranchedIcingaCommandArgumentTable extends QueryBasedTable
|
||||
{
|
||||
/** @var IcingaCommand */
|
||||
protected $command;
|
||||
|
||||
/** @var Branch */
|
||||
protected $branch;
|
||||
|
||||
protected $searchColumns = [
|
||||
'ca.argument_name',
|
||||
'ca.argument_value',
|
||||
];
|
||||
|
||||
public function __construct(IcingaCommand $command, Branch $branch)
|
||||
{
|
||||
$this->command = $command;
|
||||
$this->branch = $branch;
|
||||
$this->getAttributes()->set('data-base-target', '_self');
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this::row([
|
||||
Link::create($row->argument_name, 'director/command/arguments', [
|
||||
'argument' => $row->argument_name,
|
||||
'uuid' => $this->command->getUniqueId()->toString(),
|
||||
]),
|
||||
$row->argument_value
|
||||
]);
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Argument'),
|
||||
$this->translate('Value'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getPaginationAdapter()
|
||||
{
|
||||
return new SimpleQueryPaginationAdapter($this->getQuery());
|
||||
}
|
||||
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->prepareQuery();
|
||||
}
|
||||
|
||||
protected function fetchQueryRows()
|
||||
{
|
||||
return $this->getQuery()->fetchAll();
|
||||
}
|
||||
|
||||
protected function prepareQuery()
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->command->arguments()->toPlainObject() as $name => $argument) {
|
||||
$new = (object) [];
|
||||
$new->argument_name = $name;
|
||||
$new->argument_value = isset($argument->value) ? $argument->value : null;
|
||||
$list[] = $new;
|
||||
}
|
||||
|
||||
return (new ArrayDatasource($list))->select();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user