diff --git a/front/js/svelte/records/Edit.svelte b/front/js/svelte/records/Edit.svelte index 17e9978..ff0377e 100644 --- a/front/js/svelte/records/Edit.svelte +++ b/front/js/svelte/records/Edit.svelte @@ -52,9 +52,8 @@ window.location = channel.lucentUrl; return; } + graph = [...response.data.graph]; form.setOriginalData(); - graph = response.data.graph; - } resolve(null); @@ -87,7 +86,7 @@ bind:this={form} data={record.data} status={record.status} - {graph} + bind:graph {schema} {record} {isCreateMode} diff --git a/front/js/svelte/records/form/Form.svelte b/front/js/svelte/records/form/Form.svelte index f6e77ca..f3e1159 100644 --- a/front/js/svelte/records/form/Form.svelte +++ b/front/js/svelte/records/form/Form.svelte @@ -22,7 +22,7 @@ export let record; export let data; export let status = null; - export let graph = []; + export let graph; export let isCreateMode; let originalContent; let activeContentTab = ""; diff --git a/src/Http/Controller/RecordController.php b/src/Http/Controller/RecordController.php index 6258ab7..526a3ad 100644 --- a/src/Http/Controller/RecordController.php +++ b/src/Http/Controller/RecordController.php @@ -20,7 +20,6 @@ use Lucent\Record\Status; use Lucent\Schema\Schema\System; use Lucent\Schema\Validator\ValidatorException; use Lucent\Support\Collection; -use Lucent\Support\Result\Result; use Lucent\Support\Result\Success; use Lucent\Svelte\Svelte; use PhpOption\Option; @@ -315,7 +314,6 @@ class RecordController extends Controller { $recordId = $request->input("id"); - $recordEdgeData = (new Collection($request->input("edges")))->map(fn($item) => new RecordEdgeData( target: $item["target"], targetSchema:$item["targetSchema"], @@ -323,7 +321,6 @@ class RecordController extends Controller data: Option::fromValue(data_get($item,"data")), )); - $res = match ($request->input("isCreateMode")) { true => $this->recordService->createDocument(new NewDocumentData( schemaName: $request->input("schemaName"), @@ -368,7 +365,6 @@ class RecordController extends Controller public function clone(Request $request) { try { - $newRecordId = $this->recordService->clone( recordId: $request->route("rid"), ); diff --git a/src/Lexorank/Lexorank.php b/src/Lexorank/Lexorank.php new file mode 100644 index 0000000..b81ad29 --- /dev/null +++ b/src/Lexorank/Lexorank.php @@ -0,0 +1,135 @@ + + */ + public function after(string $prevRank): Result + { + + if (empty($prevRank)) { + return $this->forEmptySequence(); + } + + $res = Rank::fromString($prevRank); + if($res->error()->isDefined()){ + return $res; + } + $prevRank = $res->success()->get(); + $char = substr($prevRank->get(), -1); + + if (ord($char) + 1 >= ord(Rank::MAX_CHAR)) { + return Rank::fromString( + $prevRank->get() . chr(ord(Rank::MIN_CHAR) + 1) + ); + } + + $return = substr($prevRank->get(), 0, -1) . chr(ord($char) + 1); + + if(empty($return)){ + return Error::create("Lexorank empty string error"); + } + + return Rank::fromString($return); + } + + /** + * @return Result + */ + public function before(string $nextRank): Result + { + if (empty($nextRank)) { + return $this->forEmptySequence(); + } + + $res = Rank::fromString($nextRank); + if($res->error()->isDefined()){ + return $res; + } + + $nextRank = $res->success()->get(); + $char = substr($nextRank->get(), -1); + + if (ord($char) - 1 <= ord(Rank::MIN_CHAR)) { + $return = substr($nextRank->get(), 0, -1) . chr(ord($char) - 1) . chr(ord(Rank::MAX_CHAR) - 1); + return Rank::fromString($return); + } + + $return = substr($nextRank->get(), 0, -1) . chr(ord($char) - 1); + return Rank::fromString($return); + } + + /** + * @return Result + */ + public function betweenRanks(string $prevRank, string $nextRank): Result + { + $resNext = Rank::fromString($nextRank); + $resPrev = Rank::fromString($prevRank); + if($resNext->error()->isDefined()){ + return $resNext; + } + if($resPrev->error()->isDefined()){ + return $resPrev; + } + $nextRank = $resNext->success()->get(); + $prevRank = $resPrev->success()->get(); + + if (strcmp($prevRank->get(), $nextRank->get()) >= 0) { + return Error::create('Previous Rank (' . $prevRank->get() . ') is greater than or equals to Next (' . $nextRank->get() . ')'); + } + + $rank = ''; + $i = 0; + while ($i <= Rank::MAX_RANK_LEN) { + $prevChar = $prevRank->getChar($i, Rank::MIN_CHAR); + $nextChar = $nextRank->getChar($i, Rank::MAX_CHAR); + $i++; + + $midChar = $this->mid($prevChar, $nextChar); + if (in_array($midChar, [$prevChar, $nextChar])) { + $rank .= $prevChar; + continue; + } + + $rank .= $midChar; + break; + } + + return Rank::fromString($rank); + } + + + /** + * @return Result + */ + public function forEmptySequence(): Result + { + return Rank::fromString($this->mid(Rank::MIN_CHAR, Rank::MAX_CHAR)); + } + + + private function mid(string $prev, string $next): string + { + if (ord($prev) >= ord($next)) { + return $prev; + } + + return chr((int)((ord($prev) + ord($next)) / 2)); + } + + +} diff --git a/src/Lexorank/Rank.php b/src/Lexorank/Rank.php new file mode 100644 index 0000000..9ef248a --- /dev/null +++ b/src/Lexorank/Rank.php @@ -0,0 +1,93 @@ +rank = $rank; + } + + /** + * @param non-empty-string $rank + * + * @return Result + */ + private static function rankValidator(string $rank): Result + { + if (strlen($rank) > self::MAX_RANK_LEN) { + return Error::create('The length of Rank provided is too long. Rank Provided: ' . $rank . ' - Rank Length: ' . strlen($rank) . ' - Max length: ' . self::MAX_RANK_LEN); + } + + $invalidChars = array_filter( + str_split($rank), + static function ($char) { + return ord($char) < ord(self::MIN_CHAR) || ord($char) > ord(self::MAX_CHAR); + } + ); + + if ($invalidChars !== []) { + return Error::create('Rank provided contains an invalid Char. Rank Provided: ' . $rank . ' - Invalid char: ' . implode(', ', array_values($invalidChars))); + } + + $lastChar = substr($rank, -1); + if ($lastChar === self::MIN_CHAR) { + return Error::create('The last char of the rank (' . $rank . ') can\'t be equal to the min char (' . self::MIN_CHAR . ').'); + } + + return Success::create(new self($rank)); + } + + public function get(): string + { + return $this->rank; + } + + /** + * @param non-empty-string $rank + * + * @return Result + */ + public static function fromString(string $rank): Result + { + return self::rankValidator($rank); + } + + public function getChar(int $i, string $defaultChar): string + { + return $this->rank[$i] ?? $defaultChar; + } + + + +}