diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php index f40597af1..4c0e76a0e 100644 --- a/application/controllers/DashboardsController.php +++ b/application/controllers/DashboardsController.php @@ -307,8 +307,8 @@ class DashboardsController extends CompatController break; } - /** @var DashboardHome $home */ $home = $this->dashboard->getEntry($home); + /** @var DashboardHome $home */ if (! is_array($value)) { $this->dashboard->reorderWidget($home, (int) $value); @@ -323,8 +323,8 @@ class DashboardsController extends CompatController break; } - /** @var Pane $pane */ $pane = $home->hasEntry($pane) ? $home->getEntry($pane) : $orgHome->getEntry($pane); + /** @var Pane $pane */ if (! is_array($indexOrValues)) { if ($orgHome && $orgHome->hasEntry($pane->getName()) && $home->hasEntry($pane->getName())) { Notification::error(sprintf( diff --git a/application/forms/Dashboard/BaseDashboardForm.php b/application/forms/Dashboard/BaseDashboardForm.php index 65fb2c7fc..55b402143 100644 --- a/application/forms/Dashboard/BaseDashboardForm.php +++ b/application/forms/Dashboard/BaseDashboardForm.php @@ -91,7 +91,7 @@ abstract class BaseDashboardForm extends CompatForm * * @return FormElement */ - protected function createRemoveButton(Url $action, $label) + protected function createRemoveButton(Url $action, string $label) { return $this->createElement('submitButton', 'btn_remove', [ 'class' => 'remove-button', @@ -107,7 +107,7 @@ abstract class BaseDashboardForm extends CompatForm * * @return FormElement */ - protected function registerSubmitButton($label) + protected function registerSubmitButton(string $label) { $submitElement = $this->createElement('submit', 'submit', ['class' => 'btn-primary', 'label' => $label]); $this->registerElement($submitElement); diff --git a/application/forms/Dashboard/DashletForm.php b/application/forms/Dashboard/DashletForm.php index df8c8148c..60a257c7b 100644 --- a/application/forms/Dashboard/DashletForm.php +++ b/application/forms/Dashboard/DashletForm.php @@ -1,6 +1,5 @@ getParam('home'); - /** @var Dashlet $dashlet */ + /** @var Dashlet $dashboard */ $this->populate(array( 'org_home' => $home, - 'org_pane' => $dashlet->getPane()->getName(), - 'org_dashlet' => $dashlet->getName(), - 'dashlet' => $dashlet->getTitle(), - 'url' => $dashlet->getUrl()->getRelativeUrl() + 'org_pane' => $dashboard->getPane()->getName(), + 'org_dashlet' => $dashboard->getName(), + 'dashlet' => $dashboard->getTitle(), + 'url' => $dashboard->getUrl()->getRelativeUrl() )); } } diff --git a/application/forms/Dashboard/NewHomePaneForm.php b/application/forms/Dashboard/NewHomePaneForm.php index 99b38a5dc..f686c61d3 100644 --- a/application/forms/Dashboard/NewHomePaneForm.php +++ b/application/forms/Dashboard/NewHomePaneForm.php @@ -1,5 +1,7 @@ dashboard = $dashboard; - $this->setRedirectUrl(Url::fromPath(Dashboard::BASE_ROUTE)); + $this->setRedirectUrl((string) Url::fromPath(Dashboard::BASE_ROUTE)); } public function hasBeenSubmitted() diff --git a/library/Icinga/Application/Modules/DashboardContainer.php b/library/Icinga/Application/Modules/DashboardContainer.php index f3c8bc671..379e07c5a 100644 --- a/library/Icinga/Application/Modules/DashboardContainer.php +++ b/library/Icinga/Application/Modules/DashboardContainer.php @@ -13,7 +13,7 @@ class DashboardContainer extends NavigationItemContainer * * @var array */ - protected $dashlets; + protected $dashlets = []; /** * Set this dashboard's dashlets @@ -35,7 +35,11 @@ class DashboardContainer extends NavigationItemContainer */ public function getDashlets() { - return $this->dashlets ?: array(); + uasort($this->dashlets, function (array $x, array $y) { + return $x['priority'] - $y['priority']; + }); + + return $this->dashlets; } /** diff --git a/library/Icinga/Application/Modules/DashletContainer.php b/library/Icinga/Application/Modules/DashletContainer.php index d841fe17d..17771f059 100644 --- a/library/Icinga/Application/Modules/DashletContainer.php +++ b/library/Icinga/Application/Modules/DashletContainer.php @@ -43,7 +43,7 @@ class DashletContainer extends NavigationItemContainer } /** - * Set url if this dashlet item + * Set url of this dashlet item * * @param Url|string $url * diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 9ce4795b8..f243e47c0 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -217,7 +217,7 @@ class Module /** * A set of Pane elements * - * @var DashboardContainer + * @var DashboardContainer[] */ protected $paneItems = []; @@ -317,49 +317,12 @@ class Module /** * Return this module's dashboard * - * @return Navigation + * @return DashboardContainer[] */ public function getDashboard() { $this->launchConfigScript(); - return $this->createDashboard($this->paneItems); - } - - /** - * Create and return a new navigation for the given dashboard panes - * - * @param DashboardContainer[] $panes - * - * @return Navigation - */ - public function createDashboard(array $panes) - { - $navigation = new Navigation(); - foreach ($panes as $pane) { - /** @var DashboardContainer $pane */ - $dashlets = []; - foreach ($pane->getDashlets() as $dashletName => $dashletConfig) { - $dashlets[$dashletName] = [ - 'label' => $this->translate($dashletName), - 'url' => $dashletConfig['url'], - 'priority' => $dashletConfig['priority'] - ]; - } - - $navigation->addItem( - $pane->getName(), - array_merge( - $pane->getProperties(), - array( - 'label' => $this->translate($pane->getName()), - 'type' => 'dashboard-pane', - 'children' => $dashlets - ) - ) - ); - } - - return $navigation; + return $this->paneItems; } /** @@ -401,7 +364,7 @@ class Module * * @return DashletContainer */ - protected function provideDashlet($name, $url, array $properties = []) + protected function provideDashlet(string $name, $url, array $properties = []) { if (array_key_exists($name, $this->dashletItems)) { $this->dashletItems[$name]->setProperties($properties); diff --git a/library/Icinga/Common/DataExtractor.php b/library/Icinga/Common/DataExtractor.php index 6c8912d2f..30b2a5ac0 100644 --- a/library/Icinga/Common/DataExtractor.php +++ b/library/Icinga/Common/DataExtractor.php @@ -11,7 +11,7 @@ trait DataExtractor * * @return $this */ - public function fromArray(array $data) + public function fromArray(array $data): self { foreach ($data as $name => $value) { $func = 'set' . ucfirst($name); @@ -32,7 +32,7 @@ trait DataExtractor * * @return array */ - public function toArray($stringify = true) + public function toArray(bool $stringify = true): array { return []; } diff --git a/library/Icinga/Web/Dashboard/Common/BaseDashboard.php b/library/Icinga/Web/Dashboard/Common/BaseDashboard.php index abe3b9fe2..60d03954f 100644 --- a/library/Icinga/Web/Dashboard/Common/BaseDashboard.php +++ b/library/Icinga/Web/Dashboard/Common/BaseDashboard.php @@ -63,7 +63,7 @@ abstract class BaseDashboard implements DashboardEntry * @param string $name * @param array $properties */ - public function __construct($name, array $properties = []) + public function __construct(string $name, array $properties = []) { $this->name = $name; $this->title = $name; @@ -80,7 +80,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return $this */ - public function setUuid($uuid) + public function setUuid($uuid): self { $this->uuid = $uuid; @@ -90,7 +90,7 @@ abstract class BaseDashboard implements DashboardEntry /** * Get this widget's unique identifier * - * @return string + * @return string|int */ public function getUuid() { @@ -101,10 +101,14 @@ abstract class BaseDashboard implements DashboardEntry * Set the name of this widget * * @param string $name + * + * @return $this */ - public function setName($name) + public function setName(string $name): self { $this->name = $name; + + return $this; } /** @@ -112,7 +116,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -124,7 +128,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return $this */ - public function setTitle($title) + public function setTitle(string $title): self { $this->title = $title; @@ -136,7 +140,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return string */ - public function getTitle() + public function getTitle(): string { return $this->title !== null ? $this->title : $this->getName(); } @@ -148,7 +152,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return $this */ - public function setOwner($owner) + public function setOwner(string $owner): self { $this->owner = $owner; @@ -158,7 +162,7 @@ abstract class BaseDashboard implements DashboardEntry /** * Get owner of this widget * - * @return string + * @return ?string */ public function getOwner() { @@ -168,7 +172,7 @@ abstract class BaseDashboard implements DashboardEntry /** * Get the widget's description * - * @return string + * @return ?string */ public function getDescription() { @@ -182,7 +186,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return $this */ - public function setDescription($description) + public function setDescription(string $description = null): self { $this->description = $description; @@ -196,7 +200,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return $this */ - public function setPriority(int $order) + public function setPriority(int $order): self { $this->order = $order; @@ -208,7 +212,7 @@ abstract class BaseDashboard implements DashboardEntry * * @return int */ - public function getPriority() + public function getPriority(): int { return $this->order; } @@ -217,11 +221,11 @@ abstract class BaseDashboard implements DashboardEntry { } - public function getEntry($name) + public function getEntry(string $name) { } - public function hasEntry($name) + public function hasEntry(string $name) { } @@ -237,7 +241,7 @@ abstract class BaseDashboard implements DashboardEntry { } - public function createEntry($name, $url = null) + public function createEntry(string $name, $url = null) { } @@ -253,11 +257,11 @@ abstract class BaseDashboard implements DashboardEntry { } - public function manageEntry($entry, BaseDashboard $origin = null, $manageRecursive = false) + public function manageEntry($entry, BaseDashboard $origin = null, bool $manageRecursive = false) { } - public function loadDashboardEntries($name = '') + public function loadDashboardEntries(string $name = '') { } diff --git a/library/Icinga/Web/Dashboard/Common/DashboardControls.php b/library/Icinga/Web/Dashboard/Common/DashboardControls.php index 86f0f0620..8081f15df 100644 --- a/library/Icinga/Web/Dashboard/Common/DashboardControls.php +++ b/library/Icinga/Web/Dashboard/Common/DashboardControls.php @@ -22,7 +22,7 @@ trait DashboardControls return ! empty($this->dashboards); } - public function getEntry($name) + public function getEntry(string $name) { if (! $this->hasEntry($name)) { throw new ProgrammingError('Trying to retrieve invalid dashboard entry "%s"', $name); @@ -31,7 +31,7 @@ trait DashboardControls return $this->dashboards[$name]; } - public function hasEntry($name) + public function hasEntry(string $name) { return array_key_exists($name, $this->dashboards); } @@ -85,7 +85,7 @@ trait DashboardControls return $this; } - public function createEntry($name, $url = null) + public function createEntry(string $name, $url = null) { } @@ -94,7 +94,7 @@ trait DashboardControls return reset($this->dashboards); } - public function reorderWidget(BaseDashboard $dashboard, $position, Sortable $origin = null) + public function reorderWidget(BaseDashboard $dashboard, int $position, Sortable $origin = null) { if ($origin && ! $origin instanceof $this) { throw new \InvalidArgumentException(sprintf( diff --git a/library/Icinga/Web/Dashboard/Common/DashboardEntry.php b/library/Icinga/Web/Dashboard/Common/DashboardEntry.php index 92b891d9f..9b59dfe4e 100644 --- a/library/Icinga/Web/Dashboard/Common/DashboardEntry.php +++ b/library/Icinga/Web/Dashboard/Common/DashboardEntry.php @@ -25,7 +25,7 @@ interface DashboardEntry * * @return BaseDashboard */ - public function getEntry($name); + public function getEntry(string $name); /** * Get whether the given dashboard entry exists @@ -34,7 +34,7 @@ interface DashboardEntry * * @return bool */ - public function hasEntry($name); + public function hasEntry(string $name); /** * Get all dashboard entries of this widget @@ -69,7 +69,7 @@ interface DashboardEntry * * @return $this */ - public function createEntry($name, $url = null); + public function createEntry(string $name, $url = null); /** * Get an array with entry name=>title format @@ -112,7 +112,7 @@ interface DashboardEntry * * @return $this */ - public function manageEntry($entry, BaseDashboard $origin = null, $manageRecursive = false); + public function manageEntry($entry, BaseDashboard $origin = null, bool $manageRecursive = false); /** * Load all the assigned entries to this widget @@ -121,7 +121,7 @@ interface DashboardEntry * * @return $this */ - public function loadDashboardEntries($name = ''); + public function loadDashboardEntries(string $name = ''); /** * Reset the current position of the internal dashboard entries pointer diff --git a/library/Icinga/Web/Dashboard/Common/DashboardManager.php b/library/Icinga/Web/Dashboard/Common/DashboardManager.php index ea4dab8bd..289dede38 100644 --- a/library/Icinga/Web/Dashboard/Common/DashboardManager.php +++ b/library/Icinga/Web/Dashboard/Common/DashboardManager.php @@ -58,7 +58,7 @@ trait DashboardManager * * @return Connection */ - public static function getConn() + public static function getConn(): Connection { if (self::$conn === null) { self::$conn = (new self())->getDb(); @@ -74,12 +74,12 @@ trait DashboardManager * * @return string */ - public static function getSHA1($name) + public static function getSHA1(string $name): string { return sha1($name, true); } - public function loadDashboardEntries($name = '') + public function loadDashboardEntries(string $name = '') { if ($name && $this->hasEntry($name)) { $home = $this->getEntry($name); @@ -113,7 +113,7 @@ trait DashboardManager * * @return $this */ - public function activateHome(DashboardHome $home) + public function activateHome(DashboardHome $home): self { $activeHome = $this->getActiveHome(); if ($activeHome && $activeHome->getName() !== $home->getName()) { @@ -166,12 +166,12 @@ trait DashboardManager /** @var DashboardHome $home */ foreach ($homes as $home) { if (! $this->hasEntry($home->getName())) { + // Highest priority is 0, so count($entries) are always lowest prio + 1 $priority = $home->getName() === DashboardHome::DEFAULT_HOME ? 0 : count($this->getEntries()); $conn->insert(DashboardHome::TABLE, [ 'name' => $home->getName(), 'label' => $home->getTitle(), 'username' => self::getUser()->getUsername(), - // highest priority is 0, so count($entries) are always lowest prio + 1 'priority' => $priority, 'type' => $home->getType() !== Dashboard::SYSTEM ? $home->getType() : Dashboard::PRIVATE_DS ]); @@ -191,9 +191,9 @@ trait DashboardManager /** * Get and|or init the default dashboard home * - * @return BaseDashboard + * @return DashboardHome */ - public function initGetDefaultHome() + public function initGetDefaultHome(): DashboardHome { if ($this->hasEntry(DashboardHome::DEFAULT_HOME)) { return $this->getEntry(DashboardHome::DEFAULT_HOME); @@ -213,7 +213,7 @@ trait DashboardManager * * @return $this */ - public function setUser(User $user) + public function setUser(User $user): self { self::$user = $user; @@ -225,7 +225,7 @@ trait DashboardManager * * @return User */ - public static function getUser() + public static function getUser(): User { if (self::$user === null) { self::$user = Auth::getInstance()->getUser(); @@ -240,7 +240,7 @@ trait DashboardManager * * @return Pane[] */ - public static function getSystemDefaults() + public static function getSystemDefaults(): array { return self::$defaultPanes; } @@ -251,26 +251,29 @@ trait DashboardManager * * @return void */ - public static function deployModuleDashlets() + public static function deployModuleDashlets(): void { - $moduleManager = Icinga::app()->getModuleManager(); - foreach ($moduleManager->getLoadedModules() as $module) { - /** @var DashboardPane $dashboardPane */ - foreach ($module->getDashboard() as $dashboardPane) { - $pane = new Pane($dashboardPane->getName()); - $pane->setTitle($dashboardPane->getLabel()); - $pane->fromArray($dashboardPane->getAttributes()); + $mg = Icinga::app()->getModuleManager(); + foreach ($mg->getLoadedModules() as $module) { + foreach ($module->getDashboard() as $dashboard) { + $pane = new Pane($dashboard->getName()); + $pane->fromArray($dashboard->getProperties()); $priority = 0; - foreach ($dashboardPane->getIterator()->getItems() as $dashletItem) { - $uuid = self::getSHA1($module->getName() . $pane->getName() . $dashletItem->getName()); - $dashlet = new Dashlet($dashletItem->getName(), $dashletItem->getUrl(), $pane); - $dashlet->fromArray($dashletItem->getAttributes()); + foreach ($dashboard->getDashlets() as $name => $configPart) { + $uuid = self::getSHA1($module->getName() . $pane->getName() . $name); + $dashlet = new Dashlet($name, $configPart['url'], $pane); + $dashlet->fromArray($configPart); $dashlet ->setUuid($uuid) - ->setModule($module->getName()) ->setModuleDashlet(true) - ->setPriority($priority++); + ->setPriority($priority++) + ->setModule($module->getName()); + + // As we don't have a setter for labels, this might be ignored by the data extractor + if (isset($configPart['label'])) { + $dashlet->setTitle($configPart['label']); + } self::updateOrInsertModuleDashlet($dashlet); $pane->addEntry($dashlet); @@ -305,7 +308,7 @@ trait DashboardManager * * @return bool */ - public static function moduleDashletExist(Dashlet $dashlet) + public static function moduleDashletExist(Dashlet $dashlet): bool { $query = Model\ModuleDashlet::on(self::getConn())->filter(Filter::equal('id', $dashlet->getUuid())); $query->getSelectBase()->columns(new Expression('1')); @@ -317,11 +320,10 @@ trait DashboardManager * Insert or update the given module dashlet * * @param Dashlet $dashlet - * @param string $module * * @return void */ - public static function updateOrInsertModuleDashlet(Dashlet $dashlet) + public static function updateOrInsertModuleDashlet(Dashlet $dashlet): void { if (! $dashlet->isModuleDashlet()) { return; @@ -351,9 +353,11 @@ trait DashboardManager /** * Get module dashlets from the database * + * @param Query $query + * * @return array */ - public static function getModuleDashlets(Query $query) + public static function getModuleDashlets(Query $query): array { $dashlets = []; foreach ($query as $moduleDashlet) { diff --git a/library/Icinga/Web/Dashboard/Common/ItemListControl.php b/library/Icinga/Web/Dashboard/Common/ItemListControl.php index 874dd75a6..9b9b42783 100644 --- a/library/Icinga/Web/Dashboard/Common/ItemListControl.php +++ b/library/Icinga/Web/Dashboard/Common/ItemListControl.php @@ -19,40 +19,40 @@ abstract class ItemListControl extends BaseHtmlElement * * @return string */ - abstract protected function getHtmlId(); + abstract protected function getHtmlId(): string; /** * Get a class name for the collapsible control * * @return string */ - abstract protected function getCollapsibleControlClass(); + abstract protected function getCollapsibleControlClass(): string; /** * Create an action link to be added at the end of the list * - * @return HtmlElement + * @return BaseHtmlElement */ - abstract protected function createActionLink(); + abstract protected function createActionLink(): BaseHtmlElement; /** * Create the appropriate item list of this control * - * @return HtmlElement + * @return BaseHtmlElement */ - abstract protected function createItemList(); + abstract protected function createItemList(): BaseHtmlElement; /** * Assemble a header element for this item list * * @param Url $url - * @param string $header + * @param string $title * * @return void */ - protected function assembleHeader(Url $url, $header) + protected function assembleHeader(Url $url, string $title) { - $header = HtmlElement::create('h1', ['class' => 'collapsible-header'], $header); + $header = HtmlElement::create('h1', ['class' => 'collapsible-header'], $title); $header->addHtml(new Link(t('Edit'), $url, [ 'data-icinga-modal' => true, 'data-no-icinga-ajax' => true diff --git a/library/Icinga/Web/Dashboard/Common/ModuleDashlet.php b/library/Icinga/Web/Dashboard/Common/ModuleDashlet.php index c1299d439..3eed50201 100644 --- a/library/Icinga/Web/Dashboard/Common/ModuleDashlet.php +++ b/library/Icinga/Web/Dashboard/Common/ModuleDashlet.php @@ -23,7 +23,7 @@ trait ModuleDashlet /** * Get the name of the module which provides this dashlet * - * @return string + * @return ?string */ public function getModule() { @@ -37,7 +37,7 @@ trait ModuleDashlet * * @return $this */ - public function setModule($module) + public function setModule(string $module): self { $this->module = $module; @@ -49,7 +49,7 @@ trait ModuleDashlet * * @return bool */ - public function isModuleDashlet() + public function isModuleDashlet(): bool { return $this->moduleDashlet; } @@ -61,7 +61,7 @@ trait ModuleDashlet * * @return $this */ - public function setModuleDashlet(bool $moduleDashlet) + public function setModuleDashlet(bool $moduleDashlet): self { $this->moduleDashlet = $moduleDashlet; diff --git a/library/Icinga/Web/Dashboard/Common/Sortable.php b/library/Icinga/Web/Dashboard/Common/Sortable.php index 6ea9c693f..468d27768 100644 --- a/library/Icinga/Web/Dashboard/Common/Sortable.php +++ b/library/Icinga/Web/Dashboard/Common/Sortable.php @@ -14,10 +14,10 @@ interface Sortable * Insert the dashboard entry at the given position within this dashboard entries * * @param BaseDashboard $dashboard - * @param $position + * @param int $position * @param Sortable|null $origin * * @return $this */ - public function reorderWidget(BaseDashboard $dashboard, $position, Sortable $origin = null); + public function reorderWidget(BaseDashboard $dashboard, int $position, Sortable $origin = null); } diff --git a/library/Icinga/Web/Dashboard/Dashboard.php b/library/Icinga/Web/Dashboard/Dashboard.php index 94c8057da..fe4fd6bff 100644 --- a/library/Icinga/Web/Dashboard/Dashboard.php +++ b/library/Icinga/Web/Dashboard/Dashboard.php @@ -97,7 +97,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry * @param string $name The tab name to activate * */ - public function activate($name) + public function activate(string $name) { $this->getTabs()->activate($name); } diff --git a/library/Icinga/Web/Dashboard/DashboardHome.php b/library/Icinga/Web/Dashboard/DashboardHome.php index 4080f4279..eb5153a1a 100644 --- a/library/Icinga/Web/Dashboard/DashboardHome.php +++ b/library/Icinga/Web/Dashboard/DashboardHome.php @@ -73,7 +73,7 @@ class DashboardHome extends BaseDashboard implements Sortable * * @return $this */ - public function setActive($active = true) + public function setActive(bool $active = true) { $this->active = $active; @@ -97,7 +97,7 @@ class DashboardHome extends BaseDashboard implements Sortable * * @return $this */ - public function setType($type) + public function setType(string $type) { $this->type = $type; @@ -132,7 +132,7 @@ class DashboardHome extends BaseDashboard implements Sortable return $this; } - public function loadDashboardEntries($name = '') + public function loadDashboardEntries(string $name = '') { if (! $this->getActive()) { return $this; @@ -160,7 +160,7 @@ class DashboardHome extends BaseDashboard implements Sortable return $this; } - public function createEntry($name, $url = null) + public function createEntry(string $name, $url = null) { $entry = new Pane($name); $entry->setHome($this); @@ -170,7 +170,7 @@ class DashboardHome extends BaseDashboard implements Sortable return $this; } - public function manageEntry($entry, BaseDashboard $origin = null, $manageRecursive = false) + public function manageEntry($entry, BaseDashboard $origin = null, bool $manageRecursive = false) { $user = Dashboard::getUser(); $conn = Dashboard::getConn(); @@ -236,7 +236,7 @@ class DashboardHome extends BaseDashboard implements Sortable } } - public function toArray($stringify = true) + public function toArray(bool $stringify = true): array { return [ 'id' => $this->getUuid(), diff --git a/library/Icinga/Web/Dashboard/Dashlet.php b/library/Icinga/Web/Dashboard/Dashlet.php index 0b086e991..89da51a08 100644 --- a/library/Icinga/Web/Dashboard/Dashlet.php +++ b/library/Icinga/Web/Dashboard/Dashlet.php @@ -9,6 +9,7 @@ use Icinga\Web\Dashboard\Common\BaseDashboard; use Icinga\Web\Dashboard\Common\ModuleDashlet; use Icinga\Web\Request; use Icinga\Web\Url; +use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; use ipl\Web\Widget\Link; @@ -52,7 +53,7 @@ class Dashlet extends BaseDashboard * @param Url|string $url The url this dashlet uses for displaying information * @param Pane|null $pane The pane this Dashlet will be added to */ - public function __construct($name, $url, Pane $pane = null) + public function __construct(string $name, $url, Pane $pane = null) { parent::__construct($name); @@ -63,7 +64,7 @@ class Dashlet extends BaseDashboard /** * Retrieve the dashlets url * - * @return Url|null + * @return ?Url */ public function getUrl() { @@ -85,7 +86,7 @@ class Dashlet extends BaseDashboard * * @return $this */ - public function setUrl($url) + public function setUrl($url): self { $this->url = $url; @@ -99,7 +100,7 @@ class Dashlet extends BaseDashboard * * @return $this */ - public function setProgressLabel($label) + public function setProgressLabel(string $label): self { $this->progressLabel = $label; @@ -111,7 +112,7 @@ class Dashlet extends BaseDashboard * * @return string */ - public function getProgressLabel() + public function getProgressLabel(): string { if ($this->progressLabel === null) { return $this->progressLabel = t('Loading'); @@ -127,7 +128,7 @@ class Dashlet extends BaseDashboard * * @return Dashlet */ - public function setPane(Pane $pane) + public function setPane(Pane $pane): self { $this->pane = $pane; @@ -137,7 +138,7 @@ class Dashlet extends BaseDashboard /** * Get the pane of this dashlet * - * @return Pane + * @return ?Pane */ public function getPane() { @@ -147,9 +148,9 @@ class Dashlet extends BaseDashboard /** * Generate a html widget for this dashlet * - * @return HtmlElement + * @return BaseHtmlElement */ - public function getHtml() + public function getHtml(): BaseHtmlElement { $dashletHtml = HtmlElement::create('div', ['class' => 'container']); if (! $this->getUrl()) { @@ -191,7 +192,7 @@ class Dashlet extends BaseDashboard return $dashletHtml; } - public function toArray($stringify = true) + public function toArray(bool $stringify = true): array { $pane = $this->getPane(); return [ diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php index c9c0b35dc..ab4aa97ba 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php @@ -7,6 +7,7 @@ namespace Icinga\Web\Dashboard\ItemList; use Icinga\Web\Dashboard\Common\ItemListControl; use Icinga\Web\Dashboard\Dashboard; use Icinga\Web\Dashboard\DashboardHome; +use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; use ipl\Web\Url; use ipl\Web\Widget\ActionLink; @@ -30,17 +31,17 @@ class DashboardHomeList extends ItemListControl }); } - protected function getHtmlId() + protected function getHtmlId(): string { return $this->home->getUuid(); } - protected function getCollapsibleControlClass() + protected function getCollapsibleControlClass(): string { return 'dashboard-list-info'; } - protected function createItemList() + protected function createItemList(): BaseHtmlElement { $url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-home') ->setParams(['home' => $this->home->getName()]); @@ -58,7 +59,7 @@ class DashboardHomeList extends ItemListControl return $list; } - protected function createActionLink() + protected function createActionLink(): BaseHtmlElement { $url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-pane'); $url->setParams(['home' => $this->home->getName()]); diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php index ce8324a71..f264fbe3c 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php @@ -7,6 +7,7 @@ namespace Icinga\Web\Dashboard\ItemList; use Icinga\Web\Dashboard\Common\ItemListControl; use Icinga\Web\Dashboard\Dashboard; use Icinga\Web\Dashboard\Pane; +use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; use ipl\Web\Url; use ipl\Web\Widget\ActionLink; @@ -28,17 +29,17 @@ class DashboardList extends ItemListControl }); } - protected function getHtmlId() + protected function getHtmlId(): string { return bin2hex($this->pane->getUuid()); } - protected function getCollapsibleControlClass() + protected function getCollapsibleControlClass(): string { return 'dashlets-list-info'; } - protected function createItemList() + protected function createItemList(): BaseHtmlElement { $pane = $this->pane; $this->getAttributes()->set('data-toggle-element', '.dashlets-list-info'); @@ -61,7 +62,7 @@ class DashboardList extends ItemListControl return $list; } - protected function createActionLink() + protected function createActionLink(): BaseHtmlElement { $url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-dashlet'); $url->setParams([ diff --git a/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php b/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php index d83bc3750..0a71f6964 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashletListItem.php @@ -46,14 +46,14 @@ class DashletListItem extends BaseHtmlElement * * @return $this */ - protected function setDetailUrl(bool $value) + protected function setDetailUrl(bool $value): self { $this->renderEditButton = $value; return $this; } - protected function assembleTitle() + protected function assembleHeader(): HtmlElement { $title = HtmlElement::create('h1', ['class' => 'dashlet-header']); @@ -98,12 +98,10 @@ class DashletListItem extends BaseHtmlElement if (! $this->dashlet) { $section->add(t('Create a dashlet with custom url and filter')); } else { - $section->getAttributes()->set( - 'title', - $this->dashlet->getDescription() ?: t('There is no provided description.') - ); + $description = $this->dashlet->getDescription() ?: t('There is no provided description.'); + $section->getAttributes()->set('title', $description); - $section->add($this->dashlet->getDescription() ?: t('There is no provided dashlet description.')); + $section->add($description); } return $section; @@ -111,7 +109,7 @@ class DashletListItem extends BaseHtmlElement protected function assemble() { - $this->addHtml($this->assembleTitle()); + $this->addHtml($this->assembleHeader()); $this->addHtml($this->assembleSummary()); } } diff --git a/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php b/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php index af38a3b67..97636fa79 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashletListMultiSelect.php @@ -19,14 +19,14 @@ class DashletListMultiSelect extends DashletListItem * * @return $this */ - public function setCheckBox(FormElement $checkbox) + public function setCheckBox(FormElement $checkbox): self { $this->checkbox = $checkbox; return $this; } - protected function createLabel() + protected function createLabel(): HtmlElement { $label = HtmlElement::create('label'); $label->addHtml($this->checkbox); diff --git a/library/Icinga/Web/Dashboard/Pane.php b/library/Icinga/Web/Dashboard/Pane.php index cb8d2ebdb..b74e1ed7d 100644 --- a/library/Icinga/Web/Dashboard/Pane.php +++ b/library/Icinga/Web/Dashboard/Pane.php @@ -50,59 +50,21 @@ class Pane extends BaseDashboard implements Sortable * * @return $this */ - public function setHome(DashboardHome $home) + public function setHome(DashboardHome $home): self { $this->home = $home; return $this; } - public function createEntry($name, $url = null) + public function createEntry(string $name, $url = null) { - $dashlet = new Dashlet($name, $url, $this); - $this->addDashlet($dashlet); - - return $this; - } - - /** - * Add a dashlet to this pane, optionally creating it if $dashlet is a string - * - * @param string|Dashlet $dashlet - * @param ?string $url - * - * @return $this - * @throws \Icinga\Exception\ConfigurationError - */ - public function addDashlet($dashlet, $url = null) - { - if ($dashlet instanceof Dashlet) { - $this->addEntry($dashlet); - } elseif (is_string($dashlet) && $url !== null) { - $this->createEntry($dashlet, $url); - } else { - throw new ConfigurationError('Invalid dashlet added: %s', $dashlet); + if ($url === null) { + throw new ConfigurationError('Can\'t create a dashlet "%s" without a valid url', $name); } - return $this; - } - - /** - * Add a dashlet to the current pane - * - * @param string $name - * @param Url|string $url - * - * @return $this - * @see addDashlet() - */ - public function add($name, $url, $priority = 0, $description = null) - { - $this->createEntry($name, $url); - $dashlet = $this->getEntry($name); - $dashlet - ->setDescription($description) - ->setPriority($priority); + $dashlet = new Dashlet($name, $url, $this); + $this->addEntry($dashlet); return $this; } @@ -126,7 +88,7 @@ class Pane extends BaseDashboard implements Sortable return $this; } - public function loadDashboardEntries($name = '') + public function loadDashboardEntries(string $name = '') { $dashlets = Model\Dashlet::on(Dashboard::getConn()) ->utilize(self::TABLE) @@ -144,13 +106,13 @@ class Pane extends BaseDashboard implements Sortable 'description' => $dashlet->icingaweb_module_dashlet->description ]); - $this->addDashlet($newDashlet); + $this->addEntry($newDashlet); } return $this; } - public function manageEntry($entry, BaseDashboard $origin = null, $manageRecursive = false) + public function manageEntry($entry, BaseDashboard $origin = null, bool $manageRecursive = false) { if ($origin && ! $origin instanceof Pane) { throw new \InvalidArgumentException(sprintf( @@ -171,7 +133,7 @@ class Pane extends BaseDashboard implements Sortable $conn = Dashboard::getConn(); $dashlets = is_array($entry) ? $entry : [$entry]; - // highest priority is 0, so count($entries) are all always lowest prio + 1 + // Highest priority is 0, so count($entries) are always lowest prio + 1 $order = count($this->getEntries()); foreach ($dashlets as $dashlet) { if (is_array($dashlet)) { @@ -240,7 +202,7 @@ class Pane extends BaseDashboard implements Sortable return $this; } - public function toArray($stringify = true) + public function toArray(bool $stringify = true): array { $home = $this->getHome(); return [ diff --git a/library/Icinga/Web/Dashboard/Setup/SetupNewDashboard.php b/library/Icinga/Web/Dashboard/Setup/SetupNewDashboard.php index c0b3046bf..0b7466801 100644 --- a/library/Icinga/Web/Dashboard/Setup/SetupNewDashboard.php +++ b/library/Icinga/Web/Dashboard/Setup/SetupNewDashboard.php @@ -36,7 +36,7 @@ class SetupNewDashboard extends BaseDashboardForm * * @return $this */ - public function initDashlets(array $dashlets) + public function initDashlets(array $dashlets): self { $this->dashlets = $dashlets; @@ -236,9 +236,9 @@ class SetupNewDashboard extends BaseDashboardForm * Dump all module dashlets which are not selected by the user * from the member variable * - * @return $this + * @return void */ - private function dumpArbitaryDashlets() + private function dumpArbitaryDashlets(): void { $choosenDashlets = []; foreach ($this->dashlets as $module => $dashlets) { @@ -252,8 +252,6 @@ class SetupNewDashboard extends BaseDashboardForm } $this->dashlets = $choosenDashlets; - - return $this; } /** @@ -261,7 +259,7 @@ class SetupNewDashboard extends BaseDashboardForm * * @return ValidHtml */ - private function createFormListControl() + private function createFormListControl(): ValidHtml { return HtmlElement::create('div', [ 'class' => ['control-group', 'form-list-control', 'collapsible'], diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php b/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php index b9ed59572..5d0f61874 100644 --- a/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php +++ b/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php @@ -1,5 +1,5 @@