From 97f98b6d589c7ee7d931bf40043d16218550dc5d Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 11 Mar 2022 16:53:32 +0100 Subject: [PATCH] Dashboard: Introduce `DashbaordList` widget --- .../Web/Dashboard/ItemList/DashboardList.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 library/Icinga/Web/Dashboard/ItemList/DashboardList.php diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php new file mode 100644 index 000000000..83c9c8b33 --- /dev/null +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php @@ -0,0 +1,73 @@ + 'dashboard-item-list']; + + protected $tag = 'ul'; + + /** @var Pane */ + protected $pane; + + public function __construct(Pane $pane) + { + $this->pane = $pane; + + $this->getAttributes()->add('class', $pane->getName()); + } + + protected function assemble() + { + // TODO: How should disabled dashboard panes look like? + $wrapper = HtmlElement::create('div', [ + 'class' => 'dashboard-list-control collapsible', + 'data-toggle-element' => '.dashlets-list-info' + ]); + + $wrapper->addHtml(HtmlElement::create('div', ['class' => 'dashlets-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'], $this->pane->getTitle()); + $url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-pane')->setParams([ + 'home' => $this->pane->getHome()->getName(), + 'pane' => $this->pane->getName() + ]); + + $header->addHtml(new Link(t('Edit'), $url, [ + 'data-icinga-modal' => true, + 'data-no-icinga-ajax' => true + ])); + + $wrapper->addHtml($header); + + foreach ($this->pane->getDashlets() as $dashlet) { + $this->addHtml(new DashletListItem($dashlet, true)); + } + + $wrapper->addHtml(new ActionLink( + t('Add Dashlet'), + Url::fromPath(Dashboard::BASE_ROUTE . '/new-dashlet')->addParams(['pane' => $this->pane->getName()]), + 'plus', + [ + 'class' => 'add-dashlet', + 'data-icinga-modal' => true, + 'data-no-icinga-ajax' => true + ] + )); + + $this->addWrapper($wrapper); + } +}