lots
This commit is contained in:
@@ -11,11 +11,13 @@ class CollectionSchema implements Schema
|
||||
/**
|
||||
* @param Collection<FieldInterface> $fields
|
||||
* @param array<string> $visible
|
||||
* @param array<string> $fields
|
||||
*/
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public array $visible,
|
||||
public array $groups,
|
||||
public Collection $fields,
|
||||
public bool $isEntry = false,
|
||||
public string $color = "",
|
||||
|
||||
@@ -11,12 +11,14 @@ class FilesSchema implements Schema
|
||||
|
||||
/**
|
||||
* @param Collection<FieldInterface> $fields
|
||||
* @param array<string> $groups
|
||||
*/
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public Collection $fields,
|
||||
public string $path,
|
||||
public array $groups,
|
||||
public bool $isEntry = false,
|
||||
public string $color = "",
|
||||
public string $titleTemplate = "",
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
use Lucent\Field\Field;
|
||||
use Lucent\View\View;
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
**/
|
||||
function visibleFields(Schema $schema, ?View $view = null): array
|
||||
{
|
||||
|
||||
$visibleFieldNames = $schema->visible;
|
||||
if (!empty($view)) {
|
||||
$visibleFieldNames = $view->visible;
|
||||
}
|
||||
|
||||
return $schema->fields
|
||||
->filter(function (Field $f) use ($visibleFieldNames) {
|
||||
|
||||
if ($f->trashed || $f->ui == "tab") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $visibleFieldNames->contains($f->name->value);
|
||||
})
|
||||
->values()
|
||||
->map(fn(Field $f) => $f->name->value)
|
||||
->toArray();
|
||||
}
|
||||
@@ -20,19 +20,21 @@ class SchemaService
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
visible: $schemaArr["visible"] ?? [],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
isEntry: $schemaArr["isEntry"],
|
||||
color: $schemaArr["color"],
|
||||
titleTemplate: $schemaArr["titleTemplate"],
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
color: $schemaArr["color"] ?? "",
|
||||
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
||||
),
|
||||
"files" => new FilesSchema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
path: $schemaArr["path"],
|
||||
isEntry: $schemaArr["isEntry"],
|
||||
color: $schemaArr["color"],
|
||||
titleTemplate: $schemaArr["titleTemplate"]
|
||||
path: $schemaArr["path"] ?? $schemaArr["name"],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
color: $schemaArr["color"] ?? "",
|
||||
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
readonly class System
|
||||
{
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public string $ui,
|
||||
public bool $files,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static function getById(string $id): System
|
||||
{
|
||||
return self::list()[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,System>
|
||||
* */
|
||||
public static function list(): array
|
||||
{
|
||||
return [
|
||||
"_sys.status" => new System(
|
||||
name: "status",
|
||||
label: "Status",
|
||||
ui: "status",
|
||||
files: false,
|
||||
),
|
||||
"_sys.createdBy" => new System(
|
||||
name: "_sys.createdBy",
|
||||
label: "Created by",
|
||||
ui: "user",
|
||||
files: false,
|
||||
),
|
||||
"_sys.updatedBy" => new System(
|
||||
name: "_sys.updatedBy",
|
||||
label: "Updated by",
|
||||
ui: "user",
|
||||
files: false,
|
||||
),
|
||||
"_sys.createdAt" => new System(
|
||||
name: "_sys.createdAt",
|
||||
label: "Created at",
|
||||
ui: "datetime",
|
||||
files: false,
|
||||
),
|
||||
"_sys.updatedAt" => new System(
|
||||
name: "_sys.updatedAt",
|
||||
label: "Updated At",
|
||||
ui: "datetime",
|
||||
files: false,
|
||||
),
|
||||
"_file.path" => new System(
|
||||
name: "_file.path",
|
||||
label: "Filename",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.mime" => new System(
|
||||
name: "_file.mime",
|
||||
label: "Mime Type",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
|
||||
"_file.width" => new System(
|
||||
name: "_file.width",
|
||||
label: "Dimensions",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.size" => new System(
|
||||
name: "_file.size",
|
||||
label: "Size",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.originalName" => new System(
|
||||
name: "_file.originalName",
|
||||
label: "Original Name",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.checksum" => new System(
|
||||
name: "_file.checksum",
|
||||
label: "Checksum",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user