diff --git a/lib/Service/ContextService.php b/lib/Service/ContextService.php index 10937a1495..802779ae88 100644 --- a/lib/Service/ContextService.php +++ b/lib/Service/ContextService.php @@ -5,6 +5,7 @@ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCA\Tables\Service; use InvalidArgumentException; @@ -237,6 +238,56 @@ public function update(int $contextId, string $userId, ?string $name, ?string $i $currentPages[$updatedContent->getPageId()]['content'][$updatedContent->getId()] = $updatedContent->jsonSerialize(); } unset($nodesBeingAdded); + + // Update order of nodes + $startPageId = null; + foreach ($currentPages as $page) { + if ($page['page_type'] === Page::TYPE_STARTPAGE) { + $startPageId = $page['id']; + break; + } + } + + if ($startPageId !== null && isset($currentPages[$startPageId]['content'])) { + $nodeTypeIdToRelId = []; + foreach ($currentNodes as $relId => $nodeData) { + $key = sprintf('t%di%d', $nodeData['node_type'], $nodeData['node_id']); + $nodeTypeIdToRelId[$key] = $relId; + } + + $relIdToContentId = []; + foreach ($currentPages[$startPageId]['content'] as $contentId => $content) { + $relIdToContentId[$content['node_rel_id']] = $contentId; + } + + $contentsToUpdate = []; + foreach ($nodes as $index => $node) { + $key = sprintf('t%di%d', $node['type'], $node['id']); + if (isset($nodeTypeIdToRelId[$key])) { + $relId = $nodeTypeIdToRelId[$key]; + if (isset($relIdToContentId[$relId])) { + $contentId = $relIdToContentId[$relId]; + $newOrder = ($index + 1) * 10; + + // Optimistic check: if order is already correct in memory, we might skip? + // However, simpler to just add to update list, updateContentOrder should handle exceptions. + // But to avoid DB writes if nothing changed: + if ($currentPages[$startPageId]['content'][$contentId]['order'] !== $newOrder) { + $contentsToUpdate[] = [ + 'id' => $contentId, + 'order' => $newOrder + ]; + $currentPages[$startPageId]['content'][$contentId]['order'] = $newOrder; + $hasUpdatedNodeInformation = true; + } + } + } + } + + if (!empty($contentsToUpdate)) { + $this->updateContentOrder($startPageId, $contentsToUpdate); + } + } } $context = $this->contextMapper->update($context); @@ -305,8 +356,10 @@ public function transfer(int $contextId, string $newOwnerId, int $newOwnerType): $context = $this->contextMapper->update($context); $auditEvent = new CriticalActionPerformedEvent( - sprintf('Tables application with ID %d was transferred to user %s', - $contextId, $newOwnerId, + sprintf( + 'Tables application with ID %d was transferred to user %s', + $contextId, + $newOwnerId, ) ); diff --git a/src/modules/modals/EditContext.vue b/src/modules/modals/EditContext.vue index 6c74f0007a..be2d200b76 100644 --- a/src/modules/modals/EditContext.vue +++ b/src/modules/modals/EditContext.vue @@ -3,10 +3,7 @@ - SPDX-License-Identifier: AGPL-3.0-or-later --> @@ -83,6 +86,10 @@ export default { this.contextResources.push(resource) this.localResources = this.contextResources }, + updateOrder(resources) { + this.contextResources = resources + this.localResources = this.contextResources + }, updateReceivers(receivers) { this.localReceivers = receivers }, diff --git a/src/shared/components/ncContextResource/ResourceList.vue b/src/shared/components/ncContextResource/ResourceList.vue index 2738955c23..cbedaa9500 100644 --- a/src/shared/components/ncContextResource/ResourceList.vue +++ b/src/shared/components/ncContextResource/ResourceList.vue @@ -5,10 +5,16 @@ @@ -79,4 +111,9 @@ export default { .resource-label { font-style: italic; } + +.move-button { + cursor: move !important; + padding-right: 10px; +}