summaryrefslogtreecommitdiffstats
path: root/application/controllers/ShowController.php
blob: d0560f2ac4871adfca8e5907b3d7334da92f72ac (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
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
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Toplevelview\Controllers;

use Icinga\Module\Toplevelview\ViewConfig;
use Icinga\Module\Toplevelview\Web\Controller;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tab;

class ShowController extends Controller
{
    public function init()
    {
        $tabs = $this->getTabs();

        $tiles = Url::fromPath('toplevelview/show', array(
            'name' => $this->params->getRequired('name')
        ));

        $tabs->add(
            'index',
            array(
                'title' => $this->translate('Tiles'),
                'url'   => $tiles
            )
        );

        if (($id = $this->getParam('id')) !== null) {
            $tabs->add(
                'tree',
                array(
                    'title' => $this->translate('Tree'),
                    'url'   => Url::fromPath('toplevelview/show/tree', array(
                        'name' => $this->params->getRequired('name'),
                        'id'   => $id
                    ))
                )
            );
        }

        $fullscreen = new Tab(array(
            'title' => $this->translate('Go Fullscreen'),
            'icon'  => 'dashboard',
            'url'   => ((string) $tiles) . '&view=compact&showFullscreen'
        ));
        $fullscreen->setTargetBlank();
        $tabs->addAsDropdown('fullscreen', $fullscreen);

        $action = $this->getRequest()->getActionName();
        if ($tab = $tabs->get($action)) {
            $tab->setActive();
        }
    }

    public function indexAction()
    {
        $this->view->name = $name = $this->params->getRequired('name');
        $this->view->view = $view = ViewConfig::loadByName($name);
        $tree = $view->getTree();
        $tree->setBackend($this->monitoringBackend());

        if (($lifetime = $this->getParam('cache')) !== null) {
            $tree->setCacheLifetime($lifetime);
        }

        $this->setAutorefreshInterval(30);
    }

    public function treeAction()
    {
        $this->view->name = $name = $this->params->getRequired('name');
        $this->view->view = $view = ViewConfig::loadByName($name);
        $tree = $view->getTree();
        $this->view->node = $tree->getById($this->params->getRequired('id'));
        $tree->setBackend($this->monitoringBackend());

        if (($lifetime = $this->getParam('cache')) !== null) {
            $tree->setCacheLifetime($lifetime);
        }

        $this->setAutorefreshInterval(30);
    }

    public function sourceAction()
    {
        $this->view->name = $name = $this->params->getRequired('name');
        $this->view->view = $view = ViewConfig::loadByName($name);

        $this->view->text = $view->getText();
        $this->setViewScript('index', 'text');
    }
}