diff --git a/front/js/svelte/content/Table.svelte b/front/js/svelte/content/Table.svelte index ea9bca0..c77bb2d 100644 --- a/front/js/svelte/content/Table.svelte +++ b/front/js/svelte/content/Table.svelte @@ -90,11 +90,11 @@ class="me-2 text-decoration-none text-dark fs-6" href="{channel.lucentUrl}/records/{record.id}" target={inModal ? "_blank" : "_self"} - title={previewTitle(channel.schemas, record, graph)} + title={previewTitle(record, graph)} data-bs-toggle="tooltip" data-bs-placement="left" > - {previewTitle(channel.schemas, record, graph)} + {previewTitle(record, graph)}
diff --git a/front/js/svelte/content/tools/AppliedFilter.svelte b/front/js/svelte/content/tools/AppliedFilter.svelte index 146853c..00e12f4 100644 --- a/front/js/svelte/content/tools/AppliedFilter.svelte +++ b/front/js/svelte/content/tools/AppliedFilter.svelte @@ -76,7 +76,7 @@
{#if filter.isReference && filterRecord} - {filter.label} is {previewTitle(channel.schemas, filterRecord)} + {filter.label} is {previewTitle(filterRecord)} {:else} {filter.label} {operators.find((o) => o.name === filter.operator)?.symbol ?? ""} {value} {/if} diff --git a/front/js/svelte/content/tools/FilterReferenceInput.svelte b/front/js/svelte/content/tools/FilterReferenceInput.svelte index 4fa6010..7dbcc6d 100644 --- a/front/js/svelte/content/tools/FilterReferenceInput.svelte +++ b/front/js/svelte/content/tools/FilterReferenceInput.svelte @@ -62,7 +62,7 @@ on:keypress={(e) => apply(e, option)} > - {previewTitle(channel.schemas, option)} + {previewTitle( option)}
diff --git a/front/js/svelte/edges/EdgeModal.svelte b/front/js/svelte/edges/EdgeModal.svelte new file mode 100644 index 0000000..dece05a --- /dev/null +++ b/front/js/svelte/edges/EdgeModal.svelte @@ -0,0 +1,54 @@ + + + + + + diff --git a/front/js/svelte/newPreview/Preview.svelte b/front/js/svelte/newPreview/Preview.svelte new file mode 100644 index 0000000..00ddd49 --- /dev/null +++ b/front/js/svelte/newPreview/Preview.svelte @@ -0,0 +1,61 @@ + + + + +
+
+ {#if field.data} + + {:else} + + {/if} + +
+ + {#if hasDelete} +
+ +
+ {/if} +
+ + + \ No newline at end of file diff --git a/front/js/svelte/newPreview/preview/PreviewEdge.svelte b/front/js/svelte/newPreview/preview/PreviewEdge.svelte new file mode 100644 index 0000000..c409ba3 --- /dev/null +++ b/front/js/svelte/newPreview/preview/PreviewEdge.svelte @@ -0,0 +1,30 @@ + + + + + + + \ No newline at end of file diff --git a/front/js/svelte/newPreview/preview/PreviewRecord.svelte b/front/js/svelte/newPreview/preview/PreviewRecord.svelte new file mode 100644 index 0000000..193b767 --- /dev/null +++ b/front/js/svelte/newPreview/preview/PreviewRecord.svelte @@ -0,0 +1,55 @@ + +
+
+ {#if schema.type === "files"} +
+ +
+ {/if} +
+ + {cardTitle} + + + {schema.label} + + + {#if record.status === "draft"} + + {/if} + +
+
+
+ + + diff --git a/front/js/svelte/records/Edit.svelte b/front/js/svelte/records/Edit.svelte index 048f4cf..0f3cc8b 100644 --- a/front/js/svelte/records/Edit.svelte +++ b/front/js/svelte/records/Edit.svelte @@ -115,7 +115,7 @@ console.log("SAVE: SAVED"); if (isCreateMode) { - window.location = channel.lucentUrl + "/records/" + record.id; + window.location.href = channel.lucentUrl + "/records/" + record.id; } else { record = response.data.records[0] ?? null; if (!record) { @@ -141,9 +141,7 @@ } } resolve(null); - // msgSuccess = null; - // msgError = error.response.data.error; - // submitted = false; + }); }); } diff --git a/front/js/svelte/records/EditHeader.svelte b/front/js/svelte/records/EditHeader.svelte index 04bd84a..44bd3ca 100644 --- a/front/js/svelte/records/EditHeader.svelte +++ b/front/js/svelte/records/EditHeader.svelte @@ -29,7 +29,7 @@ {#if !isCreateMode} - {previewTitle(channel.schemas, record, graph)} + {previewTitle( record, graph)} {:else} New Record {/if} diff --git a/front/js/svelte/records/Preview.js b/front/js/svelte/records/Preview.js index 2aea612..238aa63 100644 --- a/front/js/svelte/records/Preview.js +++ b/front/js/svelte/records/Preview.js @@ -1,8 +1,10 @@ import Mustache from "mustache"; import {stripHtml} from "../../helpers"; +import {getContext} from "svelte"; -export function previewTitle(schemas, record, graph) { - let schema = schemas.find((aSchema) => aSchema.name === record?.schema); +export function previewTitle(record, graph) { + const channel = getContext("channel"); + let schema = channel.schemas.find((aSchema) => aSchema.name === record?.schema); if (!schema?.titleTemplate) { return noTemplate(schema, record); @@ -10,7 +12,7 @@ export function previewTitle(schemas, record, graph) { let recordData = record.data; let template = Mustache.parse(schema.titleTemplate); - + console.log({template}) let referencePreviews = template .filter(segment => segment[0] === "name") // keep only template tags .map((segment) => segment[1]) // map to fieldNames @@ -20,7 +22,7 @@ export function previewTitle(schemas, record, graph) { }).reduce((carry, field) => { // map to records let edge = graph.edges.find(edge => edge.source === record.id && edge.field === field) let referenceRecord = graph.records.find(rec => rec.id === edge?.target) - carry[field] = previewTitle(schemas, referenceRecord, graph); + carry[field] = previewTitle(referenceRecord, graph); return carry; }, {}); recordData = {...recordData, ...referencePreviews} @@ -43,7 +45,7 @@ function noTemplate(schema, record) { record?.data[schema.fields.filter((f) => f.info.name === "text")[0]?.name] ).slice(0, 300); - if(title == ""){ + if(title === ""){ return "Untitled"; } diff --git a/front/js/svelte/records/PreviewCard.svelte b/front/js/svelte/records/PreviewCard.svelte index 0737440..bba8c45 100644 --- a/front/js/svelte/records/PreviewCard.svelte +++ b/front/js/svelte/records/PreviewCard.svelte @@ -13,10 +13,9 @@ export let hasDelete = false; let schema = channel.schemas.find((aschema) => aschema.name === record.schema); - let cardTitle = previewTitle(channel.schemas, record, graph); + let cardTitle = previewTitle(record, graph); function remove(e) { e.preventDefault(); - dispatch("remove", record.id); } diff --git a/front/js/svelte/records/PreviewCardSmall.svelte b/front/js/svelte/records/PreviewCardSmall.svelte index c346b3a..b330a77 100644 --- a/front/js/svelte/records/PreviewCardSmall.svelte +++ b/front/js/svelte/records/PreviewCardSmall.svelte @@ -7,7 +7,7 @@ export let graph; $: schema = channel.schemas.find((aschema) => aschema.name === record.schema); - $: title = previewTitle(channel.schemas, record, graph); + $: title = previewTitle( record, graph); {#if record?.data} diff --git a/front/js/svelte/records/elements/File.svelte b/front/js/svelte/records/elements/File.svelte index 4baf748..15a879e 100644 --- a/front/js/svelte/records/elements/File.svelte +++ b/front/js/svelte/records/elements/File.svelte @@ -5,6 +5,7 @@ import PreviewCard from "../PreviewCard.svelte"; import Sortable from "../../libs/Sortable.svelte"; import BrowseModal from "./BrowseModal.svelte"; + import Preview from "../../newPreview/Preview.svelte"; const channel = getContext("channel"); export let field; @@ -16,8 +17,11 @@ $: references = graph?.edges .filter((edge) => edge.field === field.name) .map((edge) => { - return graph.records.find((increc) => increc.id == edge.target && record.id == edge.source); - }).filter((rec) => (rec?.id ? true : false)) ?? []; + return { + record: graph.records.find((increc) => increc.id === edge.target && record.id === edge.source), + edge: edge, + } + }).filter((recordEdge) => (!!recordEdge.record?.id)) ?? []; let collections = channel.schemas.filter((aschema) => field.collections.includes(aschema.name) @@ -101,14 +105,22 @@
{#if references.length > 0} - {#each references as reference (reference.id)} + {#each references as reference (reference.record.id)}
+ + + + + + + +
{/each}
diff --git a/src/ArrayContainer.php b/src/ArrayContainer.php index f3e7646..1820a85 100644 --- a/src/ArrayContainer.php +++ b/src/ArrayContainer.php @@ -14,10 +14,7 @@ class ArrayContainer implements ArrayAccess, JsonSerializable { } - public function get(string $key, mixed $default = null): mixed - { - return $this->data[$key] ?? $default; - } + public function offsetSet($offset, $value): void { diff --git a/src/Database/migrations/2014_10_12_000000_create_users_table.php b/src/Database/migrations/01_create_users_table.php similarity index 100% rename from src/Database/migrations/2014_10_12_000000_create_users_table.php rename to src/Database/migrations/01_create_users_table.php diff --git a/src/Database/migrations/2022_11_16_192907_create_sessions_table.php b/src/Database/migrations/02_create_sessions_table.php similarity index 100% rename from src/Database/migrations/2022_11_16_192907_create_sessions_table.php rename to src/Database/migrations/02_create_sessions_table.php diff --git a/src/Database/migrations/2023_01_20_162322_records.php b/src/Database/migrations/03_records.php similarity index 100% rename from src/Database/migrations/2023_01_20_162322_records.php rename to src/Database/migrations/03_records.php diff --git a/src/Database/migrations/2023_03_02_152122_revisions.php b/src/Database/migrations/04_revisions.php similarity index 100% rename from src/Database/migrations/2023_03_02_152122_revisions.php rename to src/Database/migrations/04_revisions.php diff --git a/src/Database/migrations/2023_10_22_152122_generatedIndexColumn.php b/src/Database/migrations/05_generatedIndexColumn.php similarity index 100% rename from src/Database/migrations/2023_10_22_152122_generatedIndexColumn.php rename to src/Database/migrations/05_generatedIndexColumn.php diff --git a/src/Database/migrations/2023_10_23_152122_RecordsUpdatedIndex.php b/src/Database/migrations/06_RecordsUpdatedIndex.php similarity index 100% rename from src/Database/migrations/2023_10_23_152122_RecordsUpdatedIndex.php rename to src/Database/migrations/06_RecordsUpdatedIndex.php diff --git a/src/Database/migrations/07_EdgeData.php b/src/Database/migrations/07_EdgeData.php new file mode 100644 index 0000000..e7825b5 --- /dev/null +++ b/src/Database/migrations/07_EdgeData.php @@ -0,0 +1,32 @@ +jsonb('data')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('records', function (Blueprint $table) { + + $table->dropColumn("data"); + }); + } +}; diff --git a/src/Edge/Edge.php b/src/Edge/Edge.php index 911a3f1..6683789 100644 --- a/src/Edge/Edge.php +++ b/src/Edge/Edge.php @@ -4,10 +4,12 @@ namespace Lucent\Edge; use Lucent\LucentException; use Lucent\Validator\Validator as LucentValidator; +use PhpOption\Option; final class Edge { /** + * @param Option $data * @throws LucentException */ public function __construct( @@ -17,6 +19,7 @@ final class Edge public string $sourceSchema, public string $targetSchema, public string $field, + public Option $data, public string $rank = "a", public int $depth = 0, ) @@ -40,6 +43,7 @@ final class Edge public function toDB(): array { $data = $this->toArray(); + $data["data"] = json_encode($data["data"]); unset($data["depth"]); return $data; } @@ -54,6 +58,7 @@ final class Edge sourceSchema: data_get($data, 'sourceSchema'), targetSchema: data_get($data, 'targetSchema'), field: data_get($data, 'field'), + data: Option::fromValue(data_get($data,"data")), rank: data_get($data, 'rank'), depth: data_get($data, 'depth', 0), ); diff --git a/src/Edge/EdgeData.php b/src/Edge/EdgeData.php new file mode 100644 index 0000000..839a2e1 --- /dev/null +++ b/src/Edge/EdgeData.php @@ -0,0 +1,50 @@ +data = array_merge($this->data, $data->toArray()); + return $this; + } + + public function get(string $key, mixed $default = null): mixed + { + return $this->data[$key] ?? $default; + } + + public function set(string $key, mixed $value): EdgeData + { + $this->data[$key] = $value; + return $this; + } + + public function isEmpty(string $key): bool + { + return empty($this->get($key)); + } + + public function isDefined(string $key): bool + { + return !empty($this->get($key)); + } + + + public function toArray(): array + { + return $this->data; + } + + public function jsonSerialize(): array + { + return $this->data; + } + + +} diff --git a/src/Edge/EdgeRepo.php b/src/Edge/EdgeRepo.php index 1c9d912..1773a37 100644 --- a/src/Edge/EdgeRepo.php +++ b/src/Edge/EdgeRepo.php @@ -3,6 +3,7 @@ use Illuminate\Support\Facades\DB; use Lucent\LucentException; use PDOException; +use PhpOption\Option; use stdClass; class EdgeRepo @@ -27,7 +28,7 @@ class EdgeRepo public function update(string $from, EdgeCollection $edges): void { - $edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray(); + $edgesDB = collect($edges)->map(fn(Edge $e) => $e->toDB())->toArray(); DB::table("edges")->where("source", $from)->delete(); DB::table("edges")->insert($edgesDB); } @@ -41,6 +42,12 @@ class EdgeRepo public function mapEdge(stdClass $edge): Edge { + if(empty($edge->data)){ + $data = none(); + }else{ + $data = some(new EdgeData(json_decode($edge->data))); + } + return new Edge( source: $edge->source, @@ -48,6 +55,7 @@ class EdgeRepo sourceSchema: $edge->sourceSchema, targetSchema: $edge->targetSchema, field: $edge->field, + data: $data, rank: $edge->rank, depth: $edge->depth ?? 0 ); diff --git a/src/Http/Controller/RecordController.php b/src/Http/Controller/RecordController.php index 6c5c663..2afcfa8 100644 --- a/src/Http/Controller/RecordController.php +++ b/src/Http/Controller/RecordController.php @@ -13,7 +13,6 @@ use Lucent\Query\Query; use Lucent\Record\Manager; use Lucent\Record\QueryRecord; use Lucent\Record\RecordService; -use Lucent\Schema\FieldInterface; use Lucent\Schema\System; use Lucent\Schema\Validator\ValidatorException; use Lucent\Svelte\Svelte; diff --git a/src/JsonSchema/Command/GenerateJsonSchema.php b/src/JsonSchema/Command/GenerateJsonSchema.php index 5410a06..e623a0c 100644 --- a/src/JsonSchema/Command/GenerateJsonSchema.php +++ b/src/JsonSchema/Command/GenerateJsonSchema.php @@ -8,7 +8,7 @@ use Lucent\JsonSchema\Definition; use Lucent\JsonSchema\JsonSchemaService; use Lucent\JsonSchema\SchemaData; use Lucent\Primitive\Collection; -use Lucent\Schema\FieldInterface; +use Lucent\Schema\Field\FieldInterface; use Lucent\Schema\Schema; use Lucent\Schema\Type; diff --git a/src/JsonSchema/Definition.php b/src/JsonSchema/Definition.php index 02f6941..c0f0b7f 100644 --- a/src/JsonSchema/Definition.php +++ b/src/JsonSchema/Definition.php @@ -3,11 +3,8 @@ namespace Lucent\JsonSchema; use Lucent\JsonSchema\Property\Property; -use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\RefProperty; -use Lucent\JsonSchema\Property\TypeProperty; use Lucent\Primitive\Collection; -use Lucent\Schema\FieldInterface; use PhpOption\Option; class Definition diff --git a/src/Query/DatabaseGraph/PgsqlDatabaseGraph.php b/src/Query/DatabaseGraph/PgsqlDatabaseGraph.php index 32f008f..1bcb67f 100644 --- a/src/Query/DatabaseGraph/PgsqlDatabaseGraph.php +++ b/src/Query/DatabaseGraph/PgsqlDatabaseGraph.php @@ -22,7 +22,7 @@ class PgsqlDatabaseGraph implements DatabaseGraph } $subquery->limit($options->childrenLimit) - ->unionAll( + ->union( DB::table(DB::raw("edges AS g, search_graph AS sg ")) ->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->whereRaw("g.source = sg.target") @@ -43,9 +43,15 @@ class PgsqlDatabaseGraph implements DatabaseGraph { $subquery = DB::table('edges AS g') ->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth ')) + ->whereIn('g.target', $ids); + + if (!empty($options->parentFields)) { + $subquery->whereIn('field', $options->parentFields); + } + + $subquery ->limit($options->parentsLimit) - ->whereIn('g.target', $ids) - ->unionAll( + ->union( DB::table(DB::raw("edges AS g, search_graph AS sg ")) ->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->whereRaw("g.target = sg.source") diff --git a/src/Query/DatabaseGraph/SqliteDatabaseGraph.php b/src/Query/DatabaseGraph/SqliteDatabaseGraph.php index 26d69b6..14d2ce9 100644 --- a/src/Query/DatabaseGraph/SqliteDatabaseGraph.php +++ b/src/Query/DatabaseGraph/SqliteDatabaseGraph.php @@ -21,7 +21,7 @@ class SqliteDatabaseGraph implements DatabaseGraph } $subquery->limit($options->childrenLimit) - ->unionAll( + ->union( DB::table(DB::raw("edges AS g, search_graph AS sg ")) ->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->whereRaw("g.source = sg.target") @@ -42,9 +42,15 @@ class SqliteDatabaseGraph implements DatabaseGraph { $subquery = DB::table('edges AS g') ->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth ')) + ->whereIn('g.target', $ids); + + if (!empty($options->parentFields)) { + $subquery->whereIn('field', $options->parentFields); + } + + $subquery ->limit($options->parentsLimit) - ->whereIn('g.target', $ids) - ->unionAll( + ->union( DB::table(DB::raw("edges AS g, search_graph AS sg ")) ->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->whereRaw("g.target = sg.source") diff --git a/src/Query/Operator.php b/src/Query/Operator.php index ddf94f0..879e6cd 100644 --- a/src/Query/Operator.php +++ b/src/Query/Operator.php @@ -154,15 +154,15 @@ final class Operator "null" => new Operator( name: "null", label: "Is null", - symbol: "=", - db: '$eq', + symbol: "is", + db: '=', uis: ["*"], ), "nnull" => new Operator( name: "nnull", label: "Not null", - symbol: "!=", - db: '$ne', + symbol: "is not", + db: '!=', uis: ["*"], ), "exists" => new Operator( diff --git a/src/Record/InputFormatter.php b/src/Record/InputFormatter.php index d92a60c..4085273 100644 --- a/src/Record/InputFormatter.php +++ b/src/Record/InputFormatter.php @@ -3,7 +3,8 @@ namespace Lucent\Record; use Lucent\Channel\ChannelService; -use Lucent\Schema\FieldInterface; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInterface; class InputFormatter { @@ -17,8 +18,9 @@ class InputFormatter public function fill(string $schemaName, RecordData $input): RecordData { $schema = $this->channelService->getSchema($schemaName)->get(); - $data = $schema->fields->reduce(fn(array $carry, FieldInterface $field) => $field->format($input->toArray(), $carry), []); - return new RecordData($data); + return $schema->fields + ->filter(fn(FieldInterface $field)=> $field instanceof FieldDataInterface) + ->reduce(fn(RecordData $carry, FieldDataInterface $field) => $field->format($input, $carry), new RecordData([])); } diff --git a/src/Record/RecordData.php b/src/Record/RecordData.php index eade6a4..784147f 100644 --- a/src/Record/RecordData.php +++ b/src/Record/RecordData.php @@ -15,10 +15,37 @@ class RecordData extends ArrayContainer return $this; } + public function get(string $key, mixed $default = null): mixed + { + return $this->data[$key] ?? $default; + } + + public function set(string $key, mixed $value): RecordData + { + $this->data[$key] = $value; + return $this; + } + + public function isEmpty(string $key): bool + { + return empty($this->get($key)); + } + + public function isDefined(string $key): bool + { + return !empty($this->get($key)); + } + + public function toArray(): array { return $this->data; } - + public function jsonSerialize(): array + { + return $this->data; + } + + } diff --git a/src/Record/RecordService.php b/src/Record/RecordService.php index 461bbbd..4ea06f2 100644 --- a/src/Record/RecordService.php +++ b/src/Record/RecordService.php @@ -13,7 +13,7 @@ use Lucent\Id\Id; use Lucent\LucentException; use Lucent\Query\Query; use Lucent\Revision\RevisionService; -use Lucent\Schema\FieldInterface; +use Lucent\Schema\Field\FieldInterface; use Lucent\Schema\Schema; use Lucent\Schema\Validator\Validator; use Lucent\Schema\Validator\ValidatorException; @@ -120,14 +120,13 @@ readonly class RecordService $uniqueEdgesCollection = new EdgeCollection(); if ($updateEdges) { $uniqueEdges = collect($edges) - ->map(function ($edge, $index) { + ->map(function ($edge, $index):Edge { $edge["rank"] = $index; - $edgeData = (array)(new Edge(...$edge)); - return $edgeData; + return Edge::fromArray($edge); }) - ->unique(fn($e) => $e['field'] . $e['source'] . $e['target'] . $e['sourceSchema']) + ->unique(fn(Edge $e) => $e->field . $e->source . $e->target . $e->sourceSchema) ->values()->toArray(); - $uniqueEdgesCollection = EdgeCollection::fromArray($uniqueEdges); + $uniqueEdgesCollection = new EdgeCollection(...$uniqueEdges); } if (Status::from($status) === Status::PUBLISHED) { diff --git a/src/Schema/BlockSchema.php b/src/Schema/BlockSchema.php index cf83693..486d745 100644 --- a/src/Schema/BlockSchema.php +++ b/src/Schema/BlockSchema.php @@ -3,6 +3,7 @@ namespace Lucent\Schema; use Lucent\Primitive\Collection; +use Lucent\Schema\Field\FieldInterface; class BlockSchema implements Schema { diff --git a/src/Schema/BlockUi/File.php b/src/Schema/BlockUi/File.php index 5fae80f..6a789be 100644 --- a/src/Schema/BlockUi/File.php +++ b/src/Schema/BlockUi/File.php @@ -4,12 +4,11 @@ namespace Lucent\Schema\BlockUi; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\RefProperty; -use Lucent\JsonSchema\Property\TypeProperty; use Lucent\Primitive\Collection; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Type; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; use PhpOption\Option; @@ -35,11 +34,6 @@ class File implements FieldInterface, MinMaxInterface $this->info = new FieldInfo("file", "File", FieldType::FILE); } - public function format(array $input, array $output): array - { - return $output; - } - public function failMin(mixed $value): bool { if (is_null($value)) { diff --git a/src/Schema/BlockUi/Heading.php b/src/Schema/BlockUi/Heading.php index 2aef187..dcfbf86 100644 --- a/src/Schema/BlockUi/Heading.php +++ b/src/Schema/BlockUi/Heading.php @@ -2,13 +2,13 @@ namespace Lucent\Schema\BlockUi; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; -use Lucent\Schema\Validator\RequiredInterface; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; -class Heading implements FieldInterface +class Heading implements FieldInterface,FieldDataInterface { public FieldInfo $info; @@ -23,9 +23,10 @@ class Heading implements FieldInterface $this->info = new FieldInfo("heading", "Heading", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $output[$this->name] = $input[$this->name] ?? ""; + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/BlockUi/Markdown.php b/src/Schema/BlockUi/Markdown.php index af3699a..0be9082 100644 --- a/src/Schema/BlockUi/Markdown.php +++ b/src/Schema/BlockUi/Markdown.php @@ -2,13 +2,13 @@ namespace Lucent\Schema\BlockUi; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; -use Lucent\Schema\Validator\RequiredInterface; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; -class Markdown implements FieldInterface +class Markdown implements FieldInterface,FieldDataInterface { public FieldInfo $info; @@ -23,9 +23,10 @@ class Markdown implements FieldInterface $this->info = new FieldInfo("markdown", "Markdown Editor", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $output[$this->name] = $input[$this->name] ?? ""; + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } public function isRequired(): bool diff --git a/src/Schema/BlockUi/Reference.php b/src/Schema/BlockUi/Reference.php index 19802e0..d212996 100644 --- a/src/Schema/BlockUi/Reference.php +++ b/src/Schema/BlockUi/Reference.php @@ -2,9 +2,9 @@ namespace Lucent\Schema\BlockUi; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; class Reference implements FieldInterface, MinMaxInterface @@ -27,10 +27,6 @@ class Reference implements FieldInterface, MinMaxInterface $this->info = new FieldInfo("reference", "Reference", FieldType::REFERENCE); } - public function format(array $input, array $output): array - { - return $output; - } public function failMin(mixed $value): bool { diff --git a/src/Schema/BlockUi/Rich.php b/src/Schema/BlockUi/Rich.php index 21efd35..31ec3af 100644 --- a/src/Schema/BlockUi/Rich.php +++ b/src/Schema/BlockUi/Rich.php @@ -2,13 +2,13 @@ namespace Lucent\Schema\BlockUi; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; -use Lucent\Schema\Validator\RequiredInterface; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; -class Rich implements FieldInterface +class Rich implements FieldInterface,FieldDataInterface { public FieldInfo $info; @@ -23,9 +23,10 @@ class Rich implements FieldInterface $this->info = new FieldInfo("rich", "Rich Editor", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $output[$this->name] = $input[$this->name] ?? ""; + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } public function isRequired(): bool diff --git a/src/Schema/BlockUi/Textarea.php b/src/Schema/BlockUi/Textarea.php index 49a8dcf..35ff320 100644 --- a/src/Schema/BlockUi/Textarea.php +++ b/src/Schema/BlockUi/Textarea.php @@ -2,13 +2,13 @@ namespace Lucent\Schema\BlockUi; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; -use Lucent\Schema\Validator\RequiredInterface; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; -class Textarea implements FieldInterface +class Textarea implements FieldInterface,FieldDataInterface { public FieldInfo $info; @@ -23,9 +23,10 @@ class Textarea implements FieldInterface $this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $output[$this->name] = $input[$this->name] ?? ""; + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } public function isRequired(): bool diff --git a/src/Schema/CollectionSchema.php b/src/Schema/CollectionSchema.php index 426080b..0b0f131 100644 --- a/src/Schema/CollectionSchema.php +++ b/src/Schema/CollectionSchema.php @@ -3,6 +3,7 @@ namespace Lucent\Schema; use Lucent\Primitive\Collection; +use Lucent\Schema\Field\FieldInterface; class CollectionSchema implements Schema { diff --git a/src/Schema/Commands/CompileSchemas.php b/src/Schema/Commands/CompileSchemas.php index afbcc11..ec677c3 100644 --- a/src/Schema/Commands/CompileSchemas.php +++ b/src/Schema/Commands/CompileSchemas.php @@ -7,7 +7,6 @@ use Illuminate\Console\Command; use Lucent\Schema\Schema; use Lucent\Schema\SchemaService; use Lucent\Schema\Type; -use function Lucent\Commands\base_path; class CompileSchemas extends Command { diff --git a/src/Schema/EdgeSchema.php b/src/Schema/EdgeSchema.php new file mode 100644 index 0000000..c3908cf --- /dev/null +++ b/src/Schema/EdgeSchema.php @@ -0,0 +1,25 @@ + $fields + */ + function __construct( + public string $name, + public string $label, + public array $groups, + public Collection $fields, + public string $titleTemplate = "", + ) + { + } + +} diff --git a/src/Schema/Field/FieldDataInterface.php b/src/Schema/Field/FieldDataInterface.php new file mode 100644 index 0000000..0f6bc21 --- /dev/null +++ b/src/Schema/Field/FieldDataInterface.php @@ -0,0 +1,15 @@ +value)) { - return $this->value; - } - - if ($this->nullable) { - return null; - } - return $this->default; - } -} diff --git a/src/Schema/SchemaService.php b/src/Schema/SchemaService.php index 282838d..462cde6 100644 --- a/src/Schema/SchemaService.php +++ b/src/Schema/SchemaService.php @@ -3,6 +3,7 @@ namespace Lucent\Schema; use Lucent\Primitive\Collection; +use Lucent\Schema\Field\FieldInterface; class SchemaService { @@ -46,6 +47,13 @@ class SchemaService name: $schemaArr["name"], label: $schemaArr["label"], fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapBlockFields']) + ), + "edge" => new EdgeSchema( + name: $schemaArr["name"], + label: $schemaArr["label"], + groups: $schemaArr["groups"] ?? [], + fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']), + titleTemplate: $schemaArr["titleTemplate"] ?? "", ) }; diff --git a/src/Schema/Type.php b/src/Schema/Type.php index e3de447..6941e52 100644 --- a/src/Schema/Type.php +++ b/src/Schema/Type.php @@ -8,4 +8,5 @@ enum Type: string case COLLECTION = 'collection'; case FILES = 'files'; case BLOCK = 'block'; + case EDGE = 'edge'; } diff --git a/src/Schema/Ui/Block.php b/src/Schema/Ui/Block.php index 9ba650c..9d01b87 100644 --- a/src/Schema/Ui/Block.php +++ b/src/Schema/Ui/Block.php @@ -5,21 +5,21 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Block implements FieldInterface, RequiredInterface +class Block implements FieldInterface, FieldDataInterface, RequiredInterface { public FieldInfo $info; public function __construct( public string $name, public string $label, - public bool $nullable = false, public bool $required = false, public string $default = "", public string $help = "", @@ -31,15 +31,15 @@ class Block implements FieldInterface, RequiredInterface $this->info = new FieldInfo("block", "Block editor", FieldType::JSON); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; + $value = $input->get($this->name); if (is_string($value)) { $value = json_decode($value, true); } - $output[$this->name] = (new Nullable($this->nullable, $value, []))->value(); + $output->set($this->name, $value ?? []); return $output; } diff --git a/src/Schema/Ui/Checkbox.php b/src/Schema/Ui/Checkbox.php index 5dd62d3..d976997 100644 --- a/src/Schema/Ui/Checkbox.php +++ b/src/Schema/Ui/Checkbox.php @@ -5,15 +5,16 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; use function is_bool; -class Checkbox implements FieldInterface, RequiredInterface +class Checkbox implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -22,8 +23,8 @@ class Checkbox implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public string $default = "", + public bool $nullable = false, public string $help = "", public bool $readonly = false, public string $group = "", @@ -32,16 +33,16 @@ class Checkbox implements FieldInterface, RequiredInterface $this->info = new FieldInfo("checkbox", "Block Checkbox", FieldType::BOOLEAN); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; + $value = $input->get($this->name); if (is_bool($value)) { $newValue = $value; } else { - $newValue = (new Nullable($this->nullable, $value, false))->value(); + $newValue = $this->nullable ? null : false; } - $output[$this->name] = $newValue; + $output->set($this->name, $newValue); return $output; } diff --git a/src/Schema/Ui/Color.php b/src/Schema/Ui/Color.php index e9d4da1..19e2d7e 100644 --- a/src/Schema/Ui/Color.php +++ b/src/Schema/Ui/Color.php @@ -5,14 +5,15 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Color implements FieldInterface, RequiredInterface +class Color implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -21,7 +22,6 @@ class Color implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public string $default = "", public string $help = "", public bool $readonly = false, @@ -34,10 +34,10 @@ class Color implements FieldInterface, RequiredInterface $this->info = new FieldInfo("color", "Color", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/Ui/Date.php b/src/Schema/Ui/Date.php index 567f40d..43d28e1 100644 --- a/src/Schema/Ui/Date.php +++ b/src/Schema/Ui/Date.php @@ -6,15 +6,16 @@ use Carbon\Carbon; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Date implements FieldInterface, RequiredInterface, MinMaxInterface +class Date implements FieldInterface,FieldDataInterface, RequiredInterface, MinMaxInterface { public FieldInfo $info; @@ -22,7 +23,6 @@ class Date implements FieldInterface, RequiredInterface, MinMaxInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public ?Carbon $min = null, public ?Carbon $max = null, public string $default = "", @@ -37,19 +37,16 @@ class Date implements FieldInterface, RequiredInterface, MinMaxInterface $this->info = new FieldInfo("date", "Date", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; + $value = $input->get($this->name); if (empty($value)) { - $newValue = (new Nullable($this->nullable, null, ""))->value(); - } else { - $date = Carbon::parse($value); - $dateFormatted = $date->format("Y-m-d"); - $newValue = (new Nullable($this->nullable, $dateFormatted, ""))->value(); + return $output->set($this->name, null); } - $output[$this->name] = $newValue; - return $output; + $date = Carbon::parse($value); + $dateFormatted = $date->format("Y-m-d"); + return $output->set($this->name, $dateFormatted); } public function failRequired(mixed $value): bool diff --git a/src/Schema/Ui/Datetime.php b/src/Schema/Ui/Datetime.php index 0c8bb6e..0a305f5 100644 --- a/src/Schema/Ui/Datetime.php +++ b/src/Schema/Ui/Datetime.php @@ -6,15 +6,16 @@ use Carbon\Carbon; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface +class Datetime implements FieldInterface,FieldDataInterface, RequiredInterface, MinMaxInterface { public FieldInfo $info; @@ -22,11 +23,10 @@ class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public ?Carbon $min = null, public ?Carbon $max = null, public string $default = "", - public string $help = "", + public string $help = "", public bool $readonly = false, public string $optionsFrom = "", public string $optionsField = "", @@ -37,19 +37,15 @@ class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface $this->info = new FieldInfo("datetime", "Datetime", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; + $value = $input->get($this->name); if (empty($value)) { - $newValue = (new Nullable($this->nullable, null, ""))->value(); - } else { - $date = Carbon::parse($value); - $dateFormatted = $date->toJSON(); - $newValue = (new Nullable($this->nullable, $dateFormatted, ""))->value(); + return $output->set($this->name, null); } - - $output[$this->name] = $newValue; - return $output; + $date = Carbon::parse($value); + $dateFormatted = $date->toJSON(); + return $output->set($this->name, $dateFormatted); } public function failRequired(mixed $value): bool diff --git a/src/Schema/Ui/File.php b/src/Schema/Ui/File.php index 41fcb90..54a5d7e 100644 --- a/src/Schema/Ui/File.php +++ b/src/Schema/Ui/File.php @@ -4,11 +4,10 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\RefProperty; -use Lucent\JsonSchema\Property\RefType; use Lucent\Primitive\Collection; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; use PhpOption\Option; @@ -28,17 +27,13 @@ class File implements FieldInterface, MinMaxInterface public ?int $min = null, public ?int $max = null, public array $collections = [], + public string $data = "", public string $group = "", ) { $this->info = new FieldInfo("file", "File", FieldType::FILE); } - public function format(array $input, array $output): array - { - return $output; - } - public function failMin(mixed $value): bool { if (is_null($value)) { diff --git a/src/Schema/Ui/Json.php b/src/Schema/Ui/Json.php index d3bf65d..13ff423 100644 --- a/src/Schema/Ui/Json.php +++ b/src/Schema/Ui/Json.php @@ -5,14 +5,16 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Json implements FieldInterface, RequiredInterface + +class Json implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -24,22 +26,21 @@ class Json implements FieldInterface, RequiredInterface public string $default = "", public string $help = "", public bool $readonly = false, - public bool $nullable = false, public string $group = "", ) { $this->info = new FieldInfo("json", "JSON", FieldType::JSON); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; + $value = $input->get($this->name); if (is_string($value)) { $value = json_decode($value, true); } - $output[$this->name] = (new Nullable($this->nullable, $value, []))->value(); + $output->set($this->name,$value ?? []); return $output; } diff --git a/src/Schema/Ui/Markdown.php b/src/Schema/Ui/Markdown.php index 78252b8..64383b5 100644 --- a/src/Schema/Ui/Markdown.php +++ b/src/Schema/Ui/Markdown.php @@ -5,14 +5,15 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Markdown implements FieldInterface, RequiredInterface +class Markdown implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -20,7 +21,6 @@ class Markdown implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public string $default = "", public string $help = "", public ?int $min = null, @@ -32,10 +32,10 @@ class Markdown implements FieldInterface, RequiredInterface $this->info = new FieldInfo("markdown", "Markdown editor", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/Ui/Number.php b/src/Schema/Ui/Number.php index 9413f94..6086c7d 100644 --- a/src/Schema/Ui/Number.php +++ b/src/Schema/Ui/Number.php @@ -5,15 +5,16 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Number implements FieldInterface, RequiredInterface, MinMaxInterface +class Number implements FieldInterface, RequiredInterface,FieldDataInterface, MinMaxInterface { public FieldInfo $info; @@ -21,7 +22,6 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public int $decimals = 0, public ?int $min = null, public ?int $max = null, @@ -37,9 +37,9 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface $this->info = new FieldInfo("number", "Number", FieldType::NUMBER); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; + $value = $input->get($this->name); if (!is_numeric($value)) { $newValue = null; } else { @@ -51,8 +51,7 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface ); $newValue = $this->decimals === 0 ? (int)$newValue : floatval($newValue); } - - $output[$this->name] = (new Nullable($this->nullable, $newValue, 0))->value(); + $output->set($this->name,$newValue); return $output; } diff --git a/src/Schema/Ui/Reference.php b/src/Schema/Ui/Reference.php index 9269834..ee12852 100644 --- a/src/Schema/Ui/Reference.php +++ b/src/Schema/Ui/Reference.php @@ -4,11 +4,10 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\RefProperty; -use Lucent\JsonSchema\Property\RefType; use Lucent\Primitive\Collection; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\MinMaxInterface; use PhpOption\Option; @@ -26,6 +25,7 @@ class Reference implements FieldInterface, MinMaxInterface public ?int $min = null, public ?int $max = null, public array $collections = [], + public string $data = "", public string $searchField = "", public string $layout = "", public string $group = "", @@ -34,11 +34,6 @@ class Reference implements FieldInterface, MinMaxInterface $this->info = new FieldInfo("reference", "Reference", FieldType::REFERENCE); } - public function format(array $input, array $output): array - { - return $output; - } - public function failMin(mixed $value): bool { if (is_null($value)) { diff --git a/src/Schema/Ui/Rich.php b/src/Schema/Ui/Rich.php index 519a909..e501cec 100644 --- a/src/Schema/Ui/Rich.php +++ b/src/Schema/Ui/Rich.php @@ -5,14 +5,15 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Rich implements FieldInterface, RequiredInterface +class Rich implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -20,7 +21,6 @@ class Rich implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public string $default = "", public string $help = "", public ?int $min = null, @@ -32,10 +32,10 @@ class Rich implements FieldInterface, RequiredInterface $this->info = new FieldInfo("rich", "Rich editor", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/Ui/Slug.php b/src/Schema/Ui/Slug.php index d69d07c..6ad8c1b 100644 --- a/src/Schema/Ui/Slug.php +++ b/src/Schema/Ui/Slug.php @@ -6,14 +6,15 @@ use Illuminate\Support\Str; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Slug implements FieldInterface, RequiredInterface +class Slug implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -21,7 +22,6 @@ class Slug implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public ?int $min = null, public ?int $max = null, public string $default = "", @@ -34,14 +34,14 @@ class Slug implements FieldInterface, RequiredInterface $this->info = new FieldInfo("slug", "Slug", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = !empty($input[$this->name]) ? (string)$input[$this->name] : null; - if(empty($value)){ - $value = Str::slug($input[$this->source]); + $value = $input->get($this->name); + if (empty($value)) { + $value = Str::slug($input->get($this->source, "")); } - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $output->set($this->name, $value); return $output; } diff --git a/src/Schema/Ui/Text.php b/src/Schema/Ui/Text.php index 664c7ad..330985c 100644 --- a/src/Schema/Ui/Text.php +++ b/src/Schema/Ui/Text.php @@ -5,14 +5,15 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Text implements FieldInterface, RequiredInterface +class Text implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -20,7 +21,6 @@ class Text implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public ?int $min = null, public ?int $max = null, public string $help = "", @@ -36,10 +36,10 @@ class Text implements FieldInterface, RequiredInterface $this->info = new FieldInfo("text", "Text", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = !empty($input[$this->name]) ? (string)$input[$this->name] : null; - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/Ui/Textarea.php b/src/Schema/Ui/Textarea.php index 876f1cc..9e712fb 100644 --- a/src/Schema/Ui/Textarea.php +++ b/src/Schema/Ui/Textarea.php @@ -5,14 +5,15 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Textarea implements FieldInterface, RequiredInterface +class Textarea implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -21,7 +22,6 @@ class Textarea implements FieldInterface, RequiredInterface public string $name, public string $label, public bool $required = false, - public bool $nullable = false, public ?int $min = null, public ?int $max = null, public string $default = "", @@ -33,10 +33,10 @@ class Textarea implements FieldInterface, RequiredInterface $this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = !empty($input[$this->name]) ? (string)$input[$this->name] : null; - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/Ui/Uuid.php b/src/Schema/Ui/Uuid.php index ebefd77..15d8c21 100644 --- a/src/Schema/Ui/Uuid.php +++ b/src/Schema/Ui/Uuid.php @@ -5,14 +5,15 @@ namespace Lucent\Schema\Ui; use Lucent\JsonSchema\Property\Property; use Lucent\JsonSchema\Property\PropertyType; use Lucent\JsonSchema\Property\TypeProperty; -use Lucent\Schema\FieldInfo; -use Lucent\Schema\FieldInterface; -use Lucent\Schema\FieldType; -use Lucent\Schema\Nullable; +use Lucent\Record\RecordData; +use Lucent\Schema\Field\FieldDataInterface; +use Lucent\Schema\Field\FieldInfo; +use Lucent\Schema\Field\FieldInterface; +use Lucent\Schema\Field\FieldType; use Lucent\Schema\Validator\RequiredInterface; use PhpOption\Option; -class Uuid implements FieldInterface, RequiredInterface +class Uuid implements FieldInterface,FieldDataInterface, RequiredInterface { public FieldInfo $info; @@ -22,7 +23,6 @@ class Uuid implements FieldInterface, RequiredInterface public string $label, public string $help = "", public bool $required = false, - public bool $nullable = false, public bool $readonly = false, public string $group = "", ) @@ -30,10 +30,10 @@ class Uuid implements FieldInterface, RequiredInterface $this->info = new FieldInfo("uuid", "FieldType", FieldType::STRING); } - public function format(array $input, array $output): array + public function format(RecordData $input, RecordData $output): RecordData { - $value = $input[$this->name] ?? null; - $output[$this->name] = (new Nullable($this->nullable, $value, ""))->value(); + $value = $input->get($this->name); + $output->set($this->name,$value); return $output; } diff --git a/src/Schema/Validator/Validator.php b/src/Schema/Validator/Validator.php index e752392..4985be2 100644 --- a/src/Schema/Validator/Validator.php +++ b/src/Schema/Validator/Validator.php @@ -6,7 +6,7 @@ use Lucent\Channel\ChannelService; use Lucent\Edge\EdgeCollection; use Lucent\Primitive\Collection; use Lucent\Record\RecordData; -use Lucent\Schema\FieldInterface; +use Lucent\Schema\Field\FieldInterface; class Validator