icingaweb2-module-director/application/controllers/CommandController.php

101 lines
2.9 KiB
PHP
Raw Normal View History

<?php
2015-10-20 22:34:04 +02:00
namespace Icinga\Module\Director\Controllers;
use dipl\Html\Html;
use Icinga\Module\Director\Forms\IcingaCommandArgumentForm;
use Icinga\Module\Director\Objects\IcingaCommand;
use Icinga\Module\Director\Resolver\CommandUsage;
2015-10-20 22:34:04 +02:00
use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Module\Director\Web\Table\IcingaCommandArgumentTable;
2015-08-03 13:42:19 +02:00
2015-10-20 22:34:04 +02:00
class CommandController extends ObjectController
{
/**
* @throws \Icinga\Exception\ProgrammingError
*/
2015-08-03 13:42:19 +02:00
public function init()
{
parent::init();
2017-07-04 21:22:20 +02:00
$o = $this->object;
if ($o && ! $o->isExternal()) {
$this->tabs()->add('arguments', [
2015-08-03 13:42:19 +02:00
'url' => 'director/command/arguments',
2017-07-04 21:22:20 +02:00
'urlParams' => ['name' => $o->getObjectName()],
2015-08-03 13:42:19 +02:00
'label' => 'Arguments'
2017-07-04 21:22:20 +02:00
]);
2015-08-03 13:42:19 +02:00
}
}
/**
* @throws \Icinga\Exception\ProgrammingError
*/
public function indexAction()
{
if (! $this->getRequest()->isApiRequest()) {
$this->showUsage();
}
parent::indexAction();
}
/**
* @throws \Icinga\Exception\ProgrammingError
*/
public function renderAction()
{
if ($this->object->isExternal()) {
$this->showUsage();
}
parent::renderAction();
}
/**
* @throws \Icinga\Exception\ProgrammingError
*/
protected function showUsage()
{
/** @var IcingaCommand $command */
$command = $this->object;
if ($command->isInUse()) {
$usage = new CommandUsage($command);
$this->content()->add(Html::tag('p', [
'class' => 'information',
'data-base-target' => '_next'
], Html::sprintf(
$this->translate('This Command is currently being used by %s'),
Html::tag('span', null, $usage->getLinks())->setSeparator(', ')
)));
} else {
$this->content()->add(Html::tag(
'p',
['class' => 'warning'],
$this->translate('This Command is currently not in use')
));
}
}
/**
* @throws \Icinga\Exception\Http\HttpNotFoundException
* @throws \Icinga\Exception\ProgrammingError
*/
2015-08-03 13:42:19 +02:00
public function argumentsAction()
{
2017-07-04 21:22:20 +02:00
$p = $this->params;
/** @var IcingaCommand $o */
2017-07-04 21:22:20 +02:00
$o = $this->object;
$this->tabs()->activate('arguments');
$this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName());
$form = IcingaCommandArgumentForm::load()->setCommandObject($o);
2017-07-04 21:22:20 +02:00
if ($id = $p->shift('argument_id')) {
$this->addBackLink('director/command/arguments', [
'name' => $p->get('name')
]);
2015-08-03 13:42:19 +02:00
$form->loadObject($id);
}
$form->handleRequest();
2017-07-21 08:23:52 +02:00
$this->content()->add([$form]);
IcingaCommandArgumentTable::create($o)->renderTo($this);
2015-08-03 13:42:19 +02:00
}
}