mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-24 10:27:46 +02:00
Simulate removal of dashboard home Default Home
This commit is contained in:
parent
dab6bdc7c6
commit
c635102d4e
@ -432,7 +432,7 @@ class DashboardsController extends CompatController
|
||||
{
|
||||
$tabs = $this->dashboard->getTabs();
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
if (($activeHome && $activeHome->hasEntries()) || count($this->dashboard->getEntries()) > 1) {
|
||||
if (($activeHome && $activeHome->hasEntries()) || (! $activeHome->isDisabled() && count($this->dashboard->getEntries()) > 1)) {
|
||||
$tabs->extend(new DashboardSettings());
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ class WelcomeForm extends CompatForm
|
||||
$conn->beginTransaction();
|
||||
|
||||
try {
|
||||
$this->dashboard->manageEntry($home);
|
||||
$home->manageEntry($this->dashboard->getSystemDefaults(), null, true);
|
||||
|
||||
$conn->commitTransaction();
|
||||
|
@ -29,6 +29,7 @@ class Home extends Model
|
||||
'username',
|
||||
'type',
|
||||
'priority',
|
||||
'disabled',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ namespace Icinga\Web\Dashboard\Common;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
use Icinga\Web\Dashboard\Dashboard;
|
||||
use function ipl\Stdlib\get_php_type;
|
||||
|
||||
trait DashboardControls
|
||||
@ -91,7 +92,14 @@ trait DashboardControls
|
||||
|
||||
public function rewindEntries()
|
||||
{
|
||||
return reset($this->dashboards);
|
||||
$dashboards = $this->dashboards;
|
||||
if ($this instanceof Dashboard) {
|
||||
$dashboards = array_filter($dashboards, function ($home) {
|
||||
return ! $home->isDisabled();
|
||||
});
|
||||
}
|
||||
|
||||
return reset($dashboards);
|
||||
}
|
||||
|
||||
public function reorderWidget(BaseDashboard $dashboard, int $position, Sortable $origin = null)
|
||||
|
@ -153,6 +153,10 @@ trait DashboardManager
|
||||
$home->removeEntries();
|
||||
if ($home->getName() !== DashboardHome::DEFAULT_HOME) {
|
||||
self::getConn()->delete(DashboardHome::TABLE, ['id = ?' => $home->getUuid()]);
|
||||
} elseif (! $home->isDisabled()) {
|
||||
self::getConn()->update(DashboardHome::TABLE, ['disabled' => 1], [
|
||||
'id = ?' => $home->getUuid()
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -180,7 +184,8 @@ trait DashboardManager
|
||||
} else {
|
||||
$conn->update(DashboardHome::TABLE, [
|
||||
'label' => $home->getTitle(),
|
||||
'priority' => $home->getPriority()
|
||||
'priority' => $home->getPriority(),
|
||||
'disabled' => 0
|
||||
], ['id = ?' => $home->getUuid()]);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,14 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $active;
|
||||
protected $active = false;
|
||||
|
||||
/**
|
||||
* A flag whether a home has been disabled (affects only default home)
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $disabled;
|
||||
|
||||
/**
|
||||
* Create a new dashboard home from the given home item
|
||||
@ -52,14 +59,15 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
*
|
||||
* @return DashboardHome
|
||||
*/
|
||||
public static function create(DashboardHomeItem $homeItem)
|
||||
public static function create(DashboardHomeItem $homeItem): self
|
||||
{
|
||||
$self = new self($homeItem->getName());
|
||||
$self
|
||||
->setTitle($homeItem->getLabel())
|
||||
->setPriority($homeItem->getPriority())
|
||||
->setType($homeItem->getAttribute('type'))
|
||||
->setUuid($homeItem->getAttribute('uuid'));
|
||||
->setUuid($homeItem->getAttribute('uuid'))
|
||||
->setDisabled($homeItem->getAttribute('disabled'));
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -73,7 +81,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setActive(bool $active = true)
|
||||
public function setActive(bool $active = true): self
|
||||
{
|
||||
$this->active = $active;
|
||||
|
||||
@ -85,7 +93,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getActive()
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
@ -97,7 +105,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setType(string $type)
|
||||
public function setType(string $type): self
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
@ -109,11 +117,35 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this home should be disabled
|
||||
*
|
||||
* @param bool $disabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisabled(bool $disabled): self
|
||||
{
|
||||
$this->disabled = $disabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this home has been disabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
return $this->disabled;
|
||||
}
|
||||
|
||||
public function removeEntry($pane)
|
||||
{
|
||||
$name = $pane instanceof Pane ? $pane->getName() : $pane;
|
||||
|
@ -47,6 +47,10 @@ class Settings extends BaseHtmlElement
|
||||
} else {
|
||||
// Make a list of dashboard homes
|
||||
foreach ($this->dashboard->getEntries() as $home) {
|
||||
if ($home->isDisabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addHtml(new DashboardHomeList($home));
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +172,7 @@ class Menu extends Navigation
|
||||
'label' => t($home->label),
|
||||
'priority' => $home->priority,
|
||||
'type' => $home->type,
|
||||
'disabled' => (bool) $home->disabled
|
||||
]);
|
||||
|
||||
$dashboardItem->addChild($dashboardHome);
|
||||
|
Loading…
x
Reference in New Issue
Block a user