diff --git a/library/Icinga/Model/Home.php b/library/Icinga/Model/Home.php index ac18d6b4b..a55ae8979 100644 --- a/library/Icinga/Model/Home.php +++ b/library/Icinga/Model/Home.php @@ -49,7 +49,7 @@ class Home extends Model public function getDefaultSort() { - return 'name'; + return 'priority'; } public function createRelations(Relations $relations) diff --git a/library/Icinga/Model/Pane.php b/library/Icinga/Model/Pane.php index 2974d68ba..3712aebc8 100644 --- a/library/Icinga/Model/Pane.php +++ b/library/Icinga/Model/Pane.php @@ -48,7 +48,7 @@ class Pane extends Model public function getDefaultSort() { - return 'icingaweb_dashboard.name'; + return 'priority'; } public function createRelations(Relations $relations) diff --git a/library/Icinga/Web/Dashboard/Common/DashboardEntries.php b/library/Icinga/Web/Dashboard/Common/DashboardEntries.php index 8c2f5e620..bb1a44e0e 100644 --- a/library/Icinga/Web/Dashboard/Common/DashboardEntries.php +++ b/library/Icinga/Web/Dashboard/Common/DashboardEntries.php @@ -18,13 +18,6 @@ trait DashboardEntries */ private $dashboards = []; - /** - * Whether to sort the entries when retrieving using getEntries() - * - * @var bool - */ - private $sortEntries = false; - public function hasEntries() { return ! empty($this->dashboards); @@ -46,23 +39,12 @@ trait DashboardEntries public function getEntries() { - if ($this->sortEntries) { - $this->sortEntries = false; - - // An entry can be added individually afterwards, it might be the case that the priority - // order gets mixed up, so we have to sort things here before being able to render them - uasort($this->dashboards, function (BaseDashboard $x, BaseDashboard $y) { - return $x->getPriority() <=> $y->getPriority(); - }); - } - return $this->dashboards; } public function setEntries(array $entries) { $this->dashboards = $entries; - $this->sortEntries = true; return $this; } @@ -73,7 +55,6 @@ trait DashboardEntries $this->getEntry($dashboard->getName())->fromArray($dashboard->toArray(false)); } else { $this->dashboards[$dashboard->getName()] = $dashboard; - $this->sortEntries = true; } return $this; @@ -134,14 +115,18 @@ trait DashboardEntries array_splice($data, $position, 0, [$dashboard]); } + $entries = []; foreach ($data as $index => $item) { if (count($data) !== 1) { $item->setPriority($index); } + $entries[$item->getName()] = $item; $this->manageEntry($item, $dashboard->getName() === $item->getName() ? $origin : null); } + $this->setEntries($entries); + return $this; } }