default sorting on schemas
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('records', function (Blueprint $table) {
|
||||
$table->dropIndex(['schema', 'status']);
|
||||
$table->index(['schema', '_sys->updatedAt','status']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('records', function (Blueprint $table) {
|
||||
|
||||
$table->dropIndex(['schema', '_sys->updatedAt','status']);
|
||||
$table->index(['schema', 'status']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -13,6 +13,7 @@ use Lucent\Query\Query;
|
||||
use Lucent\Record\Manager;
|
||||
use Lucent\Record\QueryRecord;
|
||||
use Lucent\Record\RecordService;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\System;
|
||||
use Lucent\Schema\Validator\ValidatorException;
|
||||
use Lucent\Svelte\Svelte;
|
||||
@@ -37,7 +38,7 @@ class RecordController extends Controller
|
||||
{
|
||||
$schemaName = $request->route("schemaName");
|
||||
|
||||
if(!in_array($schemaName,$this->accountService->currentReadableSchemas())){
|
||||
if (!in_array($schemaName, $this->accountService->currentReadableSchemas())) {
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordNotFound",
|
||||
@@ -48,7 +49,7 @@ class RecordController extends Controller
|
||||
$users = $this->accountService->all();
|
||||
$schema = $this->channelService->getSchema($schemaName)->get();
|
||||
$urlParams = $request->all();
|
||||
$sort = data_get($urlParams, "sort") ?? "-_sys.updatedAt";
|
||||
$sort = data_get($urlParams, "sort") ?? $schema->sortBy;
|
||||
$filter = data_get($urlParams, "filter") ?? [];
|
||||
|
||||
$arguments = array_merge([
|
||||
@@ -84,13 +85,14 @@ class RecordController extends Controller
|
||||
"graph" => toArray($graph),
|
||||
"systemFields" => array_values(System::list()),
|
||||
"operators" => array_values(Operator::list()),
|
||||
"sort" => $sort,
|
||||
"sortParam" => $sort,
|
||||
"sortField" => $schema->fields->merge(array_values(System::list()))->firstWhere(fn($field) => $field->name === $sort || "-" . $field->name === $sort || "data." . $field->name === $sort || "-data." . $field->name === $sort),
|
||||
"limit" => $limit,
|
||||
"skip" => $skip,
|
||||
"total" => $graph->total ?? 0,
|
||||
"filter" => $request->input("filter") ?? [],
|
||||
"inModal" => true,
|
||||
"isWritable" => in_array($schemaName,$this->accountService->currentWritableSchemas())
|
||||
"isWritable" => in_array($schemaName, $this->accountService->currentWritableSchemas())
|
||||
];
|
||||
|
||||
if ($request->ajax()) {
|
||||
@@ -151,7 +153,7 @@ class RecordController extends Controller
|
||||
|
||||
public function new(Request $request)
|
||||
{
|
||||
if(!in_array($request->input("schema"),$this->accountService->currentWritableSchemas())){
|
||||
if (!in_array($request->input("schema"), $this->accountService->currentWritableSchemas())) {
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordNotFound",
|
||||
@@ -172,7 +174,7 @@ class RecordController extends Controller
|
||||
"record" => $queryRecord,
|
||||
"recordHistory" => $recordHistory,
|
||||
"isCreateMode" => true,
|
||||
"isWritable" => in_array($record->schema,$this->accountService->currentWritableSchemas())
|
||||
"isWritable" => in_array($record->schema, $this->accountService->currentWritableSchemas())
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -180,7 +182,7 @@ class RecordController extends Controller
|
||||
|
||||
public function newInline(Request $request)
|
||||
{
|
||||
if(!in_array($request->input("schema"),$this->accountService->currentWritableSchemas())){
|
||||
if (!in_array($request->input("schema"), $this->accountService->currentWritableSchemas())) {
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordNotFound",
|
||||
@@ -224,7 +226,7 @@ class RecordController extends Controller
|
||||
|
||||
$record = $graph->records->first();
|
||||
|
||||
if(!in_array($record->schema,$this->accountService->currentReadableSchemas())){
|
||||
if (!in_array($record->schema, $this->accountService->currentReadableSchemas())) {
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordNotFound",
|
||||
@@ -244,7 +246,7 @@ class RecordController extends Controller
|
||||
"record" => toArray($record),
|
||||
"users" => $this->accountService->all(),
|
||||
"recordHistory" => $recordHistory,
|
||||
"isWritable" => in_array($record->schema,$this->accountService->currentWritableSchemas())
|
||||
"isWritable" => in_array($record->schema, $this->accountService->currentWritableSchemas())
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ final class Query
|
||||
}
|
||||
|
||||
$query = $this->orderByQuery($query);
|
||||
|
||||
return $query->get()->map(function ($r) {
|
||||
$r->isRoot = true;
|
||||
return $r;
|
||||
|
||||
@@ -20,6 +20,7 @@ class CollectionSchema implements Schema
|
||||
public Collection $fields,
|
||||
public bool $isEntry = false,
|
||||
public string $color = "",
|
||||
public string $sortBy = "-_sys.updatedAt",
|
||||
public string $titleTemplate = "",
|
||||
public int $revisions = 0,
|
||||
public array $read = [],
|
||||
|
||||
@@ -20,6 +20,7 @@ class FilesSchema implements Schema
|
||||
public string $path,
|
||||
public array $groups,
|
||||
public bool $isEntry = false,
|
||||
public string $sortBy = "-_sys.updatedAt",
|
||||
public string $color = "",
|
||||
public string $titleTemplate = "",
|
||||
public int $revisions = 0,
|
||||
|
||||
@@ -24,6 +24,7 @@ class SchemaService
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapFields']),
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
color: $schemaArr["color"] ?? "",
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
||||
revisions: $schemaArr["revisions"] ?? 0,
|
||||
read: $schemaArr["read"] ?? [],
|
||||
@@ -36,6 +37,7 @@ class SchemaService
|
||||
path: $schemaArr["path"] ?? $schemaArr["name"],
|
||||
groups: $schemaArr["groups"] ?? [],
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
|
||||
color: $schemaArr["color"] ?? "",
|
||||
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
||||
revisions: $schemaArr["revisions"] ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user