Skip to content

Commit

Permalink
repair schema export and import
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 Aug 26, 2024
1 parent 061f7ca commit 814849b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function createFromScheme(string $title, string $emoji, string $descripti

$column['datetimeDefault'],

$column['usergroupDefault'],
$column['usergroupDefault'] || [],

Check failure on line 166 in lib/Controller/ApiTablesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidScalarArgument

lib/Controller/ApiTablesController.php:166:6: InvalidScalarArgument: Argument 21 of OCA\Tables\Service\ColumnService::create expects null|string, but bool provided (see https://psalm.dev/012)

Check failure on line 166 in lib/Controller/ApiTablesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

TypeDoesNotContainType

lib/Controller/ApiTablesController.php:166:37: TypeDoesNotContainType: Operand of type array<never, never> is always falsy (see https://psalm.dev/056)

Check failure on line 166 in lib/Controller/ApiTablesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidScalarArgument

lib/Controller/ApiTablesController.php:166:6: InvalidScalarArgument: Argument 21 of OCA\Tables\Service\ColumnService::create expects null|string, but bool provided (see https://psalm.dev/012)

Check failure on line 166 in lib/Controller/ApiTablesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

TypeDoesNotContainType

lib/Controller/ApiTablesController.php:166:37: TypeDoesNotContainType: Operand of type array<never, never> is always falsy (see https://psalm.dev/056)
$column['usergroupMultipleItems'],
$column['usergroupSelectUsers'],
$column['usergroupSelectGroups'],
Expand Down
62 changes: 62 additions & 0 deletions lib/Model/TableScheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Tables\Model;

use JsonSerializable;
use OCA\Tables\Db\Column;
use OCA\Tables\Db\View;

class TableScheme implements JsonSerializable {

Check failure on line 14 in lib/Model/TableScheme.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

DuplicateClass

lib/Model/TableScheme.php:14:7: DuplicateClass: Class OCA\Tables\Model\TableScheme has already been defined in /home/runner/actions-runner/_work/tables/tables/lib/Controller/TableScheme.php (see https://psalm.dev/071)

protected ?string $title = null;
protected ?string $emoji = null;

/** @var Column[]|null */
protected ?array $columns = null;

/** @var View[]|null */
protected ?array $views = null;
protected ?string $description = null;
protected ?string $tablesVersion = null;

public function __construct(string $title, string $emoji, array $columns, array $view, string $description, string $tablesVersion) {
$this->tablesVersion = $tablesVersion;
$this->title = $title;
$this->emoji = $emoji;
$this->columns = $columns;
$this->description = $description;
$this->views = $view;
}

public function getTitle():string {
return $this->title | '';
}

public function jsonSerialize(): array {
return [
'title' => $this->title ?: '',
'emoji' => $this->emoji,
'columns' => $this->columns,
'views' => $this->views,
'description' => $this->description ?:'',
'tablesVersion' => $this->tablesVersion,
];
}

public function getEmoji(): ?string {
return $this->emoji;
}

public function getColumns(): ?array {
return $this->columns;
}

public function getDescription(): ?string {
return $this->description;
}
}
10 changes: 5 additions & 5 deletions src/modules/modals/CreateTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ export default {
this.$emit('close')
},
async submit() {
if (this.templateChoice === 'scheme') {
emit('tables:modal:scheme', this.title)
this.actionCancel()
return
}
if (this.title === '') {
if (this.templateChoice === 'scheme') {
emit('tables:modal:scheme', {})
this.actionCancel()
return
}
showError(t('tables', 'Cannot create new table. Title is missing.'))
this.errorTitle = true
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/modules/modals/ImportScheme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class="hidden-visually"
:accept="mimeTypes.join(',')"
@change="onUploadFileInputChange">
<span v-if="selectedUploadFile">{{ selectedUploadFile?.name }}</span>
<div class="row">
<div class="fix-col-4 end">
<NcButton :aria-label="t('tables', 'Import')" type="primary" @click="actionSubmit">
Expand Down Expand Up @@ -50,6 +51,10 @@ export default {
type: Boolean,
default: false,
},
title: {
type: String,
default: '',
},
},
data() {
return {
Expand Down Expand Up @@ -77,6 +82,9 @@ export default {
reader.readAsText(this.selectedUploadFile, 'UTF-8')
reader.onload = (evt) => {
const json = JSON.parse(evt.target.result)
if (this.title !== '') {
json.title = this.title
}
axios.post(generateOcsUrl('/apps/tables/api/2/tables/scheme'), json).then(async res => {
if (res.status === 200) {
await this.$store.dispatch('loadTablesFromBE')
Expand Down
4 changes: 3 additions & 1 deletion src/modules/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ImportScheme
:show-modal="showImportScheme"
:title="importSchemeTitle"
@close="showImportScheme = false" />
<CreateContext :show-modal="showModalCreateContext" @close="showModalCreateContext = false" />
<EditContext :context-id="editContext" :show-modal="editContext !== null" @close="editContext = null" />
Expand Down Expand Up @@ -108,6 +109,7 @@ export default {
showModalCreateContext: false,
importToElement: null,
showImportScheme: false,
importSchemeTitle: '',
createViewTableId: null, // if null, no modal open
tableToDelete: null,
viewToDelete: null,
Expand Down Expand Up @@ -152,7 +154,7 @@ export default {
// misc
subscribe('tables:modal:import', element => { this.importToElement = element })
subscribe('tables:modal:scheme', () => { this.showImportScheme = true })
subscribe('tables:modal:scheme', title => { this.importSchemeTitle = title; this.showImportScheme = true })
// context
subscribe('tables:context:create', () => { this.showModalCreateContext = true })
Expand Down

0 comments on commit 814849b

Please sign in to comment.