Skip to content

Commit

Permalink
Allow adding and editing of dashlet description.
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Jun 10, 2022
1 parent 65fc8e1 commit faf7709
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 18 deletions.
9 changes: 7 additions & 2 deletions application/forms/Dashboard/DashletForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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())) {
Expand Down
17 changes: 15 additions & 2 deletions application/forms/Dashboard/SetupNewDashboardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*
Expand All @@ -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;
Expand Down Expand Up @@ -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')
]);
}
}
}
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions etc/schema/mysql-upgrades/2.11.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
1 change: 1 addition & 0 deletions etc/schema/mysql.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
3 changes: 2 additions & 1 deletion etc/schema/pgsql-upgrades/2.11.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion etc/schema/pgsql.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion library/Icinga/Application/Modules/DashletManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions library/Icinga/Model/Dashlet.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function getColumns()
'label',
'url',
'priority',
'disabled'
'disabled',
'description'
];
}

Expand All @@ -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')
];
}

Expand Down
1 change: 1 addition & 0 deletions library/Icinga/Test/fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
13 changes: 7 additions & 6 deletions library/Icinga/Web/Dashboard/Dashlet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
];
}
}
8 changes: 5 additions & 3 deletions library/Icinga/Web/Dashboard/Pane.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit faf7709

Please sign in to comment.