Update priority order of the widget being moved properly

This commit is contained in:
Yonas Habteab 2022-05-20 17:23:55 +02:00
parent be973d29e2
commit a8a4738944
2 changed files with 9 additions and 7 deletions

View File

@ -192,7 +192,9 @@ class DashboardHome extends BaseDashboard implements Sortable
/** @var Pane $pane */
foreach ($panes as $pane) {
$uuid = Dashboard::getSHA1($user->getUsername() . $this->getName() . $pane->getName());
if (! $this->hasEntry($pane->getName()) && (! $origin || ! $origin->hasEntry($pane->getName()))) {
$movePane = $origin && $origin->hasEntry($pane->getName());
if (! $this->hasEntry($pane->getName()) && ! $movePane) {
$conn->insert(Pane::TABLE, [
'id' => $uuid,
'home_id' => $this->getUuid(),
@ -200,7 +202,7 @@ class DashboardHome extends BaseDashboard implements Sortable
'label' => $pane->getTitle(),
'priority' => $order++
]);
} elseif (! $this->hasEntry($pane->getName()) || ! $origin || ! $origin->hasEntry($pane->getName())) {
} elseif (! $this->hasEntry($pane->getName()) || ! $movePane) {
$filterCondition = [
'id = ?' => $pane->getUuid(),
'home_id = ?' => $this->getUuid()
@ -217,7 +219,7 @@ class DashboardHome extends BaseDashboard implements Sortable
'id' => $uuid,
'home_id' => $this->getUuid(),
'label' => $pane->getTitle(),
'priority' => $pane->getPriority()
'priority' => $movePane ? $order++ : $pane->getPriority()
], $filterCondition);
} else {
// Failed to move the pane! Should have been handled already by the caller

View File

@ -183,8 +183,9 @@ class Pane extends BaseDashboard implements Sortable
$url = $dashlet->getUrl();
$url = is_string($url) ?: $url->getRelativeUrl();
$uuid = Dashboard::getSHA1($user . $home->getName() . $this->getName() . $dashlet->getName());
$moveDashlet = $origin && $origin->hasEntry($dashlet->getName());
if (! $this->hasEntry($dashlet->getName()) && (! $origin || ! $origin->hasEntry($dashlet->getName()))) {
if (! $this->hasEntry($dashlet->getName()) && ! $moveDashlet) {
$conn->insert(Dashlet::TABLE, [
'id' => $uuid,
'dashboard_id' => $this->getUuid(),
@ -211,8 +212,7 @@ class Pane extends BaseDashboard implements Sortable
'module_dashlet_id' => $systemUuid
]);
}
} elseif (! $this->hasEntry($dashlet->getName()) || ! $origin
|| ! $origin->hasEntry($dashlet->getName())) {
} elseif (! $this->hasEntry($dashlet->getName()) || ! $moveDashlet) {
$filterCondition = [
'id = ?' => $dashlet->getUuid(),
'dashboard_id = ?' => $this->getUuid()
@ -230,7 +230,7 @@ class Pane extends BaseDashboard implements Sortable
'dashboard_id' => $this->getUuid(),
'label' => $dashlet->getTitle(),
'url' => $url,
'priority' => $dashlet->getPriority(),
'priority' => $moveDashlet ? $order++ : $dashlet->getPriority(),
'disabled' => DBUtils::bool2BoolEnum($dashlet->isDisabled())
], $filterCondition);
} else {