diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index 0fdb61d33..866dfe3ca 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -85,8 +85,7 @@ class Dashboard extends AbstractWidget */ private function loadUserDashboards() { - $configFile = '/var/lib/icingaweb/' . $this->user->getUsername() . '/dashboard.ini'; - $config = Config::fromIni($configFile); + $config = Config::fromIni($this->getConfigFile()); if (! count($config)) { return false; } @@ -96,6 +95,7 @@ class Dashboard extends AbstractWidget if (strpos($key, '.') === false) { $panes[$key] = new Pane($key); $panes[$key]->setTitle($part->title); + $panes[$key]->setUserWidget(); } else { list($paneName, $componentName) = explode('.', $key, 2); @@ -114,15 +114,22 @@ class Dashboard extends AbstractWidget } else { continue; } - $pane->addComponent( - new DashboardComponent( - $componentData->title, - $componentData->url, - $pane - ) + $component = new DashboardComponent( + $componentData->title, + $componentData->url, + $pane ); + + if ((bool) $componentData->get('disabled', false) === true) { + $component->setDisabled(true); + } + + $component->setUserWidget(); + $pane->addComponent($component); } + $this->mergePanes($panes); + return true; } @@ -323,4 +330,12 @@ class Dashboard extends AbstractWidget { return $this->user; } + + public function getConfigFile() + { + if ($this->user === null) { + return ''; + } + return '/var/lib/icingaweb/' . $this->user->getUsername() . '/dashboard.ini'; + } } diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php index 6edf140f5..0017ce9e3 100644 --- a/library/Icinga/Web/Widget/Dashboard/Component.php +++ b/library/Icinga/Web/Widget/Dashboard/Component.php @@ -17,7 +17,7 @@ use Icinga\Exception\IcingaException; * This is the element displaying a specific view in icinga2web * */ -class Component extends AbstractWidget +class Component extends UserWidget { /** * The url of this Component diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php index 3b0e97c73..04073411a 100644 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ b/library/Icinga/Web/Widget/Dashboard/Pane.php @@ -12,7 +12,7 @@ use Icinga\Exception\ConfigurationError; /** * A pane, displaying different Dashboard components */ -class Pane extends AbstractWidget +class Pane extends UserWidget { /** * The name of this pane, as defined in the ini file @@ -168,7 +168,13 @@ class Pane extends AbstractWidget */ public function render() { - return implode("\n", $this->components) . "\n"; + $components = array_filter( + $this->components, + function ($e) { + return ! $e->getDisabled(); + } + ); + return implode("\n", $components) . "\n"; } /** diff --git a/library/Icinga/Web/Widget/Dashboard/UserWidget.php b/library/Icinga/Web/Widget/Dashboard/UserWidget.php new file mode 100644 index 000000000..0b171964e --- /dev/null +++ b/library/Icinga/Web/Widget/Dashboard/UserWidget.php @@ -0,0 +1,37 @@ +userWidget = (bool) $userWidget; + } + + /** + * Getter for user widget flag + * + * @return boolean + */ + public function isUserWidget() + { + return $this->userWidget; + } +}