Skip to content

Commit

Permalink
Merge pull request #28 from Icinga/feature/ui-improvement
Browse files Browse the repository at this point in the history
Improve UI and user interaction
  • Loading branch information
lazyfrosch authored Aug 15, 2017
2 parents 75513b7 + 6a1b76a commit 07054f4
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 15 deletions.
2 changes: 2 additions & 0 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ConfigController extends Controller
*/
public function indexAction()
{
$this->assertPermission('config/modules');

$form = new GeneralConfigForm();
$form->setIniConfig($this->Config());
$form->handleRequest();
Expand Down
41 changes: 41 additions & 0 deletions application/controllers/GraphController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/* Icinga Web 2 | (c) 2013-2017 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Pnp\Controllers;

use Icinga\Module\Pnp\Web\Controller;

class GraphController extends Controller
{
public function indexAction()
{
$url = $this->getRequest()->getUrl();
$queryString = $url->getQueryString();

$this->view->url = sprintf(
'%s/graph?%s',
$this->getBaseUrl(),
$queryString
);

$host = $this->getParam('host');
$service = $this->getParam('srv');

$serviceTitle = '';
if ($service && $service !== '_HOST_') {
$serviceTitle = sprintf(' | %s: %s', $this->translate('Service'), $service);
}
$this->view->title = $title = sprintf('%s: %s%s',
$this->translate('Host'),
$host,
$serviceTitle
);

$this->getTabs()->add('graph', array(
'label' => $title,
'url' => $url,
))->activate('graph');

$this->setViewScript('index/iframe');
}
}
17 changes: 10 additions & 7 deletions application/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

namespace Icinga\Module\Pnp\Controllers;

use Icinga\Web\Controller;
use Icinga\Module\Pnp\Web\Controller;

class IndexController extends Controller
{
public function indexAction()
{
$baseUrl = rtrim($this->Config()->get('pnp4nagios', 'base_url', '/pnp4nagios'), '/');
$this->getTabs()->activate('pnp');

$defaultQuery = $this->Config()->get('pnp4nagios', 'default_query', 'host=.pnp-internal&srv=runtime');

$this->view->title = 'PNP';
$this->view->url = sprintf(
'%s/graph?host=%s&srv=%s&view=%d',
$baseUrl,
urlencode($this->getParam('host')),
urlencode($this->getParam('srv')),
$this->getParam('view')
'%s/graph?%s',
$this->getBaseUrl(),
$defaultQuery
);

$this->setViewScript('index/iframe');
}
}
31 changes: 25 additions & 6 deletions application/forms/Config/GeneralConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,37 @@ public function createElements(array $formData)
'text',
'pnp4nagios_config_dir',
array(
'value' => '/etc/pnp4nagios',
'label' => $this->translate('PNP4Nagios configuration'),
'description' => $this->translate('PNP4Nagios configuration path name (e.g. /etc/pnp4nagios)')
'value' => '/etc/pnp4nagios',
'label' => $this->translate('PNP4Nagios configuration'),
'description' => $this->translate('PNP4Nagios configuration path name (e.g. /etc/pnp4nagios)')
)
);
$this->addElement(
'text',
'pnp4nagios_base_url',
array(
'value' => '/pnp4nagios',
'label' => $this->translate('PNP4Nagios url'),
'description' => $this->translate('The base URL of your PNP4Nagios installation (e.g. /pnp4nagios)')
'value' => '/pnp4nagios',
'label' => $this->translate('PNP4Nagios url'),
'description' => $this->translate('The base URL of your PNP4Nagios installation (e.g. /pnp4nagios)')
)
);

$this->addElement(
'checkbox',
'pnp4nagios_menu_disabled',
array(
'label' => $this->translate('Disable menu entry'),
'description' => $this->translate('Hide PNP from main menu')
)
);

$this->addElement(
'text',
'pnp4nagios_default_query',
array(
'value' => 'host=.pnp-internal&srv=runtime',
'label' => $this->translate('Index query'),
'description' => $this->translate('Default URL query for the index view: /pnp4nagios/graph?{query}')
)
);
}
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
'label' => $this->translate('Config'),
'url' => 'config'
));


$menuDisabled = $this->getConfig()->get('pnp4nagios', 'menu_disabled');
if (! $menuDisabled) {
/** @var \Icinga\Web\Navigation\NavigationItem $section */
$section = $this->menuSection('pnp');
$section->setLabel('PNP')
->setUrl('pnp')
->setIcon('chart-line')
->setPriority(50);
}
4 changes: 2 additions & 2 deletions library/Pnp/ProvidedHook/Grapher.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private function getPreviewImg($host, $service, $view)
'%s on %s, %s', $service, $host, $viewName
);

$url = Url::fromPath('pnp', array(
$url = Url::fromPath('pnp/graph', array(
'host' => $this->pnpClean($host),
'srv' => $this->pnpClean($service),
'view' => $view
Expand All @@ -254,7 +254,7 @@ private function getPreviewImg($host, $service, $view)
$url,
htmlspecialchars($title),
$imgUrl,
htmlspecialchars($viewName)
htmlspecialchars(mt('pnp', 'Loading') . '...')
);
}

Expand Down
27 changes: 27 additions & 0 deletions library/Pnp/Web/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Icinga\Module\Pnp\Web;

use Icinga\Web\Controller as IcingaController;

class Controller extends IcingaController
{
public function init()
{
$this->getTabs()->add('pnp', array(
'label' => $this->translate('PNP'),
'url' => 'pnp',
));
}

protected function setViewScript($name)
{
$this->_helper->viewRenderer->setNoController(true);
$this->_helper->viewRenderer->setScriptAction($name);
}

protected function getBaseUrl()
{
return rtrim($this->Config()->get('pnp4nagios', 'base_url', '/pnp4nagios'), '/');
}
}

0 comments on commit 07054f4

Please sign in to comment.