diff --git a/application/forms/Dashboard/DashletForm.php b/application/forms/Dashboard/DashletForm.php index bbcd2503d5..544a4125c5 100644 --- a/application/forms/Dashboard/DashletForm.php +++ b/application/forms/Dashboard/DashletForm.php @@ -31,7 +31,8 @@ public function load(BaseDashboard $dashboard) 'org_pane' => $dashboard->getPane()->getName(), 'org_dashlet' => $dashboard->getName(), 'dashlet' => $dashboard->getTitle(), - 'url' => $dashboard->getUrl()->getRelativeUrl() + 'url' => $dashboard->getUrl()->getRelativeUrl(), + 'description' => $dashboard->getDescription(), ]); } @@ -184,6 +185,7 @@ protected function onSuccess() $customDashlet = null; if (($dashlet = $this->getPopulatedValue('dashlet')) && ($url = $this->getPopulatedValue('url'))) { $customDashlet = new Dashlet($dashlet, $url, $currentPane); + $customDashlet->setDescription($this->getPopulatedValue('description')); if ($currentPane->hasEntry($customDashlet->getName()) || $this->customDashletAlreadyExists) { if ($this->customDashletAlreadyExists) { @@ -265,11 +267,14 @@ protected function onSuccess() $orgHome->setEntries([]); } + /** @var Dashlet $currentDashlet */ $currentDashlet = clone $orgDashlet; $currentDashlet ->setPane($currentPane) ->setUrl($this->getValue('url')) - ->setTitle($this->getValue('dashlet')); + ->setTitle($this->getValue('dashlet')) + ->setDescription($this->getValue('description')); + if ($orgPane->getName() !== $currentPane->getName() && $currentPane->hasEntry($currentDashlet->getName())) { diff --git a/application/forms/Dashboard/SetupNewDashboardForm.php b/application/forms/Dashboard/SetupNewDashboardForm.php index f980be5d54..f5d4652ee0 100644 --- a/application/forms/Dashboard/SetupNewDashboardForm.php +++ b/application/forms/Dashboard/SetupNewDashboardForm.php @@ -43,7 +43,6 @@ protected function init() /** * Dump all module dashlets which are not selected by the user - * from the member variable * * @param bool $strict Whether to match populated of the dashlet against a 'y' * @@ -59,12 +58,14 @@ protected function dumpArbitaryDashlets(bool $strict = true): void if ($this->getPopulatedValue($element) === 'y' || (! $strict && $this->getPopulatedValue($element))) { $title = $this->getPopulatedValue($element); $url = $this->getPopulatedValue($element . '_url'); + $description = $this->getPopulatedValue($element . '_description'); if (! $strict && $title && $url) { $dashlet ->setUrl($url) ->setName($title . '(' . $module . ')') - ->setTitle($title); + ->setTitle($title) + ->setDescription($description); } $chosenDashlets[$module][$dashlet->getName()] = $dashlet; @@ -187,6 +188,12 @@ protected function assembleNexPageDashletPart() 'Enter url to be loaded in the dashlet. You can paste the full URL, including filters' ) ]); + + $this->addElement('textarea', $elementId . '_description', [ + 'label' => t('Description'), + 'value' => $dashlet->getDescription(), + 'description' => t('Enter description for the dashlet') + ]); } } } @@ -210,6 +217,12 @@ protected function assembleDashletElements() 'Enter url to be loaded in the dashlet. You can paste the full URL, including filters.' ), ]); + + $this->addElement('textarea', 'description', [ + 'label' => t('Description'), + 'placeholder' => t('Enter dashlet description'), + 'description' => t('Enter description for the dashlet'), + ]); } protected function assemble() diff --git a/etc/schema/mysql-upgrades/2.11.0.sql b/etc/schema/mysql-upgrades/2.11.0.sql index 71e0776fdd..6c27107c86 100644 --- a/etc/schema/mysql-upgrades/2.11.0.sql +++ b/etc/schema/mysql-upgrades/2.11.0.sql @@ -57,6 +57,7 @@ CREATE TABLE `icingaweb_dashlet` ( `url` varchar(2048) NOT NULL COLLATE utf8mb4_bin, `priority` tinyint NOT NULL, `disabled` enum ('n', 'y') DEFAULT 'n', + `description` text DEFAULT NULL COLLATE utf8mb4_unicode_ci, PRIMARY KEY (`id`), KEY `fk_dashlet_dashboard` (`dashboard_id`), CONSTRAINT `fk_dashlet_dashboard` FOREIGN KEY (`dashboard_id`) diff --git a/etc/schema/mysql.schema.sql b/etc/schema/mysql.schema.sql index f6880ce9ca..820f29ec1e 100644 --- a/etc/schema/mysql.schema.sql +++ b/etc/schema/mysql.schema.sql @@ -98,6 +98,7 @@ CREATE TABLE `icingaweb_dashlet` ( `url` varchar(2048) NOT NULL COLLATE utf8mb4_bin, `priority` tinyint NOT NULL, `disabled` enum ('n', 'y') DEFAULT 'n', + `description` text DEFAULT NULL COLLATE utf8mb4_unicode_ci, PRIMARY KEY (`id`), KEY `fk_dashlet_dashboard` (`dashboard_id`), CONSTRAINT `fk_dashlet_dashboard` FOREIGN KEY (`dashboard_id`) diff --git a/etc/schema/pgsql-upgrades/2.11.0.sql b/etc/schema/pgsql-upgrades/2.11.0.sql index 0f0b69df9c..ca55e6c893 100644 --- a/etc/schema/pgsql-upgrades/2.11.0.sql +++ b/etc/schema/pgsql-upgrades/2.11.0.sql @@ -88,7 +88,8 @@ CREATE TABLE "icingaweb_dashlet" ( "label" character varying(254) NOT NULL, "url" character varying(2048) NOT NULL, "priority" tinyuint NOT NULL, - "disabled" boolenum DEFAULT 'n' + "disabled" boolenum DEFAULT 'n', + "description" text DEFAULT NULL ); ALTER TABLE "icingaweb_dashlet" ALTER COLUMN "id" SET STORAGE PLAIN; diff --git a/etc/schema/pgsql.schema.sql b/etc/schema/pgsql.schema.sql index 60c0a8e433..501ef7e1dc 100644 --- a/etc/schema/pgsql.schema.sql +++ b/etc/schema/pgsql.schema.sql @@ -210,7 +210,8 @@ CREATE TABLE "icingaweb_dashlet" ( "label" character varying(254) NOT NULL, "url" character varying(2048) NOT NULL, "priority" tinyuint NOT NULL, - "disabled" boolenum DEFAULT 'n' + "disabled" boolenum DEFAULT 'n', + "description" text DEFAULT NULL ); ALTER TABLE "icingaweb_dashlet" ALTER COLUMN "id" SET STORAGE PLAIN; diff --git a/library/Icinga/Application/Modules/DashletManager.php b/library/Icinga/Application/Modules/DashletManager.php index dd9cdb3c9f..77c129f993 100644 --- a/library/Icinga/Application/Modules/DashletManager.php +++ b/library/Icinga/Application/Modules/DashletManager.php @@ -160,7 +160,8 @@ public static function getDashlets(): array ->setTitle($moduleDashlet->label) ->setModuleDashlet(true) ->setModule($moduleDashlet->module) - ->setPriority($moduleDashlet->priority); + ->setPriority($moduleDashlet->priority) + ->setDescription($moduleDashlet->description); if (! self::ensureItIsNotOrphaned($dashlet)) { continue; diff --git a/library/Icinga/Model/Dashlet.php b/library/Icinga/Model/Dashlet.php index 6ce3c66542..7b62ab45de 100644 --- a/library/Icinga/Model/Dashlet.php +++ b/library/Icinga/Model/Dashlet.php @@ -31,7 +31,8 @@ public function getColumns() 'label', 'url', 'priority', - 'disabled' + 'disabled', + 'description' ]; } @@ -42,7 +43,8 @@ public function getMetaData() 'name' => t('Dashlet Name'), 'label' => t('Dashlet Title'), 'url' => t('Dashlet Url'), - 'priority' => t('Dashlet Order Priority') + 'priority' => t('Dashlet Order Priority'), + 'description' => t('Dashlet Description') ]; } diff --git a/library/Icinga/Test/fixtures.sql b/library/Icinga/Test/fixtures.sql index c9720088f4..df91d896ab 100644 --- a/library/Icinga/Test/fixtures.sql +++ b/library/Icinga/Test/fixtures.sql @@ -33,6 +33,7 @@ CREATE TABLE `icingaweb_dashlet` ( `url` VARCHAR NOT NULL, `priority` tinyint NOT NULL, `disabled` TEXT CHECK ( disabled IN ('n', 'y') ) DEFAULT 'n', + `description` text DEFAULT NULL, FOREIGN KEY (`dashboard_id`) REFERENCES `icingaweb_dashboard` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ); diff --git a/library/Icinga/Web/Dashboard/Dashlet.php b/library/Icinga/Web/Dashboard/Dashlet.php index 79e2a9693e..aae92a97af 100644 --- a/library/Icinga/Web/Dashboard/Dashlet.php +++ b/library/Icinga/Web/Dashboard/Dashlet.php @@ -252,12 +252,13 @@ public function toArray(bool $stringify = true): array { $pane = $this->getPane(); return [ - 'id' => $this->getUuid(), - 'pane' => ! $stringify ? $pane : ($pane ? $pane->getName() : null), - 'name' => $this->getName(), - 'url' => $this->getUrl()->getRelativeUrl(), - 'label' => $this->getTitle(), - 'priority' => $this->getPriority(), + 'id' => $this->getUuid(), + 'pane' => ! $stringify ? $pane : ($pane ? $pane->getName() : null), + 'name' => $this->getName(), + 'url' => $this->getUrl()->getRelativeUrl(), + 'label' => $this->getTitle(), + 'priority' => $this->getPriority(), + 'description' => $this->getDescription() ]; } } diff --git a/library/Icinga/Web/Dashboard/Pane.php b/library/Icinga/Web/Dashboard/Pane.php index 3e2365d3aa..73acfc9da3 100644 --- a/library/Icinga/Web/Dashboard/Pane.php +++ b/library/Icinga/Web/Dashboard/Pane.php @@ -116,7 +116,7 @@ public function loadDashboardEntries(string $name = null) ->setDisabled($dashlet->disabled) ->setModule($dashlet->icingaweb_module_dashlet->module ?? '') ->setModuleDashlet($dashlet->system_dashlet_id !== null) - ->setDescription($dashlet->icingaweb_module_dashlet->description); + ->setDescription($dashlet->description); $this->addEntry($newDashlet); @@ -193,7 +193,8 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool 'label' => $dashlet->getTitle(), 'url' => $url, 'priority' => $order++, - 'disabled' => DBUtils::bool2BoolEnum($dashlet->isDisabled()) + 'disabled' => DBUtils::bool2BoolEnum($dashlet->isDisabled()), + 'description' => $dashlet->getDescription() ]); if ($dashlet->isModuleDashlet()) { @@ -233,7 +234,8 @@ public function manageEntry($entryOrEntries, BaseDashboard $origin = null, bool 'label' => $dashlet->getTitle(), 'url' => $url, 'priority' => $moveDashlet ? $order++ : $dashlet->getPriority(), - 'disabled' => DBUtils::bool2BoolEnum($dashlet->isDisabled()) + 'disabled' => DBUtils::bool2BoolEnum($dashlet->isDisabled()), + 'description' => $dashlet->getDescription() ], $filterCondition); } else { // Failed to move the pane! Should have already been handled by the caller,