2016-04-22 14:32:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2019-05-02 13:23:06 +02:00
|
|
|
use gipfl\IcingaWeb2\Link;
|
2017-08-16 14:01:43 +02:00
|
|
|
use Icinga\Module\Director\Forms\DirectorJobForm;
|
2016-04-22 14:32:24 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
2016-05-25 15:12:37 +02:00
|
|
|
use Icinga\Module\Director\Objects\DirectorJob;
|
2017-08-16 14:01:43 +02:00
|
|
|
use Icinga\Module\Director\Web\Widget\JobDetails;
|
2016-04-22 14:32:24 +02:00
|
|
|
|
|
|
|
class JobController extends ActionController
|
|
|
|
{
|
2018-10-06 15:35:32 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2016-05-25 15:12:37 +02:00
|
|
|
public function indexAction()
|
2016-04-22 14:32:24 +02:00
|
|
|
{
|
2019-09-17 15:06:39 +02:00
|
|
|
$this->setAutorefreshInterval(10);
|
2017-08-16 14:01:43 +02:00
|
|
|
$job = $this->requireJob();
|
|
|
|
$this
|
|
|
|
->addJobTabs($job, 'show')
|
|
|
|
->addTitle($this->translate('Job: %s'), $job->get('job_name'))
|
2018-10-15 14:49:47 +02:00
|
|
|
->addToBasketLink()
|
2017-08-16 14:01:43 +02:00
|
|
|
->content()->add(new JobDetails($job));
|
2016-04-22 14:32:24 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 14:01:43 +02:00
|
|
|
public function addAction()
|
2016-04-22 14:32:24 +02:00
|
|
|
{
|
2017-08-16 14:01:43 +02:00
|
|
|
$this
|
|
|
|
->addSingleTab($this->translate('New Job'))
|
|
|
|
->addTitle($this->translate('Add a new Job'))
|
|
|
|
->content()->add(
|
|
|
|
DirectorJobForm::load()
|
|
|
|
->setSuccessUrl('director/job')
|
|
|
|
->setDb($this->db())
|
|
|
|
->handleRequest()
|
2016-04-22 14:32:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-06 15:35:32 +02:00
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
2016-05-25 15:12:37 +02:00
|
|
|
public function editAction()
|
2016-04-22 14:32:24 +02:00
|
|
|
{
|
2017-08-16 14:01:43 +02:00
|
|
|
$job = $this->requireJob();
|
|
|
|
$form = DirectorJobForm::load()
|
|
|
|
->setListUrl('director/jobs')
|
|
|
|
->setObject($job)
|
|
|
|
->handleRequest();
|
2016-04-22 14:32:24 +02:00
|
|
|
|
2017-08-16 14:01:43 +02:00
|
|
|
$this
|
|
|
|
->addJobTabs($job, 'edit')
|
|
|
|
->addTitle($this->translate('Job: %s'), $job->get('job_name'))
|
2018-10-15 14:49:47 +02:00
|
|
|
->addToBasketLink()
|
2017-08-16 14:01:43 +02:00
|
|
|
->content()->add($form);
|
|
|
|
}
|
2016-04-22 14:32:24 +02:00
|
|
|
|
2017-08-16 14:01:43 +02:00
|
|
|
/**
|
|
|
|
* @return DirectorJob
|
2018-10-06 15:35:32 +02:00
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
2017-08-16 14:01:43 +02:00
|
|
|
*/
|
|
|
|
protected function requireJob()
|
|
|
|
{
|
2018-10-08 06:19:14 +02:00
|
|
|
return DirectorJob::loadWithAutoIncId((int) $this->params->getRequired('id'), $this->db());
|
2016-04-22 14:32:24 +02:00
|
|
|
}
|
|
|
|
|
2018-10-15 14:49:47 +02:00
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
* @throws \Icinga\Exception\MissingParameterException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
|
|
|
protected function addToBasketLink()
|
|
|
|
{
|
|
|
|
$job = $this->requireJob();
|
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
$this->translate('Add to Basket'),
|
|
|
|
'director/basket/add',
|
|
|
|
[
|
|
|
|
'type' => 'DirectorJob',
|
|
|
|
'names' => $job->getUniqueIdentifier()
|
|
|
|
],
|
|
|
|
['class' => 'icon-tag']
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:01:43 +02:00
|
|
|
protected function addJobTabs(DirectorJob $job, $active)
|
2016-04-22 14:32:24 +02:00
|
|
|
{
|
2018-10-06 15:35:32 +02:00
|
|
|
$id = $job->get('id');
|
2017-08-16 14:01:43 +02:00
|
|
|
|
|
|
|
$this->tabs()->add('show', [
|
|
|
|
'url' => 'director/job',
|
|
|
|
'urlParams' => ['id' => $id],
|
|
|
|
'label' => $this->translate('Job'),
|
|
|
|
])->add('edit', [
|
|
|
|
'url' => 'director/job/edit',
|
|
|
|
'urlParams' => ['id' => $id],
|
|
|
|
'label' => $this->translate('Config'),
|
|
|
|
])->activate($active);
|
|
|
|
|
|
|
|
return $this;
|
2016-04-22 14:32:24 +02:00
|
|
|
}
|
|
|
|
}
|