'dashboard']; /** * The @see Tabs object for displaying displayable panes * * @var Tabs */ protected $tabs; /** * The parameter that will be added to identify panes * * @var string */ private $tabParam = 'pane'; /** * A welcome form rendered when there is no dashboard panes * * @var Form */ private $welcomeForm; /** * Set the given tab name as active * * @param string $name The tab name to activate * */ public function activate(string $name) { $this->getTabs()->activate($name); } /** * Set this dashboard's tabs * * @param Tabs $tabs * * @return $this */ public function setTabs(Tabs $tabs) { $this->tabs = $tabs; return $this; } /** * Return the tab object used to navigate through this dashboard * * @return Tabs */ public function getTabs() { $activeHome = $this->getActiveHome(); if ($activeHome && $activeHome->getName() !== DashboardHome::DEFAULT_HOME) { $url = Url::fromPath(self::BASE_ROUTE . '/home')->getUrlWithout(['home', $this->tabParam]); $url->addParams(['home' => $activeHome->getName()]); } else { $url = Url::fromPath(self::BASE_ROUTE)->getUrlWithout($this->tabParam); } if ($this->tabs === null) { $this->tabs = new Tabs(); } $this->tabs->disableLegacyExtensions(); if (! $activeHome) { return $this->tabs; } /*** @var Pane $pane */ foreach ($activeHome->getEntries() as $pane) { if (! $this->tabs->get($pane->getName())) { $this->tabs->add( $pane->getName(), [ 'title' => sprintf( t('Show %s', 'dashboard.pane.tooltip'), $pane->getTitle() ), 'label' => $pane->getTitle(), 'url' => clone($url), 'urlParams' => [$this->tabParam => $pane->getName()] ] ); } } return $this->tabs; } /** * Activate the default pane of this dashboard and returns its name * * @return ?string */ private function setDefaultPane() { $active = $this->getActiveHome()->rewindEntries(); if ($active) { $active = $active->getName(); $this->activate($active); } return $active; } /** * @see determineActivePane() */ public function getActivePane() { return $this->determineActivePane(); } /** * Determine the active pane either by the selected tab or the current request * * @return Pane The currently active pane * @throws \Icinga\Exception\ProgrammingError * * @throws \Icinga\Exception\ConfigurationError */ public function determineActivePane() { $active = $this->getTabs()->getActiveTab(); $activeHome = $this->getActiveHome(); if (! $active) { if ($active = Url::fromRequest()->getParam($this->tabParam)) { if ($activeHome->hasEntry($active)) { $this->activate($active); } else { throw new ProgrammingError('Try to get an inexistent pane.'); } } else { $active = $this->setDefaultPane(); } } else { $active = $active->getName(); } if ($activeHome->hasEntry($active)) { return $activeHome->getEntry($active); } throw new ConfigurationError('Could not determine active pane'); } public function setWelcomeForm(Form $form) { $this->welcomeForm = $form; return $this; } protected function assemble() { $activeHome = $this->getActiveHome(); if (! $activeHome || (! $activeHome->hasEntries() && $activeHome->getName() === DashboardHome::DEFAULT_HOME)) { $this->setAttribute('class', 'dashboard-introduction'); $this->addHtml(HtmlElement::create('h1', null, t('Welcome to Icinga Web 2!'))); $this->addHtml(HtmlElement::create( 'p', null, t('You will see this screen every time you log in and haven\'t created any dashboards yet.') )); $message = t( 'At the moment this view is empty, but you can populate it with small portions of' . ' information called Dashlets.' ); $this->addHtml(HtmlElement::create('p', null, $message)); $message = t( 'Now you can either customize which dashlets to display, or use the system default dashlets.' . ' You will be always able to edit them afterwards.' ); $this->addHtml(HtmlElement::create('p', null, $message)); $this->addHtml($this->welcomeForm); //$this->addHtml($wrapper); } elseif (! $activeHome->hasEntries()) { $this->addHtml(HtmlElement::create('h1', null, t('No dashboard added to this dashboard home'))); } else { $activePane = $this->getActivePane(); if (! $activePane->hasEntries()) { $this->addHtml(HtmlElement::create('h1', null, t('No dashlet added to this pane.'))); } else { foreach ($activePane->getEntries() as $dashlet) { $this->addHtml($dashlet->getHtml()); } } } } }