From 052682accd3073cae9922b784725418a77553295 Mon Sep 17 00:00:00 2001 From: Konstantin Myakshin Date: Thu, 25 Jul 2024 17:54:10 +0200 Subject: [PATCH] Save full width of page on server Signed-off-by: Konstantin Myakshin --- appinfo/routes.php | 2 + lib/Controller/PageController.php | 11 ++++ lib/Db/Page.php | 8 +++ .../Version021200Date20240725154232.php | 35 +++++++++++++ lib/Model/PageInfo.php | 15 +++++- lib/Service/PageService.php | 28 ++++++++-- src/apis/collectives/pages.js | 14 +++++ src/components/Page.vue | 5 +- src/components/Page/PageActionMenu.vue | 8 +-- src/components/Page/Version.vue | 3 +- src/stores/pages.js | 51 ++++++------------- .../features/bootstrap/FeatureContext.php | 20 ++++++++ tests/Integration/features/pages.feature | 5 ++ 13 files changed, 156 insertions(+), 49 deletions(-) create mode 100644 lib/Migration/Version021200Date20240725154232.php diff --git a/appinfo/routes.php b/appinfo/routes.php index 7547951b5..ad6690a3e 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -61,6 +61,8 @@ 'verb' => 'POST', 'requirements' => ['collectiveId' => '\d+', 'parentId' => '\d+']], ['name' => 'page#touch', 'url' => '/_api/{collectiveId}/_pages/{id}/touch', 'verb' => 'GET', 'requirements' => ['collectiveId' => '\d+', 'id' => '\d+']], + ['name' => 'page#setFullWidth', 'url' => '/_api/{collectiveId}/_pages/{id}/fullWidth', + 'verb' => 'PUT', 'requirements' => ['collectiveId' => '\d+', 'id' => '\d+']], ['name' => 'page#contentSearch', 'url' => '/_api/{collectiveId}/_pages/search', 'verb' => 'GET', 'requirements' => ['collectiveId' => '\d+', 'filterString' => '\s+']], ['name' => 'page#moveOrCopy', 'url' => '/_api/{collectiveId}/_pages/{id}', diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 7dd272d76..5e096e9e1 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -137,6 +137,17 @@ public function setEmoji(int $collectiveId, int $id, ?string $emoji = null): Dat }, $this->logger); } + #[NoAdminRequired] + public function setFullWidth(int $collectiveId, int $id, bool $fullWidth): DataResponse { + return $this->handleErrorResponse(function () use ($collectiveId, $id, $fullWidth): array { + $userId = $this->getUserId(); + $pageInfo = $this->service->setFullWidth($collectiveId, $id, $userId, $fullWidth); + return [ + "data" => $pageInfo, + ]; + }, $this->logger); + } + #[NoAdminRequired] public function setSubpageOrder(int $collectiveId, int $id, ?string $subpageOrder = null): DataResponse { return $this->handleErrorResponse(function () use ($collectiveId, $id, $subpageOrder): array { diff --git a/lib/Db/Page.php b/lib/Db/Page.php index b3be52292..b0279912f 100644 --- a/lib/Db/Page.php +++ b/lib/Db/Page.php @@ -24,6 +24,8 @@ * @method void setEmoji(?string $value) * @method string getSubpageOrder() * @method void setSubpageOrder(string $value) + * @method bool getFullWidth() + * @method void setFullWidth(bool $value) * @method int|null getTrashTimestamp() * @method void setTrashTimestamp(?int $trashTimestamp) */ @@ -32,8 +34,13 @@ class Page extends Entity implements JsonSerializable { protected ?string $lastUserId = null; protected ?string $emoji = null; protected ?string $subpageOrder = null; + protected ?bool $fullWidth = null; protected ?int $trashTimestamp = null; + public function __construct() { + $this->addType('fullWidth', 'bool'); + } + public function jsonSerialize(): array { return [ 'id' => $this->id, @@ -41,6 +48,7 @@ public function jsonSerialize(): array { 'lastUserId' => $this->lastUserId, 'emoji' => $this->emoji, 'subpageOrder' => json_decode($this->getSubpageOrder() ?? '[]', true, 512, JSON_THROW_ON_ERROR), + 'fullWidth' => $this->fullWidth, 'trashTimestamp' => $this->trashTimestamp, ]; } diff --git a/lib/Migration/Version021200Date20240725154232.php b/lib/Migration/Version021200Date20240725154232.php new file mode 100644 index 000000000..1c479c6e2 --- /dev/null +++ b/lib/Migration/Version021200Date20240725154232.php @@ -0,0 +1,35 @@ +getTable('collectives_pages'); + if (!$table->hasColumn('full_width')) { + $table->addColumn('full_width', Types::BOOLEAN, [ + 'notnull' => false, + 'default' => false, + ]); + + return $schema; + } + + return null; + } +} diff --git a/lib/Model/PageInfo.php b/lib/Model/PageInfo.php index 0f93c5333..a4b2cfeee 100644 --- a/lib/Model/PageInfo.php +++ b/lib/Model/PageInfo.php @@ -24,6 +24,7 @@ class PageInfo implements JsonSerializable { private ?string $lastUserId = null; private ?string $lastUserDisplayName = null; private ?string $emoji = null; + private bool $fullWidth = false; private ?string $subpageOrder = null; private ?int $trashTimestamp = null; private string $title; @@ -67,6 +68,14 @@ public function setEmoji(?string $emoji): void { $this->emoji = $emoji; } + public function isFullWidth(): bool { + return $this->fullWidth; + } + + public function setFullWidth(bool $fullWidth): void { + $this->fullWidth = $fullWidth; + } + public function getSubpageOrder(): ?string { return $this->subpageOrder; } @@ -153,6 +162,7 @@ public function jsonSerialize(): array { 'lastUserId' => $this->lastUserId, 'lastUserDisplayName' => $this->lastUserDisplayName, 'emoji' => $this->emoji, + 'isFullWidth' => $this->fullWidth, 'subpageOrder' => json_decode($this->subpageOrder ?? '[]', true, 512, JSON_THROW_ON_ERROR), 'trashTimestamp' => $this->trashTimestamp, 'title' => $this->title, @@ -170,7 +180,7 @@ public function jsonSerialize(): array { * @throws InvalidPathException * @throws NotFoundException */ - public function fromFile(File $file, int $parentId, ?string $lastUserId = null, ?string $lastUserDisplayName = null, ?string $emoji = null, ?string $subpageOrder = null): void { + public function fromFile(File $file, int $parentId, ?string $lastUserId = null, ?string $lastUserDisplayName = null, ?string $emoji = null, ?string $subpageOrder = null, bool $fullWidth = false): void { $this->setId($file->getId()); // Set folder name as title for all index pages except the collective landing page $dirName = dirname($file->getInternalPath()); @@ -197,6 +207,9 @@ public function fromFile(File $file, int $parentId, ?string $lastUserId = null, if ($emoji !== null) { $this->setEmoji($emoji); } + if ($fullWidth !== null) { + $this->setFullWidth($fullWidth); + } if ($subpageOrder !== null) { $this->setSubpageOrder($subpageOrder); } diff --git a/lib/Service/PageService.php b/lib/Service/PageService.php index 45333a454..21bdb1a2c 100644 --- a/lib/Service/PageService.php +++ b/lib/Service/PageService.php @@ -205,7 +205,8 @@ private function getPageByFile(File $file, ?Node $parent = null): PageInfo { $lastUserId, $lastUserId ? $this->userManager->getDisplayName($lastUserId) : null, $emoji, - $subpageOrder); + $subpageOrder, + $page->getFullWidth()); } catch (FilesNotFoundException | InvalidPathException $e) { throw new NotFoundException($e->getMessage(), 0, $e); } @@ -233,7 +234,8 @@ private function getTrashPageByFile(File $file, string $filename, string $timest $lastUserId, $lastUserId ? $this->userManager->getDisplayName($lastUserId) : null, $emoji, - $subpageOrder); + $subpageOrder, + $page->getFullWidth()); $pageInfo->setTrashTimestamp($trashTimestamp); $pageInfo->setFilePath(''); $pageInfo->setTitle(basename($filename, PageInfo::SUFFIX)); @@ -258,13 +260,16 @@ private function notifyPush(int $collectiveId): void { } } - private function updatePage(int $collectiveId, int $fileId, string $userId, ?string $emoji = null): void { + private function updatePage(int $collectiveId, int $fileId, string $userId, ?string $emoji = null, ?bool $fullWidth = null): void { $page = new Page(); $page->setFileId($fileId); $page->setLastUserId($userId); if ($emoji !== null) { $page->setEmoji($emoji); } + if ($fullWidth !== null) { + $page->setFullWidth($fullWidth); + } $this->pageMapper->updateOrInsert($page); $this->notifyPush($collectiveId); } @@ -607,6 +612,23 @@ public function touch(int $collectiveId, int $id, string $userId): PageInfo { return $pageInfo; } + /** + * @throws MissingDependencyException + * @throws NotFoundException + * @throws NotPermittedException + */ + public function setFullWidth(int $collectiveId, int $id, string $userId, bool $fullWidth): PageInfo { + $this->verifyEditPermissions($collectiveId, $userId); + $folder = $this->getCollectiveFolder($collectiveId, $userId); + $file = $this->nodeHelper->getFileById($folder, $id); + $pageInfo = $this->getPageByFile($file); + $pageInfo->setLastUserId($userId); + $pageInfo->setLastUserDisplayName($this->userManager->getDisplayName($userId)); + $pageInfo->setFullWidth($fullWidth); + $this->updatePage($collectiveId, $pageInfo->getId(), $userId, fullWidth: $fullWidth); + return $pageInfo; + } + /** * @throws NotFoundException */ diff --git a/src/apis/collectives/pages.js b/src/apis/collectives/pages.js index 018f2b198..819d529e3 100644 --- a/src/apis/collectives/pages.js +++ b/src/apis/collectives/pages.js @@ -157,6 +157,20 @@ export function setPageEmoji(context, pageId, emoji) { ) } +/** + * Set full width for a page + * + * @param {object} context - either the current collective or a share context + * @param {number} pageId - Id of the page to update + * @param {boolean} fullWidth - Full width for the page + */ +export function setFullWidth(context, pageId, fullWidth) { + return axios.put( + pagesUrl(context, pageId, 'fullWidth'), + { fullWidth }, + ) +} + /** * Set subpageOrder for a page * diff --git a/src/components/Page.vue b/src/components/Page.vue index c0721b9fc..bc13e7b5d 100644 --- a/src/components/Page.vue +++ b/src/components/Page.vue @@ -4,7 +4,7 @@ -->