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