This commit is contained in:
2023-10-07 21:18:18 +03:00
parent f2faec67fe
commit 956b8dc4e3
12 changed files with 378 additions and 113 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ return [
"url" => env("LUCENT_URL", "http://localhost:8000/"),
"previewTarget" => env("LUCENT_PREVIEW_TARGET", "previewTarget"),
"generateCommand" => env("LUCENT_GENERATE_COMMAND", "generate:static"),
"imageFilters" => [],
"imageFilters" => []
];
+2 -1
View File
@@ -71,11 +71,12 @@ class ImageService
$image->filter(new $this->channelService->channel->imageFilters[$template]);
try {
$image->encode('webp', 75);
$image->save($templateFilePath);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
return $this->notFoundImage;
}
$image->save($templateFilePath);
return $templateUri;
}
+66 -75
View File
@@ -163,23 +163,20 @@ class RecordController extends Controller
]
);
}
//
//
// public function newInline(Request $request)
// {
//
// $channel = ChannelRepo::current();
// $schema = $channel->schemas->where("name.value", $request->input("schema"))->first();
// $record = Record::createEmpty($schema, AuthService::currentUserId($request));
// $queryRecord = QueryRecord::fromRecord($record);
//
// return [
// "schemas" => $channel->schemas,
// "schema" => $schema,
// "record" => $queryRecord,
// "isCreateMode" => true,
// ];
// }
public function newInline(Request $request)
{
$schema = $this->channelService->getSchema($request->input("schema"));
$record = $this->recordService->createEmpty($schema);
$queryRecord = QueryRecord::fromRecord($record);
return [
"schema" => $schema,
"record" => $queryRecord,
"isCreateMode" => true,
];
}
public function edit(Request $request)
{
@@ -224,72 +221,66 @@ class RecordController extends Controller
}
//
// public function editInline(Request $request)
// {
// $channel = ChannelRepo::current();
// $rid = $request->route("rid");
//
// $queryResult = $this->query
// ->filter(["id" => $rid])
// ->limit(1)
// ->childrenDepth(2)
// ->parentsDepth(1)
// ->run();
//
// $graph = $queryResult->getQueryRecords($channel->schemas);
// $record = $graph->records[0];
// return ok(
// [
// "graph" => $graph->toArray(),
// "record" => $record->toArray(),
// ]
// );
// }
//
//
// public function suggestions(Request $request)
// {
// $arguments = [
// "_sys.schema" => $request->input("schema"),
// ];
//
// if ($request->input("value")) {
// if (in_array($request->input("ui"), ["text", "date"])) {
// $arguments[$request->input("field") . "_regex"] = $request->input("value");
// } elseif ($request->input("ui") == "number") {
// $arguments[$request->input("field") . "_eqnum"] = floatval($request->input("value"));
// } elseif ($request->input("ui") == "date") {
// }
// }
//
//
// $queryResult = $this->query
// ->filter($arguments)
// ->limit(10)
// ->run();
//
// if (!$queryResult->hasResults()) {
// return ok([]);
// }
// $schemas = $this->schemaRepo->all();
// $graph = $queryResult->getQueryRecords($schemas);
//
// return ok($graph->records->toArray());
// }
//
public function editInline(Request $request)
{
$rid = $request->route("rid");
$graph = $this->query
->filter(["id" => $rid])
->limit(1)
->childrenDepth(2)
->parentsDepth(1)
->tree();
return ok(
[
"graph" => $graph->toArray(),
"record" => $graph->first()->toArray(),
]
);
}
public function suggestions(Request $request)
{
$arguments = [
"schema" => $request->input("schema"),
];
if ($request->input("value")) {
if (in_array($request->input("ui"), ["text", "date"])) {
$arguments["data.".$request->input("field") . "_regex"] = $request->input("value");
} elseif ($request->input("ui") == "number") {
$arguments["data.".$request->input("field") . "_eqnum"] = floatval($request->input("value"));
} elseif ($request->input("ui") == "date") {
}
}
$records = $this->query
->filter($arguments)
->limit(10)
->tree();
if ($records->isEmpty()) {
return ok([]);
}
return ok($records->toArray());
}
public function save(Request $request)
{
$recordId = $request->input("record.id");
try {
if ($request->input("isCreateMode")) {
$this->recordService->create(
$recordId = $this->recordService->create(
schemaName: $request->input("record.schema"),
data: $request->input("record.data"),
id: $request->input("record.id"),
id:$recordId ?? "",
file: $request->input("record._file") ?? [],
edges: $request->input("edges"),
edges: $request->input("edges") ?? [],
status: $request->input("record.status"),
uploadFromUrl: ""
);
@@ -304,7 +295,7 @@ class RecordController extends Controller
}
$newGraph = $this->query
->filter(["id" => $request->input("record.id")])
->filter(["id" => $recordId])
->limit(10)
->childrenDepth(2)
->parentsDepth(1)
+1 -1
View File
@@ -75,7 +75,7 @@ readonly class RecordService
}
$record = new Record(
id: $id ?? Id::new(),
id: empty($id) ? Id::new() : $id,
schema: $schema->name,
status: Status::from($status),
_sys: System::newRecord($this->authService->currentUserId()),
+1
View File
@@ -21,6 +21,7 @@ class Reference implements FieldInterface, MinMaxInterface
public ?int $min = null,
public ?int $max = null,
public array $collections = [],
public string $searchField = "",
public string $layout = "",
public string $group = "",
)
+34
View File
@@ -3,9 +3,15 @@
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
class StaticGenerator
{
/**
* @var array<string> $directoriesIndex
*/
public array $directoriesIndex = [];
public function __construct(
public Writer $writer,
@@ -16,8 +22,36 @@ class StaticGenerator
public function run(callable $callback): void
{
echo "Start".PHP_EOL;
$this->removePreviousDirectories();
echo "Removing previous data".PHP_EOL;
$callback($this->writer);
echo "Finito".PHP_EOL;
}
private function removePreviousDirectories() :void{
if(!file_exists(storage_path("lucent/directories.log"))){
return;
}
$directories = file_get_contents(storage_path("lucent/directories.log"));
$directoriesArr = array_reverse(explode(PHP_EOL,$directories));
foreach ($directoriesArr as $directory){
if(empty($directory) || $directory === "/") {
continue;
}
if(!file_exists(public_path($directory."/index.html"))){
continue;
}
unlink(public_path($directory."/index.html"));
rmdir(public_path($directory));
}
if(file_exists(public_path("index.html"))){
unlink(public_path("index.html"));
}
unlink(storage_path("lucent/directories.log"));
}
}
+4 -4
View File
@@ -22,19 +22,19 @@ class Writer
}
file_put_contents($filepath, $html);
file_put_contents(storage_path("lucent/directories.log"), $path.PHP_EOL, FILE_APPEND);
echo "Path: /$path".PHP_EOL;
}
public function recordIterator(callable $query, callable $parser, int $skip = 0): int
public function recordIterator(callable $query, callable $parser, int $skip = 0, $limit = 100): int
{
$limit = 100;
// logger("fetching $skip");
$records = $query($limit, $skip);
$parser($records);
$parser($records,$limit, $skip);
if ($records->hasResults()) {
if ($records->count() > 0) {
return $this->recordIterator($query, $parser, $skip + $limit);
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace Lucent\Support;
/**
* An in-memory memoizer that keeps the cached values around for the lifetime of this instance.
*/
class Memoize
{
/**
* The saved results
*
* @var array
*/
private array $cache = [];
/**
* $cacheTime is ignored - this will keep the results around for the lifetime of this instance.
*
* @see Memoize::memoizeCallable
*
* @param string $key
* @param callable $compute
*
* @return mixed
*/
public function memoizeCallable(string $key, callable $compute) :mixed
{
if (array_key_exists($key, $this->cache)) {
return $this->cache[$key];
}
$result = $compute();
$this->cache[$key] = $result;
return $result;
}
}
+8 -6
View File
@@ -7,13 +7,15 @@
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>@yield('title') - Lucent Data Platform</title>
<!-- if development -->
{{-- @php--}}
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
{{-- @endphp--}}
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
@php
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
@endphp
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
<!-- if production -->
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
<link rel="icon" type="image/x-icon" href="/favicon.ico">
</head>