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

View File

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

View File

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

View File

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

View File

@ -201,19 +201,9 @@ class SetupNewDashboard extends BaseDashboardForm
$title = $this->getPopulatedValue($element);
$url = $this->getPopulatedValue($element . '_url');
$dashlet
->setUrl($url)
->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()));
}
->setTitle($title);
$moduleDashlets[$dashlet->getName()] = $dashlet;
}

View File

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