Commit e6b07722 authored by Sarun Mungthanya's avatar Sarun Mungthanya
Browse files

add delete list

parent 847d61cc
......@@ -6,7 +6,7 @@ use Livewire\Component;
class MainContainer extends Component
{
public $currentContent = 'SendMultiPatch';
public $currentContent = 'DeleteMultiPatch';
public $loading = false;
public $pagePaginate = 1;
......
......@@ -6,7 +6,7 @@ use Livewire\Component;
class Navbar extends Component
{
public $currentMenu = 'Patch';
public $currentMenu = 'DeleteMultiPatch';
public function loadContent($menu)
{
......
<?php
namespace App\Http\Livewire\Pages\SendPatch;
use App\Models\ConfServerLicense;
use App\Models\ConfServerPendding;
use App\Models\ConfSmartupdate;
use Livewire\Component;
use Livewire\WithPagination;
class DeleteMultiPatch extends Component
{
public $serverkey = '', $showSearch, $searchInProgress, $results, $selectedPatches = [];
public function selectResult($key)
{
$this->serverkey = $key;
$this->results = [];
$this->showSearch = false;
$this->emit('updateServerkey', $key);
}
public function updatedServerkey()
{
$this->showSearch = true;
if ($this->searchInProgress) {
$this->reset('results');
}
$this->searchInProgress = true;
$this->results = ConfServerLicense::where('SNKEY', 'LIKE', '%' . $this->serverkey . '%')->take(50)->get();
$this->searchInProgress = false;
}
public function render()
{
return view('livewire.pages.send-patch.delete-multi-patch', [
'selectedPatches' => ConfSmartUpdate::whereIn('PID', $this->selectedPatches)->get()
]);
}
}
<?php
namespace App\Http\Livewire\Pages\SendPatch;
use Livewire\Component;
class DeleteMultiPatchBox extends Component
{
protected $listeners = ['updateSelectedPatches'];
public $selectedPatches = [];
public $selectedPatchName = [];
public $serverkey = '', $showSearch = false, $searchInProgress, $reponseMessages = [];
public $showProgressModal = false;
public $results = [];
public function mount($selectedPatches)
{
$this->selectedPatches = $selectedPatches;
}
public function updateSelectedPatches($patchId, $allSelectPatchName)
{
if (is_array($patchId)) {
$this->selectedPatches = $patchId;
$this->selectedPatchName = $allSelectPatchName;
} else {
if (in_array($patchId, $this->selectedPatches)) {
$key = array_search($patchId, $this->selectedPatches);
if ($key !== false) {
unset($this->selectedPatches[$key]);
unset($this->allSelectPatchName[$key]);
}
} else {
$this->selectedPatches[] = $patchId;
$this->selectedPatchName[] = $allSelectPatchName;
}
}
}
public function render()
{
return view('livewire.pages.send-patch.delete-multi-patch-box');
}
}
<?php
namespace App\Http\Livewire\Pages\SendPatch;
use App\Models\ConfServerLicense;
use App\Models\ConfServerPendding;
use App\Models\ConfSmartupdate;
use Livewire\Component;
use Livewire\WithPagination;
class DeleteMultiPatchList extends Component
{
use WithPagination;
public $serverkey = '';
public $searchBy, $serverId, $editPid, $message, $keyword, $perPage = 10, $searchSelected = 'PID';
public $selectedPatches = [];
protected $listeners = ['updateServerkey'];
public function mount()
{
$this->searchBy = [
'PID' => 'PID',
'PATCHNAME' => 'Patch Name',
'PDESC' => 'Description',
'MAJOR_VERSION' => 'Major Vaersion',
'Remark' => 'Remark'
];
// $this->selectedPatches = [];
}
public function search()
{
$this->resetPage();
}
public function updateServerkey($serverkey)
{
$serverLicense = ConfServerLicense::where("SNKEY", $serverkey)->first();
if (isset($serverLicense)) {
$this->serverId = $serverLicense->ID;
}
$this->render();
}
public function render()
{
$query = ConfServerPendding::select('PID', 'PATCHNAME', 'PDESC', 'PDATE', 'PLEVEL', 'Remark', 'MAJOR_VERSION')
->join('conf_smartupdate', 'conf_smartupdate.PID', '=', 'conf_server_pendding.PatchID')
->where('conf_server_pendding.ServerID', $this->serverId);
if ($this->searchSelected && $this->keyword) {
$query->where($this->searchSelected, 'LIKE', '%' . $this->keyword . '%');
}
$query->orderBy('PID', 'DESC');
$results = $query->paginate($this->perPage);
return view('livewire.pages.send-patch.delete-multi-patch-list', [
'results' => $results
]);
}
}
......@@ -27,7 +27,7 @@ class SendMultiPatchList extends Component
];
$this->selectedPatches = [];
$this->dispatchBrowserEvent('grandchild-component-loaded');
// $this->dispatchBrowserEvent('grandchild-component-loaded');
}
public function search()
......
......@@ -14,6 +14,9 @@
'pages.patch.patch-edit' => 'App\\Http\\Livewire\\Pages\\Patch\\PatchEdit',
'pages.patch.patch-index' => 'App\\Http\\Livewire\\Pages\\Patch\\PatchIndex',
'pages.role.role-index' => 'App\\Http\\Livewire\\Pages\\Role\\RoleIndex',
'pages.send-patch.delete-multi-patch' => 'App\\Http\\Livewire\\Pages\\SendPatch\\DeleteMultiPatch',
'pages.send-patch.delete-multi-patch-box' => 'App\\Http\\Livewire\\Pages\\SendPatch\\DeleteMultiPatchBox',
'pages.send-patch.delete-multi-patch-list' => 'App\\Http\\Livewire\\Pages\\SendPatch\\DeleteMultiPatchList',
'pages.send-patch.send-multi-patch-box' => 'App\\Http\\Livewire\\Pages\\SendPatch\\SendMultiPatchBox',
'pages.send-patch.send-multi-patch-list' => 'App\\Http\\Livewire\\Pages\\SendPatch\\SendMultiPatchList',
'pages.send-patch.send-patch' => 'App\\Http\\Livewire\\Pages\\SendPatch\\SendPatch',
......
......@@ -20,6 +20,8 @@
<livewire:pages.send-patch.send-patch />
@elseif ($currentContent === 'SendMultiPatch')
<livewire:pages.send-patch.send-multi-patch-list />
@elseif ($currentContent === 'DeleteMultiPatch')
<livewire:pages.send-patch.delete-multi-patch />
@elseif ($currentContent === 'Patch')
<livewire:pages.patch.patch-index />
@elseif ($currentContent === 'Parameter')
......@@ -30,4 +32,9 @@
@livewire('code-comparer')
@endif
</div>
<script>
// document.addEventListener('livewire:load', function () {
// $(".card").html("dddd")
// });
</script>
</div>
......@@ -28,6 +28,8 @@
class="block px-4 py-2 text-gray-700 hover:bg-stone-100">Send Patch</a></li>
<li><a href="#" wire:click.prevent="loadContent('SendMultiPatch')"
class="block px-4 py-2 text-gray-700 hover:bg-stone-100">Send Multi Patch</a></li>
<li><a href="#" wire:click.prevent="loadContent('DeleteMultiPatch')"
class="block px-4 py-2 text-gray-700 hover:bg-stone-100">Delete Multi Patch</a></li>
</ul>
</li>
......
<div>
{{-- The whole world belongs to you. --}}
</div>
<div x-data=" {
selectedPatch: [],
selectedPatchByPage: {},
allSelectPatches: [],
allSelectPatchName: [],
currentPage: @entangle('page'), // Bind currentPage to Livewire 'page' variable
init() {
this.$watch('currentPage', (value) => {
this.loadSelectedPatch();
this.resetCheckAllCheckbox();
});
// this.$watch('selectedPatch.length', () => {
// this.resetCheckAllCheckbox();
// });
this.loadSelectedPatch();
},
toggleAllCheckboxes(event) {
const checkboxes = document.querySelectorAll('.individual-checkbox');
const isChecked = event.target.checked;
checkboxes.forEach(checkbox => {
checkbox.checked = isChecked;
// Livewire.emit('updateSelectedPatches', checkbox.value);
const patchName = checkbox.getAttribute('data-patchname');
this.updatePatchSelection(checkbox.value, patchName, isChecked);
});
this.updateSelectedPatchList();
},
updateSelectedPatch(event) {
const patchName = event.target.getAttribute('data-patchname');
this.updatePatchSelection(event.target.value, patchName, event.target.checked);
this.updateSelectedPatchList();
},
updatePatchSelection(patch, patchName, isSelected) {
const pagePatches = this.selectedPatchByPage[this.currentPage] || [];
console.log(this.allSelectPatches)
console.log(this.allSelectPatchName)
if (isSelected) {
if (!pagePatches.includes(patch)) {
pagePatches.push(patch);
this.allSelectPatches.push(patch);
this.allSelectPatchName.push(patchName);
}
} else {
const indexPage = pagePatches.indexOf(patch);
const indexAll = this.allSelectPatches.indexOf(patch);
if (indexPage !== -1) {
pagePatches.splice(indexPage, 1);
}
if (indexAll !== -1) {
this.allSelectPatches.splice(indexAll, 1);
this.allSelectPatchName.splice(indexAll, 1);
}
}
Livewire.emit('updateSelectedPatches', this.allSelectPatches, this.allSelectPatchName);
this.selectedPatchByPage[this.currentPage] = pagePatches;
},
updateSelectedPatchList() {
this.selectedPatch = Object.values(this.selectedPatchByPage).flat();
},
loadSelectedPatch() {
const pagePatches = this.selectedPatchByPage[this.currentPage] || [];
const checkboxes = document.querySelectorAll('.individual-checkbox');
checkboxes.forEach(checkbox => {
checkbox.checked = pagePatches.includes(checkbox.value);
});
this.updateSelectedPatchList();
},
resetCheckAllCheckbox() {
const checkAllCheckbox = document.getElementById('check-all');
const pagePatches = this.selectedPatchByPage[this.currentPage] || [];
const checkboxes = document.querySelectorAll('.individual-checkbox');
checkAllCheckbox.checked = checkboxes.length > 0 && pagePatches.length === checkboxes
.length;
}
}" x-init="$watch('selectedPatch', () => resetCheckAllCheckbox())" class="min-w-[2rem]">
<div class="w-full md:w-2/3 px-3 mb-6">
<div class="p-6 bg-white shadow-md rounded-lg">
<div x-show="true" class="">
<div class="flex justify-between mb-5">
<h2 class="font-medium tracking-wide text-slate-700 line-clamp-1 dark:text-navy-100 lg:text-base">
Patch List
</h2>
<div class="inline-flex flex-initial">
<div x-data="{ isInputActive: true }">
<div class="flex gap-4 px-5 items-center">
<button @click="isInputActive = !isInputActive"
class="btn h-8 w-14 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" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
<span class="w-64" x-show="isInputActive === true">
<input
class="form-input h-9 peer w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
placeholder="Search Keyword" type="text" wire:model.defer="keyword" />
</span>
<span class="w-52" x-show="isInputActive === true">
<select wire:model.defer="searchSelected"
class="form-select h-9 w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent">
@foreach ($searchBy as $key => $by)
<option value="{{ $key }}">{{ $by }}</option>
@endforeach
</select>
</span>
<button type="button" class="bg-stone-700 text-white px-4 py-2 rounded"
wire:click="search">Search</button>
</div>
</div>
</div>
</div>
<div class="mx-3 mt-3 px-4">
<div class="is-scrollbar-hidden min-w-full table-responsive">
<table class="is-hoverable table w-full text-left">
<thead>
<tr>
<th
class="whitespace-nowrap rounded-tl-lg bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">
<input
class="form-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary hover: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" id="check-all" @click="toggleAllCheckboxes" />
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Patch ID
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Patch Name
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Description
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Server
</th>
<th
class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Date
</th>
<th
class="whitespace-nowrap rounded-tr-lg bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
Remark
</th>
</tr>
</thead>
<tbody>
@foreach ($results as $patch)
<tr class="border-y border-transparent border-b-slate-200 dark:border-b-navy-500">
<td class="whitespace-nowrap px-4 py-3 sm:px-5">
<label class="inline-flex items-center space-x-2">
<input
class="form-checkbox individual-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary hover: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" @click="updateSelectedPatch"
value="{{ $patch->PID }}"
data-patchname = "{{ $patch->PATCHNAME }}" />
</label>
</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $patch->PID }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2" data-id="{{ $patch->PID }}">
{{ \Illuminate\Support\Str::limit($patch->PATCHNAME, 40) }}
</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">
{{ \Illuminate\Support\Str::limit($patch->PDESC, 40) }}</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $patch->server }}
</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $patch->PDATE }}
</td>
<td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $patch->Remark }}
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="justify-center flex">
<span wire:loading >
<svg class="animate-spin h-16 w-16 text-primary m-2 " xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.964 7.964 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
</span>
</div>
</div>
<livewire:delete-modal />
{{ $results->links('livewire.paginate-custom') }}
</div>
</div>
</div>
</div>
</div>
<div class="w-full px-3 mb-6">
<div class="p-6 bg-white rounded-lg relative">
<div class="flex flex-col items-center">
<div class="flex flex-row justify-items-start self-start ">
<h5 class="flex justify-self-center items-center mx-2 ml-4">Serverkey</h5>
<div class="flex flex-col">
<input type="text"
class="form-input h-9 peer w-64 rounded-lg border border-slate-300 bg-transparent px-3 py-2 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
wire:model.debounce.500ms="serverkey" placeholder="Search for a server key">
@if (!empty($serverkey) && $showSearch)
<ul
class="z-50 border border-gray-200 top-14 rounded-md max-h-64 w-64 overflow-auto absolute bg-white mt-1">
@forelse($results as $result)
<li class="p-2 hover:bg-gray-100 cursor-pointer"
wire:click="selectResult('{{ $result->SNKEY }}')">
{{ $result->SNKEY }}
</li>
@empty
<li class="p-2 text-gray-500">No results found</li>
@endforelse
</ul>
@endif
</div>
<span wire:loading>
<svg class="animate-spin h-5 w-5 text-primary m-2" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.964 7.964 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
</span>
</div>
</div>
<livewire:pages.send-patch.delete-multi-patch-list :serverkey="$serverkey" :results="$results" />
<livewire:pages.send-patch.delete-multi-patch-box :selectedPatches="$selectedPatches" />
</div>
</div>
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