query records
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script>
|
||||
import ChannelLayout from "../../layouts/ChannelLayout.svelte";
|
||||
import { post } from "../../modules/remote";
|
||||
import { getApp } from "../../app";
|
||||
import Table from "./Table.svelte";
|
||||
@@ -8,7 +9,7 @@
|
||||
// import Pagination from "./pagination/Pagination.svelte";
|
||||
// import ActionsOnSelected from "./ActionsOnSelected.svelte";
|
||||
// import Table from "./Table.svelte";
|
||||
let { channel, data } = $props();
|
||||
let { channel, user, data } = $props();
|
||||
let newRecordName = $state("");
|
||||
const app = getApp();
|
||||
// export let schema;
|
||||
@@ -68,25 +69,27 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="">
|
||||
<div class={inModal ? "mt-0" : "mt-5"}>
|
||||
<h3 class="header-normal mb-5">
|
||||
{data.schema.name}
|
||||
</h3>
|
||||
<details style="max-width: 400px;">
|
||||
<summary>New Record</summary>
|
||||
<form onsubmit={handleRecordCreate}>
|
||||
<fieldset>
|
||||
<input
|
||||
bind:value={newRecordName}
|
||||
placeholder="Record title"
|
||||
required
|
||||
/>
|
||||
</fieldset>
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</details>
|
||||
<!-- {#if selected.length > 0 && !inModal && isWritable}
|
||||
<ChannelLayout {body} {channel} schemas={data.schemas} {user}></ChannelLayout>
|
||||
{#snippet body()}
|
||||
<div class="">
|
||||
<div class={inModal ? "mt-0" : "mt-5"}>
|
||||
<h3 class="header-normal mb-5">
|
||||
{data.schema.name}
|
||||
</h3>
|
||||
<details style="max-width: 400px;">
|
||||
<summary>New Record</summary>
|
||||
<form onsubmit={handleRecordCreate}>
|
||||
<fieldset>
|
||||
<input
|
||||
bind:value={newRecordName}
|
||||
placeholder="Record title"
|
||||
required
|
||||
/>
|
||||
</fieldset>
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</details>
|
||||
<!-- {#if selected.length > 0 && !inModal && isWritable}
|
||||
<ActionsOnSelected {schema} {selected} {filter}/>
|
||||
{:else}
|
||||
<Tools
|
||||
@@ -105,10 +108,10 @@
|
||||
/>
|
||||
{/if}
|
||||
-->
|
||||
<Tools fields={data.fields}></Tools>
|
||||
<Table records={data.records} fields={data.fields}></Table>
|
||||
</div>
|
||||
<!--
|
||||
<Tools fields={data.fields}></Tools>
|
||||
<Table records={data.records} fields={data.fields}></Table>
|
||||
</div>
|
||||
<!--
|
||||
<Pagination
|
||||
{limit}
|
||||
{skip}
|
||||
@@ -117,4 +120,5 @@
|
||||
{inModal}
|
||||
{modalUrl}
|
||||
/> -->
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
></Checkbox> -->
|
||||
|
||||
<a
|
||||
href="{app.url('records')}{qRecord.record.id}"
|
||||
href="{app.url('records/')}{qRecord.record.id}"
|
||||
target={inModal ? "_blank" : "_self"}
|
||||
>
|
||||
<!-- {#if record.status === "draft"}
|
||||
@@ -96,6 +96,12 @@
|
||||
<td>
|
||||
{qRecord.data.find((f) => f.fieldId === field.id)
|
||||
?.value}
|
||||
|
||||
<ul>
|
||||
{#each qRecord.children.filter((e) => e.edge.fieldId === field.id) as child}
|
||||
<li>{child.recordPreview.title}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</td>
|
||||
{/each}
|
||||
<!-- <RecordRow
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Min characters
|
||||
Min items
|
||||
<input type="number" bind:value={field.props.min} />
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Max characters
|
||||
Max items
|
||||
<input type="number" bind:value={field.props.max} />
|
||||
</label>
|
||||
</fieldset>
|
||||
|
||||
@@ -4,11 +4,13 @@ class QueryRecord
|
||||
{
|
||||
/**
|
||||
* @param RecordField[] $data
|
||||
* @param EdgeRecordPreview[] $children
|
||||
*/
|
||||
public function __construct(
|
||||
public ?Edge $edge,
|
||||
public Record $record,
|
||||
public RecordPreview $recordPreview,
|
||||
public array $data,
|
||||
public array $children,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use Lucent\Core\Data\RecordPreview;
|
||||
use Lucent\Core\Data\QueryRecord;
|
||||
use Lucent\Core\Data\RecordMode;
|
||||
use Lucent\Core\Record\RecordModule;
|
||||
use Lucent\Core\Edge\EdgeModule;
|
||||
use Lucent\Core\Record\RecordFieldModule;
|
||||
use stdClass;
|
||||
|
||||
@@ -61,8 +62,47 @@ class QueryModule
|
||||
->map(RecordFieldModule::fromDb(...))
|
||||
->toArray();
|
||||
|
||||
$recordEdges = DB::table("edges")
|
||||
->select(
|
||||
"edges.*",
|
||||
"records.id as record_id",
|
||||
"records.schema_id as record_schema_id",
|
||||
"records_data.value as record_title",
|
||||
)
|
||||
->whereIn("edges.from", $recordIds)
|
||||
->whereIn("edges.field_id", $columns)
|
||||
->join("records", "edges.to", "=", "records.id")
|
||||
->join("records_data", function ($join) {
|
||||
$join
|
||||
->on("records.id", "=", "records_data.record_id")
|
||||
->on(
|
||||
"records.title_field_id",
|
||||
"=",
|
||||
"records_data.field_id",
|
||||
);
|
||||
})
|
||||
->where("edges.mode", "=", RecordMode::DRAFT)
|
||||
->where("edges.locale", "=", "main")
|
||||
->where("records_data.mode", "=", RecordMode::DRAFT)
|
||||
->where("records_data.locale", "=", "main")
|
||||
->orderBy("edges.rank", "asc")
|
||||
->distinct()
|
||||
->get()
|
||||
->map(
|
||||
fn($row) => RecordModule::edgeRecordPreviewFromDb(
|
||||
$schemas,
|
||||
$row,
|
||||
),
|
||||
)
|
||||
->toArray();
|
||||
|
||||
return $records->map(
|
||||
fn($row) => static::fromDB($row, $schemas, $recordData),
|
||||
fn($row) => static::fromDB(
|
||||
$row,
|
||||
$schemas,
|
||||
$recordData,
|
||||
$recordEdges,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,6 +135,7 @@ class QueryModule
|
||||
stdClass $row,
|
||||
$schemas,
|
||||
array $recordData,
|
||||
array $recordEdges,
|
||||
): QueryRecord {
|
||||
return new QueryRecord(
|
||||
null,
|
||||
@@ -111,6 +152,10 @@ class QueryModule
|
||||
->where("recordId", $row->id)
|
||||
->values()
|
||||
->toArray(),
|
||||
collect($recordEdges)
|
||||
->where("edge.from", $row->id)
|
||||
->values()
|
||||
->toArray(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,19 @@ class RecordRepo
|
||||
->update(RecordModule::toDb($record));
|
||||
}
|
||||
|
||||
public static function deleteBySchemaId(string $schemaId): void
|
||||
{
|
||||
$recordIds = DB::table(self::TABLE_NAME)
|
||||
->select("id")
|
||||
->where("schema_id", $schemaId)
|
||||
->get()
|
||||
->pluck("id")
|
||||
->toArray();
|
||||
|
||||
DB::table(self::TABLE_NAME)->where("schema_id", $schemaId)->delete();
|
||||
DB::table("records_data")->whereIn("record_id", $recordIds)->delete();
|
||||
}
|
||||
|
||||
public static function findOne(string $id): ?Record
|
||||
{
|
||||
return DB::table(self::TABLE_NAME)
|
||||
@@ -55,6 +68,7 @@ class RecordRepo
|
||||
"records_data.field_id",
|
||||
);
|
||||
})
|
||||
->where("records_data.mode", RecordMode::DRAFT->value)
|
||||
->orderBy("created_at", "desc")
|
||||
->limit(5)
|
||||
->get()
|
||||
@@ -89,6 +103,7 @@ class RecordRepo
|
||||
);
|
||||
})
|
||||
->orderBy("edges.rank", "asc")
|
||||
->distinct()
|
||||
->get()
|
||||
|
||||
->map(
|
||||
|
||||
@@ -5,11 +5,13 @@ namespace Lucent\Http\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Lucent\Core\Repository\SchemaRepo;
|
||||
use Lucent\Core\Repository\FieldRepo;
|
||||
use Lucent\Core\Repository\RecordRepo;
|
||||
use Lucent\Core\Repository\RecordFieldRepo;
|
||||
use Lucent\Core\Schema\Data\Field;
|
||||
use Lucent\Core\Schema\Data\FieldProp\FieldProp;
|
||||
use Lucent\Core\Schema\Data\FieldProp\TextFieldProp;
|
||||
use Lucent\Core\Schema\Data\Schema;
|
||||
use Lucent\Id\Id;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
@@ -128,9 +130,12 @@ class SchemaController
|
||||
if (empty($schema)) {
|
||||
return response()->json(["errors" => ["Schema not found"]], 404);
|
||||
}
|
||||
DB::transaction(function () use ($schemaId) {
|
||||
SchemaRepo::delete($schemaId);
|
||||
RecordRepo::deleteBySchemaId($schemaId);
|
||||
FieldRepo::deleteBySchemaId($schemaId);
|
||||
});
|
||||
|
||||
SchemaRepo::delete($schemaId);
|
||||
FieldRepo::deleteBySchemaId($schemaId);
|
||||
return response()->json([], 200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user