Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sarun Mungthanya
SpnPatch-Laravel
Commits
885add3c
Commit
885add3c
authored
Jul 15, 2024
by
Sarun Mungthanya
Browse files
add file
parent
2a80d6b3
Changes
2
Show whitespace changes
Inline
Side-by-side
app/Http/Livewire/Pages/Patch/ModalEditCode.php
View file @
885add3c
...
@@ -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
()
{
{
...
...
resources/views/livewire/pages/patch/patch-edit.blade.php
View file @
885add3c
...
@@ -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>
--}}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment