Skip to content

Commit

Permalink
enh: add value_type column
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Jul 8, 2024
1 parent 6ec8e71 commit d175f59
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 78 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ public function indexViewColumns(int $viewId): DataResponse {
* @param string|null $selectionOptions Options for a selection (json array{id: int, label: string})
* @param string|null $selectionDefault Default option IDs for a selection (json int[])
* @param string|null $datetimeDefault Default value, if column is datetime
* @param string|null $usergroupDefault Default value, if column is usergroup (json array{id: string, icon: string, isUser: bool, displayName: string})
* @param string|null $usergroupDefault Default value, if column is usergroup (json array{id: string, type: int})
* @param bool|null $usergroupMultipleItems Can select multiple users or/and groups, if column is usergroup
* @param bool|null $usergroupSelectUsers Can select users, if column type is usergroup
* @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ApiColumnsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
*
* @param int $baseNodeId Context of the column creation
* @param string $title Title
* @param string|null $usergroupDefault Json array{id: string, isUser: bool, displayName: string}, eg [{"id": "admin", "isUser": true, "displayName": "admin"}, {"id": "user1", "isUser": true, "displayName": "user1"}]
* @param string|null $usergroupDefault Json array{id: string, type: int}, eg [{"id": "admin", "type": 0}, {"id": "user1", "type": 0}]
* @param boolean $usergroupMultipleItems Whether you can select multiple users or/and groups
* @param boolean $usergroupSelectUsers Whether you can select users
* @param boolean $usergroupSelectGroups Whether you can select groups
Expand Down
7 changes: 2 additions & 5 deletions lib/Db/ColumnTypes/UsergroupColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

class UsergroupColumnQB extends SuperColumnQB implements IColumnTypeQB {
public function passSearchValue(IQueryBuilder $qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void {
if(substr($unformattedSearchValue, 0, 1) === '@') {
// TODO
} else {
$qb->setParameter($searchValuePlaceHolder, $unformattedSearchValue, IQueryBuilder::PARAM_STR);
}
// TODO how to handle searching for multiple users/groups?
$qb->setParameter($searchValuePlaceHolder, $unformattedSearchValue, IQueryBuilder::PARAM_STR);
}
}
138 changes: 85 additions & 53 deletions lib/Db/Row2Mapper.php

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/Db/RowCellDatetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/** @template-extends RowCellSuper<RowCellDatetime> */
class RowCellDatetime extends RowCellSuper {
protected ?string $value = null;
protected ?int $valueType = null;

public function jsonSerialize(): array {
return parent::jsonSerializePreparation($this->value);
return parent::jsonSerializePreparation($this->value, $this->valueType);
}
}
15 changes: 15 additions & 0 deletions lib/Db/RowCellMapperSuper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public function findByRowAndColumn(int $rowId, int $columnId): RowCellSuper {
return $this->findEntity($qb);
}

// /**
// * @throws MultipleObjectsReturnedException
// * @throws DoesNotExistException
// * @throws Exception
// */
// public function findMultByRowAndColumn(int $rowId, int $columnId): array{
// $qb = $this->db->getQueryBuilder();
// $qb->select('*')
// ->from($this->tableName)
// ->where($qb->expr()->eq('row_id', $qb->createNamedParameter($rowId, IQueryBuilder::PARAM_INT)))
// ->andWhere($qb->expr()->eq('column_id', $qb->createNamedParameter($columnId, IQueryBuilder::PARAM_INT)));
// return $this->findEntities($qb);
// }


/**
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
Expand Down
3 changes: 2 additions & 1 deletion lib/Db/RowCellNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/** @template-extends RowCellSuper<RowCellNumber> */
class RowCellNumber extends RowCellSuper {
protected ?float $value = null;
protected ?int $valueType = null;

public function jsonSerialize(): array {
return parent::jsonSerializePreparation($this->value);
return parent::jsonSerializePreparation($this->value, $this->valueType);
}
}
3 changes: 2 additions & 1 deletion lib/Db/RowCellSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/** @template-extends RowCellSuper<RowCellSelection> */
class RowCellSelection extends RowCellSuper {
protected ?string $value = null;
protected ?int $valueType = null;

public function jsonSerialize(): array {
return parent::jsonSerializePreparation($this->value);
return parent::jsonSerializePreparation($this->value, $this->valueType);
}
}
12 changes: 10 additions & 2 deletions lib/Db/RowCellSuper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @method setRowId(int $rowId)
* @method getValue(): string
* @method setValue(string $value)
* @method getValueType(): int
* @method setValueType(int $valueType)
* @method getCreatedBy(): string
* @method setCreatedBy(string $createdBy)
* @method getCreatedAt(): string
Expand All @@ -38,15 +40,17 @@ public function __construct() {

/**
* @param float|null|string $value
* @param int $value_type
*/
public function jsonSerializePreparation(string|float|null $value): array {
public function jsonSerializePreparation(string|float|null $value, int $valueType): array {
return [
'id' => $this->id,
'columnId' => $this->columnId,
'rowId' => $this->rowId,
'lastEditBy' => $this->lastEditBy,
'lastEditAt' => $this->lastEditAt,
'value' => $value
'value' => $value,
'valueType' => $valueType
];
}

Expand All @@ -61,4 +65,8 @@ public function setColumnIdWrapper(int $columnId) {
public function setValueWrapper($value) {
$this->setValue($value);
}

public function setValueTypeWrapper($valueType) {
$this->setValueType($valueType);
}
}
3 changes: 2 additions & 1 deletion lib/Db/RowCellText.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/** @template-extends RowCellSuper<RowCellText> */
class RowCellText extends RowCellSuper {
protected ?string $value = null;
protected ?int $valueType = null;

public function jsonSerialize(): array {
return parent::jsonSerializePreparation($this->value);
return parent::jsonSerializePreparation($this->value, $this->valueType);
}
}
3 changes: 2 additions & 1 deletion lib/Db/RowCellUsergroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/** @template-extends RowCellSuper<RowCellUsergroup> */
class RowCellUsergroup extends RowCellSuper {
protected ?string $value = null;
protected ?int $valueType = null;

public function jsonSerialize(): array {
return parent::jsonSerializePreparation($this->value);
return parent::jsonSerializePreparation($this->value, $this->valueType);
}
}
7 changes: 3 additions & 4 deletions lib/Db/RowCellUsergroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public function __construct(IDBConnection $db) {
/**
* @inheritDoc
*/
public function parseValueIncoming(Column $column, $value): string {
// need to convert from array to string before saving
// TODO figure out whether to handle these conversions in the BE or FE; confusing to have both
return json_encode($value);
public function parseValueIncoming(Column $column, $value): array {
return json_decode(json_encode($value), true);
//return json_encode($value);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/Migration/Version000400Date20230406000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$column->setLength(65535);
$column->setType(Type::getType('text'));

$column = $table->getColumn('usergroup_default');
$column->setLength(65535);

$column = $table->getColumn('text_default');
$column->setLength(65535);
$column->setType(Type::getType('text'));
Expand Down
1 change: 1 addition & 0 deletions lib/Migration/Version000700Date20230916000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private function createRowValueTable(ISchemaWrapper $schema, string $name, strin
$table->addColumn('column_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('row_id', Types::INTEGER, ['notnull' => true]);
$table->addColumn('value', $type, ['notnull' => false]);
$table->addColumn('value_type', Types::INTEGER, ['notnull' => false]);
// we will write this data to use it one day to extract versions of rows based on the timestamp
$table->addColumn('last_edit_at', Types::DATETIME, ['notnull' => true]);
$table->addColumn('last_edit_by', Types::STRING, ['notnull' => true, 'length' => 64]);
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/ColumnTypes/UsergroupBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function parseValue($value, ?Column $column = null): string {
}

/**
* @param mixed $value array{id: string, isUser: bool, displayName: string}
* @param mixed $value array{id: string, type: int}
* @param Column|null $column
* @return bool
*/
Expand All @@ -41,7 +41,7 @@ public function canBeParsed($value, ?Column $column = null): bool {

foreach ($value as $v) {
// TODO: maybe check if key exists first
if(!is_string($v['id']) && !is_string($v['displayName']) && !is_bool($v['isUser'])) {
if((array_key_exists('id', $v) && !is_string($v['id'])) && (array_key_exists('type', $v) && !is_int($v['type']))) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3388,7 +3388,7 @@
{
"name": "usergroupDefault",
"in": "query",
"description": "Default value, if column is usergroup (json array{id: string, icon: string, isUser: bool, displayName: string})",
"description": "Default value, if column is usergroup (json array{id: string, type: int})",
"schema": {
"type": "string",
"nullable": true,
Expand Down Expand Up @@ -7788,7 +7788,7 @@
{
"name": "usergroupDefault",
"in": "query",
"description": "Json array{id: string, isUser: bool, displayName: string}, eg [{\"id\": \"admin\", \"isUser\": true, \"displayName\": \"admin\"}, {\"id\": \"user1\", \"isUser\": true, \"displayName\": \"user1\"}]",
"description": "Json array{id: string, type: int}, eg [{\"id\": \"admin\", \"type\": 0}, {\"id\": \"user1\", \"type\": 0}]",
"schema": {
"type": "string",
"nullable": true
Expand Down
4 changes: 2 additions & 2 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ export type operations = {
selectionDefault?: string | null;
/** @description Default value, if column is datetime */
datetimeDefault?: string | null;
/** @description Default value, if column is usergroup (json array{id: string, icon: string, isUser: bool, displayName: string}) */
/** @description Default value, if column is usergroup (json array{id: string, type: int}) */
usergroupDefault?: string | null;
/** @description Can select multiple users or/and groups, if column is usergroup */
usergroupMultipleItems?: 0 | 1 | null;
Expand Down Expand Up @@ -3410,7 +3410,7 @@ export type operations = {
baseNodeId: number;
/** @description Title */
title: string;
/** @description Json array{id: string, isUser: bool, displayName: string}, eg [{"id": "admin", "isUser": true, "displayName": "admin"}, {"id": "user1", "isUser": true, "displayName": "user1"}] */
/** @description Json array{id: string, type: int}, eg [{"id": "admin", "type": 0}, {"id": "user1", "type": 0}] */
usergroupDefault?: string | null;
/** @description Whether you can select multiple users or/and groups */
usergroupMultipleItems?: 0 | 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/APIv2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Feature: APIv2
Given table "Table 5" with emoji "👋" exists for user "participant1-v2" as "t5" via v2
Then column from main type "usergroup" for node type "table" and node name "t5" exists with name "ug-c1" and following properties via v2
| title | ug column |
| usergroupDefault | [{"id": "admin", "displayName": "admin", "isUser": true}] |
| usergroupDefault | [{"id": "admin", "type": 0}] |
Then node with node type "table" and node name "t5" has the following columns via v2
| ug column |
Then print register
Expand Down

0 comments on commit d175f59

Please sign in to comment.