mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
commit
3a0e2b4430
@ -3,9 +3,8 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
use Icinga\Web\Controller\ActionController;
|
use Icinga\Web\Controller\ActionController;
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Web\Widget;
|
use Icinga\Web\Widget;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Widget\SearchDashboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search controller
|
* Search controller
|
||||||
@ -14,47 +13,13 @@ class SearchController extends ActionController
|
|||||||
{
|
{
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
$search = $this->_request->getParam('q');
|
$this->view->dashboard = SearchDashboard::load($this->params->get('q'));
|
||||||
if (! $search) {
|
|
||||||
$this->view->tabs = Widget::create('tabs')->add(
|
// NOTE: This renders the dashboard twice. Remove this once we can catch exceptions thrown in view scripts.
|
||||||
'search',
|
$this->view->dashboard->render();
|
||||||
array(
|
}
|
||||||
'title' => $this->translate('Search'),
|
|
||||||
'url' => '/search',
|
public function hintAction()
|
||||||
)
|
{
|
||||||
)->activate('search');
|
|
||||||
$this->render('hint');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$dashboard = Widget::create('dashboard')->createPane($this->translate('Search'));
|
|
||||||
$pane = $dashboard->getPane($this->translate('Search'));
|
|
||||||
$suffix = strlen($search) ? ': ' . rtrim($search, '*') . '*' : '';
|
|
||||||
$pane->addComponent(
|
|
||||||
$this->translate('Hosts') . $suffix,
|
|
||||||
Url::fromPath('monitoring/list/hosts', array(
|
|
||||||
'host_name' => $search . '*',
|
|
||||||
'sort' => 'host_severity',
|
|
||||||
'limit' => 10,
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$pane->addComponent(
|
|
||||||
$this->translate('Services') . $suffix,
|
|
||||||
Url::fromPath('monitoring/list/services', array(
|
|
||||||
'service_description' => $search . '*',
|
|
||||||
'sort' => 'service_severity',
|
|
||||||
'limit' => 10,
|
|
||||||
)
|
|
||||||
));
|
|
||||||
$pane->addComponent('Hostgroups' . $suffix, Url::fromPath('monitoring/list/hostgroups', array(
|
|
||||||
'hostgroup' => $search . '*',
|
|
||||||
'limit' => 10,
|
|
||||||
)));
|
|
||||||
$pane->addComponent('Servicegroups' . $suffix, Url::fromPath('monitoring/list/servicegroups', array(
|
|
||||||
'servicegroup' => $search . '*',
|
|
||||||
'limit' => 10,
|
|
||||||
)));
|
|
||||||
$dashboard->activate($this->translate('Search'));
|
|
||||||
$this->view->dashboard = $dashboard;
|
|
||||||
$this->view->tabs = $dashboard->getTabs();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Menu;
|
use Icinga\Web\Menu;
|
||||||
use Icinga\Web\MenuRenderer;
|
use Icinga\Web\MenuRenderer;
|
||||||
|
use Icinga\Web\Widget\SearchDashboard;
|
||||||
|
|
||||||
// Don't render a menu for unauthenticated users unless menu is auth aware
|
// Don't render a menu for unauthenticated users unless menu is auth aware
|
||||||
if (! $this->auth()->isAuthenticated()) {
|
if (! $this->auth()->isAuthenticated()) {
|
||||||
@ -11,8 +12,10 @@ if (! $this->auth()->isAuthenticated()) {
|
|||||||
|
|
||||||
?>
|
?>
|
||||||
<div id="menu" data-base-target="_main">
|
<div id="menu" data-base-target="_main">
|
||||||
|
<? if (SearchDashboard::load('dummy')->getPane('search')->hasComponents()): ?>
|
||||||
<form action="<?= $this->href('search') ?>" method="get" role="search">
|
<form action="<?= $this->href('search') ?>" method="get" role="search">
|
||||||
<input type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
<input type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
||||||
</form>
|
</form>
|
||||||
|
<? endif; ?>
|
||||||
<?= new MenuRenderer(Menu::load(), Url::fromRequest()->without('renderLayout')->getRelativeUrl()); ?>
|
<?= new MenuRenderer(Menu::load(), Url::fromRequest()->without('renderLayout')->getRelativeUrl()); ?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
<div class="controls">
|
|
||||||
<?= $this->tabs ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1><?= $this->translate("I'm ready to search, waiting for your input") ?></h1>
|
<h1><?= $this->translate("I'm ready to search, waiting for your input") ?></h1>
|
||||||
<p><strong><?= $this->translate('Hint') ?>: </strong><?= $this->translate(
|
<p><strong><?= $this->translate('Hint') ?>: </strong><?= $this->translate(
|
||||||
'Please use the asterisk (*) as a placeholder for wildcard searches.'
|
'Please use the asterisk (*) as a placeholder for wildcard searches.'
|
||||||
. " For convenience I'll always add a wildcard after the last character"
|
. " For convenience I'll always add a wildcard in front and after your"
|
||||||
. ' you typed.'
|
. ' search string.'
|
||||||
) ?></p>
|
) ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
<?= $this->tabs ?>
|
<?= $this->dashboard->getTabs() ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content dashboard">
|
<div class="content dashboard">
|
||||||
|
@ -163,6 +163,31 @@ class Module
|
|||||||
*/
|
*/
|
||||||
protected $paneItems = array();
|
protected $paneItems = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $searchUrls = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $title
|
||||||
|
* @param string $url
|
||||||
|
*/
|
||||||
|
public function provideSearchUrl($title, $url)
|
||||||
|
{
|
||||||
|
$searchUrl = (object) array(
|
||||||
|
'title' => $title,
|
||||||
|
'url' => $url
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->searchUrls[] = $searchUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSearchUrls()
|
||||||
|
{
|
||||||
|
$this->launchConfigScript();
|
||||||
|
return $this->searchUrls;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all Menu Items
|
* Get all Menu Items
|
||||||
*
|
*
|
||||||
|
@ -135,6 +135,24 @@ class Pane extends AbstractWidget
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all or a given list of components from this pane
|
||||||
|
*
|
||||||
|
* @param array $components Optional list of component titles
|
||||||
|
* @return Pane $this
|
||||||
|
*/
|
||||||
|
public function removeComponents(array $components = null)
|
||||||
|
{
|
||||||
|
if ($components === null) {
|
||||||
|
$this->components = array();
|
||||||
|
} else {
|
||||||
|
foreach ($components as $component) {
|
||||||
|
$this->removeComponent($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all components added at this pane
|
* Return all components added at this pane
|
||||||
*
|
*
|
||||||
|
101
library/Icinga/Web/Widget/SearchDashboard.php
Normal file
101
library/Icinga/Web/Widget/SearchDashboard.php
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Web\Widget;
|
||||||
|
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Application\Modules\Module;
|
||||||
|
use Icinga\Web\Url;
|
||||||
|
use Icinga\Web\Widget\Dashboard\Pane;
|
||||||
|
use Zend_Controller_Action_Exception as ActionError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SearchDashboard display multiple search views on a single search page
|
||||||
|
*
|
||||||
|
* @package Icinga\Web\Widget
|
||||||
|
*/
|
||||||
|
class SearchDashboard extends Dashboard
|
||||||
|
{
|
||||||
|
const SEARCH_PANE = 'search';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All searchUrls provided by Modules
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $searchUrls = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all available search dashlets from modules
|
||||||
|
*
|
||||||
|
* @param $searchQuery
|
||||||
|
* @return Dashboard|SearchDashboard
|
||||||
|
*/
|
||||||
|
public static function load($searchQuery)
|
||||||
|
{
|
||||||
|
/** @var $dashboard SearchDashboard */
|
||||||
|
$dashboard = new static('searchDashboard');
|
||||||
|
$dashboard->loadSearchDashlets($searchQuery);
|
||||||
|
return $dashboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the output
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Zend_Controller_Action_Exception
|
||||||
|
*/
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
if (!$this->getPane(self::SEARCH_PANE)->hasComponents()) {
|
||||||
|
throw new ActionError('Site not found', 404);
|
||||||
|
}
|
||||||
|
return parent::render();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads search dashlets
|
||||||
|
*
|
||||||
|
* @param string $searchString
|
||||||
|
*/
|
||||||
|
protected function loadSearchDashlets($searchString)
|
||||||
|
{
|
||||||
|
$pane = $this->createPane(self::SEARCH_PANE)->getPane(self::SEARCH_PANE)->setTitle(t('Search'));
|
||||||
|
$this->activate(self::SEARCH_PANE);
|
||||||
|
|
||||||
|
$manager = Icinga::app()->getModuleManager();
|
||||||
|
|
||||||
|
foreach ($manager->getLoadedModules() as $module) {
|
||||||
|
$this->addSearchDashletsFromModule($searchString, $module, $pane);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($searchString === '' && $pane->hasComponents()) {
|
||||||
|
$pane->removeComponents();
|
||||||
|
$pane->add('Ready to search', 'search/hint');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add available search dashlets to the pane
|
||||||
|
*
|
||||||
|
* @param string $searchString
|
||||||
|
* @param Module $module
|
||||||
|
* @param Pane $pane
|
||||||
|
*/
|
||||||
|
protected function addSearchDashletsFromModule($searchString, $module, $pane)
|
||||||
|
{
|
||||||
|
$searchUrls = $module->getSearchUrls();
|
||||||
|
|
||||||
|
if (! empty($searchUrls)) {
|
||||||
|
$this->searchUrls[] = $module->getSearchUrls();
|
||||||
|
foreach ($searchUrls as $search) {
|
||||||
|
$pane->addComponent(
|
||||||
|
$search->title . ': ' . $searchString,
|
||||||
|
Url::fromPath($search->url, array('q' => $searchString))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -55,10 +55,9 @@ class Monitoring_ListController extends Controller
|
|||||||
$url->addParams(array($k => $v));
|
$url->addParams(array($k => $v));
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$q = $url->shift('q');
|
$q = $url->shift('q');
|
||||||
if ($q) {
|
if ($q !== null) {
|
||||||
$action = $this->_request->getActionName();
|
$action = $this->_request->getActionName();
|
||||||
switch($action) {
|
switch($action) {
|
||||||
case 'services':
|
case 'services':
|
||||||
@ -68,7 +67,7 @@ class Monitoring_ListController extends Controller
|
|||||||
$this->params->remove('q')->set('host_name', '*' . $q . '*');
|
$this->params->remove('q')->set('host_name', '*' . $q . '*');
|
||||||
break;
|
break;
|
||||||
case 'hostgroups':
|
case 'hostgroups':
|
||||||
$this->params->remove('q')->set('hostgroups', '*' . $q . '*');
|
$this->params->remove('q')->set('hostgroup', '*' . $q . '*');
|
||||||
break;
|
break;
|
||||||
case 'servicegroups':
|
case 'servicegroups':
|
||||||
$this->params->remove('q')->set('servicegroup', '*' . $q . '*');
|
$this->params->remove('q')->set('servicegroup', '*' . $q . '*');
|
||||||
@ -413,6 +412,9 @@ class Monitoring_ListController extends Controller
|
|||||||
|
|
||||||
public function servicegroupsAction()
|
public function servicegroupsAction()
|
||||||
{
|
{
|
||||||
|
if ($url = $this->hasBetterUrl()) {
|
||||||
|
return $this->redirectNow($url);
|
||||||
|
}
|
||||||
$this->addTitleTab('servicegroups');
|
$this->addTitleTab('servicegroups');
|
||||||
$this->setAutorefreshInterval(12);
|
$this->setAutorefreshInterval(12);
|
||||||
$query = $this->backend->select()->from('groupsummary', array(
|
$query = $this->backend->select()->from('groupsummary', array(
|
||||||
@ -441,6 +443,9 @@ class Monitoring_ListController extends Controller
|
|||||||
|
|
||||||
public function hostgroupsAction()
|
public function hostgroupsAction()
|
||||||
{
|
{
|
||||||
|
if ($url = $this->hasBetterUrl()) {
|
||||||
|
return $this->redirectNow($url);
|
||||||
|
}
|
||||||
$this->addTitleTab('hostgroups');
|
$this->addTitleTab('hostgroups');
|
||||||
$this->setAutorefreshInterval(12);
|
$this->setAutorefreshInterval(12);
|
||||||
$query = $this->backend->select()->from('groupsummary', array(
|
$query = $this->backend->select()->from('groupsummary', array(
|
||||||
|
@ -19,6 +19,14 @@ $this->provideConfigTab('security', array(
|
|||||||
'url' => 'config/security'
|
'url' => 'config/security'
|
||||||
));
|
));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Available Search Urls
|
||||||
|
*/
|
||||||
|
$this->provideSearchUrl($this->translate('Hosts'), 'monitoring/list/hosts?sort=host_severity&limit=10');
|
||||||
|
$this->provideSearchUrl($this->translate('Services'), 'monitoring/list/services?sort=service_severity&limit=10');
|
||||||
|
$this->provideSearchUrl($this->translate('Hostgroups'), 'monitoring/list/hostgroups?limit=10');
|
||||||
|
$this->provideSearchUrl($this->translate('Servicegroups'), 'monitoring/list/servicegroups?limit=10');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Problems Section
|
* Problems Section
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user