From 56bfe76a84858b99e4310db1b978ba04c5c9571c Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 3 Jun 2022 16:45:30 +0200 Subject: [PATCH] Remove unused method from ItemListControl & try to load dashboards in HomeList only when it's empty --- .../Icinga/Web/Dashboard/Common/ItemListControl.php | 7 ------- .../Web/Dashboard/ItemList/DashboardHomeList.php | 10 ++++------ .../Icinga/Web/Dashboard/ItemList/DashboardList.php | 7 +------ .../Icinga/Web/Dashboard/ItemList/DashletListItem.php | 6 +++--- .../Web/Dashboard/ItemList/DashletListMultiSelect.php | 3 ++- library/Icinga/Web/Dashboard/ItemList/EmptyDashlet.php | 6 +++--- 6 files changed, 13 insertions(+), 26 deletions(-) diff --git a/library/Icinga/Web/Dashboard/Common/ItemListControl.php b/library/Icinga/Web/Dashboard/Common/ItemListControl.php index fed31d192..a26870070 100644 --- a/library/Icinga/Web/Dashboard/Common/ItemListControl.php +++ b/library/Icinga/Web/Dashboard/Common/ItemListControl.php @@ -30,13 +30,6 @@ abstract class ItemListControl extends BaseHtmlElement */ abstract protected function shouldExpandByDefault(): bool; - /** - * Get a class name for the collapsible control - * - * @return string - */ - abstract protected function getCollapsibleControlClass(): string; - /** * Create an action link to be added at the end of the list * diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php index 06ae3a321..af0f467ee 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php @@ -26,7 +26,10 @@ class DashboardHomeList extends ItemListControl public function __construct(DashboardHome $home) { $this->home = $home; - $this->home->loadDashboardEntries(); + if (! $this->home->hasEntries()) { + // Just retry to load dashboards + $this->home->loadDashboardEntries(); + } $this->getAttributes() ->registerAttributeCallback('data-icinga-home', function () { @@ -58,11 +61,6 @@ class DashboardHomeList extends ItemListControl return $this->home->isActive(); } - protected function getCollapsibleControlClass(): string - { - return 'dashboard-list-info'; - } - protected function createItemList(): BaseHtmlElement { if (! $this->headerDisabled) { diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php index 1c7b245d9..03a0d9761 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php @@ -37,12 +37,7 @@ class DashboardList extends ItemListControl protected function shouldExpandByDefault(): bool { - return $this->pane->isActive(); - } - - protected function getCollapsibleControlClass(): string - { - return 'dashlets-list-info'; + return $this->pane->getHome()->isActive() && $this->pane->isActive(); } protected function createItemList(): BaseHtmlElement diff --git a/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php b/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php index fe5e5ef26..551ad8535 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php @@ -59,9 +59,9 @@ class DashletListItem extends BaseHtmlElement /** * Assemble header of this dashlet item * - * @return ValidHtml + * @return BaseHtmlElement */ - protected function assembleHeader(): ValidHtml + protected function assembleHeader(): BaseHtmlElement { $header = HtmlElement::create('div', ['class' => 'dashlet-header']); @@ -100,7 +100,7 @@ class DashletListItem extends BaseHtmlElement return $header; } - protected function assembleSummary() + protected function assembleSummary(): BaseHtmlElement { $section = HtmlElement::create('section', ['class' => 'caption']); diff --git a/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php b/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php index e4be64c97..4a45920ae 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php @@ -4,6 +4,7 @@ namespace Icinga\Web\Dashboard\ItemList; +use ipl\Html\BaseHtmlElement; use ipl\Html\Contract\FormElement; use ipl\Html\HtmlElement; @@ -26,7 +27,7 @@ class DashletListMultiSelect extends DashletListItem return $this; } - protected function createLabel(): HtmlElement + protected function createLabel(): BaseHtmlElement { $label = HtmlElement::create('label'); $label->addHtml($this->checkbox); diff --git a/library/Icinga/Web/Dashboard/ItemList/EmptyDashlet.php b/library/Icinga/Web/Dashboard/ItemList/EmptyDashlet.php index d5561e966..9c75d238f 100644 --- a/library/Icinga/Web/Dashboard/ItemList/EmptyDashlet.php +++ b/library/Icinga/Web/Dashboard/ItemList/EmptyDashlet.php @@ -4,12 +4,12 @@ namespace Icinga\Web\Dashboard\ItemList; +use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; -use ipl\Html\ValidHtml; class EmptyDashlet extends DashletListMultiSelect { - protected function assembleHeader(): ValidHtml + protected function assembleHeader(): BaseHtmlElement { $header = HtmlElement::create('div', ['class' => 'dashlet-header']); $header->add(t('Custom Url')); @@ -17,7 +17,7 @@ class EmptyDashlet extends DashletListMultiSelect return $header; } - protected function assembleSummary() + protected function assembleSummary(): BaseHtmlElement { $section = HtmlElement::create('section', ['class' => 'caption']); $section->add(t('Create a dashlet with custom url and filter'));