From 1f6e89526157b34ee9e0e4e4b43ec714bd56e379 Mon Sep 17 00:00:00 2001 From: grnd-alt Date: Thu, 14 Mar 2024 20:00:24 +0100 Subject: [PATCH 1/3] add description to Tables Signed-off-by: grnd-alt --- cypress/e2e/tables-archive.cy.js | 8 +- lib/Command/RenameTable.php | 3 +- lib/Controller/Api1Controller.php | 2 +- lib/Controller/ApiTablesController.php | 5 +- lib/Controller/TableController.php | 2 +- lib/Db/Table.php | 3 + .../Version000900Date20240314000000.php | 39 +++++ lib/Service/TableService.php | 5 +- openapi.json | 8 + ...lementDescription.vue => ElementTitle.vue} | 2 +- src/modules/main/sections/Table.vue | 10 +- .../main/sections/TableDescription.vue | 149 ++++++++++++++++++ src/modules/main/sections/TableWrapper.vue | 6 +- src/modules/main/sections/View.vue | 6 +- src/store/store.js | 20 ++- src/types/openapi/openapi.ts | 2 + 16 files changed, 248 insertions(+), 22 deletions(-) create mode 100644 lib/Migration/Version000900Date20240314000000.php rename src/modules/main/sections/{ElementDescription.vue => ElementTitle.vue} (98%) create mode 100644 src/modules/main/sections/TableDescription.vue diff --git a/cypress/e2e/tables-archive.cy.js b/cypress/e2e/tables-archive.cy.js index 0db3988b1..dff1a1032 100644 --- a/cypress/e2e/tables-archive.cy.js +++ b/cypress/e2e/tables-archive.cy.js @@ -20,12 +20,12 @@ describe('Archive tables/views', () => { cy.get('@tutorialTable').should('contain.text', 'Tutorial') cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true }) - cy.intercept({ method: 'PUT', url: '**/apps/tables/table/*'}).as('archiveTableReq') + cy.intercept({ method: 'PUT', url: '**/apps/tables/api/2/tables/*'}).as('archiveTableReq') cy.contains('Archive table').click({ force: true }) cy.wait('@archiveTableReq').then(request => { expect(request.response.statusCode).to.equal(200) - expect(request.response.body.archived).to.equal(true) + expect(request.response.body.ocs.data.archived).to.equal(true) }) cy.get('@tutorialTable').parent().parent().should('contain.text', 'Archived tables') @@ -37,12 +37,12 @@ describe('Archive tables/views', () => { cy.get('@tutorialTable').should('contain.text', 'Tutorial') cy.get('@tutorialTable').find('[aria-haspopup="menu"]').click({ force: true }) - cy.intercept({ method: 'PUT', url: '**/apps/tables/table/*' }).as('unarchiveTableReq') + cy.intercept({ method: 'PUT', url: '**/apps/tables/api/2/tables/*' }).as('unarchiveTableReq') cy.contains('Unarchive table').click({ force: true }) cy.wait('@unarchiveTableReq').then(request => { expect(request.response.statusCode).to.equal(200) - expect(request.response.body.archived).to.equal(false) + expect(request.response.body.ocs.data.archived).to.equal(false) }) cy.get('@tutorialTable').parent().should('contain.text', 'Tables') diff --git a/lib/Command/RenameTable.php b/lib/Command/RenameTable.php index 3a41153b5..d492cec77 100644 --- a/lib/Command/RenameTable.php +++ b/lib/Command/RenameTable.php @@ -82,9 +82,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $title = $input->getArgument('title'); $emoji = $input->getOption('emoji'); $archived = $input->getOption('archived'); + $description = $input->getOption('description'); try { - $table = $this->tableService->update($id, $title, $emoji, $archived, ''); + $table = $this->tableService->update($id, $title, $emoji, $description, $archived, ''); $arr = $table->jsonSerialize(); unset($arr['hasShares']); diff --git a/lib/Controller/Api1Controller.php b/lib/Controller/Api1Controller.php index f9614349b..438cad369 100644 --- a/lib/Controller/Api1Controller.php +++ b/lib/Controller/Api1Controller.php @@ -181,7 +181,7 @@ public function getTable(int $tableId): DataResponse { */ public function updateTable(int $tableId, string $title = null, string $emoji = null, ?bool $archived = false): DataResponse { try { - return new DataResponse($this->tableService->update($tableId, $title, $emoji, $archived, $this->userId)->jsonSerialize()); + return new DataResponse($this->tableService->update($tableId, $title, $emoji, null, $archived, $this->userId)->jsonSerialize()); } catch (PermissionError $e) { $this->logger->warning('A permission error occurred: ' . $e->getMessage()); $message = ['message' => $e->getMessage()]; diff --git a/lib/Controller/ApiTablesController.php b/lib/Controller/ApiTablesController.php index 6748d109f..11cf56962 100644 --- a/lib/Controller/ApiTablesController.php +++ b/lib/Controller/ApiTablesController.php @@ -101,15 +101,16 @@ public function create(string $title, ?string $emoji, string $template = 'custom * @param string|null $title New table title * @param string|null $emoji New table emoji * @param bool $archived whether the table is archived + * @param string $description the tables description * @return DataResponse|DataResponse * * 200: Tables returned * 403: No permissions * 404: Not found */ - public function update(int $id, ?string $title = null, ?string $emoji = null, ?bool $archived = null): DataResponse { + public function update(int $id, ?string $title = null, ?string $emoji = null, ?string $description = null, ?bool $archived = null): DataResponse { try { - return new DataResponse($this->service->update($id, $title, $emoji, $archived, $this->userId)->jsonSerialize()); + return new DataResponse($this->service->update($id, $title, $emoji, $description, $archived, $this->userId)->jsonSerialize()); } catch (PermissionError $e) { return $this->handlePermissionError($e); } catch (InternalError $e) { diff --git a/lib/Controller/TableController.php b/lib/Controller/TableController.php index 65d4e7fd0..0c2e2fa23 100644 --- a/lib/Controller/TableController.php +++ b/lib/Controller/TableController.php @@ -72,7 +72,7 @@ public function destroy(int $id): DataResponse { */ public function update(int $id, string $title = null, string $emoji = null, ?bool $archived = null): DataResponse { return $this->handleError(function () use ($id, $title, $emoji, $archived) { - return $this->service->update($id, $title, $emoji, $archived, $this->userId); + return $this->service->update($id, $title, $emoji, null, $archived, $this->userId); }); } } diff --git a/lib/Db/Table.php b/lib/Db/Table.php index 242496fe7..8877d04bb 100644 --- a/lib/Db/Table.php +++ b/lib/Db/Table.php @@ -18,6 +18,7 @@ * @method setEmoji(string $emoji) * @method getArchived(): bool * @method setArchived(bool $archived) + * @method setDescription(string $description) * @method getOwnership(): string * @method setOwnership(string $ownership) * @method getOwnerDisplayName(): string @@ -66,6 +67,7 @@ class Table extends Entity implements JsonSerializable { protected ?int $columnsCount = 0; protected ?array $views = null; protected ?array $columns = null; + protected ?string $description = null; public function __construct() { $this->addType('id', 'integer'); @@ -94,6 +96,7 @@ public function jsonSerialize(): array { 'rowsCount' => $this->rowsCount ?: 0, 'columnsCount' => $this->columnsCount ?: 0, 'views' => $this->getViewsArray(), + 'description' => $this->description ?:'', ]; } diff --git a/lib/Migration/Version000900Date20240314000000.php b/lib/Migration/Version000900Date20240314000000.php new file mode 100644 index 000000000..7dcf5ab3f --- /dev/null +++ b/lib/Migration/Version000900Date20240314000000.php @@ -0,0 +1,39 @@ +hasTable('tables_tables')) { + $table = $schema->getTable('tables_tables'); + $table->addColumn('description', Types::TEXT, [ + 'default' => '', + 'notnull' => false, + ]); + return $schema; + } + return null; + } + +} diff --git a/lib/Service/TableService.php b/lib/Service/TableService.php index e28fe5fcb..7f6dec1f8 100644 --- a/lib/Service/TableService.php +++ b/lib/Service/TableService.php @@ -431,7 +431,7 @@ public function delete(int $id, ?string $userId = null): Table { * @throws NotFoundError * @throws PermissionError */ - public function update(int $id, ?string $title, ?string $emoji, ?bool $archived = null, ?string $userId = null): Table { + public function update(int $id, ?string $title, ?string $emoji, ?string $description, ?bool $archived = null, ?string $userId = null): Table { $userId = $this->permissionsService->preCheckUserId($userId); try { @@ -459,6 +459,9 @@ public function update(int $id, ?string $title, ?string $emoji, ?bool $archived if ($archived !== null) { $table->setArchived($archived); } + if ($description !== null) { + $table->setDescription($description); + } $table->setLastEditBy($userId); $table->setLastEditAt($time->format('Y-m-d H:i:s')); try { diff --git a/openapi.json b/openapi.json index 5a96f7ff9..18788f5ec 100644 --- a/openapi.json +++ b/openapi.json @@ -5386,6 +5386,14 @@ "nullable": true } }, + { + "name": "description", + "in": "query", + "description": "the tables description", + "schema": { + "type": "string" + } + }, { "name": "archived", "in": "query", diff --git a/src/modules/main/sections/ElementDescription.vue b/src/modules/main/sections/ElementTitle.vue similarity index 98% rename from src/modules/main/sections/ElementDescription.vue rename to src/modules/main/sections/ElementTitle.vue index 5946c9cd4..da7cf87a9 100644 --- a/src/modules/main/sections/ElementDescription.vue +++ b/src/modules/main/sections/ElementTitle.vue @@ -34,7 +34,7 @@ import FilterRemove from 'vue-material-design-icons/FilterRemove.vue' import NcSmallButton from '../../../shared/components/ncSmallButton/NcSmallButton.vue' export default { - name: 'ElementDescription', + name: 'ElementTitle', components: { NcUserBubble, diff --git a/src/modules/main/sections/Table.vue b/src/modules/main/sections/Table.vue index 28dbe5e82..70e3205ec 100644 --- a/src/modules/main/sections/Table.vue +++ b/src/modules/main/sections/Table.vue @@ -1,6 +1,7 @@