Skip to content

Commit 611a9dd

Browse files
authored
Merge pull request #1929 from nextcloud/feature/add-min-width-column-setting
Enhancement: Add column width setting
2 parents 5fff0a7 + 2e4935b commit 611a9dd

File tree

22 files changed

+393
-43
lines changed

22 files changed

+393
-43
lines changed

cypress/e2e/ToDo list.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"usergroupSelectUsers": false,
3636
"usergroupSelectGroups": false,
3737
"usergroupSelectTeams": false,
38-
"showUserStatus": false
38+
"showUserStatus": false,
39+
"customSettings": {}
3940
},
4041
{
4142
"id": 92,
@@ -70,7 +71,10 @@
7071
"usergroupSelectUsers": false,
7172
"usergroupSelectGroups": false,
7273
"usergroupSelectTeams": false,
73-
"showUserStatus": false
74+
"showUserStatus": false,
75+
"customSettings": {
76+
"width": 300
77+
}
7478
},
7579
{
7680
"id": 93,
@@ -105,7 +109,8 @@
105109
"usergroupSelectUsers": false,
106110
"usergroupSelectGroups": false,
107111
"usergroupSelectTeams": false,
108-
"showUserStatus": false
112+
"showUserStatus": false,
113+
"customSettings": {}
109114
},
110115
{
111116
"id": 94,
@@ -140,7 +145,8 @@
140145
"usergroupSelectUsers": false,
141146
"usergroupSelectGroups": false,
142147
"usergroupSelectTeams": false,
143-
"showUserStatus": false
148+
"showUserStatus": false,
149+
"customSettings": {}
144150
},
145151
{
146152
"id": 95,
@@ -175,7 +181,8 @@
175181
"usergroupSelectUsers": false,
176182
"usergroupSelectGroups": false,
177183
"usergroupSelectTeams": false,
178-
"showUserStatus": false
184+
"showUserStatus": false,
185+
"customSettings": {}
179186
},
180187
{
181188
"id": 96,
@@ -210,7 +217,8 @@
210217
"usergroupSelectUsers": false,
211218
"usergroupSelectGroups": false,
212219
"usergroupSelectTeams": false,
213-
"showUserStatus": false
220+
"showUserStatus": false,
221+
"customSettings": {}
214222
}
215223
],
216224
"views": [

lib/Controller/Api1Controller.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ public function indexViewColumns(int $viewId): DataResponse {
818818
* @param bool|null $usergroupSelectTeams Can select teams, if column type is usergroup
819819
* @param bool|null $usergroupShowUserStatus Whether to show the user's status, if column type is usergroup
820820
* @param list<int>|null $selectedViewIds View IDs where this column should be added to be presented
821+
* @param array<string, mixed> $customSettings Custom settings for the column
821822
*
822823
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
823824
*
@@ -862,6 +863,7 @@ public function createColumn(
862863
?bool $usergroupShowUserStatus = null,
863864

864865
?array $selectedViewIds = [],
866+
?array $customSettings = [],
865867
): DataResponse {
866868
try {
867869
return new DataResponse($this->columnService->create(
@@ -892,7 +894,8 @@ public function createColumn(
892894
usergroupSelectUsers: $usergroupSelectUsers,
893895
usergroupSelectGroups: $usergroupSelectGroups,
894896
usergroupSelectTeams: $usergroupSelectTeams,
895-
showUserStatus: $usergroupShowUserStatus
897+
showUserStatus: $usergroupShowUserStatus,
898+
customSettings: json_encode($customSettings),
896899
),
897900
$selectedViewIds
898901
)->jsonSerialize());
@@ -938,6 +941,7 @@ public function createColumn(
938941
* @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup
939942
* @param bool|null $usergroupSelectTeams Can select teams, if column type is usergroup
940943
* @param bool|null $usergroupShowUserStatus Whether to show the user's status, if column type is usergroup
944+
* @param array<string, mixed> $customSettings Custom settings for the column
941945
*
942946
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
943947
*
@@ -977,7 +981,7 @@ public function updateColumn(
977981
?bool $usergroupSelectGroups,
978982
?bool $usergroupSelectTeams,
979983
?bool $usergroupShowUserStatus,
980-
984+
?array $customSettings = [],
981985
): DataResponse {
982986
try {
983987
$item = $this->columnService->update(
@@ -1006,7 +1010,8 @@ public function updateColumn(
10061010
usergroupSelectUsers: $usergroupSelectUsers,
10071011
usergroupSelectGroups: $usergroupSelectGroups,
10081012
usergroupSelectTeams: $usergroupSelectTeams,
1009-
showUserStatus: $usergroupShowUserStatus
1013+
showUserStatus: $usergroupShowUserStatus,
1014+
customSettings: json_encode($customSettings),
10101015
)
10111016
);
10121017
return new DataResponse($item->jsonSerialize());
@@ -1576,6 +1581,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive
15761581
* @param bool|null $usergroupSelectTeams Can select teams, if column type is usergroup
15771582
* @param bool|null $usergroupShowUserStatus Whether to show the user's status, if column type is usergroup
15781583
* @param list<int>|null $selectedViewIds View IDs where this column should be added to be presented
1584+
* @param array<string, mixed> $customSettings Custom settings for the column
15791585
*
15801586
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
15811587
*
@@ -1620,6 +1626,7 @@ public function createTableColumn(
16201626
?bool $usergroupSelectTeams = null,
16211627
?bool $usergroupShowUserStatus = null,
16221628
?array $selectedViewIds = [],
1629+
array $customSettings = [],
16231630
): DataResponse {
16241631
try {
16251632
$item = $this->columnService->create(
@@ -1650,7 +1657,8 @@ public function createTableColumn(
16501657
usergroupSelectUsers: $usergroupSelectUsers,
16511658
usergroupSelectGroups: $usergroupSelectGroups,
16521659
usergroupSelectTeams: $usergroupSelectTeams,
1653-
showUserStatus: $usergroupShowUserStatus
1660+
showUserStatus: $usergroupShowUserStatus,
1661+
customSettings: json_encode($customSettings),
16541662
),
16551663
$selectedViewIds
16561664
);

lib/Controller/ApiColumnsController.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function show(int $id): DataResponse {
112112
* @param 'progress'|'stars'|null $subtype Subtype for the new column
113113
* @param string|null $description Description
114114
* @param list<int>|null $selectedViewIds View IDs where this columns should be added
115+
* @param array<string, mixed> $customSettings Custom settings for the column
116+
*
115117
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
116118
*
117119
* 200: Column created
@@ -123,7 +125,7 @@ public function show(int $id): DataResponse {
123125
*/
124126
#[NoAdminRequired]
125127
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'baseNodeType', idParam: 'baseNodeId')]
126-
public function createNumberColumn(int $baseNodeId, string $title, ?float $numberDefault, ?int $numberDecimals, ?string $numberPrefix, ?string $numberSuffix, ?float $numberMin, ?float $numberMax, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse {
128+
public function createNumberColumn(int $baseNodeId, string $title, ?float $numberDefault, ?int $numberDecimals, ?string $numberPrefix, ?string $numberSuffix, ?float $numberMin, ?float $numberMax, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
127129
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
128130
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
129131
$column = $this->service->create(
@@ -141,7 +143,8 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
141143
numberMax: $numberMax,
142144
numberDecimals: $numberDecimals,
143145
numberPrefix: $numberPrefix,
144-
numberSuffix: $numberSuffix
146+
numberSuffix: $numberSuffix,
147+
customSettings: json_encode($customSettings),
145148
),
146149
$selectedViewIds
147150
);
@@ -164,6 +167,7 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
164167
* @param list<int>|null $selectedViewIds View IDs where this columns should be added
165168
* @param boolean $mandatory Is mandatory
166169
* @param 'table'|'view' $baseNodeType Context type of the column creation
170+
* @param array<string, mixed> $customSettings Custom settings for the column
167171
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
168172
*
169173
* 200: Column created
@@ -175,7 +179,7 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
175179
*/
176180
#[NoAdminRequired]
177181
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'baseNodeType', idParam: 'baseNodeId')]
178-
public function createTextColumn(int $baseNodeId, string $title, ?string $textDefault, ?string $textAllowedPattern, ?int $textMaxLength, ?bool $textUnique = false, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse {
182+
public function createTextColumn(int $baseNodeId, string $title, ?string $textDefault, ?string $textAllowedPattern, ?int $textMaxLength, ?bool $textUnique = false, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
179183
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
180184
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
181185
$column = $this->service->create(
@@ -191,7 +195,8 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
191195
textDefault: $textDefault,
192196
textAllowedPattern: $textAllowedPattern,
193197
textMaxLength: $textMaxLength,
194-
textUnique: $textUnique
198+
textUnique: $textUnique,
199+
customSettings: json_encode($customSettings),
195200
),
196201
$selectedViewIds
197202
);
@@ -212,6 +217,8 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
212217
* @param list<int>|null $selectedViewIds View IDs where this columns should be added
213218
* @param boolean $mandatory Is mandatory
214219
* @param 'table'|'view' $baseNodeType Context type of the column creation
220+
* @param array<string, mixed> $customSettings Custom settings for the column
221+
*
215222
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
216223
*
217224
* 200: Column created
@@ -223,7 +230,7 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
223230
*/
224231
#[NoAdminRequired]
225232
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'baseNodeType', idParam: 'baseNodeId')]
226-
public function createSelectionColumn(int $baseNodeId, string $title, string $selectionOptions, ?string $selectionDefault, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse {
233+
public function createSelectionColumn(int $baseNodeId, string $title, string $selectionOptions, ?string $selectionDefault, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
227234
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
228235
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
229236
$column = $this->service->create(
@@ -237,7 +244,8 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
237244
mandatory: $mandatory,
238245
description: $description,
239246
selectionOptions: $selectionOptions,
240-
selectionDefault: $selectionDefault
247+
selectionDefault: $selectionDefault,
248+
customSettings: json_encode($customSettings),
241249
),
242250
$selectedViewIds
243251
);
@@ -257,6 +265,8 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
257265
* @param list<int>|null $selectedViewIds View IDs where this columns should be added
258266
* @param boolean $mandatory Is mandatory
259267
* @param 'table'|'view' $baseNodeType Context type of the column creation
268+
* @param array<string, mixed> $customSettings Custom settings for the column
269+
*
260270
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
261271
*
262272
* 200: Column created
@@ -268,7 +278,7 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
268278
*/
269279
#[NoAdminRequired]
270280
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'baseNodeType', idParam: 'baseNodeId')]
271-
public function createDatetimeColumn(int $baseNodeId, string $title, ?string $datetimeDefault, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse {
281+
public function createDatetimeColumn(int $baseNodeId, string $title, ?string $datetimeDefault, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
272282
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
273283
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
274284
$column = $this->service->create(
@@ -281,7 +291,8 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
281291
subtype: $subtype,
282292
mandatory: $mandatory,
283293
description: $description,
284-
datetimeDefault: $datetimeDefault
294+
datetimeDefault: $datetimeDefault,
295+
customSettings: json_encode($customSettings),
285296
),
286297
$selectedViewIds
287298
);
@@ -303,6 +314,8 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
303314
* @param list<int>|null $selectedViewIds View IDs where this columns should be added
304315
* @param boolean $mandatory Is mandatory
305316
* @param 'table'|'view' $baseNodeType Context type of the column creation
317+
* @param array<string, mixed> $customSettings Custom settings for the column
318+
*
306319
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
307320
*
308321
* 200: Column created
@@ -314,7 +327,7 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
314327
*/
315328
#[NoAdminRequired]
316329
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'baseNodeType', idParam: 'baseNodeId')]
317-
public function createUsergroupColumn(int $baseNodeId, string $title, ?string $usergroupDefault, ?bool $usergroupMultipleItems = null, ?bool $usergroupSelectUsers = null, ?bool $usergroupSelectGroups = null, ?bool $usergroupSelectTeams = null, ?bool $showUserStatus = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse {
330+
public function createUsergroupColumn(int $baseNodeId, string $title, ?string $usergroupDefault, ?bool $usergroupMultipleItems = null, ?bool $usergroupSelectUsers = null, ?bool $usergroupSelectGroups = null, ?bool $usergroupSelectTeams = null, ?bool $showUserStatus = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
318331
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
319332
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
320333
$column = $this->service->create(
@@ -331,7 +344,8 @@ public function createUsergroupColumn(int $baseNodeId, string $title, ?string $u
331344
usergroupSelectUsers: $usergroupSelectUsers,
332345
usergroupSelectGroups: $usergroupSelectGroups,
333346
usergroupSelectTeams: $usergroupSelectTeams,
334-
showUserStatus: $showUserStatus
347+
showUserStatus: $showUserStatus,
348+
customSettings: json_encode($customSettings),
335349
),
336350
$selectedViewIds
337351
);

lib/Controller/ApiTablesController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public function createFromScheme(string $title, string $emoji, string $descripti
169169
usergroupSelectGroups: $column['usergroupSelectGroups'],
170170
usergroupSelectTeams: $column['usergroupSelectTeams'],
171171
showUserStatus: $column['showUserStatus'],
172+
customSettings: empty($column['customSettings']) ? null : json_encode($column['customSettings'])
172173
)
173174
);
174175
$colMap[$column['id']] = $col->getId();

lib/Db/Column.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
* @method setShowUserStatus(?bool $showUserStatus)
8383
* @method getViewColumnInformation(): ViewColumnInformation
8484
* @method setViewColumnInformation(ViewColumnInformation $viewColumnInformation)
85+
* @method getCustomSettings(): ?string
86+
* @method setCustomSettings(?string $customSettings)
8587
*/
8688
class Column extends EntitySuper implements JsonSerializable {
8789
// Meta column types
@@ -146,6 +148,7 @@ class Column extends EntitySuper implements JsonSerializable {
146148
protected ?bool $usergroupSelectGroups = null;
147149
protected ?bool $usergroupSelectTeams = null;
148150
protected ?bool $showUserStatus = null;
151+
protected ?string $customSettings = null;
149152

150153
// virtual properties
151154
protected ?string $createdByDisplayName = null;
@@ -175,6 +178,8 @@ public function __construct() {
175178
$this->addType('usergroupSelectGroups', 'boolean');
176179
$this->addType('usergroupSelectTeams', 'boolean');
177180
$this->addType('showUserStatus', 'boolean');
181+
182+
$this->addType('customSettings', 'string');
178183
}
179184

180185
public static function isValidMetaTypeId(int $metaTypeId): bool {
@@ -213,6 +218,7 @@ public static function fromDto(ColumnDto $data): self {
213218
$column->setUsergroupSelectGroups($data->getUsergroupSelectGroups());
214219
$column->setUsergroupSelectTeams($data->getUsergroupSelectTeams());
215220
$column->setShowUserStatus($data->getShowUserStatus());
221+
$column->setCustomSettings($data->getCustomSettings());
216222
return $column;
217223
}
218224

@@ -292,6 +298,11 @@ public function jsonSerialize(): array {
292298
'usergroupSelectGroups' => $this->usergroupSelectGroups,
293299
'usergroupSelectTeams' => $this->usergroupSelectTeams,
294300
'showUserStatus' => $this->showUserStatus,
301+
'customSettings' => $this->getCustomSettingsArray() ?: new \stdClass(),
295302
];
296303
}
304+
305+
public function getCustomSettingsArray(): array {
306+
return json_decode($this->customSettings, true) ?: [];
307+
}
297308
}

lib/Dto/Column.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct(
3333
private ?bool $usergroupSelectGroups = null,
3434
private ?bool $usergroupSelectTeams = null,
3535
private ?bool $showUserStatus = null,
36+
private ?string $customSettings = null,
3637
) {
3738
}
3839

@@ -62,6 +63,7 @@ public static function createFromArray(array $data): self {
6263
usergroupSelectGroups: $data['usergroupSelectGroups'] ?? null,
6364
usergroupSelectTeams: $data['usergroupSelectTeams'] ?? null,
6465
showUserStatus: $data['showUserStatus'] ?? null,
66+
customSettings: $data['customSettings'] ?? null,
6567
);
6668
}
6769

@@ -160,4 +162,8 @@ public function getUsergroupSelectTeams(): ?bool {
160162
public function getShowUserStatus(): ?bool {
161163
return $this->showUserStatus;
162164
}
165+
166+
public function getCustomSettings(): ?string {
167+
return $this->customSettings;
168+
}
163169
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/** @noinspection PhpUnused */
4+
5+
declare(strict_types=1);
6+
/**
7+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
8+
* SPDX-License-Identifier: AGPL-3.0-or-later
9+
*/
10+
namespace OCA\Tables\Migration;
11+
12+
use Closure;
13+
use OCP\DB\Exception;
14+
use OCP\DB\ISchemaWrapper;
15+
use OCP\DB\Types;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
19+
class Version001000Date20250720000000 extends SimpleMigrationStep {
20+
/**
21+
* @param IOutput $output
22+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
23+
* @param array $options
24+
* @return null|ISchemaWrapper
25+
* @throws Exception
26+
*/
27+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
28+
/** @var ISchemaWrapper $schema */
29+
$schema = $schemaClosure();
30+
31+
$table = $schema->getTable('tables_columns');
32+
if (!$table->hasColumn('custom_settings')) {
33+
$table->addColumn('custom_settings', Types::JSON, [
34+
'notnull' => false,
35+
]);
36+
}
37+
38+
return $schema;
39+
}
40+
}

0 commit comments

Comments
 (0)