Commit 25d1a1ce authored by Sarun Mungthanya's avatar Sarun Mungthanya
Browse files

add delete patch and pathfile

parent 6014fa9c
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Company;
class DeleteItemModal extends Component
{
public $showModal = false;
public $deleteId;
protected $listeners = ['showDeleteItemModal'];
public function showDeleteItemModal($deleteId)
{
$this->deleteId = $deleteId;
$this->showModal = true;
}
public function closeModal()
{
$this->showModal = false;
}
public function render()
{
return view('livewire.delete-item-modal',['deleteId' => $this->deleteId]);
}
}
...@@ -9,27 +9,33 @@ use GuzzleHttp\Exception\RequestException; ...@@ -9,27 +9,33 @@ use GuzzleHttp\Exception\RequestException;
use Jfcherng\Diff\Differ; use Jfcherng\Diff\Differ;
use Jfcherng\Diff\DiffHelper; use Jfcherng\Diff\DiffHelper;
use Jfcherng\Diff\Factory\RendererFactory; use Jfcherng\Diff\Factory\RendererFactory;
class ModalEditCode extends Component class ModalEditCode extends Component
{ {
public $openModalEditCode = false; public $openModalEditCode = false;
public $patchFileId, $patchFile, $gitCode, $gitCodeRaw, $dbCode, $commit, $selectedProject, $comparisonResult , $diffResult; public $patchFileId, $patchFile, $gitCode, $gitCodeRaw, $dbCode, $commit, $selectedProject, $comparisonResult, $diffResult, $message;
public $preImpHeader; public $preImpHeader;
public $isOpenEditCode= false; public $isOpenEditCode = false;
protected $listeners = ['openModalEditCode']; protected $listeners = ['openModalEditCode' , 'deleteSubItem'];
public function openModalEditCode($patchFileId , $selectedProject) public function openModalEditCode($patchFileId, $selectedProject)
{ {
$this->selectedProject = $selectedProject; $this->selectedProject = $selectedProject;
$this->patchFileId = $patchFileId; $this->patchFileId = $patchFileId;
$patchFile = TabPatchFile::where('fid', $this->patchFileId)->first(); $patchFile = TabPatchFile::where('fid', $this->patchFileId)->first();
$this->patchFile = $patchFile->file_name; $this->patchFile = $patchFile->file_name;
$this->dbCode = base64_decode($patchFile->file_content); // Adjust accordingly based on your database schema $this->dbCode = base64_decode($patchFile->file_content); // Adjust accordingly based on your database schema
$this->gitCodeRaw = $this->getFileContentFromGit($this->patchFile, $this->commit); $this->gitCodeRaw = $this->getFileContentFromGit($this->patchFile, $this->commit);
$this->gitCode = (iconv('TIS-620', 'UTF-8', $this->gitCodeRaw)); try {
$this->isOpenEditCode = true; $this->gitCode = (iconv('TIS-620', 'UTF-8', $this->gitCodeRaw));
} catch (\Throwable $th) {
$this->gitCode = "This is image cannot show !";
}
$this->isOpenEditCode = true;
} }
...@@ -39,7 +45,6 @@ class ModalEditCode extends Component ...@@ -39,7 +45,6 @@ class ModalEditCode extends Component
} }
public function updateCode() public function updateCode()
{ {
} }
private function getFileContentFromGit($filePath, $commit) private function getFileContentFromGit($filePath, $commit)
{ {
...@@ -53,7 +58,15 @@ class ModalEditCode extends Component ...@@ -53,7 +58,15 @@ class ModalEditCode extends Component
], ],
'verify' => false, 'verify' => false,
]); ]);
$filePath = str_replace("./", "IE5DEV.shippingnet/", $filePath);
if (strpos($filePath, "../SPN/") !== false) {
$filePath = str_replace("../SPN/", "SPN/", $filePath);
} else if (strpos($filePath, "../spn/") !== false) {
$filePath = str_replace("../spn/", "spn/", $filePath);
} else {
$filePath = str_replace("./", "IE5DEV.shippingnet/", $filePath);
}
try { try {
$response = $client->get("projects/{$this->selectedProject}/repository/files/" . urlencode($filePath) . "/raw", [ $response = $client->get("projects/{$this->selectedProject}/repository/files/" . urlencode($filePath) . "/raw", [
...@@ -108,7 +121,7 @@ class ModalEditCode extends Component ...@@ -108,7 +121,7 @@ class ModalEditCode extends Component
{ {
try { try {
// $this->comparisonResult = 'GitLab connection successful.'; // $this->comparisonResult = 'GitLab connection successful.';
$this->diffResult = $this->getDiff($this->gitCode, $this->dbCode); $this->diffResult = $this->getDiff($this->gitCode, $this->dbCode);
// dd($this->diffResult); // dd($this->diffResult);
...@@ -130,6 +143,21 @@ class ModalEditCode extends Component ...@@ -130,6 +143,21 @@ class ModalEditCode extends Component
return $diffHtml; return $diffHtml;
} }
public function showDeleteItemModal($patchFileId)
{
$this->emit('showDeleteItemModal' ,$patchFileId);
}
public function deleteSubItem($patchFileId) {
$pathFile = TabPatchFile::where("fid", $patchFileId)->first();
$patchId = $pathFile->ptid;
$pathFile = TabPatchFile::where("fid", $patchFileId)->delete();
$message = "Deleted File ID : " . json_encode($patchFileId) . " Successfully";
$this->message = $message;
$this->emit('reloadComponent', $patchId);
$this->isOpenEditCode = false;
}
public function render() public function render()
{ {
return view('livewire.pages.patch.modal-edit-code'); return view('livewire.pages.patch.modal-edit-code');
......
...@@ -199,10 +199,17 @@ class PatchCreate extends Component ...@@ -199,10 +199,17 @@ class PatchCreate extends Component
foreach ($this->filePathChanges as $file) { foreach ($this->filePathChanges as $file) {
$filedata = $this->getFileContentFromGit($file, $this->endCommit); $filedata = $this->getFileContentFromGit($file, $this->endCommit);
if(strpos( $file, 'SPN/') !== false ) {
$real_file = str_replace("SPN/", "../SPN/", $file);
}else if(strpos( $file, 'spn/') !== false) {
$real_file = str_replace("spn/", "../spn/", $file);
}else{
$real_file = str_replace("IE5DEV.shippingnet", ".", $file);
}
$filepath = new TabPatchFile; $filepath = new TabPatchFile;
$filepath->ptid = $confSmartUpdate->PID; $filepath->ptid = $confSmartUpdate->PID;
$filepath->file_name = str_replace("IE5DEV.shippingnet", ".", $file); $filepath->file_name = $real_file;
$filepath->file_data = base64_encode($filedata); $filepath->file_data = base64_encode($filedata);
$filepath->save(); $filepath->save();
} }
......
...@@ -35,13 +35,18 @@ class PatchEdit extends Component ...@@ -35,13 +35,18 @@ class PatchEdit extends Component
public $UNINSTALL; public $UNINSTALL;
public $PATCHCODE_SERVER; public $PATCHCODE_SERVER;
public $filePathChanges = []; public $filePathChanges = [];
protected $listeners = [ 'gotoModal']; protected $listeners = [ 'gotoModal', 'reloadComponent'];
public function mount($editPid) public function mount($editPid)
{ {
$this->patchId = $editPid; $this->patchId = $editPid;
$this->loadPatchData(); $this->loadPatchData();
} }
public function reloadComponent($id)
{
$this->patchId = $id;
$this->loadPatchData();
$this->render();
}
public function loadPatchData() public function loadPatchData()
{ {
$patch = ConfSmartUpdate::findOrFail($this->patchId); $patch = ConfSmartUpdate::findOrFail($this->patchId);
...@@ -105,7 +110,14 @@ class PatchEdit extends Component ...@@ -105,7 +110,14 @@ class PatchEdit extends Component
if (count($this->filePathChanges) > 0) { if (count($this->filePathChanges) > 0) {
foreach ($this->filePathChanges as $file) { foreach ($this->filePathChanges as $file) {
$filePath = str_replace("IE5DEV.shippingnet", ".", $file);
if(strpos($file, 'SPN/') !== false ) {
$filePath = str_replace("SPN/", "../SPN/", $file);
}else if(strpos($file, 'spn/' ) !== false) {
$filePath = str_replace("spn/", "../spn/", $file);
}else{
$filePath = str_replace("IE5DEV.shippingnet", ".", $file);
}
$filedata = $this->getFileContentFromGit($filePath, $this->endCommit); $filedata = $this->getFileContentFromGit($filePath, $this->endCommit);
...@@ -157,7 +169,15 @@ class PatchEdit extends Component ...@@ -157,7 +169,15 @@ class PatchEdit extends Component
{ {
$tree = []; $tree = [];
foreach ($files as $file) { foreach ($files as $file) {
$filePath = "IE5DEV.shippingnet" . substr($file['file_name'], 1);
if(strpos($file['file_name'], "../SPN/" ) !== false ) {
$filePath = str_replace("../SPN/", "SPN/", $file['file_name']);
}else if(strpos($file['file_name'], "../spn/" ) !== false) {
$filePath = str_replace("../spn/", "spn/", $file['file_name']);
}else{
$filePath = "IE5DEV.shippingnet" . substr($file['file_name'], 1);
}
$pathParts = explode('/', $filePath); $pathParts = explode('/', $filePath);
$current = &$tree; $current = &$tree;
...@@ -170,13 +190,16 @@ class PatchEdit extends Component ...@@ -170,13 +190,16 @@ class PatchEdit extends Component
$current['id'] = $file['fid']; $current['id'] = $file['fid'];
} }
return $tree; return $tree;
} }
public function loadPage($page) { public function loadPage($page) {
$this->emit('menuChanged', $page); $this->emit('menuChanged', $page);
} }
public function render() public function render()
{ {
return view('livewire.pages.patch.patch-edit'); return view('livewire.pages.patch.patch-edit');
......
...@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Pages\Patch; ...@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Pages\Patch;
use Livewire\Component; use Livewire\Component;
use Livewire\WithPagination; use Livewire\WithPagination;
use App\Models\ConfSmartUpdate; use App\Models\ConfSmartUpdate;
use App\Models\TabPatchFile;
class PatchIndex extends Component class PatchIndex extends Component
{ {
...@@ -57,5 +58,12 @@ class PatchIndex extends Component ...@@ -57,5 +58,12 @@ class PatchIndex extends Component
// $this->emit('showpatchEditForm'); // $this->emit('showpatchEditForm');
} }
public function deleteItem($pid) {
$pathFile = TabPatchFile::where("ptid", $pid)->delete();
$patch = ConfSmartUpdate::where("PID", $pid)->delete();
$message = "Deleted Patch ID : " . json_encode($pid) . " Successfully";
$this->message = $message;
}
} }
<?php return array ( <?php return array (
'code-comparer' => 'App\\Http\\Livewire\\CodeComparer', 'code-comparer' => 'App\\Http\\Livewire\\CodeComparer',
'delete-item-modal' => 'App\\Http\\Livewire\\DeleteItemModal',
'delete-modal' => 'App\\Http\\Livewire\\DeleteModal', 'delete-modal' => 'App\\Http\\Livewire\\DeleteModal',
'main-container' => 'App\\Http\\Livewire\\MainContainer', 'main-container' => 'App\\Http\\Livewire\\MainContainer',
'navbar' => 'App\\Http\\Livewire\\Navbar', 'navbar' => 'App\\Http\\Livewire\\Navbar',
......
<div x-data="{ showModal: @entangle('showModal') }">
<template x-if="showModal">
<div class="fixed inset-0 z-[100] flex flex-col items-center justify-center overflow-hidden px-4 py-6 sm:px-5"
@keydown.window.escape="showModal = false">
<div class="absolute inset-0 bg-slate-900/60 transition-opacity duration-300"
@click="showModal = false"></div>
<div class="relative p-4 max-w-lg rounded-lg bg-white px-4 py-10 text-center transition-opacity duration-300 dark:bg-navy-700 sm:px-5">
<svg xmlns="http://www.w3.org/2000/svg"
class="inline h-28 w-28 text-error" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z">
</path>
</svg>
<div class="mt-4 mx-5">
<h2 class="text-2xl text-slate-700 dark:text-navy-100">
Are you sure <br> you want to delete this item?
</h2>
<p class="mt-2"></p>
<button @click="showModal = false"
class="btn mt-6 bg-[#6a6e69] font-medium text-white hover:bg-[#313430] focus:bg-[#313430]-focus active:bg-[#313430]-focus/90">
Close
</button>
<button @click="$wire.emit('deleteSubItem', {{ $deleteId }}) ; showModal = false"
class="btn mt-6 bg-error font-medium text-white hover:bg-error-focus focus:bg-error-focus active:bg-error-focus/90">
Confirm
</button>
</div>
</div>
</div>
</template>
</div>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</div> </div>
</div> </div>
<div x-show="isOpenEditCode" class="fixed inset-0 z-50 bg-gray-800 bg-opacity-75 overflow-auto"> <div x-show="isOpenEditCode" class="fixed inset-0 z-50 bg-gray-800 bg-opacity-75 overflow-auto">
<div class="bg-white rounded-lg w-4/5 mx-auto mt-10 mb-10"> <div class="bg-white rounded-lg w-4/5 mx-auto mt-10 mb-10 pb-4">
<style> <style>
code[class*="language-"], code[class*="language-"],
pre[class*="language-"] { pre[class*="language-"] {
...@@ -31,8 +31,10 @@ ...@@ -31,8 +31,10 @@
color: #155724; color: #155724;
} }
</style> </style>
<div class="flex w-full justify-between rounded-t-lg bg-slate-100 px-4 py-3 dark:bg-navy-800 sm:px-5"> <div class="flex w-full justify-between rounded-t-lg bg-slate-100 px-4 py-3 dark:bg-navy-800 sm:px-5">
<h3 class="text-base font-medium text-slate-700 dark:text-navy-100">Edit Code</h3> <h3 class="text-base font-medium text-slate-700 dark:text-navy-100">Edit Code</h3>
<button type="button" @click="isOpenEditCode = false" <button type="button" @click="isOpenEditCode = false"
class="btn -mr-1.5 h-7 w-7 rounded-full p-0 hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25"> class="btn -mr-1.5 h-7 w-7 rounded-full p-0 hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4.5 w-4.5" fill="none" viewBox="0 0 24 24" <svg xmlns="http://www.w3.org/2000/svg" class="h-4.5 w-4.5" fill="none" viewBox="0 0 24 24"
...@@ -41,6 +43,8 @@ ...@@ -41,6 +43,8 @@
</svg> </svg>
</button> </button>
</div> </div>
<button type="button" wire:click="showDeleteItemModal('{{ $patchFileId }}')"
class="bg-error hover:bg-error-focus text-white font-bold py-2 px-4 rounded mx-2 my-2">remove</button>
<div class="flex" x-data="{ gitCode: @entangle('gitCode') }" style="max-height: 70vh; overflow-y: auto;"> <div class="flex" x-data="{ gitCode: @entangle('gitCode') }" style="max-height: 70vh; overflow-y: auto;">
<div class="w-1/2 p-4"> <div class="w-1/2 p-4">
<h3 class="text-lg font-semibold">GitLab Code:</h3> <h3 class="text-lg font-semibold">GitLab Code:</h3>
...@@ -53,17 +57,18 @@ ...@@ -53,17 +57,18 @@
<div class="w-1/2 p-4"> <div class="w-1/2 p-4">
<h3 class="text-lg font-semibold">Your Code:</h3> <h3 class="text-lg font-semibold">Your Code:</h3>
<textarea wire:model.defer="dbCode" rows="20" class="w-full p-2 border rounded language-none" <textarea wire:model.defer="dbCode" rows="20" class="w-full p-2 border rounded language-none"
placeholder="Paste your code here..." style="max-height: 60vh; overflow-y: auto;"></textarea> placeholder="Paste your code here..." style="max-height: 60vh; overflow-y: auto;"></textarea>
<button wire:click="compare" id="compare" <button wire:click="compare" id="compare"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-2">Compare</button> class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-2">Compare</button>
</div> </div>
</div> </div>
<div class="mx-3 mb-3"> <div class="mx-3 mb-3">
<h3 class="text-lg font-semibold mt-4">Differences:</h3> <h3 class="text-lg font-semibold mt-4">Differences:</h3>
<div class="overflow-auto p-2 bg-gray-100 rounded" style="max-height: 30vh;"> <div class="overflow-auto p-2 bg-gray-100 rounded" style="max-height: 30vh;">
<pre class="line-numbers"> <code >{!! $diffResult !!}</code></pre> <pre class="line-numbers"> <code >{!! $diffResult !!}</code></pre>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
...@@ -176,5 +176,6 @@ ...@@ -176,5 +176,6 @@
</div> </div>
</div> </div>
<livewire:pages.patch.modal-edit-code> <livewire:pages.patch.modal-edit-code>
<livewire:delete-item-modal />
</div> </div>
</div> </div>
...@@ -133,6 +133,10 @@ ...@@ -133,6 +133,10 @@
class="btn h-8 w-8 p-0 text-info hover:bg-info/20 focus:bg-info/20 active:bg-info/25"> class="btn h-8 w-8 p-0 text-info hover:bg-info/20 focus:bg-info/20 active:bg-info/25">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
</a> </a>
<a wire:click="showDeleteModal({{ $patch->PID }})"
class="btn h-8 w-8 p-0 text-info hover:bg-info/20 focus:bg-info/20 active:bg-info/25">
<i class="fa fa-trash"></i>
</a>
</div> </div>
</td> </td>
</tr> </tr>
......
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