summaryrefslogtreecommitdiffstats
path: root/application/controllers/JobController.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:43:12 +0000
commitcd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /application/controllers/JobController.php
parentInitial commit. (diff)
downloadicingaweb2-module-director-upstream.tar.xz
icingaweb2-module-director-upstream.zip
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/JobController.php')
-rw-r--r--application/controllers/JobController.php117
1 files changed, 117 insertions, 0 deletions
diff --git a/application/controllers/JobController.php b/application/controllers/JobController.php
new file mode 100644
index 0000000..278c96b
--- /dev/null
+++ b/application/controllers/JobController.php
@@ -0,0 +1,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;
+ }
+}