| 1 |
<?php |
| 2 |
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */ |
| 3 |
|
| 4 |
namespace Icinga\Module\Toplevelview\Controllers; |
| 5 |
|
| 6 |
use Icinga\Module\Toplevelview\ViewConfig; |
| 7 |
use Icinga\Module\Toplevelview\Web\Controller; |
| 8 |
|
| 9 |
use Icinga\Web\Url; |
| 10 |
use Icinga\Application\Icinga; |
| 11 |
|
| 12 |
class ShowController extends Controller |
| 13 |
{ |
| 14 |
public function init() |
| 15 |
{ |
| 16 |
$tabs = $this->getTabs(); |
| 17 |
$url = Url::fromRequest()->setParams(clone $this->params); |
| 18 |
$tiles = Url::fromPath('toplevelview/show', ['name' => $this->params->getRequired('name')]); |
| 19 |
|
| 20 |
$tabs->add('index', [ |
| 21 |
'title' => $this->translate('Tree'), |
| 22 |
'url' => $tiles |
| 23 |
]); |
| 24 |
|
| 25 |
// Add new Tabs for the entire tree |
| 26 |
if (($id = $this->getParam('id')) !== null) { |
| 27 |
$tabs->add('tree', [ |
| 28 |
'title' => $this->translate('Tiles'), |
| 29 |
'url' => Url::fromPath('toplevelview/show/tree', [ |
| 30 |
'name' => $this->params->getRequired('name'), |
| 31 |
'id' => $id |
| 32 |
]) |
| 33 |
]); |
| 34 |
} |
| 35 |
|
| 36 |
$action = $this->getRequest()->getActionName(); |
| 37 |
|
| 38 |
if ($tab = $tabs->get($action)) { |
| 39 |
$tab->setActive(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
public function indexAction() |
| 44 |
{ |
| 45 |
$this->view->name = $name = $this->params->getRequired('name'); |
| 46 |
|
| 47 |
$config_dir_module = Icinga::app() |
| 48 |
->getModuleManager() |
| 49 |
->getModule('toplevelview') |
| 50 |
->getConfigDir(); |
| 51 |
|
| 52 |
$c = new ViewConfig($config_dir_module); |
| 53 |
|
| 54 |
// Check if the user has permissions/restrictions for this View |
| 55 |
$restrictions = $c->getRestrictions('toplevelview/filter/views'); |
| 56 |
$c->assertAccessToView($restrictions, $name); |
| 57 |
|
| 58 |
$view = $c->loadByName($name); |
| 59 |
$this->view->view = $view; |
| 60 |
|
| 61 |
$tree = $view->getTree(); |
| 62 |
|
| 63 |
if (($lifetime = $this->getParam('cache')) !== null) { |
| 64 |
$tree->setCacheLifetime($lifetime); |
| 65 |
} |
| 66 |
|
| 67 |
$this->setAutorefreshInterval(30); |
| 68 |
} |
| 69 |
|
| 70 |
public function treeAction() |
| 71 |
{ |
| 72 |
$this->view->name = $name = $this->params->getRequired('name'); |
| 73 |
|
| 74 |
$config_dir_module = Icinga::app() |
| 75 |
->getModuleManager() |
| 76 |
->getModule('toplevelview') |
| 77 |
->getConfigDir(); |
| 78 |
|
| 79 |
$c = new ViewConfig($config_dir_module); |
| 80 |
|
| 81 |
// Check if the user has permissions/restrictions for this View |
| 82 |
$restrictions = $c->getRestrictions('toplevelview/filter/views'); |
| 83 |
$c->assertAccessToView($restrictions, $name); |
| 84 |
|
| 85 |
$view = $c->loadByName($name); |
| 86 |
$this->view->view = $view; |
| 87 |
|
| 88 |
$tree = $view->getTree(); |
| 89 |
|
| 90 |
$this->view->node = $tree->getById($this->params->getRequired('id')); |
| 91 |
|
| 92 |
if (($lifetime = $this->getParam('cache')) !== null) { |
| 93 |
$tree->setCacheLifetime($lifetime); |
| 94 |
} |
| 95 |
|
| 96 |
$this->setAutorefreshInterval(30); |
| 97 |
} |
| 98 |
|
| 99 |
public function sourceAction() |
| 100 |
{ |
| 101 |
$this->view->name = $name = $this->params->getRequired('name'); |
| 102 |
|
| 103 |
$config_dir_module = Icinga::app() |
| 104 |
->getModuleManager() |
| 105 |
->getModule('toplevelview') |
| 106 |
->getConfigDir(); |
| 107 |
|
| 108 |
$c = new ViewConfig($config_dir_module); |
| 109 |
|
| 110 |
// Check if the user has permissions/restrictions for this View |
| 111 |
$restrictions = $c->getRestrictions('toplevelview/filter/views'); |
| 112 |
$c->assertAccessToView($restrictions, $name); |
| 113 |
|
| 114 |
$view = $c->loadByName($name); |
| 115 |
$this->view->view = $view; |
| 116 |
|
| 117 |
$this->view->text = $view->getText(); |
| 118 |
$this->setViewScript('index', 'text'); |
| 119 |
} |
| 120 |
} |