Handle module identification directly in the ActionController

Fixes some issues with more complex customisations in a
module's controller.
Obsoletes: 93f8297344
This commit is contained in:
Johannes Meyer 2015-08-19 13:39:37 +02:00
parent 036da072c5
commit 63e639caf0
4 changed files with 39 additions and 20 deletions

View File

@ -5,7 +5,7 @@ use Icinga\Web\Notification;
use Icinga\Authentication\Auth;
$moduleName = $this->layout()->moduleName;
if ($moduleName) {
if ($moduleName !== 'default') {
$moduleClass = ' icinga-module module-' . $moduleName;
} else {
$moduleClass = '';

View File

@ -4,7 +4,7 @@ use Icinga\Web\StyleSheet;
$moduleName = $this->layout()->moduleName;
if ($moduleName) {
if ($moduleName !== 'default') {
$moduleClass = ' icinga-module module-' . $moduleName;
} else {
$moduleClass = '';

View File

@ -38,6 +38,13 @@ class ActionController extends Zend_Controller_Action
*/
protected $requiresAuthentication = true;
/**
* The current module's name
*
* @var string
*/
private $moduleName;
private $autorefreshInterval;
private $reloadCss = false;
@ -90,10 +97,11 @@ class ActionController extends Zend_Controller_Action
$this->_helper = new ActionHelperBroker($this);
$this->handlerBrowserWindows();
$this->view->translationDomain = 'icinga';
$moduleName = $this->getModuleName();
$this->view->translationDomain = $moduleName !== 'default' ? $moduleName : 'icinga';
$this->_helper->layout()->isIframe = $request->getUrl()->shift('isIframe');
$this->_helper->layout()->showFullscreen = $request->getUrl()->shift('showFullscreen');
$this->_helper->layout()->moduleName = false;
$this->_helper->layout()->moduleName = $moduleName;
$this->view->compact = $request->getParam('view') === 'compact';
if ($request->getUrl()->shift('showCompact')) {
@ -166,6 +174,20 @@ class ActionController extends Zend_Controller_Action
}
}
/**
* Return the current module's name
*
* @return string
*/
public function getModuleName()
{
if ($this->moduleName === null) {
$this->moduleName = $this->getRequest()->getModuleName();
}
return $this->moduleName;
}
public function Config($file = null)
{
if ($file === null) {

View File

@ -6,6 +6,7 @@ namespace Icinga\Web\Controller;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Manager;
use Icinga\Application\Modules\Module;
/**
* Base class for module action controllers
@ -18,25 +19,15 @@ class ModuleActionController extends ActionController
private $module;
/**
* Module name
*
* @var string
*/
protected $moduleName;
/**
* (non-PHPDoc)
* @see \Icinga\Web\Controller\ActionController For the method documentation.
*/
protected function prepareInit()
{
$this->moduleName = $this->_request->getModuleName();
$this->_helper->layout()->moduleName = $this->moduleName;
$this->view->translationDomain = $this->moduleName;
$this->moduleInit();
if ($this->getFrontController()->getDefaultModule() !== $this->moduleName) {
$this->assertPermission(Manager::MODULE_PERMISSION_NS . $this->moduleName);
if ($this->getFrontController()->getDefaultModule() !== $this->getModuleName()) {
$this->assertPermission(Manager::MODULE_PERMISSION_NS . $this->getModuleName());
}
}
@ -51,22 +42,28 @@ class ModuleActionController extends ActionController
{
if ($file === null) {
if ($this->config === null) {
$this->config = Config::module($this->moduleName);
$this->config = Config::module($this->getModuleName());
}
return $this->config;
} else {
if (! array_key_exists($file, $this->configs)) {
$this->configs[$file] = Config::module($this->moduleName, $file);
$this->configs[$file] = Config::module($this->getModuleName(), $file);
}
return $this->configs[$file];
}
}
/**
* Return this controller's module
*
* @return Module
*/
public function Module()
{
if ($this->module === null) {
$this->module = Icinga::app()->getModuleManager()->getModule($this->moduleName);
$this->module = Icinga::app()->getModuleManager()->getModule($this->getModuleName());
}
return $this->module;
}
@ -77,6 +74,6 @@ class ModuleActionController extends ActionController
public function postDispatchXhr()
{
parent::postDispatchXhr();
$this->getResponse()->setHeader('X-Icinga-Module', $this->moduleName, true);
$this->getResponse()->setHeader('X-Icinga-Module', $this->getModuleName(), true);
}
}