mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-23 09:57:58 +02:00
Clean up codes
This commit is contained in:
parent
da4edb2274
commit
a1ed493ad1
@ -307,8 +307,8 @@ class DashboardsController extends CompatController
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var DashboardHome $home */
|
|
||||||
$home = $this->dashboard->getEntry($home);
|
$home = $this->dashboard->getEntry($home);
|
||||||
|
/** @var DashboardHome $home */
|
||||||
if (! is_array($value)) {
|
if (! is_array($value)) {
|
||||||
$this->dashboard->reorderWidget($home, (int) $value);
|
$this->dashboard->reorderWidget($home, (int) $value);
|
||||||
|
|
||||||
@ -323,8 +323,8 @@ class DashboardsController extends CompatController
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Pane $pane */
|
|
||||||
$pane = $home->hasEntry($pane) ? $home->getEntry($pane) : $orgHome->getEntry($pane);
|
$pane = $home->hasEntry($pane) ? $home->getEntry($pane) : $orgHome->getEntry($pane);
|
||||||
|
/** @var Pane $pane */
|
||||||
if (! is_array($indexOrValues)) {
|
if (! is_array($indexOrValues)) {
|
||||||
if ($orgHome && $orgHome->hasEntry($pane->getName()) && $home->hasEntry($pane->getName())) {
|
if ($orgHome && $orgHome->hasEntry($pane->getName()) && $home->hasEntry($pane->getName())) {
|
||||||
Notification::error(sprintf(
|
Notification::error(sprintf(
|
||||||
|
@ -91,7 +91,7 @@ abstract class BaseDashboardForm extends CompatForm
|
|||||||
*
|
*
|
||||||
* @return FormElement
|
* @return FormElement
|
||||||
*/
|
*/
|
||||||
protected function createRemoveButton(Url $action, $label)
|
protected function createRemoveButton(Url $action, string $label)
|
||||||
{
|
{
|
||||||
return $this->createElement('submitButton', 'btn_remove', [
|
return $this->createElement('submitButton', 'btn_remove', [
|
||||||
'class' => 'remove-button',
|
'class' => 'remove-button',
|
||||||
@ -107,7 +107,7 @@ abstract class BaseDashboardForm extends CompatForm
|
|||||||
*
|
*
|
||||||
* @return FormElement
|
* @return FormElement
|
||||||
*/
|
*/
|
||||||
protected function registerSubmitButton($label)
|
protected function registerSubmitButton(string $label)
|
||||||
{
|
{
|
||||||
$submitElement = $this->createElement('submit', 'submit', ['class' => 'btn-primary', 'label' => $label]);
|
$submitElement = $this->createElement('submit', 'submit', ['class' => 'btn-primary', 'label' => $label]);
|
||||||
$this->registerElement($submitElement);
|
$this->registerElement($submitElement);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||||
/* Icinga Web 2 | (c) 2013-2022 Icinga GmbH | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Forms\Dashboard;
|
namespace Icinga\Forms\Dashboard;
|
||||||
|
|
||||||
@ -274,16 +273,16 @@ class DashletForm extends BaseDashboardForm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(BaseDashboard $dashlet)
|
public function load(BaseDashboard $dashboard)
|
||||||
{
|
{
|
||||||
$home = Url::fromRequest()->getParam('home');
|
$home = Url::fromRequest()->getParam('home');
|
||||||
/** @var Dashlet $dashlet */
|
/** @var Dashlet $dashboard */
|
||||||
$this->populate(array(
|
$this->populate(array(
|
||||||
'org_home' => $home,
|
'org_home' => $home,
|
||||||
'org_pane' => $dashlet->getPane()->getName(),
|
'org_pane' => $dashboard->getPane()->getName(),
|
||||||
'org_dashlet' => $dashlet->getName(),
|
'org_dashlet' => $dashboard->getName(),
|
||||||
'dashlet' => $dashlet->getTitle(),
|
'dashlet' => $dashboard->getTitle(),
|
||||||
'url' => $dashlet->getUrl()->getRelativeUrl()
|
'url' => $dashboard->getUrl()->getRelativeUrl()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
namespace Icinga\Forms\Dashboard;
|
namespace Icinga\Forms\Dashboard;
|
||||||
|
|
||||||
use Icinga\Web\Dashboard\Dashboard;
|
use Icinga\Web\Dashboard\Dashboard;
|
||||||
|
@ -17,7 +17,7 @@ class WelcomeForm extends CompatForm
|
|||||||
public function __construct(Dashboard $dashboard)
|
public function __construct(Dashboard $dashboard)
|
||||||
{
|
{
|
||||||
$this->dashboard = $dashboard;
|
$this->dashboard = $dashboard;
|
||||||
$this->setRedirectUrl(Url::fromPath(Dashboard::BASE_ROUTE));
|
$this->setRedirectUrl((string) Url::fromPath(Dashboard::BASE_ROUTE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasBeenSubmitted()
|
public function hasBeenSubmitted()
|
||||||
|
@ -13,7 +13,7 @@ class DashboardContainer extends NavigationItemContainer
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $dashlets;
|
protected $dashlets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this dashboard's dashlets
|
* Set this dashboard's dashlets
|
||||||
@ -35,7 +35,11 @@ class DashboardContainer extends NavigationItemContainer
|
|||||||
*/
|
*/
|
||||||
public function getDashlets()
|
public function getDashlets()
|
||||||
{
|
{
|
||||||
return $this->dashlets ?: array();
|
uasort($this->dashlets, function (array $x, array $y) {
|
||||||
|
return $x['priority'] - $y['priority'];
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->dashlets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ class DashletContainer extends NavigationItemContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set url if this dashlet item
|
* Set url of this dashlet item
|
||||||
*
|
*
|
||||||
* @param Url|string $url
|
* @param Url|string $url
|
||||||
*
|
*
|
||||||
|
@ -217,7 +217,7 @@ class Module
|
|||||||
/**
|
/**
|
||||||
* A set of Pane elements
|
* A set of Pane elements
|
||||||
*
|
*
|
||||||
* @var DashboardContainer
|
* @var DashboardContainer[]
|
||||||
*/
|
*/
|
||||||
protected $paneItems = [];
|
protected $paneItems = [];
|
||||||
|
|
||||||
@ -317,49 +317,12 @@ class Module
|
|||||||
/**
|
/**
|
||||||
* Return this module's dashboard
|
* Return this module's dashboard
|
||||||
*
|
*
|
||||||
* @return Navigation
|
* @return DashboardContainer[]
|
||||||
*/
|
*/
|
||||||
public function getDashboard()
|
public function getDashboard()
|
||||||
{
|
{
|
||||||
$this->launchConfigScript();
|
$this->launchConfigScript();
|
||||||
return $this->createDashboard($this->paneItems);
|
return $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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -401,7 +364,7 @@ class Module
|
|||||||
*
|
*
|
||||||
* @return DashletContainer
|
* @return DashletContainer
|
||||||
*/
|
*/
|
||||||
protected function provideDashlet($name, $url, array $properties = [])
|
protected function provideDashlet(string $name, $url, array $properties = [])
|
||||||
{
|
{
|
||||||
if (array_key_exists($name, $this->dashletItems)) {
|
if (array_key_exists($name, $this->dashletItems)) {
|
||||||
$this->dashletItems[$name]->setProperties($properties);
|
$this->dashletItems[$name]->setProperties($properties);
|
||||||
|
@ -11,7 +11,7 @@ trait DataExtractor
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function fromArray(array $data)
|
public function fromArray(array $data): self
|
||||||
{
|
{
|
||||||
foreach ($data as $name => $value) {
|
foreach ($data as $name => $value) {
|
||||||
$func = 'set' . ucfirst($name);
|
$func = 'set' . ucfirst($name);
|
||||||
@ -32,7 +32,7 @@ trait DataExtractor
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function toArray($stringify = true)
|
public function toArray(bool $stringify = true): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $properties
|
* @param array $properties
|
||||||
*/
|
*/
|
||||||
public function __construct($name, array $properties = [])
|
public function __construct(string $name, array $properties = [])
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->title = $name;
|
$this->title = $name;
|
||||||
@ -80,7 +80,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setUuid($uuid)
|
public function setUuid($uuid): self
|
||||||
{
|
{
|
||||||
$this->uuid = $uuid;
|
$this->uuid = $uuid;
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
/**
|
/**
|
||||||
* Get this widget's unique identifier
|
* Get this widget's unique identifier
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string|int
|
||||||
*/
|
*/
|
||||||
public function getUuid()
|
public function getUuid()
|
||||||
{
|
{
|
||||||
@ -101,10 +101,14 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
* Set the name of this widget
|
* Set the name of this widget
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setName($name)
|
public function setName(string $name): self
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +116,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
@ -124,7 +128,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setTitle($title)
|
public function setTitle(string $title): self
|
||||||
{
|
{
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
|
|
||||||
@ -136,7 +140,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTitle()
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return $this->title !== null ? $this->title : $this->getName();
|
return $this->title !== null ? $this->title : $this->getName();
|
||||||
}
|
}
|
||||||
@ -148,7 +152,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setOwner($owner)
|
public function setOwner(string $owner): self
|
||||||
{
|
{
|
||||||
$this->owner = $owner;
|
$this->owner = $owner;
|
||||||
|
|
||||||
@ -158,7 +162,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
/**
|
/**
|
||||||
* Get owner of this widget
|
* Get owner of this widget
|
||||||
*
|
*
|
||||||
* @return string
|
* @return ?string
|
||||||
*/
|
*/
|
||||||
public function getOwner()
|
public function getOwner()
|
||||||
{
|
{
|
||||||
@ -168,7 +172,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
/**
|
/**
|
||||||
* Get the widget's description
|
* Get the widget's description
|
||||||
*
|
*
|
||||||
* @return string
|
* @return ?string
|
||||||
*/
|
*/
|
||||||
public function getDescription()
|
public function getDescription()
|
||||||
{
|
{
|
||||||
@ -182,7 +186,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setDescription($description)
|
public function setDescription(string $description = null): self
|
||||||
{
|
{
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
|
|
||||||
@ -196,7 +200,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setPriority(int $order)
|
public function setPriority(int $order): self
|
||||||
{
|
{
|
||||||
$this->order = $order;
|
$this->order = $order;
|
||||||
|
|
||||||
@ -208,7 +212,7 @@ abstract class BaseDashboard implements DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getPriority()
|
public function getPriority(): int
|
||||||
{
|
{
|
||||||
return $this->order;
|
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 = '')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ trait DashboardControls
|
|||||||
return ! empty($this->dashboards);
|
return ! empty($this->dashboards);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEntry($name)
|
public function getEntry(string $name)
|
||||||
{
|
{
|
||||||
if (! $this->hasEntry($name)) {
|
if (! $this->hasEntry($name)) {
|
||||||
throw new ProgrammingError('Trying to retrieve invalid dashboard entry "%s"', $name);
|
throw new ProgrammingError('Trying to retrieve invalid dashboard entry "%s"', $name);
|
||||||
@ -31,7 +31,7 @@ trait DashboardControls
|
|||||||
return $this->dashboards[$name];
|
return $this->dashboards[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasEntry($name)
|
public function hasEntry(string $name)
|
||||||
{
|
{
|
||||||
return array_key_exists($name, $this->dashboards);
|
return array_key_exists($name, $this->dashboards);
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ trait DashboardControls
|
|||||||
return $this;
|
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);
|
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) {
|
if ($origin && ! $origin instanceof $this) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
@ -25,7 +25,7 @@ interface DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return BaseDashboard
|
* @return BaseDashboard
|
||||||
*/
|
*/
|
||||||
public function getEntry($name);
|
public function getEntry(string $name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether the given dashboard entry exists
|
* Get whether the given dashboard entry exists
|
||||||
@ -34,7 +34,7 @@ interface DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasEntry($name);
|
public function hasEntry(string $name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all dashboard entries of this widget
|
* Get all dashboard entries of this widget
|
||||||
@ -69,7 +69,7 @@ interface DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function createEntry($name, $url = null);
|
public function createEntry(string $name, $url = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array with entry name=>title format
|
* Get an array with entry name=>title format
|
||||||
@ -112,7 +112,7 @@ interface DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @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
|
* Load all the assigned entries to this widget
|
||||||
@ -121,7 +121,7 @@ interface DashboardEntry
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function loadDashboardEntries($name = '');
|
public function loadDashboardEntries(string $name = '');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the current position of the internal dashboard entries pointer
|
* Reset the current position of the internal dashboard entries pointer
|
||||||
|
@ -58,7 +58,7 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return Connection
|
* @return Connection
|
||||||
*/
|
*/
|
||||||
public static function getConn()
|
public static function getConn(): Connection
|
||||||
{
|
{
|
||||||
if (self::$conn === null) {
|
if (self::$conn === null) {
|
||||||
self::$conn = (new self())->getDb();
|
self::$conn = (new self())->getDb();
|
||||||
@ -74,12 +74,12 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getSHA1($name)
|
public static function getSHA1(string $name): string
|
||||||
{
|
{
|
||||||
return sha1($name, true);
|
return sha1($name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDashboardEntries($name = '')
|
public function loadDashboardEntries(string $name = '')
|
||||||
{
|
{
|
||||||
if ($name && $this->hasEntry($name)) {
|
if ($name && $this->hasEntry($name)) {
|
||||||
$home = $this->getEntry($name);
|
$home = $this->getEntry($name);
|
||||||
@ -113,7 +113,7 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function activateHome(DashboardHome $home)
|
public function activateHome(DashboardHome $home): self
|
||||||
{
|
{
|
||||||
$activeHome = $this->getActiveHome();
|
$activeHome = $this->getActiveHome();
|
||||||
if ($activeHome && $activeHome->getName() !== $home->getName()) {
|
if ($activeHome && $activeHome->getName() !== $home->getName()) {
|
||||||
@ -166,12 +166,12 @@ trait DashboardManager
|
|||||||
/** @var DashboardHome $home */
|
/** @var DashboardHome $home */
|
||||||
foreach ($homes as $home) {
|
foreach ($homes as $home) {
|
||||||
if (! $this->hasEntry($home->getName())) {
|
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());
|
$priority = $home->getName() === DashboardHome::DEFAULT_HOME ? 0 : count($this->getEntries());
|
||||||
$conn->insert(DashboardHome::TABLE, [
|
$conn->insert(DashboardHome::TABLE, [
|
||||||
'name' => $home->getName(),
|
'name' => $home->getName(),
|
||||||
'label' => $home->getTitle(),
|
'label' => $home->getTitle(),
|
||||||
'username' => self::getUser()->getUsername(),
|
'username' => self::getUser()->getUsername(),
|
||||||
// highest priority is 0, so count($entries) are always lowest prio + 1
|
|
||||||
'priority' => $priority,
|
'priority' => $priority,
|
||||||
'type' => $home->getType() !== Dashboard::SYSTEM ? $home->getType() : Dashboard::PRIVATE_DS
|
'type' => $home->getType() !== Dashboard::SYSTEM ? $home->getType() : Dashboard::PRIVATE_DS
|
||||||
]);
|
]);
|
||||||
@ -191,9 +191,9 @@ trait DashboardManager
|
|||||||
/**
|
/**
|
||||||
* Get and|or init the default dashboard home
|
* 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)) {
|
if ($this->hasEntry(DashboardHome::DEFAULT_HOME)) {
|
||||||
return $this->getEntry(DashboardHome::DEFAULT_HOME);
|
return $this->getEntry(DashboardHome::DEFAULT_HOME);
|
||||||
@ -213,7 +213,7 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setUser(User $user)
|
public function setUser(User $user): self
|
||||||
{
|
{
|
||||||
self::$user = $user;
|
self::$user = $user;
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
public static function getUser()
|
public static function getUser(): User
|
||||||
{
|
{
|
||||||
if (self::$user === null) {
|
if (self::$user === null) {
|
||||||
self::$user = Auth::getInstance()->getUser();
|
self::$user = Auth::getInstance()->getUser();
|
||||||
@ -240,7 +240,7 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return Pane[]
|
* @return Pane[]
|
||||||
*/
|
*/
|
||||||
public static function getSystemDefaults()
|
public static function getSystemDefaults(): array
|
||||||
{
|
{
|
||||||
return self::$defaultPanes;
|
return self::$defaultPanes;
|
||||||
}
|
}
|
||||||
@ -251,26 +251,29 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function deployModuleDashlets()
|
public static function deployModuleDashlets(): void
|
||||||
{
|
{
|
||||||
$moduleManager = Icinga::app()->getModuleManager();
|
$mg = Icinga::app()->getModuleManager();
|
||||||
foreach ($moduleManager->getLoadedModules() as $module) {
|
foreach ($mg->getLoadedModules() as $module) {
|
||||||
/** @var DashboardPane $dashboardPane */
|
foreach ($module->getDashboard() as $dashboard) {
|
||||||
foreach ($module->getDashboard() as $dashboardPane) {
|
$pane = new Pane($dashboard->getName());
|
||||||
$pane = new Pane($dashboardPane->getName());
|
$pane->fromArray($dashboard->getProperties());
|
||||||
$pane->setTitle($dashboardPane->getLabel());
|
|
||||||
$pane->fromArray($dashboardPane->getAttributes());
|
|
||||||
|
|
||||||
$priority = 0;
|
$priority = 0;
|
||||||
foreach ($dashboardPane->getIterator()->getItems() as $dashletItem) {
|
foreach ($dashboard->getDashlets() as $name => $configPart) {
|
||||||
$uuid = self::getSHA1($module->getName() . $pane->getName() . $dashletItem->getName());
|
$uuid = self::getSHA1($module->getName() . $pane->getName() . $name);
|
||||||
$dashlet = new Dashlet($dashletItem->getName(), $dashletItem->getUrl(), $pane);
|
$dashlet = new Dashlet($name, $configPart['url'], $pane);
|
||||||
$dashlet->fromArray($dashletItem->getAttributes());
|
$dashlet->fromArray($configPart);
|
||||||
$dashlet
|
$dashlet
|
||||||
->setUuid($uuid)
|
->setUuid($uuid)
|
||||||
->setModule($module->getName())
|
|
||||||
->setModuleDashlet(true)
|
->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);
|
self::updateOrInsertModuleDashlet($dashlet);
|
||||||
$pane->addEntry($dashlet);
|
$pane->addEntry($dashlet);
|
||||||
@ -305,7 +308,7 @@ trait DashboardManager
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @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 = Model\ModuleDashlet::on(self::getConn())->filter(Filter::equal('id', $dashlet->getUuid()));
|
||||||
$query->getSelectBase()->columns(new Expression('1'));
|
$query->getSelectBase()->columns(new Expression('1'));
|
||||||
@ -317,11 +320,10 @@ trait DashboardManager
|
|||||||
* Insert or update the given module dashlet
|
* Insert or update the given module dashlet
|
||||||
*
|
*
|
||||||
* @param Dashlet $dashlet
|
* @param Dashlet $dashlet
|
||||||
* @param string $module
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function updateOrInsertModuleDashlet(Dashlet $dashlet)
|
public static function updateOrInsertModuleDashlet(Dashlet $dashlet): void
|
||||||
{
|
{
|
||||||
if (! $dashlet->isModuleDashlet()) {
|
if (! $dashlet->isModuleDashlet()) {
|
||||||
return;
|
return;
|
||||||
@ -351,9 +353,11 @@ trait DashboardManager
|
|||||||
/**
|
/**
|
||||||
* Get module dashlets from the database
|
* Get module dashlets from the database
|
||||||
*
|
*
|
||||||
|
* @param Query $query
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getModuleDashlets(Query $query)
|
public static function getModuleDashlets(Query $query): array
|
||||||
{
|
{
|
||||||
$dashlets = [];
|
$dashlets = [];
|
||||||
foreach ($query as $moduleDashlet) {
|
foreach ($query as $moduleDashlet) {
|
||||||
|
@ -19,40 +19,40 @@ abstract class ItemListControl extends BaseHtmlElement
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
abstract protected function getHtmlId();
|
abstract protected function getHtmlId(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a class name for the collapsible control
|
* Get a class name for the collapsible control
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
abstract protected function getCollapsibleControlClass();
|
abstract protected function getCollapsibleControlClass(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an action link to be added at the end of the list
|
* 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
|
* 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
|
* Assemble a header element for this item list
|
||||||
*
|
*
|
||||||
* @param Url $url
|
* @param Url $url
|
||||||
* @param string $header
|
* @param string $title
|
||||||
*
|
*
|
||||||
* @return void
|
* @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, [
|
$header->addHtml(new Link(t('Edit'), $url, [
|
||||||
'data-icinga-modal' => true,
|
'data-icinga-modal' => true,
|
||||||
'data-no-icinga-ajax' => true
|
'data-no-icinga-ajax' => true
|
||||||
|
@ -23,7 +23,7 @@ trait ModuleDashlet
|
|||||||
/**
|
/**
|
||||||
* Get the name of the module which provides this dashlet
|
* Get the name of the module which provides this dashlet
|
||||||
*
|
*
|
||||||
* @return string
|
* @return ?string
|
||||||
*/
|
*/
|
||||||
public function getModule()
|
public function getModule()
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ trait ModuleDashlet
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setModule($module)
|
public function setModule(string $module): self
|
||||||
{
|
{
|
||||||
$this->module = $module;
|
$this->module = $module;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ trait ModuleDashlet
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isModuleDashlet()
|
public function isModuleDashlet(): bool
|
||||||
{
|
{
|
||||||
return $this->moduleDashlet;
|
return $this->moduleDashlet;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ trait ModuleDashlet
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setModuleDashlet(bool $moduleDashlet)
|
public function setModuleDashlet(bool $moduleDashlet): self
|
||||||
{
|
{
|
||||||
$this->moduleDashlet = $moduleDashlet;
|
$this->moduleDashlet = $moduleDashlet;
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ interface Sortable
|
|||||||
* Insert the dashboard entry at the given position within this dashboard entries
|
* Insert the dashboard entry at the given position within this dashboard entries
|
||||||
*
|
*
|
||||||
* @param BaseDashboard $dashboard
|
* @param BaseDashboard $dashboard
|
||||||
* @param $position
|
* @param int $position
|
||||||
* @param Sortable|null $origin
|
* @param Sortable|null $origin
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function reorderWidget(BaseDashboard $dashboard, $position, Sortable $origin = null);
|
public function reorderWidget(BaseDashboard $dashboard, int $position, Sortable $origin = null);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
|
|||||||
* @param string $name The tab name to activate
|
* @param string $name The tab name to activate
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function activate($name)
|
public function activate(string $name)
|
||||||
{
|
{
|
||||||
$this->getTabs()->activate($name);
|
$this->getTabs()->activate($name);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setActive($active = true)
|
public function setActive(bool $active = true)
|
||||||
{
|
{
|
||||||
$this->active = $active;
|
$this->active = $active;
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setType($type)
|
public function setType(string $type)
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDashboardEntries($name = '')
|
public function loadDashboardEntries(string $name = '')
|
||||||
{
|
{
|
||||||
if (! $this->getActive()) {
|
if (! $this->getActive()) {
|
||||||
return $this;
|
return $this;
|
||||||
@ -160,7 +160,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createEntry($name, $url = null)
|
public function createEntry(string $name, $url = null)
|
||||||
{
|
{
|
||||||
$entry = new Pane($name);
|
$entry = new Pane($name);
|
||||||
$entry->setHome($this);
|
$entry->setHome($this);
|
||||||
@ -170,7 +170,7 @@ class DashboardHome extends BaseDashboard implements Sortable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function manageEntry($entry, BaseDashboard $origin = null, $manageRecursive = false)
|
public function manageEntry($entry, BaseDashboard $origin = null, bool $manageRecursive = false)
|
||||||
{
|
{
|
||||||
$user = Dashboard::getUser();
|
$user = Dashboard::getUser();
|
||||||
$conn = Dashboard::getConn();
|
$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 [
|
return [
|
||||||
'id' => $this->getUuid(),
|
'id' => $this->getUuid(),
|
||||||
|
@ -9,6 +9,7 @@ use Icinga\Web\Dashboard\Common\BaseDashboard;
|
|||||||
use Icinga\Web\Dashboard\Common\ModuleDashlet;
|
use Icinga\Web\Dashboard\Common\ModuleDashlet;
|
||||||
use Icinga\Web\Request;
|
use Icinga\Web\Request;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
use ipl\Html\BaseHtmlElement;
|
||||||
use ipl\Html\HtmlElement;
|
use ipl\Html\HtmlElement;
|
||||||
use ipl\Web\Widget\Link;
|
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 Url|string $url The url this dashlet uses for displaying information
|
||||||
* @param Pane|null $pane The pane this Dashlet will be added to
|
* @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);
|
parent::__construct($name);
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ class Dashlet extends BaseDashboard
|
|||||||
/**
|
/**
|
||||||
* Retrieve the dashlets url
|
* Retrieve the dashlets url
|
||||||
*
|
*
|
||||||
* @return Url|null
|
* @return ?Url
|
||||||
*/
|
*/
|
||||||
public function getUrl()
|
public function getUrl()
|
||||||
{
|
{
|
||||||
@ -85,7 +86,7 @@ class Dashlet extends BaseDashboard
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setUrl($url)
|
public function setUrl($url): self
|
||||||
{
|
{
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ class Dashlet extends BaseDashboard
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setProgressLabel($label)
|
public function setProgressLabel(string $label): self
|
||||||
{
|
{
|
||||||
$this->progressLabel = $label;
|
$this->progressLabel = $label;
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ class Dashlet extends BaseDashboard
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getProgressLabel()
|
public function getProgressLabel(): string
|
||||||
{
|
{
|
||||||
if ($this->progressLabel === null) {
|
if ($this->progressLabel === null) {
|
||||||
return $this->progressLabel = t('Loading');
|
return $this->progressLabel = t('Loading');
|
||||||
@ -127,7 +128,7 @@ class Dashlet extends BaseDashboard
|
|||||||
*
|
*
|
||||||
* @return Dashlet
|
* @return Dashlet
|
||||||
*/
|
*/
|
||||||
public function setPane(Pane $pane)
|
public function setPane(Pane $pane): self
|
||||||
{
|
{
|
||||||
$this->pane = $pane;
|
$this->pane = $pane;
|
||||||
|
|
||||||
@ -137,7 +138,7 @@ class Dashlet extends BaseDashboard
|
|||||||
/**
|
/**
|
||||||
* Get the pane of this dashlet
|
* Get the pane of this dashlet
|
||||||
*
|
*
|
||||||
* @return Pane
|
* @return ?Pane
|
||||||
*/
|
*/
|
||||||
public function getPane()
|
public function getPane()
|
||||||
{
|
{
|
||||||
@ -147,9 +148,9 @@ class Dashlet extends BaseDashboard
|
|||||||
/**
|
/**
|
||||||
* Generate a html widget for this dashlet
|
* Generate a html widget for this dashlet
|
||||||
*
|
*
|
||||||
* @return HtmlElement
|
* @return BaseHtmlElement
|
||||||
*/
|
*/
|
||||||
public function getHtml()
|
public function getHtml(): BaseHtmlElement
|
||||||
{
|
{
|
||||||
$dashletHtml = HtmlElement::create('div', ['class' => 'container']);
|
$dashletHtml = HtmlElement::create('div', ['class' => 'container']);
|
||||||
if (! $this->getUrl()) {
|
if (! $this->getUrl()) {
|
||||||
@ -191,7 +192,7 @@ class Dashlet extends BaseDashboard
|
|||||||
return $dashletHtml;
|
return $dashletHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray($stringify = true)
|
public function toArray(bool $stringify = true): array
|
||||||
{
|
{
|
||||||
$pane = $this->getPane();
|
$pane = $this->getPane();
|
||||||
return [
|
return [
|
||||||
|
@ -7,6 +7,7 @@ namespace Icinga\Web\Dashboard\ItemList;
|
|||||||
use Icinga\Web\Dashboard\Common\ItemListControl;
|
use Icinga\Web\Dashboard\Common\ItemListControl;
|
||||||
use Icinga\Web\Dashboard\Dashboard;
|
use Icinga\Web\Dashboard\Dashboard;
|
||||||
use Icinga\Web\Dashboard\DashboardHome;
|
use Icinga\Web\Dashboard\DashboardHome;
|
||||||
|
use ipl\Html\BaseHtmlElement;
|
||||||
use ipl\Html\HtmlElement;
|
use ipl\Html\HtmlElement;
|
||||||
use ipl\Web\Url;
|
use ipl\Web\Url;
|
||||||
use ipl\Web\Widget\ActionLink;
|
use ipl\Web\Widget\ActionLink;
|
||||||
@ -30,17 +31,17 @@ class DashboardHomeList extends ItemListControl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHtmlId()
|
protected function getHtmlId(): string
|
||||||
{
|
{
|
||||||
return $this->home->getUuid();
|
return $this->home->getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCollapsibleControlClass()
|
protected function getCollapsibleControlClass(): string
|
||||||
{
|
{
|
||||||
return 'dashboard-list-info';
|
return 'dashboard-list-info';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createItemList()
|
protected function createItemList(): BaseHtmlElement
|
||||||
{
|
{
|
||||||
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-home')
|
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-home')
|
||||||
->setParams(['home' => $this->home->getName()]);
|
->setParams(['home' => $this->home->getName()]);
|
||||||
@ -58,7 +59,7 @@ class DashboardHomeList extends ItemListControl
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createActionLink()
|
protected function createActionLink(): BaseHtmlElement
|
||||||
{
|
{
|
||||||
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-pane');
|
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-pane');
|
||||||
$url->setParams(['home' => $this->home->getName()]);
|
$url->setParams(['home' => $this->home->getName()]);
|
||||||
|
@ -7,6 +7,7 @@ namespace Icinga\Web\Dashboard\ItemList;
|
|||||||
use Icinga\Web\Dashboard\Common\ItemListControl;
|
use Icinga\Web\Dashboard\Common\ItemListControl;
|
||||||
use Icinga\Web\Dashboard\Dashboard;
|
use Icinga\Web\Dashboard\Dashboard;
|
||||||
use Icinga\Web\Dashboard\Pane;
|
use Icinga\Web\Dashboard\Pane;
|
||||||
|
use ipl\Html\BaseHtmlElement;
|
||||||
use ipl\Html\HtmlElement;
|
use ipl\Html\HtmlElement;
|
||||||
use ipl\Web\Url;
|
use ipl\Web\Url;
|
||||||
use ipl\Web\Widget\ActionLink;
|
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());
|
return bin2hex($this->pane->getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCollapsibleControlClass()
|
protected function getCollapsibleControlClass(): string
|
||||||
{
|
{
|
||||||
return 'dashlets-list-info';
|
return 'dashlets-list-info';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createItemList()
|
protected function createItemList(): BaseHtmlElement
|
||||||
{
|
{
|
||||||
$pane = $this->pane;
|
$pane = $this->pane;
|
||||||
$this->getAttributes()->set('data-toggle-element', '.dashlets-list-info');
|
$this->getAttributes()->set('data-toggle-element', '.dashlets-list-info');
|
||||||
@ -61,7 +62,7 @@ class DashboardList extends ItemListControl
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createActionLink()
|
protected function createActionLink(): BaseHtmlElement
|
||||||
{
|
{
|
||||||
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-dashlet');
|
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/new-dashlet');
|
||||||
$url->setParams([
|
$url->setParams([
|
||||||
|
@ -46,14 +46,14 @@ class DashletListItem extends BaseHtmlElement
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
protected function setDetailUrl(bool $value)
|
protected function setDetailUrl(bool $value): self
|
||||||
{
|
{
|
||||||
$this->renderEditButton = $value;
|
$this->renderEditButton = $value;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function assembleTitle()
|
protected function assembleHeader(): HtmlElement
|
||||||
{
|
{
|
||||||
$title = HtmlElement::create('h1', ['class' => 'dashlet-header']);
|
$title = HtmlElement::create('h1', ['class' => 'dashlet-header']);
|
||||||
|
|
||||||
@ -98,12 +98,10 @@ class DashletListItem extends BaseHtmlElement
|
|||||||
if (! $this->dashlet) {
|
if (! $this->dashlet) {
|
||||||
$section->add(t('Create a dashlet with custom url and filter'));
|
$section->add(t('Create a dashlet with custom url and filter'));
|
||||||
} else {
|
} else {
|
||||||
$section->getAttributes()->set(
|
$description = $this->dashlet->getDescription() ?: t('There is no provided description.');
|
||||||
'title',
|
$section->getAttributes()->set('title', $description);
|
||||||
$this->dashlet->getDescription() ?: t('There is no provided description.')
|
|
||||||
);
|
|
||||||
|
|
||||||
$section->add($this->dashlet->getDescription() ?: t('There is no provided dashlet description.'));
|
$section->add($description);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $section;
|
return $section;
|
||||||
@ -111,7 +109,7 @@ class DashletListItem extends BaseHtmlElement
|
|||||||
|
|
||||||
protected function assemble()
|
protected function assemble()
|
||||||
{
|
{
|
||||||
$this->addHtml($this->assembleTitle());
|
$this->addHtml($this->assembleHeader());
|
||||||
$this->addHtml($this->assembleSummary());
|
$this->addHtml($this->assembleSummary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ class DashletListMultiSelect extends DashletListItem
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setCheckBox(FormElement $checkbox)
|
public function setCheckBox(FormElement $checkbox): self
|
||||||
{
|
{
|
||||||
$this->checkbox = $checkbox;
|
$this->checkbox = $checkbox;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createLabel()
|
protected function createLabel(): HtmlElement
|
||||||
{
|
{
|
||||||
$label = HtmlElement::create('label');
|
$label = HtmlElement::create('label');
|
||||||
$label->addHtml($this->checkbox);
|
$label->addHtml($this->checkbox);
|
||||||
|
@ -50,59 +50,21 @@ class Pane extends BaseDashboard implements Sortable
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setHome(DashboardHome $home)
|
public function setHome(DashboardHome $home): self
|
||||||
{
|
{
|
||||||
$this->home = $home;
|
$this->home = $home;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createEntry($name, $url = null)
|
public function createEntry(string $name, $url = null)
|
||||||
{
|
{
|
||||||
$dashlet = new Dashlet($name, $url, $this);
|
if ($url === null) {
|
||||||
$this->addDashlet($dashlet);
|
throw new ConfigurationError('Can\'t create a dashlet "%s" without a valid url', $name);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
$dashlet = new Dashlet($name, $url, $this);
|
||||||
}
|
$this->addEntry($dashlet);
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -126,7 +88,7 @@ class Pane extends BaseDashboard implements Sortable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDashboardEntries($name = '')
|
public function loadDashboardEntries(string $name = '')
|
||||||
{
|
{
|
||||||
$dashlets = Model\Dashlet::on(Dashboard::getConn())
|
$dashlets = Model\Dashlet::on(Dashboard::getConn())
|
||||||
->utilize(self::TABLE)
|
->utilize(self::TABLE)
|
||||||
@ -144,13 +106,13 @@ class Pane extends BaseDashboard implements Sortable
|
|||||||
'description' => $dashlet->icingaweb_module_dashlet->description
|
'description' => $dashlet->icingaweb_module_dashlet->description
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->addDashlet($newDashlet);
|
$this->addEntry($newDashlet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
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) {
|
if ($origin && ! $origin instanceof Pane) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
@ -171,7 +133,7 @@ class Pane extends BaseDashboard implements Sortable
|
|||||||
$conn = Dashboard::getConn();
|
$conn = Dashboard::getConn();
|
||||||
|
|
||||||
$dashlets = is_array($entry) ? $entry : [$entry];
|
$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());
|
$order = count($this->getEntries());
|
||||||
foreach ($dashlets as $dashlet) {
|
foreach ($dashlets as $dashlet) {
|
||||||
if (is_array($dashlet)) {
|
if (is_array($dashlet)) {
|
||||||
@ -240,7 +202,7 @@ class Pane extends BaseDashboard implements Sortable
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray($stringify = true)
|
public function toArray(bool $stringify = true): array
|
||||||
{
|
{
|
||||||
$home = $this->getHome();
|
$home = $this->getHome();
|
||||||
return [
|
return [
|
||||||
|
@ -36,7 +36,7 @@ class SetupNewDashboard extends BaseDashboardForm
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function initDashlets(array $dashlets)
|
public function initDashlets(array $dashlets): self
|
||||||
{
|
{
|
||||||
$this->dashlets = $dashlets;
|
$this->dashlets = $dashlets;
|
||||||
|
|
||||||
@ -236,9 +236,9 @@ class SetupNewDashboard extends BaseDashboardForm
|
|||||||
* Dump all module dashlets which are not selected by the user
|
* Dump all module dashlets which are not selected by the user
|
||||||
* from the member variable
|
* from the member variable
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function dumpArbitaryDashlets()
|
private function dumpArbitaryDashlets(): void
|
||||||
{
|
{
|
||||||
$choosenDashlets = [];
|
$choosenDashlets = [];
|
||||||
foreach ($this->dashlets as $module => $dashlets) {
|
foreach ($this->dashlets as $module => $dashlets) {
|
||||||
@ -252,8 +252,6 @@ class SetupNewDashboard extends BaseDashboardForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->dashlets = $choosenDashlets;
|
$this->dashlets = $choosenDashlets;
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -261,7 +259,7 @@ class SetupNewDashboard extends BaseDashboardForm
|
|||||||
*
|
*
|
||||||
* @return ValidHtml
|
* @return ValidHtml
|
||||||
*/
|
*/
|
||||||
private function createFormListControl()
|
private function createFormListControl(): ValidHtml
|
||||||
{
|
{
|
||||||
return HtmlElement::create('div', [
|
return HtmlElement::create('div', [
|
||||||
'class' => ['control-group', 'form-list-control', 'collapsible'],
|
'class' => ['control-group', 'form-list-control', 'collapsible'],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Icinga Web 2 | (c) 2014-2022 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
namespace Icinga\Web\Widget\Tabextension;
|
namespace Icinga\Web\Widget\Tabextension;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user