diff --git a/application/controllers/CommandController.php b/application/controllers/CommandController.php index db72b867..de0ba548 100644 --- a/application/controllers/CommandController.php +++ b/application/controllers/CommandController.php @@ -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() diff --git a/library/Director/Web/Table/BranchedIcingaCommandArgumentTable.php b/library/Director/Web/Table/BranchedIcingaCommandArgumentTable.php new file mode 100644 index 00000000..3d5dbcb2 --- /dev/null +++ b/library/Director/Web/Table/BranchedIcingaCommandArgumentTable.php @@ -0,0 +1,78 @@ +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(); + } +}