This commit is contained in:
2023-10-04 13:32:30 +03:00
parent 215d238505
commit 1ca5f4e521
82 changed files with 519 additions and 1889 deletions
+30 -39
View File
@@ -8,13 +8,13 @@ use Lucent\Account\AccountService;
use Lucent\Account\AuthService;
use Lucent\Account\UserRepo;
use Lucent\Channel\ChannelService;
use Lucent\Field\System;
use Lucent\LucentException;
use Lucent\Query\Operator;
use Lucent\Query\Query;
use Lucent\Record\Manager;
use Lucent\Record\QueryRecord;
use Lucent\Record\RecordService;
use Lucent\Schema\System;
use Lucent\Schema\Validator\ValidatorException;
use Lucent\Svelte\Svelte;
use function Lucent\Response\fail;
@@ -39,13 +39,13 @@ class RecordController extends Controller
{
$schemaName = $request->route("schemaName");
$users = $this->accountService->all();
$schema = $this->channelService->channel->schemas->where("name", $schemaName)->first();
$schema = $this->channelService->getSchema($schemaName)->get();
$urlParams = $request->all();
$sort = data_get($urlParams, "sort") ?? "-_sys.updatedAt";
$filter = data_get($urlParams, "filter") ?? [];
$arguments = array_merge([
"_sys.schema" => $schema->name,
"_sys.status_in" => "draft,published",
"schema" => $schema->name,
"status_in" => "draft,published",
], $filter);
@@ -53,38 +53,32 @@ class RecordController extends Controller
$limit = 15;
$records = [];
$graphArray = null;
$total = 0;
try {
$queryResult = $this->query
->filter($arguments)
->limit($limit)
->status(explode(",", $arguments["_sys.status_in"]))
->skip($skip)
->sort($sort)
->childrenDepth(1)
->parentsDepth(0)
->runWithCount();
$graph = $this->query
->filter($arguments)
->limit($limit)
->status(explode(",", $arguments["status_in"]))
->skip($skip)
->sort($sort)
->childrenDepth(1)
->parentsDepth(0)
->runWithCount();
$records = $graph->getRootRecords()->toArray();
$graph = $queryResult->getQueryRecords();
$graphArray = $graph->toArray();
$total = $queryResult->getTotal();
$records = $graph->getRootRecords()->toArray();
} catch (SubqueryNoResultException) {
}
$data = [
"schemas" => $this->channelService->channel->schemas,
"schema" => $schema,
"users" => $users,
"records" => $records,
"graph" => $graphArray,
"graph" => toArray($graph),
"systemFields" => array_values(System::list()),
"operators" => array_values(Operator::list()),
"sort" => $sort,
"limit" => $limit,
"skip" => $skip,
"total" => $total,
"total" => $graph->total ?? 0,
"filter" => $request->input("filter") ?? [],
"inModal" => true,
];
@@ -192,7 +186,7 @@ class RecordController extends Controller
$rid = $request->route("rid");
$queryResult = $this->query
$graph = $this->query
->filter(["id" => $rid])
->limit(1)
->skip(0)
@@ -203,9 +197,7 @@ class RecordController extends Controller
->run();
$graph = $queryResult->getQueryRecords();
if (empty($graph->records[0])) {
if ($graph->records->isEmpty()) {
return $this->svelte->render(
layout: "channel",
view: "recordNotFound",
@@ -213,8 +205,8 @@ class RecordController extends Controller
);
}
$record = $graph->records[0];
$schema = $this->channelService->channel->schemas->where("name", $record->_sys->schema)->first();
$record = $graph->records->first();
$schema = $this->channelService->getSchema($record->schema)->get();
$recordHistory = $this->recordManager->fromSession($request->session())->push($rid)->getRecords($rid);
$users = $this->userRepo->all();
return $this->svelte->render(
@@ -223,11 +215,10 @@ class RecordController extends Controller
title: "Edit Record",
data: [
"schema" => $schema,
"graph" => $graph->toArray(),
"record" => $record->toArray(),
"graph" => toArray($graph),
"record" => toArray($record),
"users" => $users,
"recordHistory" => $recordHistory,
"isCreateMode" => $record->_sys->status === "empty",
]
);
}
@@ -294,37 +285,37 @@ class RecordController extends Controller
if ($request->input("isCreateMode")) {
$this->recordService->create(
schemaName: $request->input("record._sys.schema"),
schemaName: $request->input("record.schema"),
data: $request->input("record.data"),
id: $request->input("record.id"),
file: $request->input("record._file") ?? [],
edges: $request->input("edges"),
status: $request->input("record._sys.status"),
status: $request->input("record.status"),
uploadFromUrl: ""
);
} else {
$this->recordService->update(
id: $request->input("record.id"),
data: $request->input("record.data"),
status: $request->input("record._sys.status"),
status: $request->input("record.status"),
edges: $request->input("edges"),
updateEdges: true,
);
}
$queryResult = $this->query
$newGraph = $this->query
->filter(["id" => $request->input("record.id")])
->limit(10)
->childrenDepth(2)
->parentsDepth(1)
->run();
$newGraph = $queryResult->getQueryRecords();
} catch (ValidatorException $th) {
return fail($th->getValidatorErrors());
} catch (LucentException $th) {
return fail($th);
}
return ok($newGraph->toArray());
return ok(toArray($newGraph));
}