From 077ee4b537e8c0ad69381ad28850c991ef000e8f Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 11 Mar 2022 16:55:08 +0100 Subject: [PATCH] Dashboard: Introduce `Settings` class to manage to the new dashbaords --- library/Icinga/Web/Dashboard/Settings.php | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 library/Icinga/Web/Dashboard/Settings.php diff --git a/library/Icinga/Web/Dashboard/Settings.php b/library/Icinga/Web/Dashboard/Settings.php new file mode 100644 index 000000000..c85502552 --- /dev/null +++ b/library/Icinga/Web/Dashboard/Settings.php @@ -0,0 +1,59 @@ + ['dashboard-settings content']]; + + protected $tag = 'div'; + + /** @var Dashboard */ + protected $dashboard; + + public function __construct(Dashboard $dashboard) + { + $this->dashboard = $dashboard; + } + + protected function assemble() + { + // TODO: What we should with disabled homes?? + $activeHome = $this->dashboard->getActiveHome(); + + if (empty($this->dashboard->getHomes())) { + // TODO: No dashboard homes :( what should we render now?? + } elseif (count($this->dashboard->getHomes()) === 1 && $activeHome->getName() === DashboardHome::DEFAULT_HOME) { + foreach ($activeHome->getPanes() as $pane) { + $pane->setHome($activeHome); + + $this->addHtml(new DashboardList($pane)); + } + + $this->addHtml(new ActionLink( + t('Add Dashboard'), + Url::fromPath(Dashboard::BASE_ROUTE . '/new-dashlet'), + 'plus', + [ + 'class' => 'add-dashboard', + 'data-icinga-modal' => true, + 'data-no-icinga-ajax' => true + ] + )); + } else { + // Make a list of dashbaord homes + foreach ($this->dashboard->getHomes() as $home) { + $this->addHtml(new DashboardHomeList($home)); + } + } + } +}