schemas as a tree replacing the isEntry behavior
This commit is contained in:
@@ -21,33 +21,20 @@ class CompileSchemas extends Command
|
||||
|
||||
$configDir = base_path(config('lucent.schemas_path'));
|
||||
$schemasDirIterator = new DirectoryIterator($configDir);
|
||||
$schemas = [];
|
||||
$schemas = $this->scanDir([], $schemasDirIterator);
|
||||
|
||||
foreach ($schemasDirIterator as $file) {
|
||||
if ($file->getExtension() !== "json") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$schemaJson = file_get_contents($configDir . "/" . $file->getFilename());
|
||||
$schema = json_decode($schemaJson, true);
|
||||
if (empty($schema)) {
|
||||
$this->error("Invalid JSON " . $file->getFilename());
|
||||
return 0;
|
||||
}
|
||||
$schemas[] = $schema;
|
||||
|
||||
}
|
||||
|
||||
$schemas = collect($schemas)->sortBy("label")->values();
|
||||
|
||||
$roles = $schemas
|
||||
->map([$schemaService, 'fromArray'])
|
||||
->whereIn("type", [Type::COLLECTION, Type::FILES])
|
||||
->reduce(fn($carry, Schema $schema) => array_merge(
|
||||
$carry,
|
||||
$schema->read,
|
||||
$schema->write,
|
||||
config("lucent.canInvite") ?? [],
|
||||
config("lucent.canBuild") ?? [],
|
||||
$carry,
|
||||
$schema->read,
|
||||
$schema->write,
|
||||
config("lucent.canInvite") ?? [],
|
||||
config("lucent.canBuild") ?? [],
|
||||
), []);
|
||||
|
||||
$json = [
|
||||
@@ -64,4 +51,36 @@ class CompileSchemas extends Command
|
||||
$this->info("Lucent Schemas were updated");
|
||||
}
|
||||
|
||||
private function scanDir(array $schemas, DirectoryIterator $directoryIterator, $dirName = ""): array
|
||||
{
|
||||
foreach ($directoryIterator as $file) {
|
||||
if ($file->isDir()) {
|
||||
if ($file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$newDirName = $dirName.'.'.$file->getBasename();
|
||||
$schemas = $this->scanDir($schemas, new DirectoryIterator($file->getPathname()), $newDirName);
|
||||
continue;
|
||||
}
|
||||
if ($file->getExtension() !== "json") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$schemaJson = file_get_contents($file->getPathname());
|
||||
|
||||
|
||||
$schema = json_decode($schemaJson, true);
|
||||
|
||||
if (empty($schema)) {
|
||||
$this->error("Invalid JSON " . $file->getFilename());
|
||||
die;
|
||||
}
|
||||
$schema["folder"] = trim($dirName,".");
|
||||
$schemas[] = $schema;
|
||||
|
||||
}
|
||||
|
||||
return $schemas;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class GenerateCollectionSchema extends Command
|
||||
visible: [],
|
||||
groups: [],
|
||||
fields: Collection::make(),
|
||||
folder: "",
|
||||
);
|
||||
|
||||
$json = json_encode($schema, JSON_PRETTY_PRINT);
|
||||
|
||||
@@ -23,7 +23,8 @@ class GenerateFileSchema extends Command
|
||||
fields: Collection::make(),
|
||||
disk: "lucent",
|
||||
path: $name,
|
||||
groups: []
|
||||
groups: [],
|
||||
folder: "",
|
||||
);
|
||||
|
||||
$json = json_encode($schema, JSON_PRETTY_PRINT);
|
||||
|
||||
@@ -15,10 +15,11 @@ class CollectionSchema implements Schema
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
|
||||
public array $visible,
|
||||
public array $groups,
|
||||
public Collection $fields,
|
||||
public bool $isEntry = false,
|
||||
public string $folder = "",
|
||||
public string $color = "",
|
||||
public string $sortBy = "-_sys.updatedAt",
|
||||
public ?string $cardTitle = null,
|
||||
|
||||
@@ -20,7 +20,7 @@ class FilesSchema implements Schema
|
||||
public string $disk,
|
||||
public string $path,
|
||||
public array $groups,
|
||||
public bool $isEntry = false,
|
||||
public string $folder = "",
|
||||
public string $sortBy = "-_sys.updatedAt",
|
||||
public string $color = "",
|
||||
public ?string $cardTitle = null,
|
||||
|
||||
@@ -23,7 +23,7 @@ class SchemaService
|
||||
visible: $schemaArr["visible"] ?? [],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
folder: $schemaArr["folder"] ?? "",
|
||||
color: $schemaArr["color"] ?? "",
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
|
||||
@@ -39,7 +39,7 @@ class SchemaService
|
||||
disk: $schemaArr["disk"] ?? "lucent",
|
||||
path: $schemaArr["path"] ?? $schemaArr["name"],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
folder: $schemaArr["folder"] ?? "",
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
color: $schemaArr["color"] ?? "",
|
||||
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
|
||||
|
||||
Reference in New Issue
Block a user