mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
CommandArguments: refactor table, controller
This commit is contained in:
parent
56516cf572
commit
44458d2eec
@ -2,8 +2,10 @@
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Forms\IcingaCommandArgumentForm;
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use Icinga\Module\Director\Web\Controller\ObjectController;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Module\Director\Web\Table\IcingaCommandArgumentTable;
|
||||
|
||||
class CommandController extends ObjectController
|
||||
{
|
||||
@ -23,22 +25,17 @@ class CommandController extends ObjectController
|
||||
public function argumentsAction()
|
||||
{
|
||||
$p = $this->params;
|
||||
/** @var IcingaCommand $o */
|
||||
$o = $this->object;
|
||||
$this->tabs()->activate('arguments');
|
||||
$this->setTitle($this->translate('Command arguments: %s'), $o->getObjectName());
|
||||
$this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName());
|
||||
|
||||
/** @var \Icinga\Module\Director\Forms\IcingaCommandArgumentForm $form */
|
||||
$form = $this->loadForm('icingaCommandArgument')->setCommandObject($o);
|
||||
$form = IcingaCommandArgumentForm::load()->setCommandObject($o);
|
||||
if ($id = $p->shift('argument_id')) {
|
||||
$form->loadObject($id);
|
||||
}
|
||||
$form->handleRequest();
|
||||
|
||||
$filter = Filter::where('command', $p->get('name'));
|
||||
$table = $this->loadTable('icingaCommandArgument')
|
||||
->setCommandObject($o)
|
||||
->setFilter($filter);
|
||||
|
||||
$table = IcingaCommandArgumentTable::create($o);
|
||||
$this->content()->add([$form, $table]);
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class IcingaCommandArgumentTable extends QuickTable
|
||||
{
|
||||
protected $commandObject;
|
||||
|
||||
protected $searchColumns = array(
|
||||
'command',
|
||||
);
|
||||
|
||||
public function setCommandObject(IcingaCommand $command)
|
||||
{
|
||||
$this->commandObject = $command;
|
||||
if ($this->connection === null) {
|
||||
$this->setConnection($command->getConnection());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'ca.id',
|
||||
'command_id' => 'c.id',
|
||||
'command' => 'c.object_name',
|
||||
'argument_name' => "COALESCE(ca.argument_name, '(none)')",
|
||||
'argument_value' => 'ca.argument_value',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url(
|
||||
'director/command/arguments',
|
||||
array(
|
||||
'argument_id' => $row->id,
|
||||
'name' => $this->commandObject->object_name
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'argument_name' => $view->translate('Argument'),
|
||||
'argument_value' => $view->translate('Value'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('ca' => 'icinga_command_argument'),
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('c' => 'icinga_command'),
|
||||
'ca.command_id = c.id',
|
||||
array()
|
||||
)->order('ca.sort_order')->order('ca.argument_name');
|
||||
}
|
||||
}
|
72
library/Director/Web/Table/IcingaCommandArgumentTable.php
Normal file
72
library/Director/Web/Table/IcingaCommandArgumentTable.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class IcingaCommandArgumentTable extends ZfQueryBasedTable
|
||||
{
|
||||
/** @var IcingaCommand */
|
||||
protected $command;
|
||||
|
||||
protected $searchColumns = array(
|
||||
'command',
|
||||
);
|
||||
|
||||
public static function create(IcingaCommand $command)
|
||||
{
|
||||
$self = new static($command->getConnection());
|
||||
$self->command = $command;
|
||||
return $self;
|
||||
}
|
||||
|
||||
public function assemble()
|
||||
{
|
||||
$this->attributes()->set('data-base-target', '_self');
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this::row([
|
||||
Link::create(
|
||||
$row->argument_name,
|
||||
'director/command/arguments',
|
||||
[
|
||||
'argument_id' => $row->id,
|
||||
'name' => $this->command->getObjectName()
|
||||
]
|
||||
),
|
||||
$row->argument_value
|
||||
]);
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Argument'),
|
||||
$this->translate('Value'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'ca.id',
|
||||
'argument_name' => "COALESCE(ca.argument_name, '(none)')",
|
||||
'argument_value' => 'ca.argument_value',
|
||||
);
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['ca' => 'icinga_command_argument'],
|
||||
$this->getColumns()
|
||||
)->where(
|
||||
'ca.command_id = ?',
|
||||
$this->command->get('id')
|
||||
)->order('ca.sort_order')->order('ca.argument_name');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user