Dashboard: Introduce user flag widget
Fix: Do not render disabled components. refs #4537
This commit is contained in:
parent
af799d42dc
commit
f6a2f6515d
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Widget\Dashboard;
|
||||
|
||||
use Icinga\Web\Widget\AbstractWidget;
|
||||
|
||||
abstract class UserWidget extends AbstractWidget
|
||||
{
|
||||
/**
|
||||
* Flag if widget is created by an user
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $userWidget = false;
|
||||
|
||||
/**
|
||||
* Set the user widget flag
|
||||
*
|
||||
* @param boolean $userWidget
|
||||
*/
|
||||
public function setUserWidget($userWidget = true)
|
||||
{
|
||||
$this->userWidget = (bool) $userWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for user widget flag
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUserWidget()
|
||||
{
|
||||
return $this->userWidget;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue