Skip to content

Commit

Permalink
Merge pull request #932 from nextcloud/feat/54-add-an-introduction-te…
Browse files Browse the repository at this point in the history
…xtarea

Feat/54 add an introduction textarea
  • Loading branch information
juliusknorr authored Apr 23, 2024
2 parents 9b9c67b + 0febcbe commit 6822b9e
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 28 deletions.
8 changes: 4 additions & 4 deletions cypress/e2e/tables-archive.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/tables-table.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@ describe('Manage a table', () => {
cy.get('.tile').contains('ToDo').click({ force: true })
cy.get('.modal__content').should('be.visible')
cy.get('.modal__content input[type="text"]').clear().type('to do list')
cy.get('.modal__content #description-editor .tiptap.ProseMirror').type('to Do List description')
cy.contains('button', 'Create table').click()

cy.contains('button', 'Create row').should('be.visible')
cy.contains('h1', 'to do list').should('be.visible')
cy.contains('table th', 'Task').should('exist')
cy.contains('.paragraph-content', 'to Do List description').should('be.visible')
})

it('Update title', () => {
it('Update title And Description', () => {
cy.get('.app-navigation__list').contains('to do list').click({ force: true })
cy.get('[data-cy="customTableAction"] button').click()
cy.get('.action-button__text').contains('Edit table').click()

cy.get('.modal__content').should('be.visible')
cy.get('.modal-container input').last().clear().type('ToDo list')
cy.get('.modal__content #description-editor .tiptap.ProseMirror').type('Updated ToDo List description')
cy.get('.modal-container button').contains('Save').click()

cy.wait(10).get('.toastify.toast-success').should('be.visible')
cy.get('.app-navigation__list').contains('ToDo list').should('exist')
cy.contains('.paragraph-content', 'Updated ToDo List description').should('be.visible')
})

it('Delete', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/RenameTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
10 changes: 6 additions & 4 deletions lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ public function show(int $id): DataResponse {
*
* @param string $title Title of the table
* @param string|null $emoji Emoji for the table
* @param string|null $description Description for the table
* @param string $template Template to use if wanted
*
* @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* 200: Tables returned
*/
public function create(string $title, ?string $emoji, string $template = 'custom'): DataResponse {
public function create(string $title, ?string $emoji, ?string $description, string $template = 'custom'): DataResponse {
try {
return new DataResponse($this->service->create($title, $template, $emoji)->jsonSerialize());
return new DataResponse($this->service->create($title, $template, $emoji, $description)->jsonSerialize());
} catch (InternalError|Exception $e) {
return $this->handleError($e);
}
Expand All @@ -101,15 +102,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<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/TableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
3 changes: 3 additions & 0 deletions lib/Db/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -94,6 +96,7 @@ public function jsonSerialize(): array {
'rowsCount' => $this->rowsCount ?: 0,
'columnsCount' => $this->columnsCount ?: 0,
'views' => $this->getViewsArray(),
'description' => $this->description ?:'',
];
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Migration/Version000000Date20210921000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addColumn('last_edit_at', Types::DATETIME, [
'notnull' => true,
]);
$table->addColumn('description', Types::TEXT, [
'default' => '',
'notnull' => false,
]);
$table->setPrimaryKey(['id']);
}

Expand Down
40 changes: 40 additions & 0 deletions lib/Migration/Version000900Date20240314000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/** @noinspection PhpUnused */

declare(strict_types=1);

namespace OCA\Tables\Migration;

use Closure;
use OCP\DB\Exception;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version000900Date20240314000000 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
* @throws Exception
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('tables_tables')) {
$table = $schema->getTable('tables_tables');
if (!$table->hasColumn('description')) {
$table->addColumn('description', Types::TEXT, [
'default' => '',
'notnull' => false,
]);
}
return $schema;
}
return null;
}
}
8 changes: 6 additions & 2 deletions lib/Service/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ public function find(int $id, bool $skipTableEnhancement = false, ?string $userI
* @throws InternalError
* @noinspection DuplicatedCode
*/
public function create(string $title, string $template, ?string $emoji, ?string $userId = null): Table {
public function create(string $title, string $template, ?string $emoji, ?string $description = '', ?string $userId = null): Table {
$userId = $this->permissionsService->preCheckUserId($userId, false); // we can assume that the $userId is set

$time = new DateTime();
$item = new Table();
$item->setTitle($title);
$item->setDescription($description);
if($emoji) {
$item->setEmoji($emoji);
}
Expand Down Expand Up @@ -455,7 +456,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 {
Expand Down Expand Up @@ -483,6 +484,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 {
Expand Down
17 changes: 17 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5077,6 +5077,15 @@
"nullable": true
}
},
{
"name": "description",
"in": "query",
"description": "Description for the table",
"schema": {
"type": "string",
"nullable": true
}
},
{
"name": "template",
"in": "query",
Expand Down Expand Up @@ -5386,6 +5395,14 @@
"nullable": true
}
},
{
"name": "description",
"in": "query",
"description": "the tables description",
"schema": {
"type": "string"
}
},
{
"name": "archived",
"in": "query",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions src/modules/main/sections/Table.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div>
<ElementDescription :active-element="table" :view-setting.sync="localViewSetting" />
<ElementTitle :active-element="table" :view-setting.sync="localViewSetting" />
<TableDescription :description="table.description" :read-only="true" />
<Dashboard v-if="hasViews"
:table="table"
@create-column="$emit('create-column')"
Expand All @@ -19,7 +20,8 @@
</template>

<script>
import ElementDescription from './ElementDescription.vue'
import TableDescription from './TableDescription.vue'
import ElementTitle from './ElementTitle.vue'
import Dashboard from './Dashboard.vue'
import DataTable from './DataTable.vue'
import { mapState } from 'vuex'
Expand All @@ -28,7 +30,8 @@ import { emit } from '@nextcloud/event-bus'
export default {
components: {
ElementDescription,
TableDescription,
ElementTitle,
Dashboard,
DataTable,
},
Expand Down Expand Up @@ -71,6 +74,7 @@ export default {
this.localViewSetting = this.viewSetting
},
},
methods: {
createView() {
emit('tables:view:create', { tableId: this.table.id, viewSetting: this.viewSetting.length > 0 ? this.viewSetting : this.localViewSetting })
Expand Down
Loading

0 comments on commit 6822b9e

Please sign in to comment.