Skip to content

Commit e362ae6

Browse files
committed
Allow adding and editing of dashlet description.
1 parent 65fc8e1 commit e362ae6

File tree

12 files changed

+52
-18
lines changed

12 files changed

+52
-18
lines changed

application/forms/Dashboard/DashletForm.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function load(BaseDashboard $dashboard)
3131
'org_pane' => $dashboard->getPane()->getName(),
3232
'org_dashlet' => $dashboard->getName(),
3333
'dashlet' => $dashboard->getTitle(),
34-
'url' => $dashboard->getUrl()->getRelativeUrl()
34+
'url' => $dashboard->getUrl()->getRelativeUrl(),
35+
'description' => $dashboard->getDescription(),
3536
]);
3637
}
3738

@@ -184,6 +185,7 @@ protected function onSuccess()
184185
$customDashlet = null;
185186
if (($dashlet = $this->getPopulatedValue('dashlet')) && ($url = $this->getPopulatedValue('url'))) {
186187
$customDashlet = new Dashlet($dashlet, $url, $currentPane);
188+
$customDashlet->setDescription($this->getPopulatedValue('description'));
187189

188190
if ($currentPane->hasEntry($customDashlet->getName()) || $this->customDashletAlreadyExists) {
189191
if ($this->customDashletAlreadyExists) {
@@ -265,11 +267,14 @@ protected function onSuccess()
265267
$orgHome->setEntries([]);
266268
}
267269

270+
/** @var Dashlet $currentDashlet */
268271
$currentDashlet = clone $orgDashlet;
269272
$currentDashlet
270273
->setPane($currentPane)
271274
->setUrl($this->getValue('url'))
272-
->setTitle($this->getValue('dashlet'));
275+
->setTitle($this->getValue('dashlet'))
276+
->setDescription($this->getValue('description'));
277+
273278

274279
if ($orgPane->getName() !== $currentPane->getName()
275280
&& $currentPane->hasEntry($currentDashlet->getName())) {

application/forms/Dashboard/SetupNewDashboardForm.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ protected function init()
4343

4444
/**
4545
* Dump all module dashlets which are not selected by the user
46-
* from the member variable
4746
*
4847
* @param bool $strict Whether to match populated of the dashlet against a 'y'
4948
*
@@ -59,12 +58,14 @@ protected function dumpArbitaryDashlets(bool $strict = true): void
5958
if ($this->getPopulatedValue($element) === 'y' || (! $strict && $this->getPopulatedValue($element))) {
6059
$title = $this->getPopulatedValue($element);
6160
$url = $this->getPopulatedValue($element . '_url');
61+
$description = $this->getPopulatedValue($element . '_description');
6262

6363
if (! $strict && $title && $url) {
6464
$dashlet
6565
->setUrl($url)
6666
->setName($title . '(' . $module . ')')
67-
->setTitle($title);
67+
->setTitle($title)
68+
->setDescription($description);
6869
}
6970

7071
$chosenDashlets[$module][$dashlet->getName()] = $dashlet;
@@ -187,6 +188,12 @@ protected function assembleNexPageDashletPart()
187188
'Enter url to be loaded in the dashlet. You can paste the full URL, including filters'
188189
)
189190
]);
191+
192+
$this->addElement('textarea', $elementId . '_description', [
193+
'label' => t('Description'),
194+
'value' => $dashlet->getDescription(),
195+
'description' => t('Enter description for the dashlet')
196+
]);
190197
}
191198
}
192199
}
@@ -210,6 +217,12 @@ protected function assembleDashletElements()
210217
'Enter url to be loaded in the dashlet. You can paste the full URL, including filters.'
211218
),
212219
]);
220+
221+
$this->addElement('textarea', 'description', [
222+
'label' => t('Description'),
223+
'placeholder' => t('Enter dashlet description'),
224+
'description' => t('Enter description for the dashlet'),
225+
]);
213226
}
214227

215228
protected function assemble()

etc/schema/mysql-upgrades/2.11.0.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ CREATE TABLE `icingaweb_dashlet` (
5757
`url` varchar(2048) NOT NULL COLLATE utf8mb4_bin,
5858
`priority` tinyint NOT NULL,
5959
`disabled` enum ('n', 'y') DEFAULT 'n',
60+
`description` text DEFAULT NULL COLLATE utf8mb4_unicode_ci,
6061
PRIMARY KEY (`id`),
6162
KEY `fk_dashlet_dashboard` (`dashboard_id`),
6263
CONSTRAINT `fk_dashlet_dashboard` FOREIGN KEY (`dashboard_id`)

etc/schema/mysql.schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ CREATE TABLE `icingaweb_dashlet` (
9898
`url` varchar(2048) NOT NULL COLLATE utf8mb4_bin,
9999
`priority` tinyint NOT NULL,
100100
`disabled` enum ('n', 'y') DEFAULT 'n',
101+
`description` text DEFAULT NULL COLLATE utf8mb4_unicode_ci,
101102
PRIMARY KEY (`id`),
102103
KEY `fk_dashlet_dashboard` (`dashboard_id`),
103104
CONSTRAINT `fk_dashlet_dashboard` FOREIGN KEY (`dashboard_id`)

etc/schema/pgsql-upgrades/2.11.0.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ CREATE TABLE "icingaweb_dashlet" (
8888
"label" character varying(254) NOT NULL,
8989
"url" character varying(2048) NOT NULL,
9090
"priority" tinyuint NOT NULL,
91-
"disabled" boolenum DEFAULT 'n'
91+
"disabled" boolenum DEFAULT 'n',
92+
"description" text DEFAULT NULL
9293
);
9394

9495
ALTER TABLE "icingaweb_dashlet" ALTER COLUMN "id" SET STORAGE PLAIN;

etc/schema/pgsql.schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ CREATE TABLE "icingaweb_dashlet" (
210210
"label" character varying(254) NOT NULL,
211211
"url" character varying(2048) NOT NULL,
212212
"priority" tinyuint NOT NULL,
213-
"disabled" boolenum DEFAULT 'n'
213+
"disabled" boolenum DEFAULT 'n',
214+
"description" text DEFAULT NULL
214215
);
215216

216217
ALTER TABLE "icingaweb_dashlet" ALTER COLUMN "id" SET STORAGE PLAIN;

library/Icinga/Application/Modules/DashletManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ public static function getDashlets(): array
160160
->setTitle($moduleDashlet->label)
161161
->setModuleDashlet(true)
162162
->setModule($moduleDashlet->module)
163-
->setPriority($moduleDashlet->priority);
163+
->setPriority($moduleDashlet->priority)
164+
->setDescription($moduleDashlet->description);
164165

165166
if (! self::ensureItIsNotOrphaned($dashlet)) {
166167
continue;

library/Icinga/Model/Dashlet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function getColumns()
3131
'label',
3232
'url',
3333
'priority',
34-
'disabled'
34+
'disabled',
35+
'description'
3536
];
3637
}
3738

@@ -42,7 +43,8 @@ public function getMetaData()
4243
'name' => t('Dashlet Name'),
4344
'label' => t('Dashlet Title'),
4445
'url' => t('Dashlet Url'),
45-
'priority' => t('Dashlet Order Priority')
46+
'priority' => t('Dashlet Order Priority'),
47+
'description' => t('Dashlet Description')
4648
];
4749
}
4850

library/Icinga/Test/fixtures.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CREATE TABLE `icingaweb_dashlet` (
3333
`url` VARCHAR NOT NULL,
3434
`priority` tinyint NOT NULL,
3535
`disabled` TEXT CHECK ( disabled IN ('n', 'y') ) DEFAULT 'n',
36+
`description` text DEFAULT NULL,
3637
FOREIGN KEY (`dashboard_id`) REFERENCES `icingaweb_dashboard` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
3738
);
3839

library/Icinga/Web/Dashboard/Dashlet.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,13 @@ public function toArray(bool $stringify = true): array
252252
{
253253
$pane = $this->getPane();
254254
return [
255-
'id' => $this->getUuid(),
256-
'pane' => ! $stringify ? $pane : ($pane ? $pane->getName() : null),
257-
'name' => $this->getName(),
258-
'url' => $this->getUrl()->getRelativeUrl(),
259-
'label' => $this->getTitle(),
260-
'priority' => $this->getPriority(),
255+
'id' => $this->getUuid(),
256+
'pane' => ! $stringify ? $pane : ($pane ? $pane->getName() : null),
257+
'name' => $this->getName(),
258+
'url' => $this->getUrl()->getRelativeUrl(),
259+
'label' => $this->getTitle(),
260+
'priority' => $this->getPriority(),
261+
'description' => $this->getDescription()
261262
];
262263
}
263264
}

0 commit comments

Comments
 (0)