selectedProject = $selectedProject; $this->patchFileId = $patchFileId; $patchFile = TabPatchFile::where('fid', $this->patchFileId)->first(); $this->patchFile = $patchFile->file_name; $this->dbCode = base64_decode($patchFile->file_content); // Adjust accordingly based on your database schema $this->gitCodeRaw = $this->getFileContentFromGit($this->patchFile, $this->commit); $this->gitCode = (iconv('TIS-620', 'UTF-8', $this->gitCodeRaw)); $this->isOpenEditCode = true; } public function closeModal() { $this->isOpenEditCode = false; } public function updateCode() { } private function getFileContentFromGit($filePath, $commit) { $token = env('GITLAB_API_TOKEN'); $client = new Client([ 'base_uri' => 'https://idemo.netbay.co.th/gitlab/api/v4/', 'headers' => [ 'Authorization' => "Bearer $token", 'Accept' => 'application/json', ], 'verify' => false, ]); $filePath = str_replace("./", "IE5DEV.shippingnet/", $filePath); try { $response = $client->get("projects/{$this->selectedProject}/repository/files/" . urlencode($filePath) . "/raw", [ 'query' => ['ref' => $commit] ]); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); if ($statusCode == 200) { return $content; } else { throw new \Exception("Failed to fetch file. Status code: $statusCode"); } } catch (RequestException $e) { throw $e; } catch (\Exception $e) { throw $e; } } public function getDiff($code1, $code2) { $diffOptions = [ 'context' => 0, 'ignoreCase' => false, 'ignoreWhitespace' => true, ]; $rendererOptions = [ 'detailLevel' => 'char', 'language' => 'eng', 'lineNumbers' => true, 'separateBlock' => true, 'showHeader' => true, 'spacesToNbsp' => false, 'outputFormat' => 'inline', 'mergeThreshold' => 0.8, 'originalFileName' => 'Original', 'newFileName' => 'New', 'cliColorization' => 'none', ]; $differ = new Differ(explode("\n", $code1), explode("\n", $code2), $diffOptions); $renderer = RendererFactory::make('Inline', $rendererOptions); $result = $renderer->render($differ); $result = $this->convertDiffToPrismFormat($result); return $result; } public function compare() { try { // $this->comparisonResult = 'GitLab connection successful.'; $this->diffResult = $this->getDiff($this->gitCode, $this->dbCode); // dd($this->diffResult); $this->emit('diffResultUpdated'); } catch (RequestException $e) { $this->comparisonResult = 'Error connecting to GitLab: ' . $e->getMessage(); $this->gitCode = ''; $this->gitCodeRaw = ''; } } private function convertDiffToPrismFormat($diffHtml) { $diffHtml = str_replace('', '', $diffHtml); $diffHtml = str_replace('', '', $diffHtml); $diffHtml = str_replace('-', '', $diffHtml); $diffHtml = str_replace('+', '', $diffHtml); return $diffHtml; } public function render() { return view('livewire.pages.patch.modal-edit-code'); } }