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
db34b0ab
Commit
db34b0ab
authored
Aug 05, 2024
by
Sarun Mungthanya
Browse files
update edit patch file
parent
755b18d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/Http/Livewire/Pages/Patch/PatchEdit.php
View file @
db34b0ab
...
@@ -8,10 +8,11 @@ use App\Models\TabPatchFile;
...
@@ -8,10 +8,11 @@ use App\Models\TabPatchFile;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Exception\RequestException
;
use
GuzzleHttp\Exception\RequestException
;
use
Illuminate\Support\Facades\Cache
;
use
Illuminate\Support\Facades\Cache
;
class
PatchEdit
extends
Component
class
PatchEdit
extends
Component
{
{
public
$patchId
;
public
$patchId
;
public
$progressSave
=
0
,
$isProcessing
=
false
;
public
$progressSave
=
0
,
$isProcessing
=
false
,
$progress
=
0
,
$currentStep
=
0
;
public
$searchProject
=
''
;
public
$searchProject
=
''
;
public
$selectedBranch
,
$selectedPatch
,
$showModal
;
public
$selectedBranch
,
$selectedPatch
,
$showModal
;
public
$selectedProject
;
public
$selectedProject
;
...
@@ -22,8 +23,8 @@ class PatchEdit extends Component
...
@@ -22,8 +23,8 @@ class PatchEdit extends Component
public
$filePatch
=
[];
public
$filePatch
=
[];
public
$fileChangesTemp
=
[];
public
$fileChangesTemp
=
[];
public
$fileChanges
=
[];
public
$fileChanges
=
[];
public
$startCommit
;
public
$startCommit
=
'fba646c8'
;
public
$endCommit
;
public
$endCommit
=
'3172788'
;
public
$PATCHNAME
;
public
$PATCHNAME
;
public
$PDATE
;
public
$PDATE
;
public
$PHP_VERSION
;
public
$PHP_VERSION
;
...
@@ -134,10 +135,21 @@ class PatchEdit extends Component
...
@@ -134,10 +135,21 @@ class PatchEdit extends Component
$this
->
filePatch
=
$filePath
;
$this
->
filePatch
=
$filePath
;
$this
->
filePatchChanges
=
$this
->
buildTree
(
$filePath
);
$this
->
filePatchChanges
=
$this
->
buildTree
(
$filePath
);
}
}
public
function
startProcess
()
public
function
save
()
{
{
$this
->
progress
=
0
;
$this
->
isProcessing
=
true
;
$this
->
isProcessing
=
true
;
$this
->
dispatchBrowserEvent
(
'process-started'
);
}
public
function
getProgress
()
{
return
$this
->
progress
;
}
public
function
processStep
()
{
// $this->isProcessing = true;
// $this->dispatchBrowserEvent('process-started');
// $this->validate([
// $this->validate([
// 'PATCHNAME' => 'required|string|max:255',
// 'PATCHNAME' => 'required|string|max:255',
// 'PDATE' => 'required|date',
// 'PDATE' => 'required|date',
...
@@ -172,48 +184,51 @@ class PatchEdit extends Component
...
@@ -172,48 +184,51 @@ class PatchEdit extends Component
$confSmartUpdate
->
PATCHCODE_SERVER
=
$this
->
PATCHCODE_SERVER
;
$confSmartUpdate
->
PATCHCODE_SERVER
=
$this
->
PATCHCODE_SERVER
;
$confSmartUpdate
->
save
();
$confSmartUpdate
->
save
();
$totalFiles
=
count
(
$this
->
fileChangesTemp
);
if
(
$this
->
isProcessing
&&
count
(
$this
->
fileChangesTemp
)
>
0
)
{
$successCount
=
0
;
$totalFiles
=
count
(
$this
->
fileChangesTemp
);
// $this->fileChangesTemp = 1000000;
// $currentStep = (int)($this->progress / (100 / $totalFiles));
if
(
count
(
$this
->
fileChangesTemp
)
>
0
)
{
$this
->
currentStep
=
$totalFiles
-
(
$totalFiles
-
$this
->
currentStep
);
for
(
$i
=
0
;
$i
<
$this
->
fileChangesTemp
;
$i
++
)
{
if
(
$this
->
currentStep
<
$totalFiles
)
{
$progress
=
((
$i
+
1
)
/
$this
->
fileChangesTemp
)
*
100
;
$file
=
$this
->
fileChangesTemp
[
$this
->
currentStep
];
$this
->
progressSave
=
$i
;
// Emit an event to update progress on the frontend
// $this->emit('progressUpdated', $progress);
// Use dispatch browser event to trigger frontend update
// $this->dispatchBrowserEvent('progressUpdated', ['progress' => $progress]);
}
foreach
(
$this
->
fileChangesTemp
as
$index
=>
$file
)
{
$filedata
=
$this
->
getFileContentFromGit
(
$file
,
$this
->
endCommit
);
$filedata
=
$this
->
getFileContentFromGit
(
$file
,
$this
->
endCommit
);
$filePath
=
$this
->
formatFilePath
(
$file
);
$filePath
=
$this
->
formatFilePath
(
$file
);
$filepath
=
new
TabPatchFile
;
$existingFile
=
TabPatchFile
::
where
(
'file_name'
,
$filePath
)
$filepath
->
ptid
=
$confSmartUpdate
->
PID
;
->
where
(
'ptid'
,
$confSmartUpdate
->
PID
)
$filepath
->
file_name
=
$filePath
;
->
first
();
$filepath
->
file_data
=
base64_encode
(
$filedata
);
if
(
$filepath
->
save
())
{
if
(
!
$existingFile
)
{
$successCount
++
;
// ถ้าไม่มีชื่อไฟล์นี้ในฐานข้อมูล ให้บันทึกข้อมูล
$filepath
=
new
TabPatchFile
;
$filepath
->
ptid
=
$confSmartUpdate
->
PID
;
$filepath
->
file_name
=
$filePath
;
$filepath
->
file_data
=
base64_encode
(
$filedata
);
$filepath
->
save
();
}
else
{
// file name ซ้ำ
}
}
$progress
=
((
$index
+
1
)
/
$totalFiles
)
*
100
;
$this
->
progressSave
=
$progress
;
$this
->
currentStep
+=
1
;
$this
->
progress
=
round
((
$this
->
currentStep
/
$totalFiles
)
*
100
,
2
);
// Emit an event to update progress on the frontend
}
else
{
$this
->
emit
(
'progressUpdated'
,
$progress
)
;
$this
->
isProcessing
=
false
;
session
()
->
flash
(
'message'
,
'Patch details and file changes updated successfully.'
);
// Use dispatch browser event to trigger frontend update
$this
->
reset
([
'fileChangesTemp'
,
'fileGitChanges'
,
'currentStep'
,
'progress'
]);
$this
->
dispatchBrowserEvent
(
'progressUpdated'
,
[
'progress'
=>
$progress
]
);
$this
->
emit
(
'reloadComponent'
,
$this
->
patchId
);
}
}
}
}
return
$this
->
progress
;
// session()->flash('message', 'Patch details and file changes updated successfully.');
// $this->reset(['fileChangesTemp', 'fileGitChanges']);
// $this->emit('reloadComponent', $this->patchId);
}
}
// public function processStep()
// {
// // จำลองการประมวลผล
// if ($this->progress < 100) {
// $this->progress += 10; // เพิ่มค่าความคืบหน้า
// }
// return $this->progress;
// }
private
function
formatFilePath
(
$file
)
private
function
formatFilePath
(
$file
)
{
{
...
@@ -302,7 +317,17 @@ class PatchEdit extends Component
...
@@ -302,7 +317,17 @@ class PatchEdit extends Component
// $this->message = $message;
// $this->message = $message;
$this
->
emit
(
'reloadComponent'
,
$patchId
);
$this
->
emit
(
'reloadComponent'
,
$patchId
);
}
}
public
function
deleteSelectedPatchFiles
(
$selectedFiles
)
{
foreach
(
$selectedFiles
as
$patchFileId
)
{
$pathFile
=
TabPatchFile
::
where
(
"fid"
,
$patchFileId
)
->
first
();
$patchId
=
$pathFile
->
ptid
;
TabPatchFile
::
where
(
"fid"
,
$patchFileId
)
->
delete
();
}
$this
->
emit
(
'reloadComponent'
,
$patchId
);
}
public
function
render
()
public
function
render
()
{
{
...
...
resources/views/home.blade.php
View file @
db34b0ab
...
@@ -4,6 +4,9 @@
...
@@ -4,6 +4,9 @@
{{-- Hello World --}}
{{-- Hello World --}}
{{--
</div>
--}}
{{--
</div>
--}}
{{--
</div>
--}}
{{--
</div>
--}}
<style>
[
x-cloak
]
{
display
:
none
;
}
</style>
<livewire:navbar
:currentContent=
"$currentContent"
/>
<livewire:navbar
:currentContent=
"$currentContent"
/>
<livewire:main-container
:currentContent=
"$currentContent"
/>
<livewire:main-container
:currentContent=
"$currentContent"
/>
</x-app-layout>
</x-app-layout>
\ No newline at end of file
resources/views/livewire/main-container.blade.php
View file @
db34b0ab
<div
class=
"bg-main-container mt-1 z-0 "
>
<div
class=
"bg-main-container mt-1 z-0 "
>
<link
href=
"{{ asset('css/pages/patch.css') }}"
rel=
"stylesheet"
>
<link
href=
"{{ asset('css/pages/patch.css') }}"
rel=
"stylesheet"
>
<div
wire:loading.class=
""
wire:loading.class.remove=
"hidden"
<div
wire:loading.class=
""
wire:loading.class.remove=
"hidden"
class=
"absolute inset-0 items-center justify-center z-50 bg-slate-50 dark:bg-navy-900 hidden"
>
class=
"absolute inset-0 items-center justify-center z-50 bg-slate-50 dark:bg-navy-900 hidden"
>
...
...
resources/views/livewire/navbar.blade.php
View file @
db34b0ab
<nav
class=
"shadow p-4 z-100 bg-secondary "
wire:init=
"loadNav"
>
<nav
class=
"shadow p-4 z-100 bg-secondary "
wire:init=
"loadNav"
>
{{-- @if ($navLoaded) --}}
{{-- @if ($navLoaded) --}}
<div
class=
"container mx-auto flex justify-between items-center"
>
<div
class=
"container mx-auto flex justify-between items-center"
>
<div
class=
"text-xl font-bold text-stone-700"
><a
href=
"/"
>
SPN Patch
</a></div>
<div
class=
"text-xl font-bold text-stone-700"
><a
href=
"/"
>
SPN Patch
</a></div>
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
<a
href=
"/server-license"
>
Server License Management
</a>
<a
href=
"/server-license"
>
Server License Management
</a>
<ul
x-show=
"open"
@
click=
"open = false"
@
mouseenter=
"clearTimeout(timer)"
<ul
x-cloak
x-show=
"open"
@
click=
"open = false"
@
mouseenter=
"clearTimeout(timer)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
class=
"absolute left-0 mt-2 w-48 bg-white shadow-lg"
>
class=
"absolute left-0 mt-2 w-48 bg-white shadow-lg"
>
<li><a
href=
"#"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
Submenu 1
</a>
<li><a
href=
"#"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
Submenu 1
</a>
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
<span
class=
"cursor-pointer"
@
click.stop
>
Send Patch
</span>
<span
class=
"cursor-pointer"
@
click.stop
>
Send Patch
</span>
<ul
x-show=
"open"
@
click.stop=
"open = false"
@
mouseleave=
"open = false"
<ul
x-cloak
x-show=
"open"
@
click.stop=
"open = false"
@
mouseleave=
"open = false"
class=
"absolute left-0 mt-2 w-48 bg-white shadow-lg"
>
class=
"absolute left-0 mt-2 w-48 bg-white shadow-lg"
>
<li><a
href=
"/send-patch"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
Send
<li><a
href=
"/send-patch"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
Send
Patch
</a></li>
Patch
</a></li>
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
@
mouseleave=
"timer = setTimeout(() => open = false, 100)"
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
class=
"relative px-2 py-1 rounded text-gray-700 hover:bg-primary-focus hover:text-white"
>
<a
href=
"#"
>
Configuration
</a>
<a
href=
"#"
>
Configuration
</a>
<ul
x-show=
"open"
@
click=
"open = false"
@
mouseleave=
"open = false"
<ul
x-cloak
x-show=
"open"
@
click=
"open = false"
@
mouseleave=
"open = false"
class=
"absolute left-0 mt-2 w-48 bg-white shadow-lg"
>
class=
"absolute left-0 mt-2 w-48 bg-white shadow-lg"
>
<li><a
href=
"/role"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
Role
</a></li>
<li><a
href=
"/role"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
Role
</a></li>
<li><a
href=
"/user"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
User
</a>
<li><a
href=
"/user"
class=
"block px-4 py-2 text-gray-700 hover:bg-stone-100"
>
User
</a>
...
...
resources/views/livewire/pages/patch/patch-edit.blade.php
View file @
db34b0ab
<div
class=
"bg-main-container"
>
<div
class=
"bg-main-container"
x-data=
"{ progress: 0, interval: null }"
x-init=
"window.addEventListener('process-started', () => {
interval = setInterval(() => {
$wire.call('processStep').then(result => {
console.log(result)
progress = result;
if (progress >= 100) {
clearInterval(interval);
}
});
}, 1000);
});"
>
<link
href=
"{{ asset('css/pages/patch.css') }}"
rel=
"stylesheet"
>
<link
href=
"{{ asset('css/pages/patch.css') }}"
rel=
"stylesheet"
>
<div
class=
"max-w-full mx-auto px-5"
>
<div
class=
"max-w-full mx-auto px-5"
x-cloak
>
<h2
class=
"text-2xl text-black "
>
<h2
class=
"text-2xl text-black "
>
Patch Management
Patch Management
</h2>
</h2>
<style>
.progress-bar
{
height
:
20px
;
background-color
:
#4CAF50
;
/* สีเขียว */
transition
:
width
0.5s
;
/* การเปลี่ยนแปลงเรียบๆ */
}
</style>
<a
href=
"/patch"
type=
"button"
class=
"btn mx-auto m-3 text-white bg-primary px-3 py-2"
>
Back
</a>
<a
href=
"/patch"
type=
"button"
class=
"btn mx-auto m-3 text-white bg-primary px-3 py-2"
>
Back
</a>
<div
x-show=
"progress > 0"
x-text=
"progress + '%'"
></div>
<div
class=
"progress-bar"
:style=
"`width: ${progress}%`"
></div>
<div
class=
"flex flex-wrap -mx-3"
>
<div
class=
"flex flex-wrap -mx-3"
>
<div
class=
"w-full md:w-1/2 px-3 mb-6"
>
<div
class=
"w-full md:w-1/2 px-3 mb-6"
>
<div
x-data=
"{
<div
x-data=
"{
...
@@ -50,7 +75,6 @@
...
@@ -50,7 +75,6 @@
id=
"searchProject"
placeholder=
"Enter project name"
x-model=
"searchQuery"
>
id=
"searchProject"
placeholder=
"Enter project name"
x-model=
"searchQuery"
>
</div>
</div>
</div>
</div>
<div
x-show=
"true"
class=
""
>
<div
x-show=
"true"
class=
""
>
<div
class=
"flex mb-3"
>
<div
class=
"flex mb-3"
>
<label
for=
"project"
class=
"form-label text-lg mr-2"
>
Select Project:
</label>
<label
for=
"project"
class=
"form-label text-lg mr-2"
>
Select Project:
</label>
...
@@ -77,26 +101,6 @@
...
@@ -77,26 +101,6 @@
Files
</button>
Files
</button>
</div>
</div>
</div>
</div>
<div
class=
"flex justify-center"
>
<button
type=
"button"
wire:click=
"save"
class=
"bg-stone-700 text-white px-4 py-2 rounded-md hover:bg-blue-600"
>
Save
</button>
</div>
<div
class=
"relative pt-1"
>
<div
class=
"flex mb-2 items-center justify-between"
>
<div
class=
"text-xs font-semibold inline-block py-1 px-2 rounded text-teal-600 bg-teal-200"
>
Progress
</div>
</div>
<div
class=
"flex"
>
<div
>
<div
class=
"mt-2"
>
{{--
<div
class=
"progress-bar bg-blue-500 h-4"
x-bind:style=
"`width: ${progress}%`"
></div>
<span
class=
"block mt-2"
x-text=
"progress + '%'"
></span>
--}}
</div>
</div>
</div>
</div>
<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"
>
Git Changed Files
</h3>
<h3
class=
"text-lg mb-3"
>
Git Changed Files
</h3>
...
@@ -133,16 +137,29 @@
...
@@ -133,16 +137,29 @@
</div>
</div>
</div>
</div>
<div
x-show=
"activeTab === 'tab2'"
class=
""
>
<div
x-show=
"activeTab === 'tab2'"
class=
""
x-data=
"{ selectedDeleteFiles: [], showDeleteListModal: false }"
>
<div
class=
"py-2 "
>
<div
class=
"py-2 "
>
<button
type=
"button"
<button
type=
"button"
class=
"py-2 px-3 bg-main-container border border-primary text-primary rounded-md hover:text-main-container hover:bg-primary-focus"
class=
"py-2 px-3 bg-main-container border border-primary text-primary rounded-md hover:text-main-container hover:bg-primary-focus"
wire:click=
"$emit('openModalFormPatchFile', '', '{{ $patchId }}')"
>
Add
</button>
wire:click=
"$emit('openModalFormPatchFile', '', '{{ $patchId }}')"
>
Add
</button>
<button
type=
"button"
<button
type=
"button"
class=
"py-2 px-3 bg-main-container border-error border rounded-md text-error hover:text-main-container hover:bg-error-focus"
class=
"py-2 px-3 bg-main-container border-error border rounded-md text-error hover:text-main-container hover:bg-error-focus"
wire:click=
"showModalDeletePatchFile"
>
Delete
</button>
@
click=
"showDeleteListModal = true"
>
Delete
</button>
</div>
<div
x-show=
"showDeleteListModal"
class=
"fixed inset-0 flex items-center justify-center z-50 bg-gray-900/50 bg-opacity-50"
>
<div
class=
"bg-white rounded-lg p-6 max-w-md w-full"
>
<h2
class=
"text-lg font-semibold text-gray-900"
>
Confirm Deletion
</h2>
<p
class=
"mt-2 text-gray-600"
>
Are you sure you want to delete the selected files?
</p>
<div
class=
"mt-4 flex justify-end"
>
<button
@
click=
"showDeleteListModal = false"
class=
"bg-gray-200 text-gray-700 px-4 py-2 rounded mr-2"
>
Cancel
</button>
<button
@
click=
"$wire.call('deleteSelectedPatchFiles', selectedDeleteFiles); showDeleteListModal = false;"
class=
"bg-red-500 text-white px-4 py-2 rounded"
>
Confirm
</button>
</div>
</div>
</div>
</div>
<div
class=
"is-scrollbar-hidden min-w-full table-responsive"
x-data=
"pages.tables.initExample1"
>
<div
class=
"is-scrollbar-hidden min-w-full table-responsive"
x-data=
"pages.tables.initExample1"
>
<table
class=
"is-hoverable table w-full text-left border-b"
>
<table
class=
"is-hoverable table w-full text-left border-b"
>
<thead>
<thead>
...
@@ -170,7 +187,7 @@
...
@@ -170,7 +187,7 @@
<label
class=
"inline-flex items-center space-x-2"
>
<label
class=
"inline-flex items-center space-x-2"
>
<input
<input
class=
"form-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary focus:border-primary dark:bg-navy-900 dark:border-navy-500 dark:checked:bg-accent dark:checked:border-accent dark:hover:border-accent dark:focus:border-accent"
class=
"form-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary focus:border-primary dark:bg-navy-900 dark:border-navy-500 dark:checked:bg-accent dark:checked:border-accent dark:hover:border-accent dark:focus:border-accent"
type=
"checkbox"
wire:model.defer
=
"selected
Patch
File"
type=
"checkbox"
x-model
=
"selected
Delete
File
s
"
value=
"{{ $patchFile['fid'] }}"
/>
value=
"{{ $patchFile['fid'] }}"
/>
</label>
</label>
</td>
</td>
...
@@ -284,11 +301,11 @@
...
@@ -284,11 +301,11 @@
<textarea
id=
"patchcode_server"
wire:model.defer=
"PATCHCODE_SERVER"
<textarea
id=
"patchcode_server"
wire:model.defer=
"PATCHCODE_SERVER"
class=
"w-full mt-1 p-2 border border-gray-300 rounded-md"
rows=
"5"
></textarea>
class=
"w-full mt-1 p-2 border border-gray-300 rounded-md"
rows=
"5"
></textarea>
</div>
</div>
{{--
<div
class=
"flex justify-center"
>
<div
class=
"flex justify-center"
>
<button
type=
"button"
wire:
click=
"
save
"
<button
type=
"button"
@
click=
"
$wire.call('startProcess')
"
class=
"bg-stone-700 text-white px-4 py-2 rounded-md hover:bg-blue-600"
>
Save
</button>
class=
"bg-stone-700 text-white px-4 py-2 rounded-md hover:bg-blue-600"
>
Save
</button>
</div>
--}}
</div>
</div>
</div>
...
...
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