From e0ee07fc391147f86d559319106a83517ea9c19b Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 6 Apr 2022 15:42:06 +0200 Subject: [PATCH] Remove some unused interfaces/attrs --- library/Icinga/Model/DashboardOverride.php | 53 ------------- .../Web/Dashboard/Common/OverridingWidget.php | 24 ------ .../Icinga/Web/Dashboard/DashboardHome.php | 74 +++++++++---------- library/Icinga/Web/Dashboard/Pane.php | 51 +------------ library/Icinga/Web/HomeMenu.php | 63 ---------------- 5 files changed, 36 insertions(+), 229 deletions(-) delete mode 100644 library/Icinga/Model/DashboardOverride.php delete mode 100644 library/Icinga/Web/Dashboard/Common/OverridingWidget.php delete mode 100644 library/Icinga/Web/HomeMenu.php diff --git a/library/Icinga/Model/DashboardOverride.php b/library/Icinga/Model/DashboardOverride.php deleted file mode 100644 index d498539dd..000000000 --- a/library/Icinga/Model/DashboardOverride.php +++ /dev/null @@ -1,53 +0,0 @@ - new Expression('0') - ]; - } - - public function getMetaData() - { - return ['priority' => t('Dashboard Priority Order')]; - } - - public function getSearchColumns() - { - return ['name']; - } - - public function getDefaultSort() - { - return 'dashboard.name'; - } - - public function createRelations(Relations $relations) - { - $relations->belongsTo('dashboard', Pane::class); - } -} diff --git a/library/Icinga/Web/Dashboard/Common/OverridingWidget.php b/library/Icinga/Web/Dashboard/Common/OverridingWidget.php deleted file mode 100644 index d4c6b5ec4..000000000 --- a/library/Icinga/Web/Dashboard/Common/OverridingWidget.php +++ /dev/null @@ -1,24 +0,0 @@ -getEntry($pane); - if (! $pane->isOverriding()) { - $pane->removeEntries(); + $pane->removeEntries(); - Dashboard::getConn()->delete(Pane::TABLE, [ - 'id = ?' => $pane->getUuid(), - 'home_id = ?' => $this->getUuid() - ]); - } + Dashboard::getConn()->delete(Pane::TABLE, [ + 'id = ?' => $pane->getUuid(), + 'home_id = ?' => $this->getUuid() + ]); return $this; } @@ -192,44 +190,42 @@ class DashboardHome extends BaseDashboard implements Sortable /** @var Pane $pane */ foreach ($panes as $pane) { $uuid = Dashboard::getSHA1($user->getUsername() . $this->getName() . $pane->getName()); - if (! $pane->isOverriding()) { - if (! $this->hasEntry($pane->getName()) && (! $origin || ! $origin->hasEntry($pane->getName()))) { - $conn->insert(Pane::TABLE, [ - 'id' => $uuid, - 'home_id' => $this->getUuid(), - 'name' => $pane->getName(), - 'label' => $pane->getTitle(), - 'username' => $user->getUsername(), - 'priority' => $order++ - ]); - } elseif (! $this->hasEntry($pane->getName()) || ! $origin || ! $origin->hasEntry($pane->getName())) { + if (! $this->hasEntry($pane->getName()) && (! $origin || ! $origin->hasEntry($pane->getName()))) { + $conn->insert(Pane::TABLE, [ + 'id' => $uuid, + 'home_id' => $this->getUuid(), + 'name' => $pane->getName(), + 'label' => $pane->getTitle(), + 'username' => $user->getUsername(), + 'priority' => $order++ + ]); + } elseif (! $this->hasEntry($pane->getName()) || ! $origin || ! $origin->hasEntry($pane->getName())) { + $filterCondition = [ + 'id = ?' => $pane->getUuid(), + 'home_id = ?' => $this->getUuid() + ]; + + if ($origin && $origin->hasEntry($pane->getName())) { $filterCondition = [ - 'id = ?' => $pane->getUuid(), - 'home_id = ?' => $this->getUuid() + 'id = ?' => $origin->getEntry($pane->getName())->getUuid(), + 'home_id = ?' => $origin->getUuid() ]; - - if ($origin && $origin->hasEntry($pane->getName())) { - $filterCondition = [ - 'id = ?' => $origin->getEntry($pane->getName())->getUuid(), - 'home_id = ?' => $origin->getUuid() - ]; - } - - $conn->update(Pane::TABLE, [ - 'id' => $uuid, - 'home_id' => $this->getUuid(), - 'label' => $pane->getTitle(), - 'priority' => $pane->getPriority() - ], $filterCondition); - } else { - // Failed to move the pane! Should have been handled already by the caller - break; } - $pane->setHome($this); - $pane->setUuid($uuid); + $conn->update(Pane::TABLE, [ + 'id' => $uuid, + 'home_id' => $this->getUuid(), + 'label' => $pane->getTitle(), + 'priority' => $pane->getPriority() + ], $filterCondition); + } else { + // Failed to move the pane! Should have been handled already by the caller + break; } + $pane->setHome($this); + $pane->setUuid($uuid); + if ($manageRecursive) { // Those dashboard panes are usually system defaults and go up when // the user is clicking on the "Use System Defaults" button diff --git a/library/Icinga/Web/Dashboard/Pane.php b/library/Icinga/Web/Dashboard/Pane.php index 1b2626648..cfdde08d8 100644 --- a/library/Icinga/Web/Dashboard/Pane.php +++ b/library/Icinga/Web/Dashboard/Pane.php @@ -9,7 +9,6 @@ use Icinga\Exception\ProgrammingError; use Icinga\Exception\ConfigurationError; use Icinga\Model; use Icinga\Web\Dashboard\Common\DashboardControls; -use Icinga\Web\Dashboard\Common\OverridingWidget; use Icinga\Web\Dashboard\Common\Sortable; use ipl\Stdlib\Filter; use ipl\Web\Url; @@ -19,26 +18,12 @@ use function ipl\Stdlib\get_php_type; /** * A pane, displaying different Dashboard dashlets */ -class Pane extends BaseDashboard implements Sortable, OverridingWidget +class Pane extends BaseDashboard implements Sortable { use DashboardControls; const TABLE = 'dashboard'; - /** - * Whether this widget overrides another widget - * - * @var bool - */ - protected $override; - - /** - * Number of users who have subscribed to this pane if (public) - * - * @var int - */ - protected $acceptance; - /** * A dashboard home this pane is a part of * @@ -46,40 +31,6 @@ class Pane extends BaseDashboard implements Sortable, OverridingWidget */ protected $home; - public function override(bool $override) - { - $this->override = $override; - - return $this; - } - - public function isOverriding() - { - return $this->override; - } - - /** - * Set the number of users who have subscribed to this pane if (public) - * - * @param int $acceptance - */ - public function setAcceptance($acceptance) - { - $this->acceptance = $acceptance; - - return $this; - } - - /** - * Get the number of users who have subscribed to this pane if (public) - * - * @return int - */ - public function getAcceptance() - { - return $this->acceptance; - } - /** * Get the dashboard home this pane is a part of * diff --git a/library/Icinga/Web/HomeMenu.php b/library/Icinga/Web/HomeMenu.php deleted file mode 100644 index 7bd640645..000000000 --- a/library/Icinga/Web/HomeMenu.php +++ /dev/null @@ -1,63 +0,0 @@ -initHome(); - } - - public function initHome() - { - $user = Dashboard::getUser(); - $dashboardItem = $this->getItem('dashboard'); - - $homes = Home::on(Dashboard::getConn()); - $homes->filter(Filter::equal('username', $user->getUsername())); - - foreach ($homes as $home) { - $dashboardHome = new DashboardHomeItem($home->name, [ - 'uuid' => $home->id, - 'label' => t($home->label), - 'priority' => $home->priority, - 'type' => $home->type, - ]); - - $dashboardItem->addChild($dashboardHome); - } - } - - /** - * Load dashboard homes form the navigation menu - * - * @return DashboardHome[] - */ - public function loadHomes() - { - $homes = []; - foreach ($this->getItem('dashboard')->getChildren() as $child) { - if (! $child instanceof DashboardHomeItem) { - continue; - } - - $homes[$child->getName()] = DashboardHome::create($child); - } - - return $homes; - } -}