mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 17:24:16 +02:00
Handle module identification directly in the ActionController
Fixes some issues with more complex customisations in a module's controller. Obsoletes: 93f8297344cfdb2037f4646dc84046fbea851946
This commit is contained in:
parent
036da072c5
commit
63e639caf0
@ -5,7 +5,7 @@ use Icinga\Web\Notification;
|
|||||||
use Icinga\Authentication\Auth;
|
use Icinga\Authentication\Auth;
|
||||||
|
|
||||||
$moduleName = $this->layout()->moduleName;
|
$moduleName = $this->layout()->moduleName;
|
||||||
if ($moduleName) {
|
if ($moduleName !== 'default') {
|
||||||
$moduleClass = ' icinga-module module-' . $moduleName;
|
$moduleClass = ' icinga-module module-' . $moduleName;
|
||||||
} else {
|
} else {
|
||||||
$moduleClass = '';
|
$moduleClass = '';
|
||||||
|
@ -4,7 +4,7 @@ use Icinga\Web\StyleSheet;
|
|||||||
|
|
||||||
|
|
||||||
$moduleName = $this->layout()->moduleName;
|
$moduleName = $this->layout()->moduleName;
|
||||||
if ($moduleName) {
|
if ($moduleName !== 'default') {
|
||||||
$moduleClass = ' icinga-module module-' . $moduleName;
|
$moduleClass = ' icinga-module module-' . $moduleName;
|
||||||
} else {
|
} else {
|
||||||
$moduleClass = '';
|
$moduleClass = '';
|
||||||
|
@ -38,6 +38,13 @@ class ActionController extends Zend_Controller_Action
|
|||||||
*/
|
*/
|
||||||
protected $requiresAuthentication = true;
|
protected $requiresAuthentication = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current module's name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $moduleName;
|
||||||
|
|
||||||
private $autorefreshInterval;
|
private $autorefreshInterval;
|
||||||
|
|
||||||
private $reloadCss = false;
|
private $reloadCss = false;
|
||||||
@ -90,10 +97,11 @@ class ActionController extends Zend_Controller_Action
|
|||||||
$this->_helper = new ActionHelperBroker($this);
|
$this->_helper = new ActionHelperBroker($this);
|
||||||
|
|
||||||
$this->handlerBrowserWindows();
|
$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()->isIframe = $request->getUrl()->shift('isIframe');
|
||||||
$this->_helper->layout()->showFullscreen = $request->getUrl()->shift('showFullscreen');
|
$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';
|
$this->view->compact = $request->getParam('view') === 'compact';
|
||||||
if ($request->getUrl()->shift('showCompact')) {
|
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)
|
public function Config($file = null)
|
||||||
{
|
{
|
||||||
if ($file === null) {
|
if ($file === null) {
|
||||||
|
@ -6,6 +6,7 @@ namespace Icinga\Web\Controller;
|
|||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Modules\Manager;
|
use Icinga\Application\Modules\Manager;
|
||||||
|
use Icinga\Application\Modules\Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for module action controllers
|
* Base class for module action controllers
|
||||||
@ -18,25 +19,15 @@ class ModuleActionController extends ActionController
|
|||||||
|
|
||||||
private $module;
|
private $module;
|
||||||
|
|
||||||
/**
|
|
||||||
* Module name
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $moduleName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Icinga\Web\Controller\ActionController For the method documentation.
|
* @see \Icinga\Web\Controller\ActionController For the method documentation.
|
||||||
*/
|
*/
|
||||||
protected function prepareInit()
|
protected function prepareInit()
|
||||||
{
|
{
|
||||||
$this->moduleName = $this->_request->getModuleName();
|
|
||||||
$this->_helper->layout()->moduleName = $this->moduleName;
|
|
||||||
$this->view->translationDomain = $this->moduleName;
|
|
||||||
$this->moduleInit();
|
$this->moduleInit();
|
||||||
if ($this->getFrontController()->getDefaultModule() !== $this->moduleName) {
|
if ($this->getFrontController()->getDefaultModule() !== $this->getModuleName()) {
|
||||||
$this->assertPermission(Manager::MODULE_PERMISSION_NS . $this->moduleName);
|
$this->assertPermission(Manager::MODULE_PERMISSION_NS . $this->getModuleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,22 +42,28 @@ class ModuleActionController extends ActionController
|
|||||||
{
|
{
|
||||||
if ($file === null) {
|
if ($file === null) {
|
||||||
if ($this->config === null) {
|
if ($this->config === null) {
|
||||||
$this->config = Config::module($this->moduleName);
|
$this->config = Config::module($this->getModuleName());
|
||||||
}
|
}
|
||||||
return $this->config;
|
return $this->config;
|
||||||
} else {
|
} else {
|
||||||
if (! array_key_exists($file, $this->configs)) {
|
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->configs[$file];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this controller's module
|
||||||
|
*
|
||||||
|
* @return Module
|
||||||
|
*/
|
||||||
public function Module()
|
public function Module()
|
||||||
{
|
{
|
||||||
if ($this->module === null) {
|
if ($this->module === null) {
|
||||||
$this->module = Icinga::app()->getModuleManager()->getModule($this->moduleName);
|
$this->module = Icinga::app()->getModuleManager()->getModule($this->getModuleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->module;
|
return $this->module;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +74,6 @@ class ModuleActionController extends ActionController
|
|||||||
public function postDispatchXhr()
|
public function postDispatchXhr()
|
||||||
{
|
{
|
||||||
parent::postDispatchXhr();
|
parent::postDispatchXhr();
|
||||||
$this->getResponse()->setHeader('X-Icinga-Module', $this->moduleName, true);
|
$this->getResponse()->setHeader('X-Icinga-Module', $this->getModuleName(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user