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; ...@@ -4,11 +4,12 @@ namespace App\Http\Livewire\Pages\Patch;
use App\Models\TabPatchFile; use App\Models\TabPatchFile;
use Livewire\Component; use Livewire\Component;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
class ModalEditCode extends Component class ModalEditCode extends Component
{ {
public $openModalEditCode = false; public $openModalEditCode = false;
public $patchFileId, $patchFile, $gitCode, $dbCode; public $patchFileId, $patchFile, $gitCode, $dbCode, $commit;
public $preImpHeader; public $preImpHeader;
public $isOpenEditCode= false; public $isOpenEditCode= false;
...@@ -18,8 +19,11 @@ class ModalEditCode extends Component ...@@ -18,8 +19,11 @@ class ModalEditCode extends Component
{ {
$this->patchFileId = $patchFileId; $this->patchFileId = $patchFileId;
$patchFile = TabPatchFile::where('fid', $this->patchFileId)->first();
$this->patchFile = TabPatchFile::where('fid', $this->patchFileId)->first(); $this->patchFile = TabPatchFile::where('fid', $this->patchFileId)->first();
$this->isOpenEditCode = true; $this->isOpenEditCode = true;
$this->dbCode = base64_decode( $this->patchFile)
// $this->gitCode = $this->getFileContentFromGit();
} }
public function closeModal() public function closeModal()
...@@ -30,7 +34,37 @@ class ModalEditCode extends Component ...@@ -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() public function render()
{ {
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
<div class="mt-5 bg-gray-100 p-4 rounded-lg shadow"> <div class="mt-5 bg-gray-100 p-4 rounded-lg shadow">
<h3 class="text-lg mb-3">Changed Files</h3> <h3 class="text-lg mb-3">Changed Files</h3>
<div class="file-tree"> <div class="file-tree">
<ul> <ul class='pl-4 mt-1'>
@foreach ($fileChanges as $name => $item) @foreach ($fileChanges as $name => $item)
@include('livewire.pages.patch.tree-item', [ @include('livewire.pages.patch.tree-item', [
'name' => $name, 'name' => $name,
...@@ -175,4 +175,3 @@ ...@@ -175,4 +175,3 @@
<livewire:pages.patch.modal-edit-code> <livewire:pages.patch.modal-edit-code>
</div> </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