Fix some code styles and comments

This commit is contained in:
Yonas Habteab 2022-04-06 19:49:13 +02:00
parent 876c1097bd
commit adf2013c23
5 changed files with 39 additions and 27 deletions

View File

@ -56,8 +56,6 @@ class Pane extends Model
$relations->belongsTo('home', Home::class)
->setCandidateKey('home_id');
$relations->hasMany('dashboard_override', DashboardOverride::class)
->setJoinType('LEFT');
$relations->hasMany('dashlet', Dashlet::class)
->setJoinType('LEFT');
}

View File

@ -5,6 +5,7 @@
namespace Icinga\Web\Dashboard\Common;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\DashletContainer;
use Icinga\Authentication\Auth;
use Icinga\Common\Database;
use Icinga\Exception\ProgrammingError;
@ -14,7 +15,8 @@ use Icinga\Web\Dashboard\Dashboard;
use Icinga\Web\Dashboard\DashboardHome;
use Icinga\Web\Dashboard\Dashlet;
use Icinga\Web\Dashboard\Pane;
use Icinga\Web\HomeMenu;
use Icinga\Web\Menu;
use Icinga\Web\Navigation\DashboardPane;
use ipl\Orm\Query;
use ipl\Sql\Connection;
use ipl\Sql\Expression;
@ -40,7 +42,7 @@ trait DashboardManager
public function load()
{
$this->setEntries((new HomeMenu())->loadHomes());
$this->setEntries((new Menu())->loadHomes());
$this->loadDashboardEntries();
$this->initGetDefaultHome();
@ -253,36 +255,47 @@ trait DashboardManager
{
$moduleManager = Icinga::app()->getModuleManager();
foreach ($moduleManager->getLoadedModules() as $module) {
/** @var DashboardPane $dashboardPane */
foreach ($module->getDashboard() as $dashboardPane) {
$priority = 0;
/** @var Dashlet $dashlet */
foreach ($dashboardPane->getEntries() as $dashlet) {
$uuid = self::getSHA1($module->getName() . $dashboardPane->getName() . $dashlet->getName());
$pane = new Pane($dashboardPane->getName());
$pane->setTitle($dashboardPane->getLabel());
$pane->fromArray($dashboardPane->getAttributes());
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());
$dashlet
->setUuid($uuid)
->setPriority($priority++)
->setModule($module->getName())
->setModuleDashlet(true);
->setModuleDashlet(true)
->setPriority($dashletItem->getPriority());
self::updateOrInsertModuleDashlet($dashlet);
$pane->addEntry($dashlet);
}
if (in_array($module->getName(), ['monitoring', 'icingadb'], true)) {
self::$defaultPanes[$dashboardPane->getName()] = $dashboardPane;
self::$defaultPanes[$pane->getName()] = $pane;
}
}
$priority = 0;
foreach ($module->getDashlets() as $dashlet) {
$identifier = self::getSHA1($module->getName() . $dashlet->getName());
$dashlet
$newDashlet = new Dashlet($dashlet->getName(), $dashlet->getUrl());
$newDashlet->fromArray($dashlet->getProperties());
$newDashlet
->setUuid($identifier)
->setPriority($priority++)
->setModule($module->getName())
->setModuleDashlet(true);
self::updateOrInsertModuleDashlet($dashlet);
if (! $newDashlet->getPriority()) {
$newDashlet->setPriority($priority);
}
self::updateOrInsertModuleDashlet($newDashlet);
$priority++;
}
}
}

View File

@ -19,28 +19,28 @@ abstract class ItemListControl extends BaseHtmlElement
*
* @return string
*/
protected abstract function getHtmlId();
abstract protected function getHtmlId();
/**
* Get a class name for the collapsible control
*
* @return string
*/
protected abstract function getCollapsibleControlClass();
abstract protected function getCollapsibleControlClass();
/**
* Create an action link to be added at the end of the list
*
* @return HtmlElement
*/
protected abstract function createActionLink();
abstract protected function createActionLink();
/**
* Create the appropriate item list of this control
*
* @return HtmlElement
*/
protected abstract function createItemList();
abstract protected function createItemList();
/**
* Assemble a header element for this item list

View File

@ -28,6 +28,8 @@ class Settings extends BaseHtmlElement
{
$activeHome = $this->dashboard->getActiveHome();
if (count($this->dashboard->getEntries()) === 1 && $activeHome->getName() === DashboardHome::DEFAULT_HOME) {
$this->setAttribute('data-icinga-home', DashboardHome::DEFAULT_HOME);
foreach ($activeHome->getEntries() as $pane) {
$pane->setHome($activeHome);

View File

@ -1,5 +1,5 @@
<?php
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
/* Icinga Web 2 | (c) 2014-2022 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Widget\Tabextension;
@ -14,17 +14,17 @@ use ipl\Web\Widget\Link;
*/
class DashboardSettings implements Tabextension
{
/** @var array|null url params to be attached to the dropdown menus. */
private $urlParam;
/** @var array|null url params to be attached to the cog icon being rendered on the dashboard tab */
private $urlParams;
/**
* DashboardSettings constructor.
*
* @param array $urlParam
* @param array $urlParams
*/
public function __construct(array $urlParam = [])
public function __construct(array $urlParams = [])
{
$this->urlParam = $urlParam;
$this->urlParams = $urlParams;
}
/**
@ -34,8 +34,7 @@ class DashboardSettings implements Tabextension
*/
public function apply(Tabs $tabs)
{
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/settings');
$url = empty($this->urlParam) ? $url : $url->addParams($this->urlParam);
$url = Url::fromPath(Dashboard::BASE_ROUTE . '/settings')->addParams($this->urlParams);
$tabs->add('dashboard_settings', [
'icon' => 'service',
'url' => (string) $url,