Skip to content

Commit

Permalink
add tables Description to createTable
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Apr 17, 2024
1 parent 91bc7d0 commit 4472313
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
5 changes: 3 additions & 2 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 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
11 changes: 6 additions & 5 deletions lib/Migration/Version000900Date20240314000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

if ($schema->hasTable('tables_tables')) {
$table = $schema->getTable('tables_tables');
$table->addColumn('description', Types::TEXT, [
'default' => '',
'notnull' => false,
]);
if (!$table->hasColumn('description')) {
$table->addColumn('description', Types::TEXT, [
'default' => '',
'notnull' => false,
]);
}
return $schema;
}
return null;
}

}
3 changes: 2 additions & 1 deletion lib/Service/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,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
9 changes: 9 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
17 changes: 17 additions & 0 deletions src/modules/modals/CreateTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
@input="titleChangedManually">
</div>
</div>
<div class="row">
<div class="col-4 mandatory">
{{ t('tables', 'Description') }}
</div>
<div class="col-4">
<TableDescription :description.sync="description" :read-only="false" />
</div>
</div>
<div class="row space-T">
<div class="col-2 block space-R space-B">
<NcTile
Expand Down Expand Up @@ -65,6 +73,7 @@ import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import NcTile from '../../shared/components/ncTile/NcTile.vue'
import displayError from '../../shared/utils/displayError.js'
import TableDescription from '../../modules/main/sections/TableDescription.vue'
export default {
name: 'CreateTable',
Expand All @@ -73,6 +82,7 @@ export default {
NcEmojiPicker,
NcButton,
NcTile,
TableDescription,
},
props: {
showModal: {
Expand All @@ -84,6 +94,7 @@ export default {
return {
title: '',
icon: '',
description: '',
errorTitle: false,
templates: null,
templateChoice: 'custom',
Expand Down Expand Up @@ -159,6 +170,7 @@ export default {
async sendNewTableToBE(template) {
const data = {
title: this.title,
description: this.description,
emoji: this.icon,
template,
}
Expand Down Expand Up @@ -190,6 +202,11 @@ export default {
</script>
<style lang="scss" scoped>
:deep(.element-description) {
padding-inline: 0 !important;
max-width: 100%;
}
.modal__content {
padding-right: 0 !important;
}
Expand Down
18 changes: 1 addition & 17 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default new Vuex.Store({
let res = null

try {
res = await axios.post(generateUrl('/apps/tables/table'), data)
res = (await axios.post(generateOcsUrl('/apps/tables/api/2/tables'), data)).data.ocs
} catch (e) {
displayError(e, t('tables', 'Could not insert table.'))
return false
Expand Down Expand Up @@ -262,22 +262,6 @@ export default new Vuex.Store({
}
return true
},
async updateTableProperty({ state, commit, dispatch }, { id, data, property }) {
let res = null

try {
res = (await axios.put(generateOcsUrl('/apps/tables/api/2/tables/' + id), data)).data.ocs
} catch (e) {
displayError(e, t('tables', 'Could not update table.'))
return false
}

const table = res.data
const tables = state.tables
const index = tables.findIndex(t => t.id === table.id)
Vue.set(state.tables[index], property, data[property])
return true
},
async updateTable({ state, commit, dispatch }, { id, data }) {
let res = null

Expand Down
2 changes: 2 additions & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,8 @@ export type operations = {
title: string;
/** @description Emoji for the table */
emoji?: string | null;
/** @description Description for the table */
description?: string | null;
/** @description Template to use if wanted */
template?: string;
};
Expand Down

0 comments on commit 4472313

Please sign in to comment.