From b5c99929128a5d48d57167113cb5b6fba4831d82 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 26 Sep 2024 12:10:59 +0200 Subject: [PATCH 01/12] fixed php issues --- lib/Db/Register.php | 2 -- lib/Db/Schema.php | 1 - lib/Db/Source.php | 2 -- 3 files changed, 5 deletions(-) diff --git a/lib/Db/Register.php b/lib/Db/Register.php index 7e4a99dfcc..0f93c77580 100644 --- a/lib/Db/Register.php +++ b/lib/Db/Register.php @@ -8,7 +8,6 @@ class Register extends Entity implements JsonSerializable { - protected ?string $id = null; protected ?string $title = null; protected ?string $description = null; protected ?array $schemas = null; @@ -18,7 +17,6 @@ class Register extends Entity implements JsonSerializable protected ?DateTime $created = null; public function __construct() { - $this->addType('id', 'string'); $this->addType('title', 'title'); $this->addType('description', 'string'); $this->addType('schemas', 'array'); diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index fae5121c08..c018748b56 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -8,7 +8,6 @@ class Schema extends Entity implements JsonSerializable { - protected ?string $title = null; protected ?string $version = null; protected ?string $description = null; protected ?string $summary = null; diff --git a/lib/Db/Source.php b/lib/Db/Source.php index 2bd9693585..1c63001ba5 100644 --- a/lib/Db/Source.php +++ b/lib/Db/Source.php @@ -8,7 +8,6 @@ class Source extends Entity implements JsonSerializable { - protected ?string $id = null; protected ?string $name = null; protected ?string $description = null; protected ?string $databaseUrl = null; @@ -17,7 +16,6 @@ class Source extends Entity implements JsonSerializable protected ?DateTime $created = null; public function __construct() { - $this->addType('id', 'string'); $this->addType('title', 'string'); $this->addType('description', 'string'); $this->addType('databaseUrl', 'string'); From f20890c515d0602fffbbdcf91a78668ee685db5c Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Thu, 26 Sep 2024 13:16:13 +0200 Subject: [PATCH 02/12] title hydration hotfix --- lib/Db/Register.php | 39 ++++++++++++++++++++++++++++----------- lib/Db/Schema.php | 7 ++++++- lib/Db/Source.php | 27 +++++++++++++++++++++------ 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/lib/Db/Register.php b/lib/Db/Register.php index 7e4a99dfcc..68ad1028be 100644 --- a/lib/Db/Register.php +++ b/lib/Db/Register.php @@ -8,41 +8,58 @@ class Register extends Entity implements JsonSerializable { - protected ?string $id = null; protected ?string $title = null; protected ?string $description = null; - protected ?array $schemas = null; + protected ?array $schemas = []; protected ?string $source = null; protected ?string $tablePrefix = null; protected ?DateTime $updated = null; protected ?DateTime $created = null; public function __construct() { - $this->addType('id', 'string'); - $this->addType('title', 'title'); - $this->addType('description', 'string'); - $this->addType('schemas', 'array'); - $this->addType('source', 'string'); - $this->addType('tablePrefix', 'string'); - $this->addType('updated', 'datetime'); - $this->addType('created', 'datetime'); + $this->addType(fieldName: 'title', type: 'string'); + $this->addType(fieldName: 'description', type: 'string'); + $this->addType(fieldName: 'properties', type: 'json'); + $this->addType(fieldName: 'source', type: 'string'); + $this->addType(fieldName: 'tablePrefix', type: 'string'); + $this->addType(fieldName:'updated', type: 'datetime'); + $this->addType(fieldName:'created', type: 'datetime'); + } + + public function getJsonFields(): array + { + return array_keys( + array_filter($this->getFieldTypes(), function ($field) { + return $field === 'json'; + }) + ); } public function hydrate(array $object): self { + $jsonFields = $this->getJsonFields(); + + if(isset($object['metadata']) === false) { + $object['metadata'] = []; + } + foreach($object as $key => $value) { + if (in_array($key, $jsonFields) === true && $value === []) { + $value = null; + } + $method = 'set'.ucfirst($key); try { $this->$method($value); } catch (\Exception $exception) { - // Error handling can be added here } } return $this; } + public function jsonSerialize(): array { return [ diff --git a/lib/Db/Schema.php b/lib/Db/Schema.php index fae5121c08..e5fc470db3 100644 --- a/lib/Db/Schema.php +++ b/lib/Db/Schema.php @@ -20,13 +20,13 @@ class Schema extends Entity implements JsonSerializable protected ?DateTime $created = null; public function __construct() { - $this->addType(fieldName: 'archive', type: 'json'); $this->addType(fieldName: 'title', type: 'string'); $this->addType(fieldName: 'version', type: 'string'); $this->addType(fieldName: 'description', type: 'string'); $this->addType(fieldName: 'summary', type: 'string'); $this->addType(fieldName: 'required', type: 'json'); $this->addType(fieldName: 'properties', type: 'json'); + $this->addType(fieldName: 'archive', type: 'json'); $this->addType(fieldName: 'source', type: 'string'); $this->addType(fieldName:'updated', type: 'datetime'); $this->addType(fieldName:'created', type: 'datetime'); @@ -45,6 +45,10 @@ public function hydrate(array $object): self { $jsonFields = $this->getJsonFields(); + if(isset($object['metadata']) === false) { + $object['metadata'] = []; + } + foreach($object as $key => $value) { if (in_array($key, $jsonFields) === true && $value === []) { $value = null; @@ -61,6 +65,7 @@ public function hydrate(array $object): self return $this; } + public function jsonSerialize(): array { $properties = []; diff --git a/lib/Db/Source.php b/lib/Db/Source.php index 2bd9693585..017285b72a 100644 --- a/lib/Db/Source.php +++ b/lib/Db/Source.php @@ -8,8 +8,7 @@ class Source extends Entity implements JsonSerializable { - protected ?string $id = null; - protected ?string $name = null; + protected ?string $title = null; protected ?string $description = null; protected ?string $databaseUrl = null; protected ?string $type = null; @@ -17,8 +16,7 @@ class Source extends Entity implements JsonSerializable protected ?DateTime $created = null; public function __construct() { - $this->addType('id', 'string'); - $this->addType('title', 'string'); + $this->addType(fieldName: 'title', type: 'string'); $this->addType('description', 'string'); $this->addType('databaseUrl', 'string'); $this->addType('type', 'string'); @@ -26,21 +24,38 @@ public function __construct() { $this->addType('created', 'datetime'); } + public function getJsonFields(): array + { + return array_keys( + array_filter($this->getFieldTypes(), function ($field) { + return $field === 'json'; + }) + ); + } + public function hydrate(array $object): self { + $jsonFields = $this->getJsonFields(); + + if(isset($object['metadata']) === false) { + $object['metadata'] = []; + } + foreach($object as $key => $value) { + if (in_array($key, $jsonFields) === true && $value === []) { + $value = null; + } + $method = 'set'.ucfirst($key); try { $this->$method($value); } catch (\Exception $exception) { - // Error handling can be added here } } return $this; } - public function jsonSerialize(): array { return [ From cc125a986894abab48ddceb82d40879b6ee0b951 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 26 Sep 2024 13:17:43 +0200 Subject: [PATCH 03/12] fixed more php issues thanks ruben --- lib/Controller/RegistersController.php | 2 +- lib/Controller/SchemasController.php | 2 +- lib/Controller/SourcesController.php | 2 +- lib/Db/Register.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Controller/RegistersController.php b/lib/Controller/RegistersController.php index 58270c1efe..13b27ba3a2 100644 --- a/lib/Controller/RegistersController.php +++ b/lib/Controller/RegistersController.php @@ -63,7 +63,7 @@ public function page(): TemplateResponse public function index(ObjectService $objectService, SearchService $searchService): JSONResponse { $filters = $this->request->getParams(); - $fieldsToSearch = ['name', 'description']; + $fieldsToSearch = ['title', 'description']; $searchParams = $searchService->createMySQLSearchParams(filters: $filters); $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); diff --git a/lib/Controller/SchemasController.php b/lib/Controller/SchemasController.php index 127e717724..7f7badff3c 100644 --- a/lib/Controller/SchemasController.php +++ b/lib/Controller/SchemasController.php @@ -63,7 +63,7 @@ public function page(): TemplateResponse public function index(ObjectService $objectService, SearchService $searchService): JSONResponse { $filters = $this->request->getParams(); - $fieldsToSearch = ['name', 'description']; + $fieldsToSearch = ['title', 'description']; $searchParams = $searchService->createMySQLSearchParams(filters: $filters); $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); diff --git a/lib/Controller/SourcesController.php b/lib/Controller/SourcesController.php index 4b10ae7492..bc98c2d219 100644 --- a/lib/Controller/SourcesController.php +++ b/lib/Controller/SourcesController.php @@ -63,7 +63,7 @@ public function page(): TemplateResponse public function index(ObjectService $objectService, SearchService $searchService): JSONResponse { $filters = $this->request->getParams(); - $fieldsToSearch = ['name', 'description']; + $fieldsToSearch = ['title', 'description']; $searchParams = $searchService->createMySQLSearchParams(filters: $filters); $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); diff --git a/lib/Db/Register.php b/lib/Db/Register.php index 0f93c77580..232fbcac65 100644 --- a/lib/Db/Register.php +++ b/lib/Db/Register.php @@ -17,7 +17,7 @@ class Register extends Entity implements JsonSerializable protected ?DateTime $created = null; public function __construct() { - $this->addType('title', 'title'); + $this->addType('title', 'string'); $this->addType('description', 'string'); $this->addType('schemas', 'array'); $this->addType('source', 'string'); From 5a65caf8717143be35effafd5fedcf8854f14ced Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Thu, 26 Sep 2024 13:47:43 +0200 Subject: [PATCH 04/12] Registers hotfixes --- lib/Controller/RegistersController.php | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/Controller/RegistersController.php b/lib/Controller/RegistersController.php index 58270c1efe..782ed80a0f 100644 --- a/lib/Controller/RegistersController.php +++ b/lib/Controller/RegistersController.php @@ -4,8 +4,8 @@ use OCA\OpenRegister\Service\ObjectService; use OCA\OpenRegister\Service\SearchService; -use OCA\OpenRegister\Db\Source; -use OCA\OpenRegister\Db\SourceMapper; +use OCA\OpenRegister\Db\Register; +use OCA\OpenRegister\Db\RegisterMapper; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\JSONResponse; @@ -15,7 +15,7 @@ class RegistersController extends Controller { /** - * Constructor for the SourcesController + * Constructor for the RegistersController * * @param string $appName The name of the app * @param IRequest $request The request object @@ -25,7 +25,7 @@ public function __construct( $appName, IRequest $request, private readonly IAppConfig $config, - private readonly SourceMapper $sourceMapper + private readonly RegisterMapper $registerMapper ) { parent::__construct($appName, $request); @@ -51,14 +51,14 @@ public function page(): TemplateResponse } /** - * Retrieves a list of all sources + * Retrieves a list of all registers * - * This method returns a JSON response containing an array of all sources in the system. + * This method returns a JSON response containing an array of all registers in the system. * * @NoAdminRequired * @NoCSRFRequired * - * @return JSONResponse A JSON response containing the list of sources + * @return JSONResponse A JSON response containing the list of registers */ public function index(ObjectService $objectService, SearchService $searchService): JSONResponse { @@ -69,38 +69,38 @@ public function index(ObjectService $objectService, SearchService $searchService $searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch); $filters = $searchService->unsetSpecialQueryParams(filters: $filters); - return new JSONResponse(['results' => $this->sourceMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); + return new JSONResponse(['results' => $this->registerMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]); } /** - * Retrieves a single source by its ID + * Retrieves a single register by its ID * - * This method returns a JSON response containing the details of a specific source. + * This method returns a JSON response containing the details of a specific register. * * @NoAdminRequired * @NoCSRFRequired * - * @param string $id The ID of the source to retrieve - * @return JSONResponse A JSON response containing the source details + * @param string $id The ID of the register to retrieve + * @return JSONResponse A JSON response containing the register details */ public function show(string $id): JSONResponse { try { - return new JSONResponse($this->sourceMapper->find(id: (int) $id)); + return new JSONResponse($this->registerMapper->find(id: (int) $id)); } catch (DoesNotExistException $exception) { return new JSONResponse(data: ['error' => 'Not Found'], statusCode: 404); } } /** - * Creates a new source + * Creates a new register * - * This method creates a new source based on POST data. + * This method creates a new register based on POST data. * * @NoAdminRequired * @NoCSRFRequired * - * @return JSONResponse A JSON response containing the created source + * @return JSONResponse A JSON response containing the created register */ public function create(): JSONResponse { @@ -116,19 +116,19 @@ public function create(): JSONResponse unset($data['id']); } - return new JSONResponse($this->sourceMapper->createFromArray(object: $data)); + return new JSONResponse($this->registerMapper->createFromArray(object: $data)); } /** - * Updates an existing source + * Updates an existing register * - * This method updates an existing source based on its ID. + * This method updates an existing register based on its ID. * * @NoAdminRequired * @NoCSRFRequired * - * @param string $id The ID of the source to update - * @return JSONResponse A JSON response containing the updated source details + * @param string $id The ID of the register to update + * @return JSONResponse A JSON response containing the updated register details */ public function update(int $id): JSONResponse { @@ -142,23 +142,23 @@ public function update(int $id): JSONResponse if (isset($data['id'])) { unset($data['id']); } - return new JSONResponse($this->sourceMapper->updateFromArray(id: (int) $id, object: $data)); + return new JSONResponse($this->registerMapper->updateFromArray(id: (int) $id, object: $data)); } /** - * Deletes a source + * Deletes a register * - * This method deletes a source based on its ID. + * This method deletes a register based on its ID. * * @NoAdminRequired * @NoCSRFRequired * - * @param string $id The ID of the source to delete + * @param string $id The ID of the register to delete * @return JSONResponse An empty JSON response */ public function destroy(int $id): JSONResponse { - $this->sourceMapper->delete($this->sourceMapper->find((int) $id)); + $this->registerMapper->delete($this->registerMapper->find((int) $id)); return new JSONResponse([]); } From ef6c1ef956ba735bda06602fdb8b77a1c6388b48 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 26 Sep 2024 13:47:53 +0200 Subject: [PATCH 05/12] consistency --- lib/Db/Source.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Db/Source.php b/lib/Db/Source.php index 017285b72a..9203b6e253 100644 --- a/lib/Db/Source.php +++ b/lib/Db/Source.php @@ -17,11 +17,11 @@ class Source extends Entity implements JsonSerializable public function __construct() { $this->addType(fieldName: 'title', type: 'string'); - $this->addType('description', 'string'); - $this->addType('databaseUrl', 'string'); - $this->addType('type', 'string'); - $this->addType('updated', 'datetime'); - $this->addType('created', 'datetime'); + $this->addType(fieldName: 'description', type: 'string'); + $this->addType(fieldName: 'databaseUrl', type: 'string'); + $this->addType(fieldName: 'type', type: 'string'); + $this->addType(fieldName: 'updated', type: 'datetime'); + $this->addType(fieldName: 'created', type: 'datetime'); } public function getJsonFields(): array From 2b3867aebb2fc095690d8b7cd518deabf2a79f40 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 26 Sep 2024 14:19:26 +0200 Subject: [PATCH 06/12] meer backend fixes --- lib/Migration/Version1Date20240924200009.php | 12 ++++++------ src/modals/register/EditRegister.vue | 2 -- src/modals/source/EditSource.vue | 2 -- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Migration/Version1Date20240924200009.php b/lib/Migration/Version1Date20240924200009.php index 0d950fdb47..f13c802c22 100755 --- a/lib/Migration/Version1Date20240924200009.php +++ b/lib/Migration/Version1Date20240924200009.php @@ -45,8 +45,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn('description', Types::TEXT, ['notnull' => false]); $table->addColumn('database_url', Types::STRING, ['notnull' => true, 'length' => 255]); $table->addColumn('type', Types::STRING, ['notnull' => true, 'length' => 64]); - $table->addColumn('updated', Types::DATETIME, ['notnull' => true]); - $table->addColumn('created', Types::DATETIME, ['notnull' => true]); + $table->addColumn('updated', Types::DATETIME, ['notnull' => true, 'default' => 'CURRENT_TIMESTAMP']); + $table->addColumn('created', Types::DATETIME, ['notnull' => true, 'default' => 'CURRENT_TIMESTAMP']); $table->setPrimaryKey(['id']); $table->addIndex(['title'], 'register_sources_title_index'); @@ -64,8 +64,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn('properties', Types::JSON, ['notnull' => false]); $table->addColumn('archive', Types::JSON, ['notnull' => false]); $table->addColumn('source', Types::STRING, ['notnull' => true, 'length' => 64]); - $table->addColumn('updated', Types::DATETIME, ['notnull' => true]); - $table->addColumn('created', Types::DATETIME, ['notnull' => true]); + $table->addColumn('updated', Types::DATETIME, ['notnull' => true, 'default' => 'CURRENT_TIMESTAMP']); + $table->addColumn('created', Types::DATETIME, ['notnull' => true, 'default' => 'CURRENT_TIMESTAMP']); $table->setPrimaryKey(['id']); $table->addIndex(['title'], 'register_schemas_title_index'); @@ -80,8 +80,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn('schemas', Types::JSON, ['notnull' => false]); $table->addColumn('source', Types::STRING, ['notnull' => true, 'length' => 64]); $table->addColumn('table_prefix', Types::STRING, ['notnull' => true, 'length' => 64]); - $table->addColumn('updated', Types::DATETIME, ['notnull' => true]); - $table->addColumn('created', Types::DATETIME, ['notnull' => true]); + $table->addColumn('updated', Types::DATETIME, ['notnull' => true, 'default' => 'CURRENT_TIMESTAMP']); + $table->addColumn('created', Types::DATETIME, ['notnull' => true, 'default' => 'CURRENT_TIMESTAMP']); $table->setPrimaryKey(['id']); $table->addIndex(['title'], 'registers_title_index'); diff --git a/src/modals/register/EditRegister.vue b/src/modals/register/EditRegister.vue index b7a642d4da..314b995b84 100644 --- a/src/modals/register/EditRegister.vue +++ b/src/modals/register/EditRegister.vue @@ -181,8 +181,6 @@ export default { registerStore.saveRegister({ ...this.registerItem, schemas: this.schemas?.value?.map((schema) => schema.id) || [], - created: !this.registerItem?.id ? new Date().toISOString() : this.registerItem.created, - updated: this.registerItem?.id ? new Date().toISOString() : null, }).then(({ response }) => { this.success = response.ok this.error = false diff --git a/src/modals/source/EditSource.vue b/src/modals/source/EditSource.vue index 48a56772a3..44f2e51fb8 100644 --- a/src/modals/source/EditSource.vue +++ b/src/modals/source/EditSource.vue @@ -133,8 +133,6 @@ export default { sourceStore.saveSource({ ...this.sourceItem, - created: !this.sourceItem?.id ? new Date().toISOString() : this.sourceItem.created, - updated: this.sourceItem?.id ? new Date().toISOString() : null, }).then(({ response }) => { this.success = response.ok this.error = false From 82f866b6da7a7ed4ab3ce00498ae654ad8a5f7d5 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 26 Sep 2024 16:31:07 +0200 Subject: [PATCH 07/12] finished fixing the register modal and added source select --- lib/Db/Register.php | 2 +- src/entities/register/register.mock.ts | 46 ++++++---- src/entities/register/register.spec.ts | 109 ++++++++++++++---------- src/entities/register/register.ts | 84 +++++++++++------- src/entities/register/register.types.ts | 15 +++- src/entities/source/source.mock.ts | 27 ++++-- src/entities/source/source.ts | 64 +++++++++----- src/entities/source/source.types.ts | 21 +++-- src/modals/register/EditRegister.vue | 41 ++++++++- src/store/modules/register.js | 6 +- src/store/modules/source.js | 23 ++--- 11 files changed, 293 insertions(+), 145 deletions(-) diff --git a/lib/Db/Register.php b/lib/Db/Register.php index 68ad1028be..6cf83515ea 100644 --- a/lib/Db/Register.php +++ b/lib/Db/Register.php @@ -19,7 +19,7 @@ class Register extends Entity implements JsonSerializable public function __construct() { $this->addType(fieldName: 'title', type: 'string'); $this->addType(fieldName: 'description', type: 'string'); - $this->addType(fieldName: 'properties', type: 'json'); + $this->addType(fieldName: 'schemas', type: 'json'); $this->addType(fieldName: 'source', type: 'string'); $this->addType(fieldName: 'tablePrefix', type: 'string'); $this->addType(fieldName:'updated', type: 'datetime'); diff --git a/src/entities/register/register.mock.ts b/src/entities/register/register.mock.ts index 2221a7d271..108b32f83d 100644 --- a/src/entities/register/register.mock.ts +++ b/src/entities/register/register.mock.ts @@ -2,22 +2,34 @@ import { Register } from './register' import { TRegister } from './register.types' export const mockRegisterData = (): TRegister[] => [ - { - id: "1234a1e5-b54d-43ad-abd1-4b5bff5fcd3f", - name: "Character Register", - description: "Stores character data for the game", - schemas: ["5678a1e5-b54d-43ad-abd1-4b5bff5fcd3f"], - databaseId: "db1-a1e5-b54d-43ad-abd1-4b5bff5fcd3f", - tablePrefix: "character_" - }, - { - id: "5678a1e5-b54d-43ad-abd1-4b5bff5fcd3f", - name: "Item Register", - description: "Stores item data for the game", - schemas: ["9012a1e5-b54d-43ad-abd1-4b5bff5fcd3f"], - databaseId: "db2-a1e5-b54d-43ad-abd1-4b5bff5fcd3f", - tablePrefix: "item_" - } + { + id: '1234a1e5-b54d-43ad-abd1-4b5bff5fcd3f', + title: 'Character Register', + description: 'Stores character data for the game', + schemas: ['5678a1e5-b54d-43ad-abd1-4b5bff5fcd3f'], + source: '1', + databaseId: 'db1-a1e5-b54d-43ad-abd1-4b5bff5fcd3f', + tablePrefix: 'character_', + created: { + date: new Date().toISOString(), + timezone_type: 3, + timezone: 'UTC', + }, + }, + { + id: '5678a1e5-b54d-43ad-abd1-4b5bff5fcd3f', + title: 'Item Register', + description: 'Stores item data for the game', + schemas: ['9012a1e5-b54d-43ad-abd1-4b5bff5fcd3f'], + source: '1', + databaseId: 'db2-a1e5-b54d-43ad-abd1-4b5bff5fcd3f', + tablePrefix: 'item_', + created: { + date: new Date().toISOString(), + timezone_type: 3, + timezone: 'UTC', + }, + }, ] -export const mockRegister = (data: TRegister[] = mockRegisterData()): TRegister[] => data.map(item => new Register(item)) \ No newline at end of file +export const mockRegister = (data: TRegister[] = mockRegisterData()): TRegister[] => data.map(item => new Register(item)) diff --git a/src/entities/register/register.spec.ts b/src/entities/register/register.spec.ts index 20b0124654..41d0666032 100644 --- a/src/entities/register/register.spec.ts +++ b/src/entities/register/register.spec.ts @@ -1,49 +1,68 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { Register } from './register' import { mockRegisterData } from './register.mock' describe('Register Entity', () => { - it('should create a Register entity with full data', () => { - const register = new Register(mockRegisterData()[0]) - - expect(register).toBeInstanceOf(Register) - expect(register).toEqual(mockRegisterData()[0]) - expect(register.validate().success).toBe(true) - }) - - it('should create a Register entity with partial data', () => { - const partialData = { - name: 'Partial Register', - description: 'A register with partial data', - schemas: [] as any[], // Explicitly typing schemas as any[] - databaseId: 'db1-a1e5-b54d-43ad-abd1-4b5bff5fcd3f' - } - const register = new Register(partialData) - - expect(register).toBeInstanceOf(Register) - expect(register.id).toBe('') - expect(register.name).toBe(partialData.name) - expect(register.tablePrefix).toBe('') - expect(register.validate().success).toBe(true) - }) - - it('should fail validation with invalid data', () => { - const invalidData = { - name: '', - description: 'Invalid register', - schemas: [] as any[], // Explicitly type the schemas property - databaseId: '' - } - const register = new Register(invalidData) - - expect(register).toBeInstanceOf(Register) - expect(register.validate().success).toBe(false) - }) - - it('should correctly combine database and register prefixes', () => { - const register = new Register(mockRegisterData()[0]) - - expect(register.getFullTablePrefix('myorg_')).toBe('myorg_character_') - expect(register.getFullTablePrefix('myorg_')).toBe('myorg_character_') - expect(register.getFullTablePrefix('')).toBe('character_') - }) -}) \ No newline at end of file + it('should create a Register entity with full data', () => { + const register = new Register(mockRegisterData()[0]) + + expect(register).toBeInstanceOf(Register) + expect(register).toEqual(mockRegisterData()[0]) + expect(register.validate().success).toBe(true) + }) + + it('should create a Register entity with partial data', () => { + const partialData = { + name: 'Partial Register', + description: 'A register with partial data', + schemas: [] as any[], // Explicitly typing schemas as any[] + databaseId: 'db1-a1e5-b54d-43ad-abd1-4b5bff5fcd3f', + title: 'Partial Register Title', + source: 'Test Source', + created: { + date: new Date().toISOString(), + timezone_type: 3, + timezone: 'UTC', + }, + } + const register = new Register(partialData) + + expect(register).toBeInstanceOf(Register) + expect(register.id).toBe('') + expect(register.title).toBe(partialData.title) + expect(register.tablePrefix).toBe('') + expect(register.validate().success).toBe(true) + }) + + it('should fail validation with invalid data', () => { + const invalidData = { + name: '', + description: 'Invalid register', + schemas: [] as any[], // Explicitly type the schemas property + databaseId: '', + title: '', + source: '', + created: { + date: new Date().toISOString(), + timezone_type: 3, + timezone: 'UTC', + }, + } + const register = new Register(invalidData) + + expect(register).toBeInstanceOf(Register) + expect(register.validate().success).toBe(false) + expect(register.validate().error?.issues).toContainEqual(expect.objectContaining({ + path: ['name'], + message: 'String must contain at least 1 character(s)', + })) + }) + + it('should correctly combine database and register prefixes', () => { + const register = new Register(mockRegisterData()[0]) + + expect(register.getFullTablePrefix('myorg_')).toBe('myorg_character_') + expect(register.getFullTablePrefix('myorg_')).toBe('myorg_character_') + expect(register.getFullTablePrefix('')).toBe('character_') + }) +}) diff --git a/src/entities/register/register.ts b/src/entities/register/register.ts index 5085c59741..a5b112d42d 100644 --- a/src/entities/register/register.ts +++ b/src/entities/register/register.ts @@ -2,36 +2,62 @@ import { SafeParseReturnType, z } from 'zod' import { TRegister } from './register.types' export class Register implements TRegister { - public id: string - public name: string - public description: string - public schemas: string[] - public databaseId: string - public tablePrefix: string - - constructor(register: TRegister) { - this.id = register.id || '' - this.name = register.name - this.description = register.description - this.schemas = register.schemas || [] - this.databaseId = register.databaseId - this.tablePrefix = register.tablePrefix || '' - } - public validate(): SafeParseReturnType { - const schema = z.object({ - id: z.string().min(1), - name: z.string().min(1), - description: z.string(), - schemas: z.array(z.string()), - databaseId: z.string().min(1), - tablePrefix: z.string() - }) - - return schema.safeParse(this) + public id: string + public title: string + public description: string + public schemas: string[] + public source: string + public databaseId: string + public tablePrefix: string + public updated: { + date: string; + timezone_type: number; + timezone: string; } - public getFullTablePrefix(databasePrefix: string): string { - return `${databasePrefix}${this.tablePrefix}`.replace(/_{2,}/g, '_') + public created: { + date: string; + timezone_type: number; + timezone: string; } -} \ No newline at end of file + + constructor(register: TRegister) { + this.id = register.id || '' + this.title = register.title + this.description = register.description + this.schemas = register.schemas || [] + this.source = register.source || '' + this.databaseId = register.databaseId + this.tablePrefix = register.tablePrefix || '' + this.updated = register.updated || { + date: '', + timezone_type: 0, + timezone: '', + } + this.created = register.created || { + date: '', + timezone_type: 0, + timezone: '', + } + } + + public validate(): SafeParseReturnType { + const schema = z.object({ + id: z.string().min(1), + title: z.string().min(1), + description: z.string(), + schemas: z.array(z.string()), + source: z.string(), + databaseId: z.string().min(1), + tablePrefix: z.string(), + }) + + return schema.safeParse(this) + } + + public getFullTablePrefix(databasePrefix: string): string { + return `${databasePrefix}${this.tablePrefix}`.replace(/_{2,}/g, '_') + } + +} diff --git a/src/entities/register/register.types.ts b/src/entities/register/register.types.ts index 06566cd9b1..526081a906 100644 --- a/src/entities/register/register.types.ts +++ b/src/entities/register/register.types.ts @@ -1,8 +1,19 @@ export type TRegister = { id?: string - name: string + title: string description: string schemas: string[] // Array of Schema UUIDs + source: string // Reference to the Source entity databaseId: string // Reference to the Database entity tablePrefix?: string -} \ No newline at end of file + updated?: { + date: string; + timezone_type: number; + timezone: string; + } + created: { + date: string; + timezone_type: number; + timezone: string; + } +} diff --git a/src/entities/source/source.mock.ts b/src/entities/source/source.mock.ts index aa4be7de80..82aaa428dd 100644 --- a/src/entities/source/source.mock.ts +++ b/src/entities/source/source.mock.ts @@ -2,13 +2,24 @@ import { Source } from './source' import { TSource } from './source.types' export const mockSourceData = (): TSource[] => [ - { - id: "5678a1e5-b54d-43ad-abd1-4b5bff5fcd3f", - name: "Main PostgreSQL Database", - description: "Primary database for user data", - databaseUrl: "postgresql://user:password@localhost:5432/maindb" - }, - // ... existing code ... + { + id: 1, + title: 'Main PostgreSQL Database', + description: 'Primary database for user data', + databaseUrl: 'postgresql://user:password@localhost:5432/maindb', + type: 'postgresql', + updated: { + date: '2024-03-15 09:30:00.000000', + timezone_type: 3, + timezone: 'UTC', + }, + created: { + date: '2024-03-15 09:30:00.000000', + timezone_type: 3, + timezone: 'UTC', + }, + }, + // ... existing code ... ] -export const mockSource = (data: TSource[] = mockSourceData()): TSource[] => data.map(item => new Source(item)) \ No newline at end of file +export const mockSource = (data: TSource[] = mockSourceData()): TSource[] => data.map(item => new Source(item)) diff --git a/src/entities/source/source.ts b/src/entities/source/source.ts index 5a1141b85a..397ca67886 100644 --- a/src/entities/source/source.ts +++ b/src/entities/source/source.ts @@ -2,26 +2,52 @@ import { SafeParseReturnType, z } from 'zod' import { TSource } from './source.types' export class Source implements TSource { - public id: string - public name: string - public description: string - public databaseUrl: string - constructor(source: TSource) { - this.id = source.id || '' - this.name = source.name || '' - this.description = source.description || '' - this.databaseUrl = source.databaseUrl || '' + public id: string | number + public title: string + public description: string + public databaseUrl: string + public type: string + public updated: { + date: string; + timezone_type: number; + timezone: string; } - public validate(): SafeParseReturnType { - const schema = z.object({ - id: z.string().min(1), - name: z.string().min(1), - description: z.string(), - databaseUrl: z.string().url(), - }) - - return schema.safeParse(this) + public created: { + date: string; + timezone_type: number; + timezone: string; } -} \ No newline at end of file + + constructor(source: TSource) { + this.id = source.id || '' + this.title = source.title || '' + this.description = source.description || '' + this.databaseUrl = source.databaseUrl || '' + this.type = source.type || '' + this.updated = source.updated || { + date: '', + timezone_type: 0, + timezone: '', + } + this.created = source.created || { + date: '', + timezone_type: 0, + timezone: '', + } + } + + public validate(): SafeParseReturnType { + const schema = z.object({ + id: z.union([z.string(), z.number()]), + title: z.string().min(1), + description: z.string(), + databaseUrl: z.string().url(), + type: z.string(), + }) + + return schema.safeParse(this) + } + +} diff --git a/src/entities/source/source.types.ts b/src/entities/source/source.types.ts index 8636af4eb2..bb45da5eea 100644 --- a/src/entities/source/source.types.ts +++ b/src/entities/source/source.types.ts @@ -1,6 +1,17 @@ export type TSource = { - id?: string - name: string - description: string - databaseUrl: string -} \ No newline at end of file + id?: string | number; + title: string; + description: string; + databaseUrl: string; + type: string; + updated: { + date: string; + timezone_type: number; + timezone: string; + }; + created: { + date: string; + timezone_type: number; + timezone: string; + }; +} diff --git a/src/modals/register/EditRegister.vue b/src/modals/register/EditRegister.vue index 314b995b84..676babcfe9 100644 --- a/src/modals/register/EditRegister.vue +++ b/src/modals/register/EditRegister.vue @@ -1,5 +1,5 @@ diff --git a/src/views/source/SourceDetails.vue b/src/views/source/SourceDetails.vue index c788f139db..3ea2748a5f 100644 --- a/src/views/source/SourceDetails.vue +++ b/src/views/source/SourceDetails.vue @@ -1,5 +1,5 @@ diff --git a/src/views/source/SourcesList.vue b/src/views/source/SourcesList.vue index 6a1d0ad025..f9acb2d227 100644 --- a/src/views/source/SourcesList.vue +++ b/src/views/source/SourcesList.vue @@ -33,7 +33,7 @@ import { sourceStore, navigationStore, searchStore } from '../../store/store.js'
From 34347b0f68c48b7109f5e0d345b79609ef6755b5 Mon Sep 17 00:00:00 2001 From: Thijn Date: Fri, 27 Sep 2024 15:59:25 +0200 Subject: [PATCH 09/12] updated date format --- lib/Db/Register.php | 4 ++-- lib/Db/Source.php | 4 ++-- src/entities/register/register.mock.ts | 14 ++++---------- src/entities/register/register.ts | 25 ++++--------------------- src/entities/register/register.types.ts | 12 ++---------- src/entities/source/source.mock.ts | 13 ++----------- src/entities/source/source.ts | 25 ++++--------------------- src/entities/source/source.types.ts | 12 ++---------- src/store/modules/register.js | 3 +-- 9 files changed, 23 insertions(+), 89 deletions(-) diff --git a/lib/Db/Register.php b/lib/Db/Register.php index 6cf83515ea..4d289fc1a7 100644 --- a/lib/Db/Register.php +++ b/lib/Db/Register.php @@ -69,8 +69,8 @@ public function jsonSerialize(): array 'schemas' => $this->schemas, 'source' => $this->source, 'tablePrefix' => $this->tablePrefix, - 'updated' => $this->updated, - 'created' => $this->created + 'updated' => isset($this->updated) ? $this->updated->format('c') : null, + 'created' => isset($this->created) ? $this->created->format('c') : null ]; } } \ No newline at end of file diff --git a/lib/Db/Source.php b/lib/Db/Source.php index 9203b6e253..1a8b9289e8 100644 --- a/lib/Db/Source.php +++ b/lib/Db/Source.php @@ -64,8 +64,8 @@ public function jsonSerialize(): array 'description' => $this->description, 'databaseUrl' => $this->databaseUrl, 'type' => $this->type, - 'updated' => $this->updated, - 'created' => $this->created + 'updated' => isset($this->updated) ? $this->updated->format('c') : null, + 'created' => isset($this->created) ? $this->created->format('c') : null ]; } } \ No newline at end of file diff --git a/src/entities/register/register.mock.ts b/src/entities/register/register.mock.ts index 108b32f83d..3e7bb13c26 100644 --- a/src/entities/register/register.mock.ts +++ b/src/entities/register/register.mock.ts @@ -10,11 +10,8 @@ export const mockRegisterData = (): TRegister[] => [ source: '1', databaseId: 'db1-a1e5-b54d-43ad-abd1-4b5bff5fcd3f', tablePrefix: 'character_', - created: { - date: new Date().toISOString(), - timezone_type: 3, - timezone: 'UTC', - }, + created: new Date().toISOString(), + updated: new Date().toISOString(), }, { id: '5678a1e5-b54d-43ad-abd1-4b5bff5fcd3f', @@ -24,11 +21,8 @@ export const mockRegisterData = (): TRegister[] => [ source: '1', databaseId: 'db2-a1e5-b54d-43ad-abd1-4b5bff5fcd3f', tablePrefix: 'item_', - created: { - date: new Date().toISOString(), - timezone_type: 3, - timezone: 'UTC', - }, + created: new Date().toISOString(), + updated: new Date().toISOString(), }, ] diff --git a/src/entities/register/register.ts b/src/entities/register/register.ts index a5b112d42d..6d29555b25 100644 --- a/src/entities/register/register.ts +++ b/src/entities/register/register.ts @@ -10,17 +10,8 @@ export class Register implements TRegister { public source: string public databaseId: string public tablePrefix: string - public updated: { - date: string; - timezone_type: number; - timezone: string; - } - - public created: { - date: string; - timezone_type: number; - timezone: string; - } + public updated: string + public created: string constructor(register: TRegister) { this.id = register.id || '' @@ -30,16 +21,8 @@ export class Register implements TRegister { this.source = register.source || '' this.databaseId = register.databaseId this.tablePrefix = register.tablePrefix || '' - this.updated = register.updated || { - date: '', - timezone_type: 0, - timezone: '', - } - this.created = register.created || { - date: '', - timezone_type: 0, - timezone: '', - } + this.updated = register.updated || '' + this.created = register.created || '' } public validate(): SafeParseReturnType { diff --git a/src/entities/register/register.types.ts b/src/entities/register/register.types.ts index 526081a906..1016d45c68 100644 --- a/src/entities/register/register.types.ts +++ b/src/entities/register/register.types.ts @@ -6,14 +6,6 @@ export type TRegister = { source: string // Reference to the Source entity databaseId: string // Reference to the Database entity tablePrefix?: string - updated?: { - date: string; - timezone_type: number; - timezone: string; - } - created: { - date: string; - timezone_type: number; - timezone: string; - } + updated?: string + created: string } diff --git a/src/entities/source/source.mock.ts b/src/entities/source/source.mock.ts index 82aaa428dd..a9e1f95689 100644 --- a/src/entities/source/source.mock.ts +++ b/src/entities/source/source.mock.ts @@ -8,18 +8,9 @@ export const mockSourceData = (): TSource[] => [ description: 'Primary database for user data', databaseUrl: 'postgresql://user:password@localhost:5432/maindb', type: 'postgresql', - updated: { - date: '2024-03-15 09:30:00.000000', - timezone_type: 3, - timezone: 'UTC', - }, - created: { - date: '2024-03-15 09:30:00.000000', - timezone_type: 3, - timezone: 'UTC', - }, + updated: new Date().toISOString(), + created: new Date().toISOString(), }, - // ... existing code ... ] export const mockSource = (data: TSource[] = mockSourceData()): TSource[] => data.map(item => new Source(item)) diff --git a/src/entities/source/source.ts b/src/entities/source/source.ts index 397ca67886..ffa715ebc2 100644 --- a/src/entities/source/source.ts +++ b/src/entities/source/source.ts @@ -8,17 +8,8 @@ export class Source implements TSource { public description: string public databaseUrl: string public type: string - public updated: { - date: string; - timezone_type: number; - timezone: string; - } - - public created: { - date: string; - timezone_type: number; - timezone: string; - } + public updated: string + public created: string constructor(source: TSource) { this.id = source.id || '' @@ -26,16 +17,8 @@ export class Source implements TSource { this.description = source.description || '' this.databaseUrl = source.databaseUrl || '' this.type = source.type || '' - this.updated = source.updated || { - date: '', - timezone_type: 0, - timezone: '', - } - this.created = source.created || { - date: '', - timezone_type: 0, - timezone: '', - } + this.updated = source.updated || '' + this.created = source.created || '' } public validate(): SafeParseReturnType { diff --git a/src/entities/source/source.types.ts b/src/entities/source/source.types.ts index bb45da5eea..05e55d1d65 100644 --- a/src/entities/source/source.types.ts +++ b/src/entities/source/source.types.ts @@ -4,14 +4,6 @@ export type TSource = { description: string; databaseUrl: string; type: string; - updated: { - date: string; - timezone_type: number; - timezone: string; - }; - created: { - date: string; - timezone_type: number; - timezone: string; - }; + updated: string; + created: string; } diff --git a/src/store/modules/register.js b/src/store/modules/register.js index cc91b9793d..f5c34648cd 100644 --- a/src/store/modules/register.js +++ b/src/store/modules/register.js @@ -105,8 +105,7 @@ export const useRegisterStore = defineStore('register', { : `/index.php/apps/openregister/api/registers/${registerItem.id}` const method = isNewRegister ? 'POST' : 'PUT' - // change updated to current date as a singular iso date string and created to the date string - registerItem.created = registerItem.created.date + // change updated to current date as a singular iso date string registerItem.updated = new Date().toISOString() try { From 8ecf1aaebf578b9e7244bc1d9e2de87e7007007e Mon Sep 17 00:00:00 2001 From: Thijn Date: Fri, 27 Sep 2024 16:00:51 +0200 Subject: [PATCH 10/12] fixed error with specs --- src/entities/register/register.spec.ts | 32 +++----------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/src/entities/register/register.spec.ts b/src/entities/register/register.spec.ts index 41d0666032..6c774b43db 100644 --- a/src/entities/register/register.spec.ts +++ b/src/entities/register/register.spec.ts @@ -12,43 +12,17 @@ describe('Register Entity', () => { }) it('should create a Register entity with partial data', () => { - const partialData = { - name: 'Partial Register', - description: 'A register with partial data', - schemas: [] as any[], // Explicitly typing schemas as any[] - databaseId: 'db1-a1e5-b54d-43ad-abd1-4b5bff5fcd3f', - title: 'Partial Register Title', - source: 'Test Source', - created: { - date: new Date().toISOString(), - timezone_type: 3, - timezone: 'UTC', - }, - } - const register = new Register(partialData) + const register = new Register(mockRegisterData()[0]) expect(register).toBeInstanceOf(Register) expect(register.id).toBe('') - expect(register.title).toBe(partialData.title) + expect(register.title).toBe(mockRegisterData()[0].title) expect(register.tablePrefix).toBe('') expect(register.validate().success).toBe(true) }) it('should fail validation with invalid data', () => { - const invalidData = { - name: '', - description: 'Invalid register', - schemas: [] as any[], // Explicitly type the schemas property - databaseId: '', - title: '', - source: '', - created: { - date: new Date().toISOString(), - timezone_type: 3, - timezone: 'UTC', - }, - } - const register = new Register(invalidData) + const register = new Register(mockRegisterData()[1]) expect(register).toBeInstanceOf(Register) expect(register.validate().success).toBe(false) From e8ca0784b7f1cb2701970fec3fe3d0c653c2f4ab Mon Sep 17 00:00:00 2001 From: Thijn Date: Fri, 27 Sep 2024 16:01:51 +0200 Subject: [PATCH 11/12] updated updated date --- src/store/modules/source.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/store/modules/source.js b/src/store/modules/source.js index 4ee42ca36c..a3c96fb48f 100644 --- a/src/store/modules/source.js +++ b/src/store/modules/source.js @@ -97,6 +97,8 @@ export const useSourceStore = defineStore( : `/index.php/apps/openregister/api/sources/${sourceItem.id}` const method = isNewSource ? 'POST' : 'PUT' + sourceItem.updated = new Date().toISOString() + const response = await fetch( endpoint, { From 04cc458f900b265a9ac0f5579996d01e5e0dafc8 Mon Sep 17 00:00:00 2001 From: Remko Date: Mon, 30 Sep 2024 13:35:22 +0200 Subject: [PATCH 12/12] updated css --- css/main.css | 16 ++++++++-------- src/views/register/RegisterDetails.vue | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/css/main.css b/css/main.css index a7a8e73598..290da6e181 100755 --- a/css/main.css +++ b/css/main.css @@ -1,7 +1,7 @@ :root { - --Larp-margin-10: 10px; - --Larp-margin-20: 20px; - --Larp-margin-50: 50px; + --OR-margin-10: 10px; + --OR-margin-20: 20px; + --OR-margin-50: 50px; } /* Pages */ @@ -43,9 +43,9 @@ /* Detail pages */ .detailContainer { - margin-block-start: var(--Larp-margin-20); - margin-inline-start: var(--Larp-margin-20); - margin-inline-end: var(--Larp-margin-20); + margin-block-start: var(--OR-margin-20); + margin-inline-start: var(--OR-margin-20); + margin-inline-end: var(--OR-margin-20); } .tabContainer > * ul > li { @@ -83,7 +83,7 @@ } .tabContainer > * div[role="tabpanel"] { - margin-block-start: var(--Larp-margin-10); + margin-block-start: var(--OR-margin-10); } .tabPanel { @@ -112,7 +112,7 @@ /* Modals */ .modalContent { - margin: var(--Larp-margin-50); + margin: var(--OR-margin-50); text-align: center; } diff --git a/src/views/register/RegisterDetails.vue b/src/views/register/RegisterDetails.vue index 599fe23586..5fe0a4d0c7 100644 --- a/src/views/register/RegisterDetails.vue +++ b/src/views/register/RegisterDetails.vue @@ -86,8 +86,8 @@ h4 { display: grid; grid-gap: 24px; grid-template-columns: 1fr 1fr; - margin-block-start: var(--zaa-margin-50); - margin-block-end: var(--zaa-margin-50); + margin-block-start: var(--OR-margin-50); + margin-block-end: var(--OR-margin-50); } .gridContent {