diff --git a/application/controllers/SearchController.php b/application/controllers/SearchController.php index 92aeabe54..0b8b55983 100644 --- a/application/controllers/SearchController.php +++ b/application/controllers/SearchController.php @@ -3,23 +3,21 @@ namespace Icinga\Controllers; -use Icinga\Web\Controller\ActionController; -use Icinga\Web\Widget; use Icinga\Web\Widget\SearchDashboard; +use ipl\Web\Compat\CompatController; /** * Search controller */ -class SearchController extends ActionController +class SearchController extends CompatController { public function indexAction() { $searchDashboard = new SearchDashboard(); $searchDashboard->setUser($this->Auth()->getUser()); - $this->view->dashboard = $searchDashboard->search($this->params->get('q')); - // NOTE: This renders the dashboard twice. Remove this once we can catch exceptions thrown in view scripts. - $this->view->dashboard->render(); + $this->controls->setTabs($searchDashboard->getTabs()); + $this->content = $searchDashboard->search($this->getParam('q')); } public function hintAction() diff --git a/library/Icinga/Web/Widget/SearchDashboard.php b/library/Icinga/Web/Widget/SearchDashboard.php index 1ce4c464b..f6301f049 100644 --- a/library/Icinga/Web/Widget/SearchDashboard.php +++ b/library/Icinga/Web/Widget/SearchDashboard.php @@ -3,15 +3,23 @@ namespace Icinga\Web\Widget; -use Zend_Controller_Action_Exception; +use Icinga\Exception\Http\HttpNotFoundException; use Icinga\Application\Icinga; +use Icinga\Web\Navigation\DashboardHome; use Icinga\Web\Url; /** * Class SearchDashboard display multiple search views on a single search page */ -class SearchDashboard extends Dashboard +class SearchDashboard extends \Icinga\Web\Dashboard\Dashboard { + /** + * Name for the search home + * + * @var string + */ + const SEARCH_HOME = 'Search Home'; + /** * Name for the search pane * @@ -20,12 +28,23 @@ class SearchDashboard extends Dashboard const SEARCH_PANE = 'search'; /** - * {@inheritdoc} + * Dashboard home of this search dashboard + * + * @var DashboardHome */ + protected $searchHome; + + public function __construct() + { + $this->searchHome = new DashboardHome(self::SEARCH_HOME); + $this->searchHome->setActive(); + } + public function getTabs() { if ($this->tabs === null) { - $this->tabs = new Tabs(); + $this->tabs = new \ipl\Web\Widget\Tabs(); + $this->tabs->add( 'search', array( @@ -35,9 +54,15 @@ class SearchDashboard extends Dashboard ) ); } + return $this->tabs; } + public function getActiveHome() + { + return $this->searchHome; + } + /** * Load all available search dashlets from modules * @@ -47,18 +72,18 @@ class SearchDashboard extends Dashboard */ public function search($searchString = '') { - $pane = $this->createPane(self::SEARCH_PANE)->getPane(self::SEARCH_PANE)->setTitle(t('Search')); + $pane = $this->searchHome->addPane(self::SEARCH_PANE)->getPane(self::SEARCH_PANE)->setTitle(t('Search')); $this->activate(self::SEARCH_PANE); $manager = Icinga::app()->getModuleManager(); $searchUrls = array(); foreach ($manager->getLoadedModules() as $module) { - if ($this->getUser()->can($manager::MODULE_PERMISSION_NS . $module->getName())) { + if (self::getUser()->can($manager::MODULE_PERMISSION_NS . $module->getName())) { $moduleSearchUrls = $module->getSearchUrls(); if (! empty($moduleSearchUrls)) { if ($searchString === '') { - $pane->add(t('Ready to search'), 'search/hint'); + $pane->addDashlet(t('Ready to search'), 'search/hint'); return $this; } $searchUrls = array_merge($searchUrls, $moduleSearchUrls); @@ -69,28 +94,21 @@ class SearchDashboard extends Dashboard usort($searchUrls, array($this, 'compareSearchUrls')); foreach (array_reverse($searchUrls) as $searchUrl) { - $pane->createDashlet( - $searchUrl->title . ': ' . $searchString, - Url::fromPath($searchUrl->url, array('q' => $searchString)) - )->setProgressLabel(t('Searching')); + $title = $searchUrl->title . ': ' . $searchString; + $pane->addDashlet($title, Url::fromPath($searchUrl->url, array('q' => $searchString))); + $pane->getDashlet($title)->setProgressLabel(t('Searching')); } return $this; } - /** - * Renders the output - * - * @return string - * - * @throws Zend_Controller_Action_Exception - */ - public function render() + protected function assemble() { - if (! $this->getPane(self::SEARCH_PANE)->hasDashlets()) { - throw new Zend_Controller_Action_Exception(t('Page not found'), 404); + if (! $this->searchHome->getPane(self::SEARCH_PANE)->hasDashlets()) { + throw new HttpNotFoundException(t('Page not found')); } - return parent::render(); + + $this->add($this->searchHome->getPane(self::SEARCH_PANE)->getDashlets()); } /**