Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .scoper-production-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ psr/http-client
psr/http-factory
psr/http-message
psr/simple-cache
symfony/uid
symfony/polyfill-uuid
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Share your tables and views with users and groups within your cloud.
Have a good time and manage whatever you want.

]]></description>
<version>2.2.0</version>
<version>2.2.1-dev.0</version>
<licence>AGPL-3.0-or-later</licence>
<author>Nextcloud GmbH and Nextcloud contributors</author>
<namespace>Tables</namespace>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"require": {
"phpoffice/phpspreadsheet": "^5.1",
"ext-json": "*",
"bamarni/composer-bin-plugin": "^1.9.1"
"bamarni/composer-bin-plugin": "^1.9.1",
"symfony/uid": "^6.4"
}
}
163 changes: 162 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/Analytics/AnalyticsDatasource.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ private function getData(int $nodeId, ?int $limit, ?int $offset, ?string $nodeTy
if ($datum['columnId'] === $column->getId()) {
// if column type selection, the corresponding labels need to be fetched
if ($column->getType() === 'selection') {
foreach ($column->getSelectionOptionsArray() as $option) {
if ($option['id'] === $datum['value']) {
$value = $option['label'];
foreach ($column->getSelectionOptionsCollection() as $option) {
if ($option->key() === $datum['value']) {
$value = $option->label();
}
}
} else {
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
use OCA\Tables\Middleware\Attribute\RequirePermission;
use OCA\Tables\Model\SelectionOptions;
use OCA\Tables\Model\ViewUpdateInput;
use OCA\Tables\ResponseDefinitions;
use OCA\Tables\Service\ColumnService;
Expand Down
70 changes: 54 additions & 16 deletions lib/Db/Column.php
Comment thread
blizzz marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
use JsonSerializable;
use OCA\Tables\Constants\ColumnType;
use OCA\Tables\Dto\Column as ColumnDto;
use OCA\Tables\Model\SelectionOptions;
use OCA\Tables\ResponseDefinitions;
use OCA\Tables\Service\ValueObject\ViewColumnInformation;
use OCA\Tables\Vendor\Symfony\Component\Uid\Uuid;
use ValueError;

/**
* @psalm-suppress PropertyNotSetInConstructor
*
* @psalm-import-type TablesColumn from ResponseDefinitions
*
* @method string|null getUuid()
* @method setUuid(?string $uuid)
* @method getTitle(): string
* @method setTitle(string $title)
* @method getTableId(): int
Expand Down Expand Up @@ -58,14 +62,12 @@
* @method setTextDefault(?string $textDefault)
* @method getTextAllowedPattern(): string
* @method setTextAllowedPattern(?string $textAllowedPattern)
* @method getTextAllowedPattern(): ?string
* @method getTextMaxLength(): int
* @method setTextMaxLength(?int $textMaxLength)
* @method getTextUnique(): bool
* @method setTextUnique(?bool $textUnique)
* @method getSelectionOptions(): string
* @method getSelectionDefault(): string
* @method setSelectionOptions(?string $selectionOptionsArray)
* @method string getSelectionOptions()
* @method setSelectionOptions(?string $selectionOptions)
* @method setSelectionDefault(?string $selectionDefault)
* @method getSelectionDefault(): ?string
* @method getDatetimeDefault(): string
Expand Down Expand Up @@ -113,6 +115,7 @@ class Column extends EntitySuper implements JsonSerializable {

public const META_ID_TITLE = 'id';

protected ?string $uuid = null;
protected ?string $title = null;
protected ?int $tableId = null;
protected ?string $createdBy = null;
Expand Down Expand Up @@ -164,6 +167,7 @@ class Column extends EntitySuper implements JsonSerializable {

public function __construct() {
$this->addType('id', 'integer');
$this->addType('uuid', 'string');
$this->addType('tableId', 'integer');
$this->addType('mandatory', 'boolean');

Expand All @@ -185,6 +189,8 @@ public function __construct() {
$this->addType('showUserStatus', 'boolean');

$this->addType('customSettings', 'string');

$this->addType('selectionOptions', 'string');
}

public static function isValidMetaTypeId(int $metaTypeId): bool {
Expand All @@ -197,8 +203,41 @@ public static function isValidMetaTypeId(int $metaTypeId): bool {
], true);
}

public function setter (string $name, array $args): void {
if ($name === 'uuid') {
$this->setOrAssignUuid((string)$args[0]);
return;
}

parent::setter($name, $args);
}

private function assignUuid(): void {
if ($this->uuid !== null) {
throw new \RuntimeException('This column already has a UUID, they are immutable');
}
$this->applyUuid(Uuid::v7()->toRfc4122());
}

private function setOrAssignUuid(?string $uuid): void {
if ($this->uuid !== null) {
throw new \RuntimeException('This column already has a UUID, they are immutable');
}
if ($uuid === null) {
$this->assignUuid();
return;
}
$this->applyUuid($uuid);
}

private function applyUuid(string $uuid): void {
$this->uuid = $uuid;
$this->markFieldUpdated('uuid');
}

Comment thread
blizzz marked this conversation as resolved.
public static function fromDto(ColumnDto $data): self {
$column = new self();
$column->assignUuid();
$column->setTitle($data->getTitle());
$column->setType($data->getType());
$column->setSubtype($data->getSubtype() ?? '');
Expand All @@ -214,8 +253,7 @@ public static function fromDto(ColumnDto $data): self {
$column->setNumberDecimals($data->getNumberDecimals());
$column->setNumberPrefix($data->getNumberPrefix() ?? '');
$column->setNumberSuffix($data->getNumberSuffix() ?? '');
$column->setSelectionOptions($data->getSelectionOptions());
$column->setSelectionDefault($data->getSelectionDefault());
$column->setSelectionOptionsCollection(SelectionOptions::createFromInputJsonString($data->getSelectionOptions() ?? '[]', $data->getSelectionDefault()));
$column->setDatetimeDefault($data->getDatetimeDefault());
$column->setUsergroupDefault($data->getUsergroupDefault());
$column->setUsergroupMultipleItems($data->getUsergroupMultipleItems());
Expand All @@ -241,18 +279,17 @@ public function setUsergroupDefaultArray(array $array):void {
$this->setUsergroup($json);
}

public function getSelectionOptionsArray(): array {
$options = $this->getSelectionOptions();
if ($options !== '' && $options !== null && $options !== 'null') {
return \json_decode($options, true);
} else {
return [];
}
public function getSelectionOptionsCollection(): SelectionOptions {
return SelectionOptions::createFromInputJsonString($this->getSelectionOptions() ?? '[]', $this->getSelectionDefault());
}

public function setSelectionOptionsArray(array $array):void {
$json = \json_encode($array);
$this->setSelectionOptions($json);
public function setSelectionOptionsCollection(SelectionOptions $selectionOptions): void {
$this->setSelectionOptions(json_encode($selectionOptions->jsonSerialize()));
$this->setSelectionDefault($selectionOptions->defaultSerialized());
}

public function getSelectionOptionsArray(): ?array {
return $this->getSelectionOptionsCollection()->jsonSerialize();
}

/**
Expand All @@ -261,6 +298,7 @@ public function setSelectionOptionsArray(array $array):void {
public function jsonSerialize(): array {
return [
'id' => $this->id,
'uuid' => $this->uuid,
Comment thread
blizzz marked this conversation as resolved.
'tableId' => $this->tableId,
'title' => $this->title,
'createdBy' => $this->createdBy,
Expand Down
Loading