singleton and embed records
This commit is contained in:
@@ -16,6 +16,7 @@ use Lucent\Record\Manager;
|
||||
use Lucent\Record\QueryRecord;
|
||||
use Lucent\Record\RecordService;
|
||||
use Lucent\Record\Status;
|
||||
use Lucent\Schema\SingletonSchema;
|
||||
use Lucent\Schema\System;
|
||||
use Lucent\Schema\Validator\ValidatorException;
|
||||
use Lucent\Svelte\Svelte;
|
||||
@@ -50,8 +51,9 @@ class RecordController extends Controller
|
||||
|
||||
$users = $this->accountService->all();
|
||||
$schema = $this->channelService->getSchema($schemaName)->get();
|
||||
|
||||
$urlParams = $request->all();
|
||||
$sort = data_get($urlParams, "sort") ?? $schema->sortBy;
|
||||
$sort = data_get($urlParams, "sort") ?? $schema->sortBy ?? "";
|
||||
$filter = data_get($urlParams, "filter") ?? [];
|
||||
|
||||
$arguments = array_merge([
|
||||
@@ -80,6 +82,13 @@ class RecordController extends Controller
|
||||
|
||||
|
||||
$records = $graph->getRootRecords()->toArray();
|
||||
if(get_class($schema) === SingletonSchema::class){
|
||||
$id = $records[0]->id ?? null;
|
||||
if(empty($id)){
|
||||
return redirect($this->channelService->channel->lucentUrl."/records/new?schema=".$schemaName);
|
||||
}
|
||||
return redirect($this->channelService->channel->lucentUrl."/records/".$id);
|
||||
}
|
||||
|
||||
$data = [
|
||||
"schemas" => $this->channelService->channel->schemas,
|
||||
@@ -341,20 +350,15 @@ class RecordController extends Controller
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
|
||||
$ids = array_map(fn($rec) => $rec["id"], $request->input("records"));
|
||||
|
||||
|
||||
$this->recordService->changeStatusBulk(
|
||||
status: $request->route("status"),
|
||||
recordsIds: $ids,
|
||||
recordsIds: $request->input("records"),
|
||||
);
|
||||
return ok();
|
||||
}
|
||||
|
||||
public function emptyTrash(Request $request)
|
||||
{
|
||||
|
||||
$this->recordService->emptyTrash($request->route("schemaName"));
|
||||
return redirect($this->channelService->channel->lucentUrl . "/content/" . $request->route("schemaName"));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ class CollectionSchema implements Schema
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
|
||||
public array $visible,
|
||||
public array $groups,
|
||||
public Collection $fields,
|
||||
|
||||
@@ -32,6 +32,19 @@ class SchemaService
|
||||
read: $schemaArr["read"] ?? [],
|
||||
write: $schemaArr["write"] ?? [],
|
||||
),
|
||||
"singleton" => new SingletonSchema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
folder: $schemaArr["folder"] ?? "",
|
||||
color: $schemaArr["color"] ?? "",
|
||||
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
|
||||
cardImage: $schemaArr["cardImage"] ?? null,
|
||||
revisions: $schemaArr["revisions"] ?? 0,
|
||||
read: $schemaArr["read"] ?? [],
|
||||
write: $schemaArr["write"] ?? [],
|
||||
),
|
||||
"files" => new FilesSchema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
use Lucent\Primitive\Collection;
|
||||
|
||||
class SingletonSchema implements Schema
|
||||
{
|
||||
public Type $type = Type::COLLECTION;
|
||||
|
||||
/**
|
||||
* @param Collection<FieldInterface> $fields
|
||||
*/
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public array $groups,
|
||||
public Collection $fields,
|
||||
public string $folder = "",
|
||||
public string $color = "",
|
||||
public ?string $cardTitle = null,
|
||||
public ?string $cardImage = null,
|
||||
public int $revisions = 0,
|
||||
public array $read = [],
|
||||
public array $write = [],
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use Lucent\Record\QueryRecord;
|
||||
use Lucent\Schema\CollectionSchema;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FilesSchema;
|
||||
use Lucent\Schema\SingletonSchema;
|
||||
use Mustache_Engine;
|
||||
|
||||
class ViewModel
|
||||
@@ -23,7 +24,7 @@ class ViewModel
|
||||
$schema = $this->channelService->getSchema($record->schema)->get();
|
||||
if (empty($schema->titleTemplate)) {
|
||||
$title = match (get_class($schema)) {
|
||||
CollectionSchema::class => $record->data[$schema->fields->filter(fn(FieldInterface $f) => $f->info->name === "text")->first()->name],
|
||||
CollectionSchema::class,SingletonSchema::class => $record->data[$schema->fields->filter(fn(FieldInterface $f) => $f->info->name === "text")->first()->name],
|
||||
FilesSchema::class => $record->_file->path,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user