summaryrefslogtreecommitdiffstats
path: root/application/controllers/JobsController.php
blob: 48deede72fbdce35ce820e5628defe0cbce6ef3e (plain)
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
<?php

// Icinga Web 2 X.509 Module | (c) 2018 Icinga GmbH | GPLv2

namespace Icinga\Module\X509\Controllers;

use Icinga\Module\X509\Common\Database;
use Icinga\Module\X509\Forms\Jobs\JobConfigForm;
use Icinga\Module\X509\Model\X509Job;
use Icinga\Module\X509\Widget\Jobs;
use ipl\Web\Compat\CompatController;
use ipl\Web\Url;
use ipl\Web\Widget\ButtonLink;

class JobsController extends CompatController
{
    /**
     * List all jobs
     */
    public function indexAction()
    {
        $this->addTitleTab($this->translate('Jobs'));
        $this->getTabs()->add('sni', [
            'title'      => $this->translate('Configure SNI'),
            'label'      => $this->translate('SNI'),
            'url'        => 'x509/sni',
            'baseTarget' => '_main'
        ]);

        $jobs = X509Job::on(Database::get());
        if ($this->hasPermission('config/x509')) {
            $this->addControl(
                (new ButtonLink($this->translate('New Job'), Url::fromPath('x509/jobs/new'), 'plus'))
                    ->openInModal()
            );
        }

        $sortControl = $this->createSortControl($jobs, [
            'name'   => $this->translate('Name'),
            'author' => $this->translate('Author'),
            'ctime'  => $this->translate('Date Created'),
            'mtime'  => $this->translate('Date Modified')
        ]);

        $this->controls->getAttributes()->add('class', 'default-layout');
        $this->addControl($sortControl);

        $this->addContent(new Jobs($jobs));
    }

    public function newAction()
    {
        $this->assertPermission('config/x509');

        $this->addTitleTab($this->translate('New Job'));

        $form = (new JobConfigForm())
            ->setAction((string) Url::fromRequest())
            ->on(JobConfigForm::ON_SUCCESS, function () {
                $this->closeModalAndRefreshRelatedView(Url::fromPath('x509/jobs'));
            })
            ->handleRequest($this->getServerRequest());

        $this->addContent($form);
    }
}