From 3dcf9fa02a21a3eb444dd4c005f13e1e063bd381 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 11 Mar 2022 16:54:13 +0100 Subject: [PATCH] Dashboard: Introduce `DashboardHomeList` widget --- .../Dashboard/ItemList/DashboardHomeList.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php new file mode 100644 index 000000000..5e1c39ddf --- /dev/null +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php @@ -0,0 +1,72 @@ + 'home-item-list']; + + protected $tag = 'ul'; + + /** @var DashboardHome */ + protected $home; + + public function __construct(DashboardHome $home) + { + $this->home = $home; + $this->home->setActive(); + $this->home->loadDashboardsFromDB(); + + $this->getAttributes()->add('class', $home->getName()); + } + + protected function assemble() + { + $wrapper = HtmlElement::create('div', [ + 'class' => 'home-list-control collapsible', + 'data-toggle-element' => '.dashboard-list-info' + ]); + + $wrapper->addHtml(HtmlElement::create('div', ['class' => 'dashboard-list-info'], [ + new Icon('angle-down', ['class' => 'expand-icon', 'title' => t('Expand')]), + new Icon('angle-up', ['class' => 'collapse-icon', 'title' => t('Collapse')]) + ])); + + $header = HtmlElement::create('h1', ['class' => 'collapsible-header home'], $this->home->getLabel()); + $url = Url::fromPath(Dashboard::BASE_ROUTE . '/rename-home')->setParams(['home' => $this->home->getName()]); + + $header->addHtml(new Link(t('Edit'), $url, [ + 'data-icinga-modal' => true, + 'data-no-icinga-ajax' => true + ])); + + $wrapper->addHtml($header); + + // List all dashboard panes + foreach ($this->home->getPanes() as $pane) { + $pane->setHome($this->home); // In case it's not set + + $this->addHtml(new DashboardList($pane)); + } + + $url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-dashlet'); + $url->setParams(['home' => $this->home->getName()]); + + $wrapper->addHtml(new ActionLink(t('Add Dashboard'), $url, 'plus', [ + 'class' => 'add-dashboard', + 'data-icinga-modal' => true, + 'data-no-icinga-ajax' => true + ])); + + $this->addWrapper($wrapper); + } +}