Commit 885add3c authored by Sarun Mungthanya's avatar Sarun Mungthanya
Browse files

add file

parent 2a80d6b3
......@@ -4,11 +4,12 @@ namespace App\Http\Livewire\Pages\Patch;
use App\Models\TabPatchFile;
use Livewire\Component;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
class ModalEditCode extends Component
{
public $openModalEditCode = false;
public $patchFileId, $patchFile, $gitCode, $dbCode;
public $patchFileId, $patchFile, $gitCode, $dbCode, $commit;
public $preImpHeader;
public $isOpenEditCode= false;
......@@ -18,8 +19,11 @@ class ModalEditCode extends Component
{
$this->patchFileId = $patchFileId;
$patchFile = TabPatchFile::where('fid', $this->patchFileId)->first();
$this->patchFile = TabPatchFile::where('fid', $this->patchFileId)->first();
$this->isOpenEditCode = true;
$this->dbCode = base64_decode( $this->patchFile)
// $this->gitCode = $this->getFileContentFromGit();
}
public function closeModal()
......@@ -30,7 +34,37 @@ class ModalEditCode extends Component
{
}
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,
]);
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 render()
{
......
......@@ -69,7 +69,7 @@
<div class="mt-5 bg-gray-100 p-4 rounded-lg shadow">
<h3 class="text-lg mb-3">Changed Files</h3>
<div class="file-tree">
<ul>
<ul class='pl-4 mt-1'>
@foreach ($fileChanges as $name => $item)
@include('livewire.pages.patch.tree-item', [
'name' => $name,
......@@ -175,4 +175,3 @@
<livewire:pages.patch.modal-edit-code>
</div>
{{-- <li class='text-gray-700'><a href='#' wire:click='openEditCode(${key})'></a><i class='fa fa-file text-base mr-2'></i>${key} </li> --}}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment