file uploads
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
<script>
|
||||
import {getContext} from "svelte";
|
||||
import Preview from "../files/Preview.svelte";
|
||||
import {selectRecord} from "./functions/recordSelect.js";
|
||||
|
||||
const channel = getContext("channel");
|
||||
|
||||
export let schema;
|
||||
export let records;
|
||||
export let isWritable;
|
||||
export let selected = [];
|
||||
|
||||
function select(record) {
|
||||
selected = selectRecord(record, selected)
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
<div class="row" style="max-width:1000px">
|
||||
{#each records as record (record.id)}
|
||||
<div class="col-6 col-md-4">
|
||||
<div
|
||||
class="file-wrapper rounded p-2 mb-4 bg-light"
|
||||
class:selected={selected.includes(record)}
|
||||
>
|
||||
{#if isWritable}
|
||||
<div class="form-check">
|
||||
<input
|
||||
on:change={() => select(record)}
|
||||
class="form-check-input "
|
||||
type="checkbox"
|
||||
checked={selected.find(
|
||||
(r) => r.id === record.id
|
||||
)}
|
||||
value={record}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="d-flex justify-content-center">
|
||||
<Preview {record} size="medium"/>
|
||||
</div>
|
||||
|
||||
<a
|
||||
href="{channel.lucentUrl}/records/{record.id}"
|
||||
title={record._file.path}
|
||||
class="d-block text-center overflow-hidden text-nowrap my-2 "
|
||||
style="
|
||||
text-overflow: ellipsis;
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
">{record._file.path}</a
|
||||
>
|
||||
<span
|
||||
class="lx-small-text text-muted d-block text-center"
|
||||
>{record._file.mime}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
|
||||
<style>
|
||||
.form-check {
|
||||
display: inline-block;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -47,7 +47,7 @@
|
||||
</script>
|
||||
|
||||
<div class="">
|
||||
<div class="{inModal ? 'mt-0' : 'mt-5'}">
|
||||
<div class={inModal ? "mt-0" : "mt-5"}>
|
||||
<h3 class="header-normal mb-5">
|
||||
{schema.label}
|
||||
</h3>
|
||||
@@ -82,7 +82,6 @@
|
||||
{isWritable}
|
||||
bind:selected
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
<Pagination
|
||||
@@ -94,4 +93,3 @@
|
||||
{modalUrl}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
export let sortParam;
|
||||
export let sortField;
|
||||
export let visibleColumns;
|
||||
|
||||
</script>
|
||||
|
||||
{#each visibleColumns as field, index}
|
||||
@@ -34,26 +33,34 @@
|
||||
{#if schema.visible?.includes("_sys.createdBy")}
|
||||
<td
|
||||
class="text-center"
|
||||
class:is-sort={"-_sys.createdBy" == sortParam || "_sys.createdBy" == sortParam}
|
||||
class:is-sort={"-_sys.createdBy" == sortParam ||
|
||||
"_sys.createdBy" == sortParam}
|
||||
>
|
||||
<Avatar name={usernameById(users, record._sys.createdBy)} side={24}/>
|
||||
<Avatar name={usernameById(users, record.createdBy)} side={24} />
|
||||
</td>
|
||||
{/if}
|
||||
{#if schema.visible?.includes("_sys.updatedBy")}
|
||||
<td
|
||||
class="text-center"
|
||||
class:is-sort={"-_sys.updatedBy" == sortParam || "_sys.updatedBy" == sortParam}
|
||||
class:is-sort={"-_sys.updatedBy" == sortParam ||
|
||||
"_sys.updatedBy" == sortParam}
|
||||
>
|
||||
<Avatar name={usernameById(users, record._sys.updatedBy)} side={24}/>
|
||||
<Avatar name={usernameById(users, record.updatedBy)} side={24} />
|
||||
</td>
|
||||
{/if}
|
||||
{#if schema.visible?.includes("_sys.createdAt")}
|
||||
<td class:is-sort={"-_sys.createdAt" == sortParam || "_sys.createdAt" == sortParam}>
|
||||
{friendlyDate(record._sys.createdAt)}
|
||||
<td
|
||||
class:is-sort={"-_sys.createdAt" == sortParam ||
|
||||
"_sys.createdAt" == sortParam}
|
||||
>
|
||||
{friendlyDate(record.createdAt)}
|
||||
</td>
|
||||
{/if}
|
||||
{#if schema.visible?.includes("_sys.updatedAt")}
|
||||
<td class:is-sort={"-_sys.updatedAt" == sortParam || "_sys.updatedAt" == sortParam}>
|
||||
{friendlyDate(record._sys.updatedAt)}
|
||||
<td
|
||||
class:is-sort={"-_sys.updatedAt" == sortParam ||
|
||||
"_sys.updatedAt" == sortParam}
|
||||
>
|
||||
{friendlyDate(record.updatedAt)}
|
||||
</td>
|
||||
{/if}
|
||||
|
||||
@@ -23,14 +23,16 @@
|
||||
export let selected = [];
|
||||
|
||||
function eventToggleAll(e) {
|
||||
selected = toggleAll(e, records, selected)
|
||||
selected = toggleAll(e, records, selected);
|
||||
}
|
||||
|
||||
function select(record) {
|
||||
selected = selectRecord(record, selected)
|
||||
selected = selectRecord(record, selected);
|
||||
}
|
||||
|
||||
$: visibleColumns = schema.fields.filter(c => schema.visible?.includes(c.name) ?? [])
|
||||
$: visibleColumns = schema.fields.filter(
|
||||
(c) => schema.visible?.includes(c.name) ?? [],
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="table mt-5">
|
||||
@@ -42,10 +44,10 @@
|
||||
<Checkbox
|
||||
value=""
|
||||
on:change={eventToggleAll}
|
||||
indeterminate={selected.length > 0 && selected.length < records.length}
|
||||
indeterminate={selected.length > 0 &&
|
||||
selected.length < records.length}
|
||||
checked={selected.length === records.length}
|
||||
>
|
||||
</Checkbox>
|
||||
></Checkbox>
|
||||
</th>
|
||||
{/if}
|
||||
|
||||
@@ -54,12 +56,13 @@
|
||||
class="field-ui-{field.info.name ?? field.ui}"
|
||||
class:is-sort={field.name === sortField.name}
|
||||
scope="col"
|
||||
title={field.help}
|
||||
>{field.label}</th
|
||||
title={field.help}>{field.label}</th
|
||||
>
|
||||
{/each}
|
||||
{#each systemFields.filter(c => schema.visible?.includes(c.name)) as sysField}
|
||||
<th class:is-sort={sysField.name === sortField.name}>{sysField.label}</th>
|
||||
{#each systemFields.filter( (c) => schema.visible?.includes(c.name), ) as sysField}
|
||||
<th class:is-sort={sysField.name === sortField.name}
|
||||
>{sysField.label}</th
|
||||
>
|
||||
{/each}
|
||||
<th></th>
|
||||
</tr>
|
||||
@@ -68,59 +71,29 @@
|
||||
{#each records as record (record.id)}
|
||||
<tr>
|
||||
<td class="title-td">
|
||||
<div
|
||||
class="title-td-contents"
|
||||
>
|
||||
<div class="title-td-contents">
|
||||
{#if isWritable}
|
||||
<Checkbox
|
||||
on:change={() => select(record)}
|
||||
checked={selected.find((r) => r.id === record.id)}
|
||||
checked={selected.find(
|
||||
(r) => r.id === record.id,
|
||||
)}
|
||||
value={record}
|
||||
>
|
||||
</Checkbox>
|
||||
|
||||
></Checkbox>
|
||||
{/if}
|
||||
{#if record._file?.path}
|
||||
<div class="file-table-row">
|
||||
<Preview record={record} size={record._file?.width > 0 ? "medium" : "small"}/>
|
||||
|
||||
<div>
|
||||
{#if record.status === "draft"}
|
||||
<span style="text-transform: uppercase;font-size:10px">{record.status}</span>
|
||||
{/if}
|
||||
<a
|
||||
href="{channel.lucentUrl}/records/{record.id}"
|
||||
target={inModal ? "_blank" : "_self"}
|
||||
>
|
||||
{previewTitle(channel.schemas, record, graph)}
|
||||
</a>
|
||||
<span>{(record._file.size / 1024).toFixed(1)}kB</span>
|
||||
|
||||
{#if record._file.width > 0}
|
||||
<span>{record._file.width + "x" + record._file.height}</span>
|
||||
{/if}
|
||||
<a
|
||||
href="{fileurl(channel,record)}"
|
||||
target="_blank"
|
||||
>
|
||||
Download
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{:else}
|
||||
<a
|
||||
href="{channel.lucentUrl}/records/{record.id}"
|
||||
target={inModal ? "_blank" : "_self"}
|
||||
>
|
||||
{#if record.status === "draft"}
|
||||
<span style="text-transform: uppercase;font-size:10px">{record.status}</span>
|
||||
<span
|
||||
style="text-transform: uppercase;font-size:10px"
|
||||
>{record.status}</span
|
||||
>
|
||||
{/if}
|
||||
{previewTitle(channel.schemas, record, graph)}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
|
||||
</div>
|
||||
</td>
|
||||
<RecordRow
|
||||
@@ -134,10 +107,7 @@
|
||||
/>
|
||||
<td>
|
||||
<Avatar
|
||||
name={usernameById(
|
||||
users,
|
||||
record._sys.updatedBy
|
||||
)}
|
||||
name={usernameById(users, record.updatedBy)}
|
||||
side={24}
|
||||
/>
|
||||
</td>
|
||||
@@ -146,4 +116,3 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script>
|
||||
import FilterFields from "./FilterFields.svelte";
|
||||
import Uploader from "../../files/Uploader.svelte";
|
||||
import Icon from "../../common/Icon.svelte";
|
||||
import SortFields from "./SortFields.svelte";
|
||||
import AppliedFilter from "./AppliedFilter.svelte";
|
||||
|
||||
@@ -33,18 +33,12 @@
|
||||
|
||||
function insert(e) {
|
||||
e.preventDefault();
|
||||
dispatch("insert", {
|
||||
records: selectedRecords,
|
||||
action: "insert",
|
||||
});
|
||||
dispatch("insert_files", selectedRecords);
|
||||
}
|
||||
|
||||
function replace(e) {
|
||||
e.preventDefault();
|
||||
dispatch("insert", {
|
||||
records: selectedRecords,
|
||||
action: "replace",
|
||||
});
|
||||
dispatch("replace_files", selectedRecords);
|
||||
}
|
||||
|
||||
export function open(recordId) {
|
||||
|
||||
@@ -97,21 +97,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<!-- <RecordRow
|
||||
{record}
|
||||
{graph}
|
||||
{schema}
|
||||
{visibleColumns}
|
||||
{sortParam}
|
||||
{sortField}
|
||||
{users}
|
||||
/> -->
|
||||
<!-- <td>
|
||||
<Avatar
|
||||
name={usernameById(users, record._sys.updatedBy)}
|
||||
side={24}
|
||||
/>
|
||||
</td> -->
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
|
||||
|
||||
|
||||
export function sortByField(from, to, edges, fieldName, references) {
|
||||
if (from === to) {
|
||||
return edges;
|
||||
}
|
||||
let referenceIds = references.map(r => r.id);
|
||||
let edgesTosort = edges?.filter((ed) => ed.field === fieldName && ed.depth === 1 && referenceIds.includes(ed.target)) ?? [];
|
||||
let remainingEdge = edges?.filter((ed) => !(ed.field === fieldName && ed.depth === 1)) ?? [];
|
||||
let referenceIds = references.map((r) => r.id);
|
||||
let edgesTosort =
|
||||
edges?.filter(
|
||||
(ed) =>
|
||||
ed.field === fieldName &&
|
||||
ed.depth === 1 &&
|
||||
referenceIds.includes(ed.target),
|
||||
) ?? [];
|
||||
let remainingEdge =
|
||||
edges?.filter((ed) => !(ed.field === fieldName && ed.depth === 1)) ?? [];
|
||||
|
||||
edgesTosort = array_move(edgesTosort, from, to);
|
||||
return [...remainingEdge, ...edgesTosort];
|
||||
}
|
||||
|
||||
function array_move(arr, old_index, new_index) {
|
||||
export function array_move(arr, old_index, new_index) {
|
||||
if (new_index >= arr.length) {
|
||||
var k = new_index - arr.length + 1;
|
||||
while (k--) {
|
||||
@@ -22,4 +26,4 @@ function array_move(arr, old_index, new_index) {
|
||||
}
|
||||
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
|
||||
return arr; // for testing
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,10 +11,9 @@
|
||||
export let graph;
|
||||
export let record;
|
||||
let schema = channel.schemas.find((s) => s.name === record.schema);
|
||||
let frieldlyUpdatedAt = formatDistanceToNow(
|
||||
parseJSON(record._sys.updatedAt),
|
||||
{addSuffix: true}
|
||||
);
|
||||
let frieldlyUpdatedAt = formatDistanceToNow(parseJSON(record.updatedAt), {
|
||||
addSuffix: true,
|
||||
});
|
||||
</script>
|
||||
|
||||
<td>
|
||||
@@ -25,24 +24,17 @@
|
||||
{#if schema.type === "files"}
|
||||
<Preview {record} size="tiny" showFilename={true} />
|
||||
{:else}
|
||||
<a
|
||||
href="{channel.lucentUrl}/records/{record.id}"
|
||||
|
||||
>
|
||||
<a href="{channel.lucentUrl}/records/{record.id}">
|
||||
{previewTitle(channel.schemas, record, graph)}
|
||||
</a>
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
<td><a
|
||||
href="{channel.lucentUrl}/content/{schema.name}">{schema.label}</a
|
||||
>
|
||||
</td>
|
||||
|
||||
<td><a href="{channel.lucentUrl}/content/{schema.name}">{schema.label}</a> </td>
|
||||
|
||||
<td>
|
||||
<div style="display: flex;gap: 14px">
|
||||
<Avatar name={usernameById(users, record._sys.updatedBy)} side={24}/>
|
||||
<Avatar name={usernameById(users, record.updatedBy)} side={24} />
|
||||
<div class="ms-2">
|
||||
{frieldlyUpdatedAt}
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script>
|
||||
|
||||
// https://codesandbox.io/s/codemirror-remark-editor-4m4z9?file=/src/CodeEditor.js:374-387
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { basicSetup, EditorView } from "codemirror";
|
||||
@@ -17,10 +16,10 @@
|
||||
|
||||
export function insertMedia(info) {
|
||||
let insertText = "";
|
||||
if (info.record._file.width > 0) {
|
||||
insertText = ``;
|
||||
if (info.file.width > 0) {
|
||||
insertText = ``;
|
||||
} else {
|
||||
insertText = `[${info.record._file.originalName}](${info.originalUrl})`;
|
||||
insertText = `[${info.file.filename}](${info.originalUrl})`;
|
||||
}
|
||||
const cursor = codeMirrorView.state.selection.main.head;
|
||||
const transaction = codeMirrorView.state.update({
|
||||
@@ -46,11 +45,7 @@
|
||||
doc: value,
|
||||
extensions: [
|
||||
basicSetup,
|
||||
keymap.of([
|
||||
indentWithTab,
|
||||
...lintKeymap,
|
||||
...completionKeymap
|
||||
]),
|
||||
keymap.of([indentWithTab, ...lintKeymap, ...completionKeymap]),
|
||||
language.of(markdown()),
|
||||
markdown(),
|
||||
autocompletion(),
|
||||
@@ -63,17 +58,14 @@
|
||||
}
|
||||
}),
|
||||
EditorView.lineWrapping,
|
||||
EditorView.contentAttributes.of({spellcheck: "true"})
|
||||
EditorView.contentAttributes.of({ spellcheck: "true" }),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
codeMirrorView = new EditorView({
|
||||
state,
|
||||
parent: parentElement,
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
|
||||
@@ -1,61 +1,60 @@
|
||||
<script>
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import Trix from "trix"
|
||||
import "trix/dist/trix.css"
|
||||
import Trix from "trix";
|
||||
import "trix/dist/trix.css";
|
||||
|
||||
export let value = "";
|
||||
export let field;
|
||||
let editor;
|
||||
|
||||
|
||||
function updateValue(e) {
|
||||
value = e.target.value;
|
||||
}
|
||||
|
||||
export function insertMedia(info) {
|
||||
if(info.record._file.width > 0){
|
||||
var attachment = new Trix.Attachment({ content: info.html })
|
||||
editor.editor.insertAttachment(attachment)
|
||||
if (info.file.width > 0) {
|
||||
var attachment = new Trix.Attachment({ content: info.html });
|
||||
editor.editor.insertAttachment(attachment);
|
||||
} else {
|
||||
editor.editor.insertHTML(`<a href="${info.originalUrl}">${info.record._file.originalName}</a>`)
|
||||
|
||||
editor.editor.insertHTML(
|
||||
`<a href="${info.originalUrl}">${info.file.filename}</a>`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
editor.addEventListener("trix-file-accept", (e) => {
|
||||
e.preventDefault();
|
||||
})
|
||||
});
|
||||
|
||||
editor.addEventListener("trix-before-initialize", (e) => {
|
||||
Trix.config.blockAttributes.heading1.tagName = 'h2';
|
||||
const { toolbarElement } = e.target
|
||||
const h1Button = toolbarElement.querySelector("[data-trix-attribute=heading1]")
|
||||
h1Button.insertAdjacentHTML("afterend", `<button style="text-indent: initial;padding: 14px 10px !important;" type="button" class="trix-button trix-button--icon" data-trix-attribute="heading3" title="Heading 3" tabindex="-1" data-trix-active="">H3</button>`)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
Trix.config.blockAttributes.heading1.tagName = "h2";
|
||||
const { toolbarElement } = e.target;
|
||||
const h1Button = toolbarElement.querySelector(
|
||||
"[data-trix-attribute=heading1]",
|
||||
);
|
||||
h1Button.insertAdjacentHTML(
|
||||
"afterend",
|
||||
`<button style="text-indent: initial;padding: 14px 10px !important;" type="button" class="trix-button trix-button--icon" data-trix-attribute="heading3" title="Heading 3" tabindex="-1" data-trix-active="">H3</button>`,
|
||||
);
|
||||
});
|
||||
});
|
||||
// onDestroy(() => {
|
||||
// editor.removeEventListener("trix-before-initialize")
|
||||
// })
|
||||
|
||||
|
||||
Trix.config.blockAttributes.default.breakOnReturn = false
|
||||
Trix.config.blockAttributes.default.breakOnReturn = false;
|
||||
Trix.config.blockAttributes.heading3 = {
|
||||
tagName: 'h3',
|
||||
tagName: "h3",
|
||||
terminal: true,
|
||||
breakOnReturn: true,
|
||||
group: false
|
||||
}
|
||||
group: false,
|
||||
};
|
||||
// console.log(Trix.config)
|
||||
|
||||
</script>
|
||||
|
||||
<div class="tox-wrapper">
|
||||
<input id="x-{field.name}" {value} type="hidden">
|
||||
<input id="x-{field.name}" {value} type="hidden" />
|
||||
<trix-editor
|
||||
bind:this={editor}
|
||||
class=" content"
|
||||
@@ -63,6 +62,5 @@
|
||||
role="textbox"
|
||||
tabindex="0"
|
||||
on:trix-change={updateValue}
|
||||
|
||||
></trix-editor>
|
||||
</div>
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
import { afterUpdate, getContext, onMount } from "svelte";
|
||||
import { isEqual } from "lodash";
|
||||
import axios from "axios";
|
||||
import EditHeader from "./header/EditHeader.svelte"
|
||||
import FilePreview from "./FilePreview.svelte"
|
||||
import ContentTabs from "./header/ContentTabs.svelte"
|
||||
import FormField from "./FormField.svelte"
|
||||
import Graph from "./Graph.svelte"
|
||||
import Info from "./Info.svelte"
|
||||
import ErrorAlert from "../common/ErrorAlert.svelte"
|
||||
import EditHeader from "./header/EditHeader.svelte";
|
||||
import ContentTabs from "./header/ContentTabs.svelte";
|
||||
import FormField from "./FormField.svelte";
|
||||
import Graph from "./Graph.svelte";
|
||||
import Info from "./Info.svelte";
|
||||
import ErrorAlert from "../common/ErrorAlert.svelte";
|
||||
import Title from "./header/Title.svelte";
|
||||
|
||||
const channel = getContext("channel");
|
||||
@@ -17,7 +16,7 @@
|
||||
export let record;
|
||||
export let graph = {
|
||||
records: [],
|
||||
edges: []
|
||||
edges: [],
|
||||
};
|
||||
// export let recordHistory;
|
||||
export let isCreateMode;
|
||||
@@ -33,10 +32,7 @@
|
||||
} error(s)`
|
||||
: null;
|
||||
|
||||
let activeFields = schema.fields.filter(
|
||||
(f) => f.name !== "id"
|
||||
);
|
||||
|
||||
let activeFields = schema.fields.filter((f) => f.name !== "id");
|
||||
|
||||
onMount(() => {
|
||||
setOriginalContent();
|
||||
@@ -45,10 +41,7 @@
|
||||
function setOriginalContent() {
|
||||
originalContent = {
|
||||
data: JSON.parse(JSON.stringify(record.data)),
|
||||
schema: record.schema,
|
||||
status: record.status,
|
||||
_sys: JSON.parse(JSON.stringify(record._sys)),
|
||||
_file: JSON.parse(JSON.stringify(record._file)),
|
||||
edges: JSON.parse(JSON.stringify(graph.edges)),
|
||||
};
|
||||
}
|
||||
@@ -79,10 +72,7 @@
|
||||
}
|
||||
return !isEqual(originalContent, {
|
||||
data: record.data,
|
||||
schema: record.schema,
|
||||
status: record.status,
|
||||
_sys: record._sys,
|
||||
_file: record._file,
|
||||
edges: graph.edges,
|
||||
});
|
||||
}
|
||||
@@ -104,7 +94,9 @@
|
||||
}
|
||||
|
||||
// remove trashed edges
|
||||
graph.edges = graph.edges?.filter((edge) => !edge._isTrashed && edge.source === record.id);
|
||||
graph.edges = graph.edges?.filter(
|
||||
(edge) => !edge._isTrashed && edge.source === record.id,
|
||||
);
|
||||
axios
|
||||
.post(channel.lucentUrl + "/records", {
|
||||
record: record,
|
||||
@@ -115,7 +107,8 @@
|
||||
console.log("SAVE: SAVED");
|
||||
|
||||
if (isCreateMode) {
|
||||
window.location = channel.lucentUrl + "/records/" + record.id;
|
||||
window.location =
|
||||
channel.lucentUrl + "/records/" + record.id;
|
||||
} else {
|
||||
record = response.data.records[0] ?? null;
|
||||
if (!record) {
|
||||
@@ -137,7 +130,7 @@
|
||||
errorMessage = error.response.data.error;
|
||||
} else {
|
||||
validationErrors = error.response.data.error;
|
||||
console.log(validationErrors)
|
||||
console.log(validationErrors);
|
||||
}
|
||||
}
|
||||
resolve(null);
|
||||
@@ -156,10 +149,7 @@
|
||||
<!-- <Manager managerRecords={recordHistory} {graph}/>-->
|
||||
<EditHeader {schema} bind:record {isCreateMode} bind:activeContentTab />
|
||||
{#if isCreateMode}
|
||||
<button
|
||||
class="button primary btn-spinner"
|
||||
on:click={save}
|
||||
>
|
||||
<button class="button primary btn-spinner" on:click={save}>
|
||||
<span
|
||||
class="spinner-border spinner-border-sm"
|
||||
role="status"
|
||||
@@ -181,26 +171,19 @@
|
||||
Save
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
<Title {schema} {record} {isCreateMode} />
|
||||
|
||||
|
||||
<ErrorAlert message={errorMessage} />
|
||||
|
||||
<div class=" mt-4" style="margin-bottom:150px;position:relative;">
|
||||
<ContentTabs
|
||||
{schema}
|
||||
{isCreateMode}
|
||||
bind:active={activeContentTab}
|
||||
/>
|
||||
<ContentTabs {schema} {isCreateMode} bind:active={activeContentTab} />
|
||||
{#if !["_graph", "_info"].includes(activeContentTab)}
|
||||
<FilePreview {record} {schema}/>
|
||||
{#each activeFields as field (field.name)}
|
||||
{#if activeContentTab === field.group}
|
||||
<FormField
|
||||
bind:data={record.data}
|
||||
bind:graph={graph}
|
||||
bind:graph
|
||||
{field}
|
||||
{schema}
|
||||
{record}
|
||||
|
||||
@@ -47,23 +47,18 @@
|
||||
<div class="editor-field">
|
||||
<FieldHeader {field} {id} />
|
||||
{#if field.info.name === "reference" && field.layout === "tags"}
|
||||
<ReferenceTags
|
||||
bind:graph
|
||||
{id}
|
||||
{record}
|
||||
{field}
|
||||
{validationErrors}
|
||||
/>
|
||||
<ReferenceTags bind:graph {id} {record} {field} {validationErrors} />
|
||||
{:else if field.info.name === "reference"}
|
||||
<Reference
|
||||
bind:graph
|
||||
{id}
|
||||
<Reference bind:graph {id} {record} {field} {validationErrors} />
|
||||
{:else if field.info.name === "file"}
|
||||
<!-- <File bind:graph {record} {field} {validationErrors} /> -->
|
||||
<File
|
||||
bind:value={data[field.name]}
|
||||
{record}
|
||||
{id}
|
||||
{field}
|
||||
{validationErrors}
|
||||
/>
|
||||
{:else if field.info.name === "file"}
|
||||
<File bind:graph {record} {field} {validationErrors}/>
|
||||
{:else if field.info.name === "text"}
|
||||
<Text
|
||||
bind:value={data[field.name]}
|
||||
|
||||
@@ -30,27 +30,27 @@
|
||||
});
|
||||
|
||||
function getEdgesByField(fieldsWithDiff, revision) {
|
||||
|
||||
edgeFieldsDiff = graph.edges.filter((e) => e.depth === 1).reduce((c, e) => {
|
||||
edgeFieldsDiff = graph.edges
|
||||
.filter((e) => e.depth === 1)
|
||||
.reduce((c, e) => {
|
||||
if (!c[e.field]) {
|
||||
c[e.field] = {
|
||||
record: [],
|
||||
revision: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
c[e.field]["record"].push(e)
|
||||
c[e.field]["record"].push(e);
|
||||
return c;
|
||||
}, {});
|
||||
|
||||
|
||||
edgeFieldsDiff = revision._edges.reduce((c, e) => {
|
||||
if (!c[e.field]) {
|
||||
c[e.field] = {
|
||||
record: [],
|
||||
revision: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
c[e.field]["revision"].push(e)
|
||||
c[e.field]["revision"].push(e);
|
||||
return c;
|
||||
}, edgeFieldsDiff);
|
||||
}
|
||||
@@ -62,7 +62,7 @@
|
||||
fieldsWithDiff = schema.fields.filter((f) => {
|
||||
return !isEqual(selectedRevision.data[f.name], record.data[f.name]);
|
||||
});
|
||||
getEdgesByField(fieldsWithDiff, revision)
|
||||
getEdgesByField(fieldsWithDiff, revision);
|
||||
revisionSection.scrollIntoView();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
rollbackError = "";
|
||||
axios
|
||||
.post(
|
||||
`${channel.lucentUrl}/records/${record.id}/rollback/${selectedRevision._sys.version}`
|
||||
`${channel.lucentUrl}/records/${record.id}/rollback/${selectedRevision.version}`,
|
||||
)
|
||||
.then((response) => {
|
||||
window.location.reload();
|
||||
@@ -93,29 +93,27 @@
|
||||
</div>
|
||||
<div>
|
||||
<span class="label text-end text-muted">current version </span>
|
||||
{record._sys.version}
|
||||
{record.version}
|
||||
</div>
|
||||
<div>
|
||||
<span class="label text-end text-muted"> created </span>
|
||||
<Avatar
|
||||
name={usernameById(users, record._sys.createdBy)}
|
||||
name={usernameById(users, record.createdBy)}
|
||||
side={24}
|
||||
/>
|
||||
{friendlyDate(record._sys.createdAt)}
|
||||
{friendlyDate(record.createdAt)}
|
||||
</div>
|
||||
<div>
|
||||
<span class="label text-end text-muted">updated </span>
|
||||
<Avatar
|
||||
name={usernameById(users, record._sys.updatedBy)}
|
||||
name={usernameById(users, record.updatedBy)}
|
||||
side={24}
|
||||
/>
|
||||
{friendlyDate(record._sys.updatedAt)}
|
||||
{friendlyDate(record.updatedAt)}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<span class="label d-block text-muted "
|
||||
>Rules for this schema
|
||||
</span>
|
||||
<span class="label d-block text-muted">Rules for this schema </span>
|
||||
<small>
|
||||
Each record maintains the last {schema.revisions}
|
||||
versions
|
||||
@@ -127,31 +125,29 @@
|
||||
{#if schema.revisions > 0}
|
||||
<div class="header-small mb-3">Revisions</div>
|
||||
{#each revisions as revision}
|
||||
{#if revision._sys.version !== record._sys.version}
|
||||
{#if revision.version !== record.version}
|
||||
<div
|
||||
class="revision"
|
||||
class:active={revision._sys.version ===
|
||||
selectedRevision?._sys.version}
|
||||
class:active={revision.version ===
|
||||
selectedRevision?.version}
|
||||
>
|
||||
|
||||
<div class="version">
|
||||
<span>version {revision._sys.version}</span>
|
||||
<span>version {revision.version}</span>
|
||||
<Avatar
|
||||
name={usernameById(users, revision._sys.updatedBy)}
|
||||
name={usernameById(users, revision.updatedBy)}
|
||||
side={24}
|
||||
/>
|
||||
{friendlyDate(revision._sys.updatedAt)}
|
||||
{friendlyDate(revision.updatedAt)}
|
||||
</div>
|
||||
|
||||
<div class="col-3 text-center">
|
||||
<button
|
||||
disabled={revision._sys.version ===
|
||||
selectedRevision?._sys.version}
|
||||
disabled={revision.version ===
|
||||
selectedRevision?.version}
|
||||
class="button"
|
||||
on:click={(e) => compare(e, revision)}
|
||||
>Compare
|
||||
</button
|
||||
>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -169,15 +165,13 @@
|
||||
<p class="text-center fw-bold mb-3 mt-5">
|
||||
If you choose to rollback to this revision
|
||||
</p>
|
||||
<button
|
||||
on:click={rollback}
|
||||
class="button"
|
||||
>
|
||||
Rollback to version {selectedRevision._sys.version}
|
||||
<button on:click={rollback} class="button">
|
||||
Rollback to version {selectedRevision.version}
|
||||
</button>
|
||||
|
||||
{#if rollbackError}
|
||||
<span class="d-block text-danger mt-3">{rollbackError}</span>
|
||||
<span class="d-block text-danger mt-3">{rollbackError}</span
|
||||
>
|
||||
{/if}
|
||||
<div class="mt-3">
|
||||
{#each fieldsWithDiff as field}
|
||||
@@ -188,10 +182,7 @@
|
||||
<!-- <div class="d-block" style="width:200px;">
|
||||
{field.label}
|
||||
</div> -->
|
||||
<div
|
||||
class="revision-field"
|
||||
style="overflow:hidden"
|
||||
>
|
||||
<div class="revision-field" style="overflow:hidden">
|
||||
<div class="compare-left">
|
||||
<RevisionCell
|
||||
{field}
|
||||
@@ -226,19 +217,13 @@
|
||||
{/if}
|
||||
|
||||
<div class="mt-3">
|
||||
<p class="text-center fw-bold mb-3 mt-5">
|
||||
Record References
|
||||
</p>
|
||||
<p class="text-center fw-bold mb-3 mt-5">Record References</p>
|
||||
{#each Object.entries(edgeFieldsDiff) as [field, edges]}
|
||||
<div
|
||||
class="revision-references"
|
||||
style="overflow:hidden"
|
||||
>
|
||||
<div class="revision-references" style="overflow:hidden">
|
||||
<div class="reference-field">
|
||||
{field}:
|
||||
</div>
|
||||
<div class="reference-compare">
|
||||
|
||||
<p class="">Record</p>
|
||||
{#each edges.record as edge}
|
||||
<RevisionEdgeRow {edge} />
|
||||
@@ -258,7 +243,5 @@
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<script>
|
||||
import {afterUpdate, createEventDispatcher, getContext, onMount} from "svelte";
|
||||
import {
|
||||
afterUpdate,
|
||||
createEventDispatcher,
|
||||
getContext,
|
||||
onMount,
|
||||
} from "svelte";
|
||||
|
||||
import { isEqual } from "lodash";
|
||||
import FormField from "./FormField.svelte";
|
||||
@@ -16,7 +21,7 @@
|
||||
export let record;
|
||||
export let graph = {
|
||||
records: [],
|
||||
edges: []
|
||||
edges: [],
|
||||
};
|
||||
export let isCreateMode;
|
||||
let originalContent;
|
||||
@@ -29,9 +34,7 @@
|
||||
} error(s)`
|
||||
: null;
|
||||
|
||||
let activeFields = schema.fields.filter(
|
||||
(f) => f.name !== "id"
|
||||
);
|
||||
let activeFields = schema.fields.filter((f) => f.name !== "id");
|
||||
|
||||
let tabname = "_default";
|
||||
let fieldToTabs = schema.fields.reduce((c, f) => {
|
||||
@@ -53,8 +56,6 @@
|
||||
data: JSON.parse(JSON.stringify(record.data)),
|
||||
schema: record.schema,
|
||||
status: record.status,
|
||||
_sys: JSON.parse(JSON.stringify(record._sys)),
|
||||
_file: JSON.parse(JSON.stringify(record._file)),
|
||||
edges: JSON.parse(JSON.stringify(graph.edges)),
|
||||
};
|
||||
}
|
||||
@@ -87,8 +88,6 @@
|
||||
data: record.data,
|
||||
schema: record.schema,
|
||||
status: record.status,
|
||||
_sys: record._sys,
|
||||
_file: record._file,
|
||||
edges: graph.edges,
|
||||
});
|
||||
}
|
||||
@@ -114,8 +113,10 @@
|
||||
return;
|
||||
}
|
||||
// remove trashed edges
|
||||
graph.edges = graph.edges?.filter((edge) => !edge._isTrashed && edge.source === record.id) ?? [];
|
||||
|
||||
graph.edges =
|
||||
graph.edges?.filter(
|
||||
(edge) => !edge._isTrashed && edge.source === record.id,
|
||||
) ?? [];
|
||||
|
||||
axios
|
||||
.post(channel.lucentUrl + "/records", {
|
||||
@@ -156,10 +157,7 @@
|
||||
<div class="tools-header">
|
||||
<EditHeader {schema} bind:record {isCreateMode} bind:activeContentTab />
|
||||
{#if isCreateMode}
|
||||
<button
|
||||
class="button primary btn-spinner"
|
||||
on:click={save}
|
||||
>
|
||||
<button class="button primary btn-spinner" on:click={save}>
|
||||
<span
|
||||
class="spinner-border spinner-border-sm"
|
||||
role="status"
|
||||
@@ -181,24 +179,19 @@
|
||||
Save
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
<Title {schema} {record} {isCreateMode} />
|
||||
<ErrorAlert message={errorMessage} />
|
||||
|
||||
<div class=" mt-4" style="margin-bottom:150px;position:relative;">
|
||||
<ContentTabs
|
||||
{schema}
|
||||
{isCreateMode}
|
||||
bind:active={activeContentTab}
|
||||
/>
|
||||
<ContentTabs {schema} {isCreateMode} bind:active={activeContentTab} />
|
||||
<FilePreview {record} {schema} />
|
||||
<!-- <fieldset disabled="disabled"> -->
|
||||
{#each activeFields as field (field.name)}
|
||||
{#if activeContentTab === field.group}
|
||||
<FormField
|
||||
bind:data={record.data}
|
||||
bind:graph={graph}
|
||||
bind:graph
|
||||
{field}
|
||||
{schema}
|
||||
{record}
|
||||
@@ -210,4 +203,3 @@
|
||||
<!-- </fieldset> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ export function previewTitle(schemas, record, graph) {
|
||||
|
||||
function noTemplate(schema, record) {
|
||||
if (schema?.type === "files") {
|
||||
return record._file.path;
|
||||
return file.path;
|
||||
}
|
||||
|
||||
let title = stripHtml(
|
||||
record?.data[schema.fields.filter((f) => f.info.name === "text")[0]?.name]
|
||||
record?.data[schema.fields.filter((f) => f.info.name === "text")[0]?.name],
|
||||
).slice(0, 300);
|
||||
|
||||
if (title.trim() === "") {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
<script>
|
||||
import { sortByField } from "../../edges/sortEdges";
|
||||
import { array_move } from "../../edges/sortEdges";
|
||||
import Sortable from "../../libs/Sortable.svelte";
|
||||
import PreviewFile from "../previews/PreviewFile.svelte";
|
||||
import Dropdown from "../../common/Dropdown.svelte";
|
||||
import Dialog from "../../dialog/Dialog.svelte";
|
||||
import { insertEdges } from "./reference.js";
|
||||
import { getContext } from "svelte";
|
||||
import FileDialog from "../../dialog/FileDialog.svelte";
|
||||
import Uploader from "../../files/Uploader.svelte";
|
||||
@@ -12,36 +9,28 @@
|
||||
const channel = getContext("channel");
|
||||
export let field;
|
||||
export let record;
|
||||
export let graph;
|
||||
export let value = [];
|
||||
let browseModal;
|
||||
|
||||
function removeReference(e) {
|
||||
function removeFile(e) {
|
||||
e.preventDefault();
|
||||
graph.edges = graph.edges.filter(
|
||||
(edge) => !(edge.target === e.detail && edge.field === field.name),
|
||||
);
|
||||
value = value.filter((f) => !(f.id === e.detail));
|
||||
}
|
||||
|
||||
async function reorder(e) {
|
||||
graph.edges = await sortByField(
|
||||
e.detail.source,
|
||||
e.detail.target,
|
||||
graph.edges,
|
||||
field.name,
|
||||
references,
|
||||
);
|
||||
value = await array_move(value, e.detail.source, e.detail.target);
|
||||
}
|
||||
|
||||
function insert(e) {
|
||||
function insertFiles(e) {
|
||||
e.preventDefault();
|
||||
browseModal.close();
|
||||
graph = insertEdges(
|
||||
graph,
|
||||
record,
|
||||
e.detail.records,
|
||||
field.name,
|
||||
e.detail.action,
|
||||
);
|
||||
value = [...(value ?? []), ...(e.detail ?? [])];
|
||||
}
|
||||
|
||||
function replaceFiles(e) {
|
||||
e.preventDefault();
|
||||
browseModal.close();
|
||||
value = e.detail ?? [];
|
||||
}
|
||||
|
||||
function uploadComplete(e) {
|
||||
@@ -61,18 +50,22 @@
|
||||
<Uploader recordId={record.id} on:uploadComplete={uploadComplete} />
|
||||
</div>
|
||||
</div>
|
||||
<!-- {#if references.length > 0}
|
||||
{#if value.length > 0}
|
||||
<Sortable sortableClass="mt-3" on:update={reorder}>
|
||||
{#each references as reference (reference.id)}
|
||||
{#each value ?? [] as aFile (aFile.id)}
|
||||
<!--This div helps the sorting thing-->
|
||||
<!-- <div>
|
||||
<div>
|
||||
<PreviewFile
|
||||
record={reference}
|
||||
file={aFile}
|
||||
hasDelete={true}
|
||||
on:remove={removeReference}
|
||||
on:remove_file={removeFile}
|
||||
></PreviewFile>
|
||||
</div>
|
||||
{/each}
|
||||
</Sortable>
|
||||
{/if} -->
|
||||
<FileDialog bind:this={browseModal} on:insert={insert}></FileDialog>
|
||||
{/if}
|
||||
<FileDialog
|
||||
bind:this={browseModal}
|
||||
on:insert_files={insertFiles}
|
||||
on:replace_files={replaceFiles}
|
||||
></FileDialog>
|
||||
|
||||
@@ -4,88 +4,77 @@
|
||||
import { createEventDispatcher, getContext } from "svelte";
|
||||
import Preview from "../../files/Preview.svelte";
|
||||
import { previewTitle } from "./../Preview";
|
||||
import {fileurl, htmlurl} from "../../files/imageserver.js"
|
||||
import { fileurl, htmlurl } from "../../files/imageserver.js";
|
||||
import Status from "./../Status.svelte";
|
||||
import Dropdown from "../../common/Dropdown.svelte";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const channel = getContext("channel");
|
||||
export let record;
|
||||
export let file;
|
||||
export let hasDelete = false;
|
||||
export let hasInsert = false;
|
||||
|
||||
let schema = channel.schemas.find((aschema) => aschema.name === record.schema);
|
||||
let cardTitle = previewTitle(channel.schemas, record);
|
||||
let imagePresets = Object.keys(channel.imageFilters);
|
||||
|
||||
function remove(e) {
|
||||
e.preventDefault();
|
||||
dispatch("remove", record.id);
|
||||
dispatch("remove_file", file.id);
|
||||
}
|
||||
|
||||
function insert(e, preset) {
|
||||
e.preventDefault();
|
||||
let html = htmlurl(channel, record, preset)
|
||||
let url = !preset ? `/${record._file.path}` : `/templates/${preset}/${record._file.path}`;
|
||||
dispatch("editor-insert", {
|
||||
html: html,
|
||||
url: channel.filesUrl + url,
|
||||
originalUrl: channel.filesUrl + "/" + record._file.path,
|
||||
record: record
|
||||
});
|
||||
// let html = htmlurl(channel, record, preset);
|
||||
// let url = !preset
|
||||
// ? `/${record._file.path}`
|
||||
// : `/templates/${preset}/${record._file.path}`;
|
||||
// dispatch("editor-insert", {
|
||||
// html: html,
|
||||
// url: channel.filesUrl + url,
|
||||
// originalUrl: channel.filesUrl + "/" + record._file.path,
|
||||
// record: record,
|
||||
// });
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="preview-file">
|
||||
<div style="display: flex;align-items: center;gap: 10px;">
|
||||
<div class="image">
|
||||
<Preview {record} size="small"/>
|
||||
<Preview {file} size="small" />
|
||||
</div>
|
||||
<div class="title">
|
||||
<div>
|
||||
<a
|
||||
class="record-title"
|
||||
href="{channel.lucentUrl}/records/{record.id}"
|
||||
{file.filename}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style="display: flex;gap:4px; align-items: center; margin-right: 10px;"
|
||||
>
|
||||
{cardTitle}
|
||||
</a>
|
||||
<small class="d-block">
|
||||
from {schema.label}
|
||||
{#if record.status === "draft"}
|
||||
<Status status={record.status}/>
|
||||
{/if}
|
||||
</small>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: flex;gap:4px; align-items: center; margin-right: 10px;">
|
||||
{#if hasInsert}
|
||||
<div class="reference-action">
|
||||
<Dropdown>
|
||||
<div slot="button">
|
||||
<Icon icon="photo-film" />
|
||||
</div>
|
||||
<button class="dropdown-item button" on:click={e => insert(e,null)}>original</button>
|
||||
<button
|
||||
class="dropdown-item button"
|
||||
on:click={(e) => insert(e, null)}>original</button
|
||||
>
|
||||
{#each imagePresets as preset}
|
||||
<button class="dropdown-item button" on:click={e => insert(e,preset)}>{preset}</button>
|
||||
<button
|
||||
class="dropdown-item button"
|
||||
on:click={(e) => insert(e, preset)}>{preset}</button
|
||||
>
|
||||
{/each}
|
||||
</Dropdown>
|
||||
|
||||
</div>
|
||||
{/if}
|
||||
{#if hasDelete}
|
||||
<div class="reference-action">
|
||||
<button
|
||||
class="button"
|
||||
on:click={remove}
|
||||
>
|
||||
<button class="button" on:click={remove}>
|
||||
<Icon icon="trash-can" />
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -12,22 +12,9 @@
|
||||
<div class="{colorClass} field-content">
|
||||
<div class="d-flex align-items-center text-center flex-wrap">
|
||||
{#each edges[field.name] as edgeRecord}
|
||||
{#if edgeRecord._file?.path}
|
||||
<div
|
||||
class="ms-2 "
|
||||
style="max-width:64px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;"
|
||||
>
|
||||
<Preview
|
||||
record={edgeRecord}
|
||||
size="small"
|
||||
showFilename={true}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="ms-2">
|
||||
<PreviewCardSmall record={edgeRecord} />
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -43,7 +30,6 @@
|
||||
|
||||
<!-- {/if} -->
|
||||
<style>
|
||||
|
||||
.field-content {
|
||||
max-height: 200px;
|
||||
overflow-y: scroll;
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Lucent\Channel;
|
||||
|
||||
use Lucent\Channel\Data\UserCommand;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Schema\FilesSchema;
|
||||
use Lucent\Schema\Schema;
|
||||
|
||||
final class Channel
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Schema\FilesSchema;
|
||||
|
||||
class GenerateFileSchema extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'lucent:generate:file {name}';
|
||||
|
||||
protected $description = 'Generate a lucent file schema';
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$name = $this->argument('name');
|
||||
$schema = new FilesSchema(
|
||||
name: $name,
|
||||
label: $name,
|
||||
fields: Collection::make(),
|
||||
disk: "lucent",
|
||||
path: $name,
|
||||
groups: []
|
||||
);
|
||||
|
||||
$json = json_encode($schema, JSON_PRETTY_PRINT);
|
||||
$configDir = base_path(config('lucent.schemas_path'));
|
||||
$schemaPath = $configDir . "/" . $name . '.json';
|
||||
|
||||
if (file_exists($schemaPath)) {
|
||||
$this->error("The schema file already exists.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
file_put_contents($schemaPath, $json);
|
||||
$this->info("The schema file has been created.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\File\FileRepo;
|
||||
use Lucent\File\FileService;
|
||||
use Lucent\Query\Query;
|
||||
use Lucent\Schema\FilesSchema;
|
||||
@@ -26,35 +27,16 @@ class RebuildThumbnails extends Command
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle(ChannelService $channelService): int
|
||||
public function handle(): void
|
||||
{
|
||||
$channelService->channel->schemas
|
||||
->filter(
|
||||
fn(Schema $schema) => get_class($schema) === FilesSchema::class,
|
||||
)
|
||||
->map([$this, "rebuildThumbnails"]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function rebuildThumbnails(FilesSchema $schema): void
|
||||
{
|
||||
$this->info("Rebuilding thumbnails for " . $schema->name);
|
||||
$records = $this->query
|
||||
->limit(0)
|
||||
->filter(["schema" => $schema->name])
|
||||
->run()->records;
|
||||
$disk = $this->fileService->loadDisk($schema->disk);
|
||||
foreach ($records as $record) {
|
||||
$this->info("Rebuilding thumbnails ");
|
||||
$files = FileRepo::query()->get();
|
||||
$disk = $this->fileService->loadDisk();
|
||||
foreach ($files as $file) {
|
||||
try {
|
||||
$this->fileService->createTemplates(
|
||||
$disk,
|
||||
$record->_file->path,
|
||||
);
|
||||
$this->fileService->createTemplates($disk, $file->path);
|
||||
} catch (Exception $e) {
|
||||
echo "File " .
|
||||
$record->_file->originalName .
|
||||
" could not be rebuilt \n";
|
||||
echo "File " . $file->filename . " could not be rebuilt \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,19 +71,23 @@ class SetupDatabase extends Command
|
||||
) {
|
||||
$table->uuid("id")->primary();
|
||||
$table->string("schema");
|
||||
$table->integer("version");
|
||||
$table->string("status");
|
||||
$table->jsonb("data");
|
||||
$table->jsonb("_sys");
|
||||
$table->timestampTz("createdAt");
|
||||
$table->timestampTz("updatedAt");
|
||||
$table->string("createdBy");
|
||||
$table->string("updatedBy");
|
||||
$table->text("search")->default("");
|
||||
// $table->index(["schema", "_sys->updatedAt", "status"]);
|
||||
$table->index(["schema", "updatedAt", "status"]);
|
||||
$table->index("search");
|
||||
});
|
||||
|
||||
DB::statement(
|
||||
"CREATE INDEX ON " .
|
||||
$this->prefix .
|
||||
'records (schema, ((_sys->>\'updatedAt\')), status)',
|
||||
);
|
||||
// DB::statement(
|
||||
// "CREATE INDEX ON " .
|
||||
// $this->prefix .
|
||||
// 'records (schema, ((_sys->>\'updatedAt\')), status)',
|
||||
// );
|
||||
}
|
||||
|
||||
if (!$schema->hasTable($this->prefix . "edges")) {
|
||||
@@ -140,8 +144,11 @@ class SetupDatabase extends Command
|
||||
$table->uuid("recordId");
|
||||
$table->string("schema");
|
||||
$table->jsonb("data");
|
||||
$table->jsonb("_sys");
|
||||
$table->jsonb("_file");
|
||||
$table->integer("version");
|
||||
$table->timestampTz("createdAt");
|
||||
$table->timestampTz("updatedAt");
|
||||
$table->string("createdBy");
|
||||
$table->string("updatedBy");
|
||||
$table->jsonb("_edges");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Lucent\Database\Database;
|
||||
|
||||
class UpgradeFiles122 extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'lucent:upgrade:files_1_2_2 {schema} {disk}';
|
||||
protected $description = 'Upgrade to the new filesystem';
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$schema = $this->argument('schema');
|
||||
$disk = $this->argument('disk');
|
||||
$db = Database::make();
|
||||
$records = $db->table("lucent_records")->where("schema", $schema)->get();
|
||||
foreach ($records as $record) {
|
||||
$array = json_decode($record->_file, true);
|
||||
$array["disk"] = $disk;
|
||||
$db->table("lucent_records")->where("id", $record->id)->update(["_file" => json_encode($array)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Lucent\File;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Lucent\Data\File as DataFile;
|
||||
use Lucent\Database\Database;
|
||||
use Lucent\Data\File;
|
||||
@@ -15,6 +16,11 @@ class FileRepo
|
||||
Database::make()->table("lucent_files")->insert($file->toDB());
|
||||
}
|
||||
|
||||
public static function query(): Builder
|
||||
{
|
||||
return Database::make()->table("lucent_files");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return File[]
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,6 @@ use Lucent\Id\Id;
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Data\File as DataFile;
|
||||
use Lucent\Record\QueryRecord;
|
||||
use Lucent\Schema\FilesSchema;
|
||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||
|
||||
class FileService
|
||||
@@ -25,15 +24,8 @@ class FileService
|
||||
public Logger $logger,
|
||||
) {}
|
||||
|
||||
public function getPath(QueryRecord $file): string
|
||||
{
|
||||
return $this->channelService->channel->filesUrl .
|
||||
"/" .
|
||||
$file->_file->path;
|
||||
}
|
||||
|
||||
public function createFromUrl(
|
||||
FilesSchema $schema,
|
||||
string $recordId,
|
||||
string $url,
|
||||
): FileUploadResult {
|
||||
$pathinfo = pathinfo($url);
|
||||
@@ -44,7 +36,7 @@ class FileService
|
||||
$file = "/tmp/" . $pathinfo["basename"];
|
||||
file_put_contents($file, $contents);
|
||||
$uploadedFile = new UploadedFile($file, $pathinfo["basename"]);
|
||||
return $this->upload($schema, $uploadedFile);
|
||||
return $this->upload($recordId, $uploadedFile);
|
||||
}
|
||||
|
||||
public function upload(string $recordId, UploadedFile $file): DataFile
|
||||
@@ -130,21 +122,6 @@ class FileService
|
||||
return Storage::disk(config("lucent.disk"));
|
||||
}
|
||||
|
||||
private function checkDuplicate(
|
||||
string $schemaName,
|
||||
string $checksum,
|
||||
int $filesize,
|
||||
): string {
|
||||
$record = Database::make()
|
||||
->table("lucent_records")
|
||||
->where("schema", $schemaName)
|
||||
->where("_file->checksum", $checksum)
|
||||
->where("_file->size", $filesize)
|
||||
->first();
|
||||
|
||||
return $record->id ?? "";
|
||||
}
|
||||
|
||||
public function createTemplates(Filesystem $disk, string $path): void
|
||||
{
|
||||
$originalImage = $this->imageManager->make($disk->get($path));
|
||||
|
||||
@@ -58,7 +58,6 @@ class RecordController extends Controller
|
||||
|
||||
$users = $this->accountService->all();
|
||||
$schema = $this->channelService->getSchema($schemaName)->get();
|
||||
|
||||
$urlParams = $request->all();
|
||||
$sort = data_get($urlParams, "sort") ?? $schema->sortBy;
|
||||
$filter = data_get($urlParams, "filter") ?? [];
|
||||
@@ -86,8 +85,8 @@ class RecordController extends Controller
|
||||
->childrenFields($schema?->visible ?? [])
|
||||
->childrenDepth(1)
|
||||
->parentsDepth(0)
|
||||
->runWithCount();
|
||||
|
||||
->runWithCount();
|
||||
$records = $graph->getRootRecords()->toArray();
|
||||
|
||||
$data = [
|
||||
|
||||
@@ -89,8 +89,6 @@ class LucentServiceProvider extends ServiceProvider
|
||||
RemoveOrphanEdges::class,
|
||||
SetupDatabase::class,
|
||||
GenerateCollectionSchema::class,
|
||||
GenerateFileSchema::class,
|
||||
UpgradeFiles122::class,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -78,6 +78,7 @@ final class Query
|
||||
->table("lucent_records")
|
||||
->whereIn("id", $edgesIds)
|
||||
->whereIn("status", $this->options->status)
|
||||
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
@@ -295,7 +296,8 @@ final class Query
|
||||
public function orderByQuery(Builder $query): Builder
|
||||
{
|
||||
foreach ($this->options->sort as $item) {
|
||||
$field = str_replace(".", "->", ltrim($item, "-"));
|
||||
$field = str_replace("_sys.", "", ltrim($item, "-"));
|
||||
$field = str_replace(".", "->", $field);
|
||||
$dir = str_starts_with($item, "-") ? "desc" : "asc";
|
||||
if ($field) {
|
||||
$query->orderBy($field, $dir);
|
||||
|
||||
@@ -2,24 +2,25 @@
|
||||
|
||||
namespace Lucent\Record;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Lucent\LucentException;
|
||||
|
||||
class QueryRecord
|
||||
{
|
||||
|
||||
function __construct(
|
||||
public string $id,
|
||||
public string $schema,
|
||||
public Status $status,
|
||||
public System $_sys,
|
||||
public RecordData $data,
|
||||
public Carbon $createdAt,
|
||||
public Carbon $updatedAt,
|
||||
public string $createdBy,
|
||||
public string $updatedBy,
|
||||
public int $version,
|
||||
public bool $isRoot,
|
||||
public ?FileData $_file = null,
|
||||
public array $_children = [],
|
||||
public array $_parents = [],
|
||||
)
|
||||
{
|
||||
}
|
||||
) {}
|
||||
|
||||
public static function fromRecord(Record $record): QueryRecord
|
||||
{
|
||||
@@ -27,10 +28,13 @@ class QueryRecord
|
||||
id: $record->id,
|
||||
schema: $record->schema,
|
||||
status: $record->status,
|
||||
_sys: $record->_sys,
|
||||
data: $record->data,
|
||||
createdAt: $record->createdAt,
|
||||
updatedAt: $record->updatedAt,
|
||||
createdBy: $record->createdBy,
|
||||
updatedBy: $record->updatedBy,
|
||||
version: $record->version,
|
||||
isRoot: false,
|
||||
_file: $record->_file,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+33
-29
@@ -2,36 +2,46 @@
|
||||
|
||||
namespace Lucent\Record;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use JsonSerializable;
|
||||
use stdClass;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Record implements JsonSerializable
|
||||
{
|
||||
|
||||
|
||||
function __construct(
|
||||
public string $id,
|
||||
public string $schema,
|
||||
public Status $status,
|
||||
public System $_sys,
|
||||
public Carbon $createdAt,
|
||||
public Carbon $updatedAt,
|
||||
public string $createdBy,
|
||||
public string $updatedBy,
|
||||
public int $version,
|
||||
public RecordData $data,
|
||||
public ?FileData $_file = null,
|
||||
)
|
||||
) {}
|
||||
|
||||
private function indexValues(array $arrObject)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private function indexValues(array $arrObject){
|
||||
|
||||
return trim(Str::lower(collect($arrObject)
|
||||
return trim(
|
||||
Str::lower(
|
||||
collect($arrObject)
|
||||
->map(function ($value) {
|
||||
if (is_array($value)) {
|
||||
return $this->indexValues($value ?? []);
|
||||
}
|
||||
return str_replace(array("\r", "\n"), '', strip_tags((string)$value));
|
||||
return str_replace(
|
||||
["\r", "\n"],
|
||||
"",
|
||||
strip_tags((string) $value),
|
||||
);
|
||||
})
|
||||
->values()->join(" ")." ". $this->_file?->originalName ?? ""));
|
||||
->values()
|
||||
->join(" ") .
|
||||
" " .
|
||||
"",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function toDB(): array
|
||||
@@ -41,8 +51,11 @@ class Record implements JsonSerializable
|
||||
"id" => $this->id,
|
||||
"status" => $this->status->value,
|
||||
"schema" => $this->schema,
|
||||
"_sys" => json_encode($this->_sys),
|
||||
"_file" => json_encode($this->_file),
|
||||
"createdAt" => $this->createdAt->toDateTimeString(),
|
||||
"updatedAt" => $this->updatedAt->toDateTimeString(),
|
||||
"createdBy" => $this->createdBy,
|
||||
"updatedBy" => $this->updatedBy,
|
||||
"version" => $this->version,
|
||||
"data" => json_encode($this->data),
|
||||
"search" => $searchIndex,
|
||||
];
|
||||
@@ -50,30 +63,21 @@ class Record implements JsonSerializable
|
||||
|
||||
public static function fromDB(stdClass $data): Record
|
||||
{
|
||||
|
||||
$file = json_decode($data->_file, true);
|
||||
if (!empty($file)) {
|
||||
|
||||
$file = FileData::fromArray($file);
|
||||
} else {
|
||||
$file = null;
|
||||
}
|
||||
|
||||
return new Record(
|
||||
id: $data->id,
|
||||
schema: $data->schema,
|
||||
status: Status::from($data->status),
|
||||
_sys: System::fromArray(json_decode($data->_sys, true)),
|
||||
createdAt: Carbon::parse($data->createdAt),
|
||||
updatedAt: Carbon::parse($data->updatedAt),
|
||||
createdBy: $data->createdBy,
|
||||
updatedBy: $data->updatedBy,
|
||||
version: $data->version,
|
||||
data: new RecordData(json_decode($data->data, true)),
|
||||
_file: $file,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function jsonSerialize(): static
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Lucent\Record;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
use Lucent\Account\AuthService;
|
||||
@@ -16,7 +17,7 @@ use Lucent\Record\InputData\EdgeInputData;
|
||||
use Lucent\Record\InputData\RecordInputData;
|
||||
use Lucent\Revision\RevisionService;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\Schema;
|
||||
use Lucent\Data\Schema;
|
||||
use Lucent\Schema\Type;
|
||||
use Lucent\Schema\Validator\Validator;
|
||||
use Lucent\Schema\Validator\ValidatorException;
|
||||
@@ -115,9 +116,12 @@ readonly class RecordService
|
||||
id: $newRecordId,
|
||||
schema: $data->schemaName,
|
||||
status: $data->status,
|
||||
_sys: System::newRecord($this->authService->currentUserId()),
|
||||
version: 1,
|
||||
createdBy: $this->authService->currentUserId(),
|
||||
updatedBy: $this->authService->currentUserId(),
|
||||
createdAt: Carbon::now(),
|
||||
updatedAt: Carbon::now(),
|
||||
data: $formattedData,
|
||||
_file: !empty($file) ? FileData::fromArray(toArray($file)) : null,
|
||||
);
|
||||
|
||||
if ($data->status === Status::PUBLISHED) {
|
||||
@@ -173,9 +177,12 @@ readonly class RecordService
|
||||
id: $record->id,
|
||||
schema: $record->schema,
|
||||
status: $status,
|
||||
_sys: $record->_sys->update($this->authService->currentUserId()),
|
||||
version: $record->version + 1,
|
||||
createdBy: $record->createdBy,
|
||||
updatedBy: $this->authService->currentUserId(),
|
||||
createdAt: $record->createdAt,
|
||||
updatedAt: Carbon::now(),
|
||||
data: $record->data->merge($formattedData),
|
||||
_file: $record->_file,
|
||||
);
|
||||
|
||||
RecordRepo::update($newRecord);
|
||||
@@ -205,12 +212,12 @@ readonly class RecordService
|
||||
$record->schema,
|
||||
new RecordData($data),
|
||||
);
|
||||
|
||||
if ($status === Status::PUBLISHED) {
|
||||
$errors = $this->recordValidator->check(
|
||||
$record->schema,
|
||||
$formattedData,
|
||||
);
|
||||
|
||||
if ($errors->isNotEmpty()) {
|
||||
$this->recordValidator->throwException($errors);
|
||||
}
|
||||
@@ -220,9 +227,12 @@ readonly class RecordService
|
||||
id: $record->id,
|
||||
schema: $record->schema,
|
||||
status: $status,
|
||||
_sys: $record->_sys->update($this->authService->currentUserId()),
|
||||
version: $record->version + 1,
|
||||
createdBy: $record->createdBy,
|
||||
updatedBy: $this->authService->currentUserId(),
|
||||
createdAt: $record->createdAt,
|
||||
updatedAt: Carbon::now(),
|
||||
data: $record->data->merge($formattedData),
|
||||
_file: $record->_file,
|
||||
);
|
||||
|
||||
RecordRepo::update($newRecord);
|
||||
@@ -278,7 +288,6 @@ readonly class RecordService
|
||||
data: $record->data->toArray(),
|
||||
status: Status::DRAFT,
|
||||
),
|
||||
file: $record->_file,
|
||||
edges: $newEdgesData,
|
||||
);
|
||||
}
|
||||
@@ -337,9 +346,12 @@ readonly class RecordService
|
||||
id: Id::new(),
|
||||
schema: $schema->name,
|
||||
status: Status::DRAFT,
|
||||
_sys: System::newRecord($this->authService->currentUserId()),
|
||||
version: 1,
|
||||
createdBy: $this->authService->currentUserId(),
|
||||
updatedBy: $this->authService->currentUserId(),
|
||||
createdAt: Carbon::now(),
|
||||
updatedAt: Carbon::now(),
|
||||
data: $formattedData,
|
||||
_file: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Record;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Lucent\Schema\Schema;
|
||||
|
||||
readonly class System
|
||||
{
|
||||
|
||||
|
||||
function __construct(
|
||||
public int $version,
|
||||
public string $createdBy,
|
||||
public string $updatedBy,
|
||||
public string $createdAt,
|
||||
public string $updatedAt,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function fromArray(array $data): System
|
||||
{
|
||||
return new System(
|
||||
version: data_get($data, "version"),
|
||||
createdBy: data_get($data, "createdBy"),
|
||||
updatedBy: data_get($data, "updatedBy"),
|
||||
createdAt: data_get($data, "createdAt"),
|
||||
updatedAt: data_get($data, "updatedAt"),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static function newRecord(string $userId): System
|
||||
{
|
||||
$now = Carbon::now()->toJson();
|
||||
return new System(
|
||||
version: 1,
|
||||
createdBy: $userId,
|
||||
updatedBy: $userId,
|
||||
createdAt: $now,
|
||||
updatedAt: $now,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function update(string $userId): System
|
||||
{
|
||||
$now = Carbon::now()->toJson();
|
||||
return new System(
|
||||
version: $this->version + 1,
|
||||
createdBy: $this->createdBy,
|
||||
updatedBy: $userId,
|
||||
createdAt: $this->createdAt,
|
||||
updatedAt: $now,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
-16
@@ -2,38 +2,33 @@
|
||||
|
||||
namespace Lucent\Revision;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Lucent\Edge\Edge;
|
||||
use Lucent\Record\FileData;
|
||||
use Lucent\Record\Record;
|
||||
use Lucent\Record\RecordData;
|
||||
use Lucent\Record\System;
|
||||
|
||||
readonly class Revision
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $recordId
|
||||
* @param string $schema
|
||||
* @param System $_sys
|
||||
* @param RecordData $data
|
||||
* @param list<Edge> $_edges
|
||||
* @param FileData|null $_file
|
||||
*/
|
||||
function __construct(
|
||||
public string $id,
|
||||
public string $recordId,
|
||||
public string $schema,
|
||||
public System $_sys,
|
||||
public Carbon $createdAt,
|
||||
public Carbon $updatedAt,
|
||||
public string $createdBy,
|
||||
public string $updatedBy,
|
||||
public int $version,
|
||||
public RecordData $data,
|
||||
public array $_edges,
|
||||
public ?FileData $_file = null,
|
||||
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
) {}
|
||||
|
||||
public static function fromRecord(Record $record, array $edges): Revision
|
||||
{
|
||||
@@ -41,12 +36,13 @@ readonly class Revision
|
||||
id: (string) Str::uuid(),
|
||||
recordId: $record->id,
|
||||
schema: $record->schema,
|
||||
_sys: $record->_sys,
|
||||
createdAt: $record->createdAt,
|
||||
updatedAt: $record->updatedAt,
|
||||
createdBy: $record->createdBy,
|
||||
updatedBy: $record->updatedBy,
|
||||
version: $record->version,
|
||||
data: $record->data,
|
||||
_edges: $edges,
|
||||
_file: $record->_file
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,12 @@ namespace Lucent\Revision;
|
||||
use Lucent\Database\Database;
|
||||
use Lucent\Edge\Edge;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Record\FileData;
|
||||
use Lucent\Record\RecordData;
|
||||
use Lucent\Record\System;
|
||||
use PhpOption\Option;
|
||||
use stdClass;
|
||||
|
||||
class RevisionRepo
|
||||
{
|
||||
|
||||
private string $table = "lucent_revisions";
|
||||
|
||||
public function create(Revision $revision): string
|
||||
@@ -23,17 +20,17 @@ class RevisionRepo
|
||||
return $revision->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Collection<Revision>
|
||||
**/
|
||||
public function getByRecordId(string $rid): Collection
|
||||
{
|
||||
$revisions = Database::make()->table($this->table)
|
||||
$revisions = Database::make()
|
||||
->table($this->table)
|
||||
->where("recordId", $rid)
|
||||
->get()
|
||||
->map([$this, 'fromDB'])
|
||||
->sortByDesc("_sys.version")
|
||||
->map([$this, "fromDB"])
|
||||
->sortByDesc("version")
|
||||
->toArray();
|
||||
|
||||
return new Collection($revisions);
|
||||
@@ -41,29 +38,31 @@ class RevisionRepo
|
||||
|
||||
public function cleanupRecord(string $rid, int $numKeep): void
|
||||
{
|
||||
$revisionIds = Database::make()->table($this->table)
|
||||
$revisionIds = Database::make()
|
||||
->table($this->table)
|
||||
->where("recordId", $rid)
|
||||
->orderBy("_sys->version", "desc")
|
||||
->orderBy("version", "desc")
|
||||
->limit(100)
|
||||
->skip($numKeep)
|
||||
->get()
|
||||
->pluck("id");
|
||||
|
||||
Database::make()->table($this->table)
|
||||
Database::make()
|
||||
->table($this->table)
|
||||
->whereIn("id", $revisionIds)
|
||||
->delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Option<Revision>
|
||||
*/
|
||||
public function getByRecordIdAndVersion(string $rid, int $version): Option
|
||||
{
|
||||
|
||||
$res = Database::make()->table($this->table)
|
||||
$res = Database::make()
|
||||
->table($this->table)
|
||||
->where("recordId", $rid)
|
||||
->where('_sys->version', $version)->first();
|
||||
->where("version", $version)
|
||||
->first();
|
||||
|
||||
if (empty($res)) {
|
||||
return none();
|
||||
@@ -78,8 +77,11 @@ class RevisionRepo
|
||||
"id" => $revision->id,
|
||||
"recordId" => $revision->recordId,
|
||||
"schema" => $revision->schema,
|
||||
"_sys" => json_encode($revision->_sys),
|
||||
"_file" => json_encode($revision->_file),
|
||||
"createdAt" => $revision->createdAt->toDateTimeString(),
|
||||
"updatedAt" => $revision->updatedAt->toDateTimeString(),
|
||||
"createdBy" => $revision->createdBy,
|
||||
"updatedBy" => $revision->updatedBy,
|
||||
"version" => $revision->version,
|
||||
"data" => json_encode($revision->data),
|
||||
"_edges" => json_encode($revision->_edges),
|
||||
];
|
||||
@@ -87,24 +89,22 @@ class RevisionRepo
|
||||
|
||||
public function fromDB(stdClass $data): Revision
|
||||
{
|
||||
$file = json_decode($data->_file, true);
|
||||
if (!empty($file)) {
|
||||
|
||||
$file = FileData::fromArray($file);
|
||||
} else {
|
||||
$file = null;
|
||||
}
|
||||
|
||||
$edges = array_map(fn($e) => Edge::fromArray($e), json_decode($data->_edges ?? "[]", true));
|
||||
$edges = array_map(
|
||||
fn($e) => Edge::fromArray($e),
|
||||
json_decode($data->_edges ?? "[]", true),
|
||||
);
|
||||
|
||||
return new Revision(
|
||||
id: $data->id,
|
||||
recordId: $data->recordId,
|
||||
schema: $data->schema,
|
||||
_sys: System::fromArray(json_decode($data->_sys, true)),
|
||||
createdBy: $data->createdBy,
|
||||
updatedBy: $data->updatedBy,
|
||||
createdAt: $data->createdAt,
|
||||
updatedAt: $data->updatedAt,
|
||||
version: $data->version,
|
||||
data: new RecordData(json_decode($data->data, true)),
|
||||
_edges: $edges,
|
||||
_file: $file
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,18 @@ final class Nullable
|
||||
public bool $nullable,
|
||||
public mixed $value,
|
||||
public mixed $default,
|
||||
)
|
||||
{
|
||||
) {}
|
||||
|
||||
public static function make(
|
||||
bool $nullable,
|
||||
mixed $value,
|
||||
mixed $default,
|
||||
): Nullable {
|
||||
return new self($nullable, $value, $default);
|
||||
}
|
||||
|
||||
public function value(): mixed
|
||||
{
|
||||
|
||||
if (!empty($this->value)) {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,16 @@ class SchemaService
|
||||
|
||||
public function fromArray(array $schemaArr): Schema
|
||||
{
|
||||
$schemaArr["fields"] = [
|
||||
[
|
||||
"ui" => "text",
|
||||
"name" => "name",
|
||||
"label" => "Name",
|
||||
"required" => true,
|
||||
],
|
||||
...$schemaArr["fields"],
|
||||
];
|
||||
|
||||
return new Schema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
|
||||
+2
-44
@@ -9,10 +9,7 @@ readonly class System
|
||||
public string $label,
|
||||
public string $ui,
|
||||
public bool $files,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
) {}
|
||||
|
||||
public static function getById(string $id): System
|
||||
{
|
||||
@@ -26,7 +23,7 @@ readonly class System
|
||||
{
|
||||
return [
|
||||
"_sys.status" => new System(
|
||||
name: "status",
|
||||
name: "_sys.status",
|
||||
label: "Status",
|
||||
ui: "status",
|
||||
files: false,
|
||||
@@ -55,45 +52,6 @@ readonly class System
|
||||
ui: "datetime",
|
||||
files: false,
|
||||
),
|
||||
"_file.path" => new System(
|
||||
name: "_file.path",
|
||||
label: "Filename",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.mime" => new System(
|
||||
name: "_file.mime",
|
||||
label: "Mime Type",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
|
||||
"_file.width" => new System(
|
||||
name: "_file.width",
|
||||
label: "Dimensions",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.size" => new System(
|
||||
name: "_file.size",
|
||||
label: "Size",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.originalName" => new System(
|
||||
name: "_file.originalName",
|
||||
label: "Original Name",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
"_file.checksum" => new System(
|
||||
name: "_file.checksum",
|
||||
label: "Checksum",
|
||||
ui: "text",
|
||||
files: true,
|
||||
),
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ class File implements FieldInterface, MinMaxInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
|
||||
/**
|
||||
* @param string[] $collections
|
||||
*/
|
||||
@@ -24,13 +23,14 @@ class File implements FieldInterface, MinMaxInterface
|
||||
public ?int $max = null,
|
||||
public array $collections = [],
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->info = new FieldInfo("file", "File", FieldType::FILE);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$value = $input[$this->name] ?? [];
|
||||
$output[$this->name] = $value;
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,4 @@ class File implements FieldInterface, MinMaxInterface
|
||||
|
||||
return count($value) < $this->min;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,26 +25,29 @@ class Slug implements FieldInterface, RequiredInterface
|
||||
public bool $readonly = false,
|
||||
public string $source = "",
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->info = new FieldInfo("slug", "Slug", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$value = !empty($input[$this->name]) ? (string)$input[$this->name] : null;
|
||||
$value = !empty($input[$this->name])
|
||||
? (string) $input[$this->name]
|
||||
: null;
|
||||
if (empty($value)) {
|
||||
$value = Str::slug($input[$this->source]);
|
||||
}
|
||||
|
||||
$output[$this->name] = (new Nullable($this->nullable, $value, ""))->value();
|
||||
$output[$this->name] = new Nullable(
|
||||
$this->nullable,
|
||||
$value,
|
||||
"",
|
||||
)->value();
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public function failRequired(mixed $value): bool
|
||||
{
|
||||
return empty(trim($value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-18
@@ -3,7 +3,7 @@
|
||||
use PhpOption\None;
|
||||
use PhpOption\Some;
|
||||
|
||||
if (!function_exists('some')) {
|
||||
if (!function_exists("some")) {
|
||||
/**
|
||||
* @template T
|
||||
* @param T $value
|
||||
@@ -15,51 +15,50 @@ if (!function_exists('some')) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('none')) {
|
||||
if (!function_exists("none")) {
|
||||
function none(): None
|
||||
{
|
||||
return None::create();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('toArray')) {
|
||||
if (!function_exists("toArray")) {
|
||||
function toArray(mixed $data): array
|
||||
{
|
||||
return \json_decode(\json_encode($data), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('make_dir_r')) {
|
||||
if (!function_exists("make_dir_r")) {
|
||||
function make_dir_r(string $path): void
|
||||
{
|
||||
is_dir($path) || mkdir($path, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('schemas_path')) {
|
||||
if (!function_exists("schemas_path")) {
|
||||
function schemas_path(): string
|
||||
{
|
||||
return storage_path("lucent/lucent.schemas.json");
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('lucent_file')) {
|
||||
function lucent_file(\Lucent\Record\QueryRecord $record): string
|
||||
if (!function_exists("lucent_file")) {
|
||||
function lucent_file(\Lucent\Data\File $file): string
|
||||
{
|
||||
$path = $record->_file->path;
|
||||
return app()->make(\Lucent\Channel\ChannelService::class)->channel->disks[$record->_file->disk] ."/". $path;
|
||||
$path = $file->path;
|
||||
return app()->make(\Lucent\Channel\ChannelService::class)->channel
|
||||
->filesUrl .
|
||||
"/" .
|
||||
$path;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('lucent_image')) {
|
||||
function lucent_image(\Lucent\Record\QueryRecord $record, string $template): string
|
||||
if (!function_exists("lucent_image")) {
|
||||
function lucent_image(\Lucent\Data\File $file, string $template): string
|
||||
{
|
||||
$path = $record->_file->path;
|
||||
return app()->make(\Lucent\Channel\ChannelService::class)->channel->disks[$record->_file->disk] . "/templates/$template/$path";
|
||||
$path = $file->path;
|
||||
return app()->make(\Lucent\Channel\ChannelService::class)->channel
|
||||
->filesUrl . "/templates/$template/$path";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user