create record wip
This commit is contained in:
@@ -2,24 +2,28 @@
|
||||
|
||||
namespace Lucent\Http\Controller;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Lucent\Account\AccountService;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Core\Auth\AuthModule;
|
||||
use Lucent\Core\Data\RecordField;
|
||||
use Lucent\Core\Repository\SchemaRepo;
|
||||
use Lucent\Id\Id;
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Query\Operator\OperatorRegistry;
|
||||
use Lucent\Query\Query;
|
||||
use Lucent\Record\InputData\EdgeInputData;
|
||||
use Lucent\Record\InputData\RecordInputData;
|
||||
use Lucent\Record\Manager;
|
||||
use Lucent\Record\QueryRecord;
|
||||
use Lucent\Core\Repository\RecordRepo;
|
||||
use Lucent\Record\RecordService;
|
||||
use Lucent\Record\Status;
|
||||
use Lucent\Schema\System;
|
||||
use Lucent\Schema\Ui\Reference;
|
||||
use Lucent\Schema\Validator\ValidatorException;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use Lucent\ViewModel\ViewModel;
|
||||
use Lucent\Core\Data\Record;
|
||||
use function Lucent\Response\fail;
|
||||
use function Lucent\Response\ok;
|
||||
|
||||
@@ -38,90 +42,84 @@ class RecordController
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$schemaName = $request->route("schemaName");
|
||||
$schemaId = $request->route("id");
|
||||
$schemas = SchemaRepo::all();
|
||||
$schema = collect($schemas)->firstWhere("id", $schemaId);
|
||||
// $users = $this->accountService->all();
|
||||
$users = [];
|
||||
// $schema = $this->channelService->getSchema($schemaName)->get();
|
||||
// $urlParams = $request->all();
|
||||
// $sort = data_get($urlParams, "sort") ?? $schema->sortBy;
|
||||
// $filter = data_get($urlParams, "filter") ?? [];
|
||||
|
||||
if (
|
||||
!in_array(
|
||||
$schemaName,
|
||||
$this->accountService->currentReadableSchemas(),
|
||||
)
|
||||
) {
|
||||
return Svelte::view("recordNotFound", "Schema Not Found", []);
|
||||
}
|
||||
// $arguments = array_merge(
|
||||
// [
|
||||
// "schema" => $schema->name,
|
||||
// "status_in" => "draft,published",
|
||||
// ],
|
||||
// $filter,
|
||||
// );
|
||||
|
||||
$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") ?? [];
|
||||
|
||||
$arguments = array_merge(
|
||||
[
|
||||
"schema" => $schema->name,
|
||||
"status_in" => "draft,published",
|
||||
],
|
||||
$filter,
|
||||
);
|
||||
|
||||
$skip = data_get($urlParams, "skip") ?? 0;
|
||||
// $skip = data_get($urlParams, "skip") ?? 0;
|
||||
$skip = 0;
|
||||
$limit = 30;
|
||||
$records = [];
|
||||
$graphArray = null;
|
||||
// $graphArray = null;
|
||||
|
||||
$graph = $this->query
|
||||
->filter($arguments)
|
||||
->notLinked($request->input("notlinked") ?? "")
|
||||
->limit($limit)
|
||||
->status(explode(",", $arguments["status_in"]))
|
||||
->skip($skip)
|
||||
->sort($sort)
|
||||
->childrenFields($schema?->visible ?? [])
|
||||
->childrenDepth(1)
|
||||
->parentsDepth(0)
|
||||
->runWithCount();
|
||||
// $graph = $this->query
|
||||
// ->filter($arguments)
|
||||
// ->notLinked($request->input("notlinked") ?? "")
|
||||
// ->limit($limit)
|
||||
// ->status(explode(",", $arguments["status_in"]))
|
||||
// ->skip($skip)
|
||||
// ->sort($sort)
|
||||
// ->childrenFields($schema?->visible ?? [])
|
||||
// ->childrenDepth(1)
|
||||
// ->parentsDepth(0)
|
||||
// ->runWithCount();
|
||||
|
||||
$records = $graph->getRootRecords()->toArray();
|
||||
// $records = $graph->getRootRecords()->toArray();
|
||||
|
||||
$data = [
|
||||
"schemas" => $this->channelService->channel->schemas,
|
||||
"schemas" => $schemas,
|
||||
"schema" => $schema,
|
||||
"users" => $users,
|
||||
"records" => $records,
|
||||
"graph" => toArray($graph),
|
||||
"systemFields" => array_values(System::list()),
|
||||
"operators" => $this->operatorRegistry->all(),
|
||||
"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(),
|
||||
),
|
||||
// "graph" => toArray($graph),
|
||||
// "systemFields" => array_values(System::list()),
|
||||
// "operators" => $this->operatorRegistry->all(),
|
||||
// "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(),
|
||||
// ),
|
||||
];
|
||||
|
||||
if ($request->ajax()) {
|
||||
$data["modalUrl"] = $request->fullUrl();
|
||||
if (str_starts_with(config("lucent.url"), "https")) {
|
||||
$data["modalUrl"] = str_replace(
|
||||
"http://",
|
||||
"https://",
|
||||
$request->fullUrl(),
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
$data["inModal"] = false;
|
||||
// if ($request->ajax()) {
|
||||
// $data["modalUrl"] = $request->fullUrl();
|
||||
// if (str_starts_with(config("lucent.url"), "https")) {
|
||||
// $data["modalUrl"] = str_replace(
|
||||
// "http://",
|
||||
// "https://",
|
||||
// $request->fullUrl(),
|
||||
// );
|
||||
// }
|
||||
// return $data;
|
||||
// }
|
||||
// $data["inModal"] = false;
|
||||
return Svelte::view(
|
||||
view: "contentIndex",
|
||||
title: "Records",
|
||||
@@ -219,78 +217,6 @@ class RecordController
|
||||
}, []);
|
||||
}
|
||||
|
||||
public function new(Request $request)
|
||||
{
|
||||
if (
|
||||
!in_array(
|
||||
$request->input("schema"),
|
||||
$this->accountService->currentWritableSchemas(),
|
||||
)
|
||||
) {
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordNotFound",
|
||||
title: "Schema Not Found",
|
||||
);
|
||||
}
|
||||
|
||||
$schema = $this->channelService->channel->schemas
|
||||
->where("name", $request->input("schema"))
|
||||
->first();
|
||||
$recordHistory = $this->recordManager
|
||||
->fromSession($request->session())
|
||||
->getRecords();
|
||||
$record = $this->recordService->createEmpty($schema);
|
||||
$queryRecord = QueryRecord::fromRecord($record);
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordEdit",
|
||||
title: "New Record",
|
||||
data: [
|
||||
"schema" => $schema,
|
||||
"record" => $queryRecord,
|
||||
"recordHistory" => $recordHistory,
|
||||
"isCreateMode" => true,
|
||||
"isWritable" => in_array(
|
||||
$record->schema,
|
||||
$this->accountService->currentWritableSchemas(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function newInline(Request $request)
|
||||
{
|
||||
if (
|
||||
!in_array(
|
||||
$request->input("schema"),
|
||||
$this->accountService->currentWritableSchemas(),
|
||||
)
|
||||
) {
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "recordNotFound",
|
||||
title: "Schema Not Found",
|
||||
);
|
||||
}
|
||||
|
||||
$schema = $this->channelService
|
||||
->getSchema($request->input("schema"))
|
||||
->get();
|
||||
$record = $this->recordService->createEmpty($schema);
|
||||
$queryRecord = QueryRecord::fromRecord($record);
|
||||
|
||||
return [
|
||||
"schema" => $schema,
|
||||
"record" => $queryRecord,
|
||||
"isCreateMode" => true,
|
||||
"isWritable" => in_array(
|
||||
$record->schema,
|
||||
$this->accountService->currentWritableSchemas(),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function edit(Request $request)
|
||||
{
|
||||
$rid = $request->route("rid");
|
||||
@@ -381,6 +307,41 @@ class RecordController
|
||||
return ok($records->toArray());
|
||||
}
|
||||
|
||||
public function postCreate(Request $request)
|
||||
{
|
||||
$schemaId = $request->input("schemaId");
|
||||
$title = $request->input("title");
|
||||
$now = Carbon::now();
|
||||
$userId = AuthModule::getCurrentUserId();
|
||||
|
||||
$titleField = new RecordField(
|
||||
id: "_title",
|
||||
locale: "main",
|
||||
value: $title,
|
||||
createdAt: $now,
|
||||
createdBy: $userId,
|
||||
updatedAt: $now,
|
||||
updatedBy: $userId,
|
||||
version: 1,
|
||||
);
|
||||
|
||||
$record = new Record(
|
||||
id: Id::new(),
|
||||
schemaId: $schemaId,
|
||||
draftData: [$titleField],
|
||||
liveData: [],
|
||||
createdAt: $now,
|
||||
createdBy: $userId,
|
||||
publishedAt: null,
|
||||
publishedBy: null,
|
||||
trashedAt: null,
|
||||
trashedBy: null,
|
||||
);
|
||||
|
||||
RecordRepo::insert($record);
|
||||
return ok(toArray($record));
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$recordId = $request->input("record.id");
|
||||
|
||||
Reference in New Issue
Block a user