wip create/edit
This commit is contained in:
@@ -8,12 +8,14 @@ import {dropdown} from "./components/dropdown.js";
|
||||
import {colorPicker} from "./recordEditor/colorPicker.js";
|
||||
import {sortReferences} from "./recordEditor/sortReferences.js";
|
||||
import {recordDialog} from "./recordEditor/recordDialog.js";
|
||||
import {createRecordEntry} from "./recordEditor/createRecordEntry.js";
|
||||
|
||||
addEventListener("load", (event) => {
|
||||
dropdown()
|
||||
colorPicker()
|
||||
sortReferences()
|
||||
recordDialog()
|
||||
createRecordEntry()
|
||||
});
|
||||
|
||||
Mustache.escape = function (value) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import axios from "axios";
|
||||
|
||||
export function createRecordEntry() {
|
||||
const createButton = document.getElementById("record-create-button");
|
||||
createButton.addEventListener("click", save)
|
||||
}
|
||||
|
||||
|
||||
function save(e) {
|
||||
e.preventDefault();
|
||||
const recordForm = document.getElementById("record-form");
|
||||
let validationErrors = null;
|
||||
let errorMessage = "";
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const schemaName = urlParams.get("schema")
|
||||
console.log("SAVE: Attempt");
|
||||
|
||||
let formData = new FormData(recordForm)
|
||||
|
||||
axios
|
||||
.post("/lucent/records", {
|
||||
schema: schemaName,
|
||||
data: Object.fromEntries(formData),
|
||||
status: "draft",
|
||||
// edges: graph.edges,
|
||||
isCreateMode: true,
|
||||
})
|
||||
.then(function (response) {
|
||||
console.log("SAVE: SAVED");
|
||||
window.location.href = "/lucent/records/" + record.id;
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (!error?.response) {
|
||||
}
|
||||
if (typeof error?.response.data.error === "string") {
|
||||
errorMessage = error.response.data.error;
|
||||
} else {
|
||||
validationErrors = error.response.data.error;
|
||||
console.log(validationErrors)
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import axios from "axios";
|
||||
|
||||
export function recordDialog() {
|
||||
|
||||
document.querySelectorAll("[data-open-modal]").forEach(el => {
|
||||
const schema = el.dataset.openModal
|
||||
el.addEventListener("click", e => {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>@yield('title') - Lucent Data Platform</title>
|
||||
<title>{{$title}} - Lucent Data Platform</title>
|
||||
@if(config("lucent.env") == "production")
|
||||
<!-- if production -->
|
||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.js']["css"][0] }}"/>
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
@yield('content')
|
||||
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
<div class=" mt-4" style="margin-bottom:150px;position:relative;">
|
||||
<x-lucent::tabs :schema="$schema" :createMode="$createMode"></x-lucent::tabs>
|
||||
</div>
|
||||
|
||||
<form id="record-form">
|
||||
@foreach($schema->fields as $field)
|
||||
@include("lucent::records-editor.fields", ["field" => $field])
|
||||
@endforeach
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
@php
|
||||
$references = $graph->edges
|
||||
->filter(fn($edge) => $edge->field === $field->name && $edge->source === $record->id)
|
||||
->map(fn($edge) => $graph->records->firstWhere("id", $edge->target));
|
||||
// $references = $graph->edges
|
||||
// ->filter(fn($edge) => $edge->field === $field->name && $edge->source === $record->id)
|
||||
// ->map(fn($edge) => $graph->records->firstWhere("id", $edge->target));
|
||||
//
|
||||
$references = collect([]);
|
||||
|
||||
$collectionSchemas = $schemas->whereIn("name",$field->collections);
|
||||
@endphp
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
@else
|
||||
<input
|
||||
type="text"
|
||||
name="{{$field->name}}"
|
||||
id="{{$id}}"
|
||||
value="{{$value}}"
|
||||
class="form-control {{!empty($errorMessage) ? "is-invalid" : "" }}"
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
</div>
|
||||
@if($createMode)
|
||||
<button
|
||||
id="record-create-button"
|
||||
class="button primary btn-spinner"
|
||||
>
|
||||
<span
|
||||
@@ -48,6 +49,7 @@
|
||||
</button>
|
||||
@else
|
||||
<button
|
||||
id="record-save-button"
|
||||
type="button"
|
||||
class="button primary ms-2 btn btn-primary btn-spinner"
|
||||
>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
{{-- on:refresh={refresh}--}}
|
||||
{{-- />--}}
|
||||
{{-- {/if}--}}
|
||||
@include("lucent::records.tools")
|
||||
@include("lucent::records.table")
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,6 +2,5 @@
|
||||
|
||||
@section("content")
|
||||
@include("lucent::records.index")
|
||||
|
||||
@endsection
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-filters">
|
||||
|
||||
{{-- <SortFields--}}
|
||||
{{-- {schema}--}}
|
||||
{{-- {sortParam}--}}
|
||||
{{-- {sortField}--}}
|
||||
{{-- {systemFields}--}}
|
||||
{{-- {inModal}--}}
|
||||
{{-- {modalUrl}--}}
|
||||
{{-- on:refresh--}}
|
||||
{{-- />--}}
|
||||
|
||||
|
||||
{{-- <FilterFields--}}
|
||||
{{-- bind:schema--}}
|
||||
{{-- {systemFields}--}}
|
||||
{{-- {operators}--}}
|
||||
{{-- {filter}--}}
|
||||
{{-- {inModal}--}}
|
||||
{{-- {modalUrl}--}}
|
||||
{{-- on:refresh--}}
|
||||
{{-- />--}}
|
||||
|
||||
<form method="GET">
|
||||
<input type="search" name="filter[search_regex]" placeholder="Search"
|
||||
class="search" required>
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div style="display:flex;align-items: center;gap:4px">
|
||||
@if(get_class($schema) === \Lucent\Schema\CollectionSchema::class)
|
||||
@if(!$inModal && $isWritable)
|
||||
<a
|
||||
href="{{lucent_url("records/new?schema=")}}{{$schema->name}}"
|
||||
class="button"
|
||||
>
|
||||
New Record
|
||||
</a>
|
||||
@endif
|
||||
@else
|
||||
<div>
|
||||
{{-- <Uploader {schema} on:uploadComplete={uploadComplete}/>--}}
|
||||
</div>
|
||||
@endif
|
||||
@if(!$inModal)
|
||||
{{-- <Dropdown orientation="right">--}}
|
||||
{{-- <div slot="button">--}}
|
||||
{{-- <Icon icon="ellipsis-vertical"/>--}}
|
||||
{{-- </div>--}}
|
||||
{{-- {#if filter["status_in"] === "trashed"}--}}
|
||||
{{-- {#if isWritable}--}}
|
||||
{{-- <a--}}
|
||||
{{-- class="dropdown-item"--}}
|
||||
{{-- href="{channel.lucentUrl}/content/{schema.name}/emptyTrash"--}}
|
||||
{{-- >--}}
|
||||
{{-- Empty trash--}}
|
||||
{{-- </a>--}}
|
||||
{{-- {/if}--}}
|
||||
{{-- {:else}--}}
|
||||
|
||||
{{-- <a--}}
|
||||
{{-- class="dropdown-item"--}}
|
||||
{{-- href={csvUrl}--}}
|
||||
{{-- >Export to CSV</a--}}
|
||||
{{-- >--}}
|
||||
{{-- <a--}}
|
||||
{{-- class="dropdown-item"--}}
|
||||
{{-- href="{channel.lucentUrl}/content/{schema.name}?filter[status_in]=trashed"--}}
|
||||
{{-- >View trashed records</a--}}
|
||||
{{-- >--}}
|
||||
{{-- <a--}}
|
||||
{{-- class="dropdown-item"--}}
|
||||
{{-- href="{channel.lucentUrl}/content/{schema.name}?notlinked=*"--}}
|
||||
{{-- >View unlinked records</a--}}
|
||||
{{-- >--}}
|
||||
{{-- {/if}--}}
|
||||
{{-- </Dropdown>--}}
|
||||
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{--<div class="applied-filters">--}}
|
||||
{{-- <AppliedFilterNotLinked--}}
|
||||
{{-- {inModal}--}}
|
||||
{{-- {modalUrl}--}}
|
||||
{{-- on:refresh--}}
|
||||
{{-- ></AppliedFilterNotLinked>--}}
|
||||
{{-- {#if Object.entries(filter).length > 0}--}}
|
||||
{{-- {#each Object.entries(filter) as [k, v]}--}}
|
||||
{{-- <AppliedFilter--}}
|
||||
{{-- {schema}--}}
|
||||
{{-- {operators}--}}
|
||||
{{-- key={k}--}}
|
||||
{{-- value={v}--}}
|
||||
{{-- {inModal}--}}
|
||||
{{-- {modalUrl}--}}
|
||||
{{-- {graph}--}}
|
||||
{{-- on:refresh--}}
|
||||
{{-- />--}}
|
||||
{{-- {/each}--}}
|
||||
{{-- {/if}--}}
|
||||
{{--</div>--}}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ class RecordController extends Controller
|
||||
|
||||
|
||||
$data = [
|
||||
"title" => $schema->label,
|
||||
"schemas" => $this->channelService->channel->schemas,
|
||||
"schema" => $schema,
|
||||
"users" => $users,
|
||||
@@ -170,6 +171,16 @@ class RecordController extends Controller
|
||||
$recordHistory = $this->recordManager->fromSession($request->session())->getRecords();
|
||||
$record = $this->recordService->createEmpty($schema);
|
||||
$queryRecord = QueryRecord::fromRecord($record);
|
||||
|
||||
return view("lucent::records-editor.edit",[
|
||||
"title"=> "New Record",
|
||||
"schema" => $schema,
|
||||
"record" => $queryRecord,
|
||||
"recordHistory" => $recordHistory,
|
||||
"createMode" => true,
|
||||
"isWritable" => in_array($record->schema, $this->accountService->currentWritableSchemas())
|
||||
]);
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordEdit",
|
||||
@@ -243,6 +254,7 @@ class RecordController extends Controller
|
||||
$recordHistory = $this->recordManager->fromSession($request->session())->push($rid)->getRecords($rid);
|
||||
|
||||
return view("lucent::records-editor.edit",[
|
||||
"title" => "Edit Record",
|
||||
"schema" => $schema,
|
||||
"graph" => $graph,
|
||||
"record" => $record,
|
||||
@@ -304,10 +316,10 @@ class RecordController extends Controller
|
||||
if ($request->input("isCreateMode")) {
|
||||
$recordId = $this->recordService->create(
|
||||
data: new RecordInputData(
|
||||
$request->input("record.schema"),
|
||||
$request->input("schema"),
|
||||
$recordId ?? "",
|
||||
$request->input("record.data"),
|
||||
Status::from($request->input("record.status")),
|
||||
$request->input("data"),
|
||||
Status::from($request->input("status")),
|
||||
),
|
||||
edges: array_map(EdgeInputData::fromArray(...), $request->input("edges") ?? [])
|
||||
);
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ if (!function_exists('lucent_thumbnail')) {
|
||||
if (!function_exists('lucent_url')) {
|
||||
function lucent_url(string $path): string
|
||||
{
|
||||
return rtrim(config("lucent.url") ?? "", "/")."/".trim($path, "/");
|
||||
return rtrim(config("lucent.url") ?? "", "/")."/lucent/".trim($path, "/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user