Adjust how module dashlets are handled

This commit is contained in:
Yonas Habteab 2022-04-11 11:42:46 +02:00
parent 217faab3fc
commit a34dc9a8cf
6 changed files with 27 additions and 56 deletions

View File

@ -45,11 +45,7 @@ class DashboardsController extends CompatController
$activeHome = $this->dashboard->getActiveHome(); $activeHome = $this->dashboard->getActiveHome();
if (! $activeHome || ! $activeHome->hasEntries()) { if (! $activeHome || ! $activeHome->hasEntries()) {
$this->getTabs()->add('dashboard', [ $this->addTitleTab(t('Welcome'));
'active' => true,
'title' => t('Welcome'),
'url' => Url::fromRequest()
]);
// Setup dashboard introduction form // Setup dashboard introduction form
$welcomeForm = new WelcomeForm($this->dashboard); $welcomeForm = new WelcomeForm($this->dashboard);
@ -85,11 +81,7 @@ class DashboardsController extends CompatController
$activeHome = $this->dashboard->getActiveHome(); $activeHome = $this->dashboard->getActiveHome();
if (! $activeHome->getEntries()) { if (! $activeHome->getEntries()) {
$this->getTabs()->add($activeHome->getName(), [ $this->addTitleTab($activeHome->getTitle());
'active' => true,
'title' => $activeHome->getTitle(),
'url' => Url::fromRequest()
]);
} }
// Not to render the cog icon before the above tab // Not to render the cog icon before the above tab

View File

@ -369,14 +369,16 @@ trait DashboardManager
$dashlet->fromArray([ $dashlet->fromArray([
'label' => t($moduleDashlet->label), 'label' => t($moduleDashlet->label),
'priority' => $moduleDashlet->priority, 'priority' => $moduleDashlet->priority,
'uuid' => $moduleDashlet->id 'uuid' => $moduleDashlet->id,
'module' => $moduleDashlet->module
]); ]);
if (($pane = $moduleDashlet->pane)) { if (($pane = $moduleDashlet->pane)) {
$dashlet->setPane(new Pane($pane)); $dashlet->setPane(new Pane($pane));
} }
$dashlets[$moduleDashlet->module][$dashlet->getName()] = $dashlet; $dashlet->setModuleDashlet(true);
$dashlets[$dashlet->getModule()][$dashlet->getName()] = $dashlet;
} }
return $dashlets; return $dashlets;

View File

@ -140,10 +140,11 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
return $this->tabs; return $this->tabs;
} }
foreach ($activeHome->getEntries() as $key => $pane) { /*** @var Pane $pane */
if (! $this->tabs->get($key)) { foreach ($activeHome->getEntries() as $pane) {
if (! $this->tabs->get($pane->getName())) {
$this->tabs->add( $this->tabs->add(
$key, $pane->getName(),
[ [
'title' => sprintf( 'title' => sprintf(
t('Show %s', 'dashboard.pane.tooltip'), t('Show %s', 'dashboard.pane.tooltip'),
@ -151,7 +152,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
), ),
'label' => $pane->getTitle(), 'label' => $pane->getTitle(),
'url' => clone($url), 'url' => clone($url),
'urlParams' => [$this->tabParam => $key] 'urlParams' => [$this->tabParam => $pane->getName()]
] ]
); );
} }
@ -163,18 +164,13 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
/** /**
* Activate the default pane of this dashboard and returns its name * Activate the default pane of this dashboard and returns its name
* *
* @return ?int|string * @return ?string
*/ */
private function setDefaultPane() private function setDefaultPane()
{ {
$active = null; $active = $this->getActiveHome()->rewindEntries();
$activeHome = $this->getActiveHome(); if ($active) {
foreach ($activeHome->getEntries() as $key => $pane) { $active = $active->getName();
$active = $key;
break;
}
if ($active !== null) {
$this->activate($active); $this->activate($active);
} }
@ -216,9 +212,8 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
$active = $active->getName(); $active = $active->getName();
} }
$panes = $activeHome->getEntries(); if ($activeHome->hasEntry($active)) {
if (isset($panes[$active])) { return $activeHome->getEntry($active);
return $panes[$active];
} }
throw new ConfigurationError('Could not determine active pane'); throw new ConfigurationError('Could not determine active pane');

View File

@ -156,20 +156,16 @@ class Pane extends BaseDashboard implements Sortable
]); ]);
if ($dashlet->isModuleDashlet()) { if ($dashlet->isModuleDashlet()) {
$systemUuid = $dashlet->getUuid(); $data = $dashlet->getModule();
if (! $systemUuid && $dashlet->getPane()) { if (($pane = $dashlet->getPane())) {
$systemUuid = Dashboard::getSHA1( $data .= $pane->getName();
$dashlet->getModule() . $dashlet->getPane()->getName() . $dashlet->getName()
);
} }
if ($systemUuid) {
$conn->insert('icingaweb_system_dashlet', [ $conn->insert('icingaweb_system_dashlet', [
'dashlet_id' => $uuid, 'dashlet_id' => $uuid,
'module_dashlet_id' => $systemUuid 'module_dashlet_id' => Dashboard::getSHA1($data . $dashlet->getName())
]); ]);
} }
}
} elseif (! $this->hasEntry($dashlet->getName()) || ! $origin } elseif (! $this->hasEntry($dashlet->getName()) || ! $origin
|| ! $origin->hasEntry($dashlet->getName())) { || ! $origin->hasEntry($dashlet->getName())) {
$filterCondition = [ $filterCondition = [

View File

@ -201,19 +201,9 @@ class SetupNewDashboard extends BaseDashboardForm
$title = $this->getPopulatedValue($element); $title = $this->getPopulatedValue($element);
$url = $this->getPopulatedValue($element . '_url'); $url = $this->getPopulatedValue($element . '_url');
$dashlet $dashlet
->setUrl($url) ->setUrl($url)
->setTitle($title) ->setTitle($title);
->setModule($module)
->setModuleDashlet(true);
if ($dashlet->getPane()) {
$paneName = $dashlet->getPane()->getName();
$dashlet->setUuid(Dashboard::getSHA1($module . $paneName . $dashlet->getName()));
} else {
$dashlet->setUuid(Dashboard::getSHA1($module . $dashlet->getName()));
}
$moduleDashlets[$dashlet->getName()] = $dashlet; $moduleDashlets[$dashlet->getName()] = $dashlet;
} }

View File

@ -305,7 +305,7 @@ form.icinga-form .control-group.form-controls .remove-button {
margin-right: auto; margin-right: auto;
} }
.modal-form .form-controls .modal-cancel { .modal-form .control-group.form-controls .modal-cancel {
padding: .5em 1em; padding: .5em 1em;
} }
@ -325,13 +325,9 @@ form.icinga-form .control-group.form-controls .remove-button {
.sortable-chosen { .sortable-chosen {
.box-shadow(); .box-shadow();
background: fade(@icinga-blue, 20); background: fade(@icinga-blue, 20);
border: 5px @body-bg-color dashed; border: .5em @body-bg-color dashed;
} }
.home-list-control.sortable-drag { .home-list-control.sortable-drag {
width: calc(85% + 1.4em); width: calc(85% + 1.4em);
} }
.draggable-element {
opacity: .4;
}