1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<?php
namespace Icinga\Module\Director\Controllers;
use gipfl\IcingaWeb2\Link;
use Icinga\Module\Director\Forms\DirectorJobForm;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Objects\DirectorJob;
use Icinga\Module\Director\Web\Controller\BranchHelper;
use Icinga\Module\Director\Web\Widget\JobDetails;
class JobController extends ActionController
{
use BranchHelper;
/**
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
*/
public function indexAction()
{
$this->setAutorefreshInterval(10);
$job = $this->requireJob();
$this
->addJobTabs($job, 'show')
->addTitle($this->translate('Job: %s'), $job->get('job_name'))
->addToBasketLink()
->content()->add(new JobDetails($job));
}
public function addAction()
{
$this
->addSingleTab($this->translate('New Job'))
->addTitle($this->translate('Add a new Job'));
if ($this->showNotInBranch($this->translate('Creating Jobs'))) {
return;
}
$this->content()->add(
DirectorJobForm::load()
->setSuccessUrl('director/job')
->setDb($this->db())
->handleRequest()
);
}
/**
* @throws \Icinga\Exception\MissingParameterException
* @throws \Icinga\Exception\NotFoundError
*/
public function editAction()
{
$job = $this->requireJob();
$this
->addJobTabs($job, 'edit')
->addTitle($this->translate('Job: %s'), $job->get('job_name'))
->addToBasketLink();
if ($this->showNotInBranch($this->translate('Modifying Jobs'))) {
return;
}
$form = DirectorJobForm::load()
->setListUrl('director/jobs')
->setObject($job)
->handleRequest();
$this->content()->add($form);
}
/**
* @return DirectorJob
* @throws \Icinga\Exception\NotFoundError
* @throws \Icinga\Exception\MissingParameterException
*/
protected function requireJob()
{
return DirectorJob::loadWithAutoIncId((int) $this->params->getRequired('id'), $this->db());
}
/**
* @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;
}
protected function addJobTabs(DirectorJob $job, $active)
{
$id = $job->get('id');
$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;
}
}
|