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} {channel}
fields={data.fields} fields={data.fields}
edgeRecordPreviews={data.edgeRecordPreviewsDraft} edgeRecordPreviews={data.edgeRecordPreviewsDraft}
filesPreviews={data.filesPreviewsDraft}
{record} {record}
{selectedLocales} {selectedLocales}
validationErrors={data.validationErrors} validationErrors={data.validationErrors}
@@ -62,6 +63,7 @@
{channel} {channel}
fields={data.fields} fields={data.fields}
edgeRecordPreviews={data.edgeRecordPreviewsLive} edgeRecordPreviews={data.edgeRecordPreviewsLive}
filesPreviews={data.filesPreviewsLive}
{record} {record}
{selectedLocales} {selectedLocales}
validationErrors={data.validationErrors} validationErrors={data.validationErrors}
@@ -9,6 +9,7 @@
validationErrors, validationErrors,
fieldData, fieldData,
edgeRecordPreviews, edgeRecordPreviews,
filesPreviews,
selectedLocales, selectedLocales,
} = $props(); } = $props();
const findFieldValidationError = (field, locale) => { const findFieldValidationError = (field, locale) => {
@@ -26,6 +27,13 @@
(e) => e.edge.fieldId === field.id && e.edge.locale === locale, (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> </script>
{#each fields as field} {#each fields as field}
@@ -88,6 +96,6 @@
schemaField={field} schemaField={field}
{locale} {locale}
dataField={findDataField(field, locale)} dataField={findDataField(field, locale)}
edgeRecordPreviews={findFieldEdges(field, locale)} filesPreviews={findFieldFiles(field, locale)}
></FileField> ></FileField>
{/snippet} {/snippet}
@@ -13,6 +13,7 @@
locale, locale,
validationError, validationError,
edgeRecordPreviews, edgeRecordPreviews,
filesPreviews,
} = $props(); } = $props();
let originalValue = dataField?.value ?? schemaField.props.default; let originalValue = dataField?.value ?? schemaField.props.default;
let newValue = $state(originalValue); let newValue = $state(originalValue);
@@ -26,7 +27,7 @@
let suggestionsLoaded = $state(false); let suggestionsLoaded = $state(false);
let suggestions = $state([]); let suggestions = $state([]);
let selectedRecordIds = $state([]); let selectedFilesIds = $state([]);
let dialog = $state(); let dialog = $state();
function handleModalOpen(e) { function handleModalOpen(e) {
@@ -35,10 +36,10 @@
if (suggestionsLoaded) { if (suggestionsLoaded) {
return; return;
} }
// get(app.url("records/files"), { recordId: record.id }, (data, err) => { get(app.url("records/files"), { recordId: record.id }, (data, err) => {
suggestionsLoaded = true; suggestionsLoaded = true;
// suggestions = data; suggestions = data;
// }); });
} }
function handleModalClose(e) { function handleModalClose(e) {
@@ -48,9 +49,9 @@
function handleInsertSelected() { function handleInsertSelected() {
suggestionsLoaded = false; suggestionsLoaded = false;
post( post(
app.url("edges/many"), app.url("records/files"),
{ {
toIds: selectedRecordIds, toIds: selectedFilesIds,
from: record.id, from: record.id,
fieldId: schemaField.id, fieldId: schemaField.id,
locale: locale, locale: locale,
@@ -179,17 +180,13 @@
<input <input
type="checkbox" type="checkbox"
value={suggestion.id} value={suggestion.id}
bind:group={selectedRecordIds} bind:group={selectedFilesIds}
/> />
</td> </td>
<td> <td>
<a href="#">{suggestion.title}</a> <a href="#">{suggestion.name}</a>
</td>
<td>
<a href="#">
{suggestion.schemaName}
</a>
</td> </td>
<td> </td>
</tr> </tr>
{/each} {/each}
</tbody> </tbody>
@@ -201,21 +198,20 @@
</article> </article>
</dialog> </dialog>
<div> <div>
{#if edgeRecordPreviews.length == 0} {#if filesPreviews.length == 0}
No relations exist No files exist
{:else} {:else}
<Sortable <Sortable
onUpdate={handleSortUpdate} onUpdate={handleSortUpdate}
items={edgeRecordPreviews} items={filesPreviews}
itemKey="edge.id" itemKey="recordFile.id"
> >
{#snippet itemView(edgeRecordPreview)} {#snippet itemView(filesPreview)}
<div> <div>
<a href="#">{edgeRecordPreview.recordPreview.title}</a> <a href="#">{filesPreview.file.name}</a>
{edgeRecordPreview.recordPreview.schemaName}
<button <button
onclick={(e) => onclick={(e) =>
handleRemoveEdge(edgeRecordPreview.edge.id)} handleRemoveEdge(filesPreview.recordFile.id)}
>remove</button >remove</button
> >
</div> </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; <?php namespace Lucent\Core\File;
use Carbon\Carbon;
use Lucent\Core\Data\File; use Lucent\Core\Data\File;
use stdClass; use stdClass;
@@ -32,7 +31,7 @@ class FileModule
mime: data_get($data, "mime"), mime: data_get($data, "mime"),
checksum: data_get($data, "checksum"), checksum: data_get($data, "checksum"),
recordId: data_get($data, "recordId"), 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; <?php namespace Lucent\Core\File;
use Lucent\Core\Data\RecordFile; use Lucent\Core\Data\RecordFile;
use Lucent\Core\Data\RecordFilePreview;
use Lucent\Core\Data\RecordMode; use Lucent\Core\Data\RecordMode;
use Lucent\Core\Data\File;
use stdClass; use stdClass;
class RecordFileModule class RecordFileModule
@@ -23,7 +25,7 @@ class RecordFileModule
{ {
return new RecordFile( return new RecordFile(
id: data_get($data, "id"), id: data_get($data, "id"),
recordId: data_get($data, "recordId"), recordId: data_get($data, "record_id"),
fileId: data_get($data, "file_id"), fileId: data_get($data, "file_id"),
fieldId: data_get($data, "field_id"), fieldId: data_get($data, "field_id"),
mode: RecordMode::from(data_get($data, "mode")), mode: RecordMode::from(data_get($data, "mode")),
@@ -31,4 +33,31 @@ class RecordFileModule
rank: data_get($data, "rank"), 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) // ->where("id", $file->id)
// ->update(FileModule::toDb($file)); // ->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 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\RecordPreview;
use Lucent\Core\Data\RecordMode; use Lucent\Core\Data\RecordMode;
use Lucent\Core\Data\EdgeRecordPreview; use Lucent\Core\Data\EdgeRecordPreview;
use Lucent\Core\File\FileModule;
use Lucent\Core\File\RecordFileModule;
use Lucent\Core\Record\RecordModule; use Lucent\Core\Record\RecordModule;
class RecordRepo class RecordRepo
@@ -159,4 +161,28 @@ class RecordRepo
) )
->toArray(); ->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\FieldRepo;
use Lucent\Core\Repository\SchemaRepo; use Lucent\Core\Repository\SchemaRepo;
use Lucent\Core\Repository\EdgeRepo; use Lucent\Core\Repository\EdgeRepo;
use Lucent\Core\Repository\FileRepo;
use Lucent\Core\Repository\RecordFieldRepo; use Lucent\Core\Repository\RecordFieldRepo;
use Lucent\Core\Record\RecordModule; use Lucent\Core\Record\RecordModule;
use Lucent\Core\Record\RecordFieldModule; use Lucent\Core\Record\RecordFieldModule;
@@ -154,27 +155,6 @@ class RecordController
public function edit(Request $request) public function edit(Request $request)
{ {
$recordId = $request->route("id"); $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); $record = RecordRepo::findOne($recordId);
$recordFields = RecordFieldRepo::findByRecordId($recordId); $recordFields = RecordFieldRepo::findByRecordId($recordId);
$draftData = collect($recordFields) $draftData = collect($recordFields)
@@ -213,6 +193,20 @@ class RecordController
$recordEdges, $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( return Svelte::view(
view: "recordEdit", view: "recordEdit",
title: "Edit Record", title: "Edit Record",
@@ -222,6 +216,8 @@ class RecordController
"fields" => $fields, "fields" => $fields,
"edgeRecordPreviewsDraft" => toArray($edgeRecordPreviewsDraft), "edgeRecordPreviewsDraft" => toArray($edgeRecordPreviewsDraft),
"edgeRecordPreviewsLive" => toArray($edgeRecordPreviewsLive), "edgeRecordPreviewsLive" => toArray($edgeRecordPreviewsLive),
"filesPreviewsDraft" => toArray($recordFilesPreviewsDraft),
"filesPreviewsLive" => toArray($recordFilesPreviewsLive),
"record" => toArray($record), "record" => toArray($record),
"draftData" => $draftData, "draftData" => $draftData,
"liveData" => $liveData, "liveData" => $liveData,
@@ -240,6 +236,17 @@ class RecordController
return ok(toArray($records)); 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) public function postCreate(Request $request)
{ {
$schemaId = $request->input("schemaId"); $schemaId = $request->input("schemaId");
+3
View File
@@ -70,6 +70,9 @@ Route::group(
// CONTENT // CONTENT
Route::get("content/{id}", [RecordController::class, "index"]); Route::get("content/{id}", [RecordController::class, "index"]);
// RECORD FILES
Route::get("records/files", [RecordController::class, "files"]);
// RECORD // RECORD
Route::get("records/suggest", [RecordController::class, "suggest"]); Route::get("records/suggest", [RecordController::class, "suggest"]);
Route::get("records/{id}", [RecordController::class, "edit"]); Route::get("records/{id}", [RecordController::class, "edit"]);