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()
|
private function loadUserDashboards()
|
||||||
{
|
{
|
||||||
$configFile = '/var/lib/icingaweb/' . $this->user->getUsername() . '/dashboard.ini';
|
$config = Config::fromIni($this->getConfigFile());
|
||||||
$config = Config::fromIni($configFile);
|
|
||||||
if (! count($config)) {
|
if (! count($config)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +95,7 @@ class Dashboard extends AbstractWidget
|
||||||
if (strpos($key, '.') === false) {
|
if (strpos($key, '.') === false) {
|
||||||
$panes[$key] = new Pane($key);
|
$panes[$key] = new Pane($key);
|
||||||
$panes[$key]->setTitle($part->title);
|
$panes[$key]->setTitle($part->title);
|
||||||
|
$panes[$key]->setUserWidget();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
list($paneName, $componentName) = explode('.', $key, 2);
|
list($paneName, $componentName) = explode('.', $key, 2);
|
||||||
|
@ -114,15 +114,22 @@ class Dashboard extends AbstractWidget
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$pane->addComponent(
|
$component = new DashboardComponent(
|
||||||
new DashboardComponent(
|
$componentData->title,
|
||||||
$componentData->title,
|
$componentData->url,
|
||||||
$componentData->url,
|
$pane
|
||||||
$pane
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ((bool) $componentData->get('disabled', false) === true) {
|
||||||
|
$component->setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$component->setUserWidget();
|
||||||
|
$pane->addComponent($component);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mergePanes($panes);
|
$this->mergePanes($panes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,4 +330,12 @@ class Dashboard extends AbstractWidget
|
||||||
{
|
{
|
||||||
return $this->user;
|
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
|
* This is the element displaying a specific view in icinga2web
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Component extends AbstractWidget
|
class Component extends UserWidget
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The url of this Component
|
* The url of this Component
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Icinga\Exception\ConfigurationError;
|
||||||
/**
|
/**
|
||||||
* A pane, displaying different Dashboard components
|
* 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
|
* The name of this pane, as defined in the ini file
|
||||||
|
@ -168,7 +168,13 @@ class Pane extends AbstractWidget
|
||||||
*/
|
*/
|
||||||
public function render()
|
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