This commit is contained in:
2026-01-13 18:20:01 +02:00
parent 268c696d64
commit 64e067eb59
10 changed files with 144 additions and 47 deletions
@@ -50,6 +50,7 @@
{channel}
fields={data.fields}
edgeRecordPreviews={data.edgeRecordPreviewsDraft}
filesPreviews={data.filesPreviewsDraft}
{record}
{selectedLocales}
validationErrors={data.validationErrors}
@@ -62,6 +63,7 @@
{channel}
fields={data.fields}
edgeRecordPreviews={data.edgeRecordPreviewsLive}
filesPreviews={data.filesPreviewsLive}
{record}
{selectedLocales}
validationErrors={data.validationErrors}
@@ -9,6 +9,7 @@
validationErrors,
fieldData,
edgeRecordPreviews,
filesPreviews,
selectedLocales,
} = $props();
const findFieldValidationError = (field, locale) => {
@@ -26,6 +27,13 @@
(e) => e.edge.fieldId === field.id && e.edge.locale === locale,
);
};
const findFieldFiles = (field, locale) => {
return filesPreviews.filter(
(f) =>
f.recordFile.fieldId === field.id &&
f.recordFile.locale === locale,
);
};
</script>
{#each fields as field}
@@ -88,6 +96,6 @@
schemaField={field}
{locale}
dataField={findDataField(field, locale)}
edgeRecordPreviews={findFieldEdges(field, locale)}
filesPreviews={findFieldFiles(field, locale)}
></FileField>
{/snippet}
@@ -13,6 +13,7 @@
locale,
validationError,
edgeRecordPreviews,
filesPreviews,
} = $props();
let originalValue = dataField?.value ?? schemaField.props.default;
let newValue = $state(originalValue);
@@ -26,7 +27,7 @@
let suggestionsLoaded = $state(false);
let suggestions = $state([]);
let selectedRecordIds = $state([]);
let selectedFilesIds = $state([]);
let dialog = $state();
function handleModalOpen(e) {
@@ -35,10 +36,10 @@
if (suggestionsLoaded) {
return;
}
// get(app.url("records/files"), { recordId: record.id }, (data, err) => {
get(app.url("records/files"), { recordId: record.id }, (data, err) => {
suggestionsLoaded = true;
// suggestions = data;
// });
suggestions = data;
});
}
function handleModalClose(e) {
@@ -48,9 +49,9 @@
function handleInsertSelected() {
suggestionsLoaded = false;
post(
app.url("edges/many"),
app.url("records/files"),
{
toIds: selectedRecordIds,
toIds: selectedFilesIds,
from: record.id,
fieldId: schemaField.id,
locale: locale,
@@ -179,17 +180,13 @@
<input
type="checkbox"
value={suggestion.id}
bind:group={selectedRecordIds}
bind:group={selectedFilesIds}
/>
</td>
<td>
<a href="#">{suggestion.title}</a>
</td>
<td>
<a href="#">
{suggestion.schemaName}
</a>
<a href="#">{suggestion.name}</a>
</td>
<td> </td>
</tr>
{/each}
</tbody>
@@ -201,21 +198,20 @@
</article>
</dialog>
<div>
{#if edgeRecordPreviews.length == 0}
No relations exist
{#if filesPreviews.length == 0}
No files exist
{:else}
<Sortable
onUpdate={handleSortUpdate}
items={edgeRecordPreviews}
itemKey="edge.id"
items={filesPreviews}
itemKey="recordFile.id"
>
{#snippet itemView(edgeRecordPreview)}
{#snippet itemView(filesPreview)}
<div>
<a href="#">{edgeRecordPreview.recordPreview.title}</a>
{edgeRecordPreview.recordPreview.schemaName}
<a href="#">{filesPreview.file.name}</a>
<button
onclick={(e) =>
handleRemoveEdge(edgeRecordPreview.edge.id)}
handleRemoveEdge(filesPreview.recordFile.id)}
>remove</button
>
</div>
+9
View File
@@ -0,0 +1,9 @@
<?php namespace Lucent\Core\Data;
class RecordFilePreview
{
public function __construct(
public RecordFile $recordFile,
public File $file,
) {}
}
+1 -2
View File
@@ -1,6 +1,5 @@
<?php namespace Lucent\Core\File;
use Carbon\Carbon;
use Lucent\Core\Data\File;
use stdClass;
@@ -32,7 +31,7 @@ class FileModule
mime: data_get($data, "mime"),
checksum: data_get($data, "checksum"),
recordId: data_get($data, "recordId"),
isShared: data_get($data, "isShared"),
isShared: data_get($data, "is_shared"),
);
}
}
+30 -1
View File
@@ -1,7 +1,9 @@
<?php namespace Lucent\Core\File;
use Lucent\Core\Data\RecordFile;
use Lucent\Core\Data\RecordFilePreview;
use Lucent\Core\Data\RecordMode;
use Lucent\Core\Data\File;
use stdClass;
class RecordFileModule
@@ -23,7 +25,7 @@ class RecordFileModule
{
return new RecordFile(
id: data_get($data, "id"),
recordId: data_get($data, "recordId"),
recordId: data_get($data, "record_id"),
fileId: data_get($data, "file_id"),
fieldId: data_get($data, "field_id"),
mode: RecordMode::from(data_get($data, "mode")),
@@ -31,4 +33,31 @@ class RecordFileModule
rank: data_get($data, "rank"),
);
}
public static function recordFilePreviewFromDb(
stdClass $data,
): RecordFilePreview {
return new RecordFilePreview(
new RecordFile(
id: data_get($data, "record_file_id"),
recordId: data_get($data, "record_id"),
fileId: data_get($data, "file_id"),
fieldId: data_get($data, "field_id"),
mode: RecordMode::from(data_get($data, "mode")),
locale: data_get($data, "locale"),
rank: data_get($data, "rank"),
),
new File(
id: data_get($data, "file_id"),
name: data_get($data, "name"),
size: data_get($data, "size"),
width: data_get($data, "width"),
height: data_get($data, "height"),
mime: data_get($data, "mime"),
checksum: data_get($data, "checksum"),
recordId: data_get($data, "recordId"),
isShared: data_get($data, "is_shared"),
),
);
}
}
+18
View File
@@ -19,6 +19,24 @@ class FileRepo
// ->where("id", $file->id)
// ->update(FileModule::toDb($file));
// }
//
public static function findShared(): array
{
return DB::table(self::TABLE_NAME)
->where("is_shared", true)
->get()
->map(fn($file) => FileModule::fromDb($file))
->toArray();
}
public static function findByRecordId(string $recordId): array
{
return DB::table(self::TABLE_NAME)
->where("record_id", $recordId)
->get()
->map(fn($file) => FileModule::fromDb($file))
->toArray();
}
public static function delete(string $fileId): void
{
+26
View File
@@ -5,6 +5,8 @@ use Lucent\Core\Data\Record;
use Lucent\Core\Data\RecordPreview;
use Lucent\Core\Data\RecordMode;
use Lucent\Core\Data\EdgeRecordPreview;
use Lucent\Core\File\FileModule;
use Lucent\Core\File\RecordFileModule;
use Lucent\Core\Record\RecordModule;
class RecordRepo
@@ -159,4 +161,28 @@ class RecordRepo
)
->toArray();
}
/**
* @param Schema[] $schemas
* @return RecordFilePreview[]
*/
public static function findRecordFilePreviewsByRecordId(
string $recordId,
): array {
return DB::table("records_files")
->select(
"records_files.*",
"files.*",
"files.id as file_id",
"records_files.id as record_file_id",
)
->where("records_files.record_id", $recordId)
->join("files", "records_files.file_id", "=", "files.id")
->orderBy("records_files.rank", "asc")
->distinct()
->get()
->map(fn($row) => RecordFileModule::recordFilePreviewFromDb($row))
->toArray();
}
}
+28 -21
View File
@@ -12,6 +12,7 @@ use Lucent\Core\Query\QueryModule;
use Lucent\Core\Repository\FieldRepo;
use Lucent\Core\Repository\SchemaRepo;
use Lucent\Core\Repository\EdgeRepo;
use Lucent\Core\Repository\FileRepo;
use Lucent\Core\Repository\RecordFieldRepo;
use Lucent\Core\Record\RecordModule;
use Lucent\Core\Record\RecordFieldModule;
@@ -154,27 +155,6 @@ class RecordController
public function edit(Request $request)
{
$recordId = $request->route("id");
// $graph = $this->query
// ->filter(["id" => $rid])
// ->limit(1)
// ->skip(0)
// ->childrenDepth(2)
// ->childrenLimit(200)
// ->parentsDepth(1)
// ->parentsLimit(200)
// ->run();
// if ($graph->records->isEmpty()) {
// return $this->svelte->render(
// layout: "channel",
// view: "recordNotFound",
// title: "Record Not Found",
// );
// }
// $record = $graph->records->first();
//
$record = RecordRepo::findOne($recordId);
$recordFields = RecordFieldRepo::findByRecordId($recordId);
$draftData = collect($recordFields)
@@ -213,6 +193,20 @@ class RecordController
$recordEdges,
);
$recordFilesPreviews = RecordRepo::findRecordFilePreviewsByRecordId(
$record->id,
);
$recordFilesPreviewsDraft = collect($recordFilesPreviews)
->where("recordFile.mode", RecordMode::DRAFT)
->values()
->toArray();
$recordFilesPreviewsLive = collect($recordFilesPreviews)
->where("recordFile.mode", RecordMode::LIVE)
->values()
->toArray();
return Svelte::view(
view: "recordEdit",
title: "Edit Record",
@@ -222,6 +216,8 @@ class RecordController
"fields" => $fields,
"edgeRecordPreviewsDraft" => toArray($edgeRecordPreviewsDraft),
"edgeRecordPreviewsLive" => toArray($edgeRecordPreviewsLive),
"filesPreviewsDraft" => toArray($recordFilesPreviewsDraft),
"filesPreviewsLive" => toArray($recordFilesPreviewsLive),
"record" => toArray($record),
"draftData" => $draftData,
"liveData" => $liveData,
@@ -240,6 +236,17 @@ class RecordController
return ok(toArray($records));
}
public function files(Request $request)
{
$recordId = $request->input("recordId");
$files = empty($recordId)
? FileRepo::findShared()
: FileRepo::findByRecordId($recordId);
return ok(toArray($files));
}
public function postCreate(Request $request)
{
$schemaId = $request->input("schemaId");
+3
View File
@@ -70,6 +70,9 @@ Route::group(
// CONTENT
Route::get("content/{id}", [RecordController::class, "index"]);
// RECORD FILES
Route::get("records/files", [RecordController::class, "files"]);
// RECORD
Route::get("records/suggest", [RecordController::class, "suggest"]);
Route::get("records/{id}", [RecordController::class, "edit"]);