wip create/edit

This commit is contained in:
2024-10-02 18:58:30 +03:00
parent 4389dba49d
commit b8c5f82e47
13 changed files with 183 additions and 12 deletions
+2
View File
@@ -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
View File
@@ -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 => {
+1 -2
View File
@@ -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')
+2 -1
View File
@@ -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"
>
+1
View File
@@ -22,6 +22,7 @@
{{-- on:refresh={refresh}--}}
{{-- />--}}
{{-- {/if}--}}
@include("lucent::records.tools")
@include("lucent::records.table")
</div>
-1
View File
@@ -2,6 +2,5 @@
@section("content")
@include("lucent::records.index")
@endsection
+109
View File
@@ -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>--}}