fixing multiple references
This commit is contained in:
@@ -16,19 +16,13 @@ class CompileSchemas extends Command
|
||||
protected $description = 'Compiles schemas';
|
||||
|
||||
|
||||
public function __construct(
|
||||
public SchemaService $schemaService
|
||||
)
|
||||
public function handle(SchemaService $schemaService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$configDir = base_path(config('lucent.schemas_path'));
|
||||
$schemasDirIterator = new DirectoryIterator($configDir);
|
||||
$schemas = [];
|
||||
|
||||
foreach ($schemasDirIterator as $file) {
|
||||
if ($file->getExtension() !== "json") {
|
||||
continue;
|
||||
@@ -46,7 +40,7 @@ class CompileSchemas extends Command
|
||||
|
||||
$schemas = collect($schemas)->sortBy("label")->values();
|
||||
$roles = $schemas
|
||||
->map([$this->schemaService, 'fromArray'])
|
||||
->map([$schemaService, 'fromArray'])
|
||||
->whereIn("type", [Type::COLLECTION, Type::FILES])
|
||||
->reduce(fn($carry, Schema $schema) => array_merge(
|
||||
$carry,
|
||||
|
||||
@@ -31,4 +31,19 @@ return [
|
||||
"canInvite" => ["admin"],
|
||||
"canBuild" => ["admin"],
|
||||
"systemUserId" => "",
|
||||
"schemaFields" => [
|
||||
\Lucent\Schema\Ui\Checkbox::class,
|
||||
\Lucent\Schema\Ui\Color::class,
|
||||
\Lucent\Schema\Ui\Date::class,
|
||||
\Lucent\Schema\Ui\Datetime::class,
|
||||
\Lucent\Schema\Ui\File::class,
|
||||
\Lucent\Schema\Ui\Json::class,
|
||||
\Lucent\Schema\Ui\Markdown::class,
|
||||
\Lucent\Schema\Ui\Number::class,
|
||||
\Lucent\Schema\Ui\Reference::class,
|
||||
\Lucent\Schema\Ui\Rich::class,
|
||||
\Lucent\Schema\Ui\Slug::class,
|
||||
\Lucent\Schema\Ui\Text::class,
|
||||
\Lucent\Schema\Ui\Textarea::class
|
||||
]
|
||||
];
|
||||
|
||||
@@ -5,6 +5,9 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
|
||||
protected $connection = 'lucentDb';
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
|
||||
@@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
protected $connection = 'lucentDb';
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
|
||||
@@ -5,6 +5,8 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
|
||||
protected $connection = 'lucentDb';
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
|
||||
@@ -5,6 +5,8 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
|
||||
protected $connection = 'lucentDb';
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
|
||||
@@ -5,6 +5,8 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
|
||||
protected $connection = 'lucentDb';
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
|
||||
@@ -5,6 +5,9 @@ use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
|
||||
protected $connection = 'lucentDb';
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
@@ -14,7 +17,7 @@ return new class extends Migration {
|
||||
{
|
||||
Schema::table('records', function (Blueprint $table) {
|
||||
$table->dropIndex(['schema', 'status']);
|
||||
$table->index(['schema', '_sys->updatedAt','status']);
|
||||
$table->index(['schema', '_sys->updatedAt', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,7 +30,7 @@ return new class extends Migration {
|
||||
{
|
||||
Schema::table('records', function (Blueprint $table) {
|
||||
|
||||
$table->dropIndex(['schema', '_sys->updatedAt','status']);
|
||||
$table->dropIndex(['schema', '_sys->updatedAt', 'status']);
|
||||
$table->index(['schema', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ class RecordController extends Controller
|
||||
|
||||
$schema = $this->channelService->channel->schemas->where("name", $request->input("schema"))->first();
|
||||
$recordHistory = $this->recordManager->fromSession($request->session())->getRecords();
|
||||
$record = $this->recordService->createEmpty($schema, $this->authService->currentUserId());
|
||||
$record = $this->recordService->createEmpty($schema);
|
||||
$queryRecord = QueryRecord::fromRecord($record);
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
@@ -200,6 +200,7 @@ class RecordController extends Controller
|
||||
"schema" => $schema,
|
||||
"record" => $queryRecord,
|
||||
"isCreateMode" => true,
|
||||
"isWritable" => in_array($record->schema, $this->accountService->currentWritableSchemas())
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Validator\MinMaxInterface;
|
||||
|
||||
class File implements FieldInterface, MinMaxInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
|
||||
/**
|
||||
* @param string[] $collections
|
||||
*/
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public string $mime = "",
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public array $collections = [],
|
||||
)
|
||||
{
|
||||
$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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
public function failMax(mixed $value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class Heading implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("heading", "Heading", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class Markdown implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("markdown", "Markdown Editor", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Validator\MinMaxInterface;
|
||||
|
||||
class Reference implements FieldInterface, MinMaxInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
/**
|
||||
* @param string[] $collections
|
||||
*/
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public array $collections = [],
|
||||
public string $searchField = "",
|
||||
public string $layout = "",
|
||||
)
|
||||
{
|
||||
$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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
public function failMax(mixed $value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class Rich implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("rich", "Rich Editor", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class Textarea implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Primitive\Collection;
|
||||
|
||||
class SchemaService
|
||||
@@ -52,16 +53,32 @@ class SchemaService
|
||||
|
||||
public function mapFields(array $field): FieldInterface
|
||||
{
|
||||
$className = "\\Lucent\Schema\Ui\\" . ucfirst($field["ui"]);
|
||||
unset($field["ui"]);
|
||||
|
||||
return new $className(...$field);
|
||||
$schemaFields = [
|
||||
\Lucent\Schema\Ui\Checkbox::class,
|
||||
\Lucent\Schema\Ui\Color::class,
|
||||
\Lucent\Schema\Ui\Date::class,
|
||||
\Lucent\Schema\Ui\Datetime::class,
|
||||
\Lucent\Schema\Ui\File::class,
|
||||
\Lucent\Schema\Ui\Json::class,
|
||||
\Lucent\Schema\Ui\Markdown::class,
|
||||
\Lucent\Schema\Ui\Number::class,
|
||||
\Lucent\Schema\Ui\Reference::class,
|
||||
\Lucent\Schema\Ui\Rich::class,
|
||||
\Lucent\Schema\Ui\Slug::class,
|
||||
\Lucent\Schema\Ui\Text::class,
|
||||
\Lucent\Schema\Ui\Textarea::class,
|
||||
];
|
||||
$ui = collect($schemaFields)->filter(function ($className) use ($field) {
|
||||
return str_ends_with(strtolower($className), "\\" . strtolower($field["ui"]));
|
||||
})->first();
|
||||
|
||||
if (empty($ui)) {
|
||||
throw new LucentException("Field UI " . $field["ui"] . " not found");
|
||||
}
|
||||
|
||||
unset($field["ui"]);
|
||||
return new $ui(...$field);
|
||||
}
|
||||
|
||||
public function mapBlockFields(array $field): FieldInterface
|
||||
{
|
||||
$className = "\\Lucent\Schema\BlockUi\\" . ucfirst($field["ui"]);
|
||||
unset($field["ui"]);
|
||||
return new $className(...$field);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\Ui;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Block implements FieldInterface, 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 = "",
|
||||
public bool $readonly = false,
|
||||
public string $schema = "",
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("block", "Block editor", FieldType::JSON);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$value = $input[$this->name] ?? null;
|
||||
|
||||
if (is_string($value)) {
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
|
||||
$output[$this->name] = (new Nullable($this->nullable, $value, []))->value();
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function failRequired(mixed $value): bool
|
||||
{
|
||||
return empty($value);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class Checkbox implements FieldInterface, RequiredInterface
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("checkbox", "Block Checkbox", FieldType::BOOLEAN);
|
||||
$this->info = new FieldInfo("checkbox", "Checkbox", FieldType::BOOLEAN);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
|
||||
Reference in New Issue
Block a user