diff --git a/app/Http/Controllers/admin/package/IPMapping.php b/app/Http/Controllers/admin/package/IPMapping.php index df1a347..f397d25 100644 --- a/app/Http/Controllers/admin/package/IPMapping.php +++ b/app/Http/Controllers/admin/package/IPMapping.php @@ -4,21 +4,17 @@ namespace App\Http\Controllers\admin\package; use App\Http\Controllers\Controller; use App\Http\Requests\Package\IPRequest; -use App\Models\ModuleDatacenter; -use App\Models\ModuleHost; -use App\Models\ModuleIpAddress; -use App\Models\ModuleNetwork; -use App\Models\vCenter; use App\Repositories\Module\IpAddress\IpAddressRepositoryInterface; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Validator; +use Yajra\DataTables\Facades\DataTables; class IPMapping extends Controller { public function __construct( public IpAddressRepositoryInterface $ipAddressRepository - ) {} + ) { + } public function index(Request $request) { $listIP = $this->ipAddressRepository->filter( @@ -102,7 +98,7 @@ class IPMapping extends Controller $ipaddress = $this->ipAddressRepository->findWithRelationships($id, ['host.datacenter.vCenter']); - if (! $ipaddress) { + if (!$ipaddress) { return back()->withErrors('Can\'t find IP Address by ID #' . $id); } @@ -116,7 +112,7 @@ class IPMapping extends Controller { $ipaddress = $this->ipAddressRepository->find($id); - if (! $ipaddress) { + if (!$ipaddress) { return back()->withErrors('Can\'t find IP Address by ID #' . $id); } @@ -142,9 +138,9 @@ class IPMapping extends Controller public function destroy(int $id = 0) { - $ipaddress = $this->ipAddressRepository->find($id); + $ipaddress = $this->ipAddressRepository->find($id); - if (! $ipaddress) { + if (!$ipaddress) { return back()->withErrors('Can\'t find IP Address by ID #' . $id); } @@ -158,4 +154,28 @@ class IPMapping extends Controller } return back()->with('success', 'Deleted Successfully'); } + + public function datatable(Request $request) + { + $query = $this->ipAddressRepository->filter( + $request->all(), + ['host.datacenter.vCenter'], + [], + ['*'], + true + ); + + return DataTables::eloquent($query) + ->addColumn( + 'action', + fn($d) => + 'Edit' + ) + ->filterColumn('host.datacenter.v_center.host', function ($query, $keyword) { + $query->whereHas('host.datacenter.vCenter', function ($q) use ($keyword) { + $q->where('host', 'like', "%{$keyword}%"); + }); + }) + ->make(true); + } } diff --git a/app/Http/Controllers/admin/package/OsVersion.php b/app/Http/Controllers/admin/package/OsVersion.php index cd14c29..b99955a 100644 --- a/app/Http/Controllers/admin/package/OsVersion.php +++ b/app/Http/Controllers/admin/package/OsVersion.php @@ -122,18 +122,10 @@ class OsVersion extends Controller return $d->getStatus(); }) ->addColumn('action', function ($d) { - $editBtn = ' - - '; - - $deleteBtn = ''; - - return '
' . $editBtn . $deleteBtn . '
'; + return view('administrator.pages.package.version.datatable.action', [ + 'id' => $d->id, + 'version' => $d->version + ])->render(); }) ->filterColumn('host', function ($query, $keyword) { $query->whereHas('host', function ($q) use ($keyword) { diff --git a/app/Repositories/Module/IpAddress/IpAddressCachedRepository.php b/app/Repositories/Module/IpAddress/IpAddressCachedRepository.php index 4f18ad1..49a19fd 100644 --- a/app/Repositories/Module/IpAddress/IpAddressCachedRepository.php +++ b/app/Repositories/Module/IpAddress/IpAddressCachedRepository.php @@ -16,19 +16,32 @@ class IpAddressCachedRepository extends BaseCachedRepository implements IpAddres { return $this->ipAddressRepository->getModel(); } - public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*']) - { + public function filter( + array $data = [], + array $relationships = [], + array $withCount = [], + array $select = ['*'], + bool $returnQuery = false + ) { + if ( + $returnQuery || + !empty($data['paginate']) + ) { + return $this->ipAddressRepository + ->filter($data, $relationships, $withCount, $select, $returnQuery); + } + $cacheKey = $this->getCacheKey(md5(json_encode([ - 'filterItem' => [ - 'data' => $data, - 'relationships' => $relationships, - 'select' => $select, - 'withCount' => $withCount - ] + 'filter' => compact('data', 'relationships', 'withCount', 'select') ]))); - return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) { - return $this->ipAddressRepository->filter($data, $relationships, $withCount, $select); - }); + + return Cache::remember( + $cacheKey, + $this->cacheTime, + fn() => + $this->ipAddressRepository + ->filter($data, $relationships, $withCount, $select, $returnQuery) + ); } public function updateBy(array $condistions = [], array $data = []) { @@ -36,7 +49,7 @@ class IpAddressCachedRepository extends BaseCachedRepository implements IpAddres $this->clearCache(); return $this; } - public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []) + public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []) { $cacheKey = $this->getCacheKey(md5(json_encode([ 'findWithRelationships' => [ @@ -44,8 +57,8 @@ class IpAddressCachedRepository extends BaseCachedRepository implements IpAddres 'relationships' => $relationships ] ]))); - return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) { - return $this->ipAddressRepository->findWithRelationships($id, $relationships,$withCount,$withSum); + return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $withSum) { + return $this->ipAddressRepository->findWithRelationships($id, $relationships, $withCount, $withSum); }); } public function findBy(string $key = '', string|int|null $value = '') diff --git a/app/Repositories/Module/IpAddress/IpAddressRepository.php b/app/Repositories/Module/IpAddress/IpAddressRepository.php index a02a694..1bc48ee 100644 --- a/app/Repositories/Module/IpAddress/IpAddressRepository.php +++ b/app/Repositories/Module/IpAddress/IpAddressRepository.php @@ -11,23 +11,30 @@ class IpAddressRepository extends BaseRepository implements IpAddressRepositoryI { return ModuleIpAddress::class; } - public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*']) + public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false) { - $model = $this->model->with($relationships)->select($select); + $query = $this->model->with($relationships)->select($select); if (isset($data['status'])) { - $model = $model->where("status", $data['status']); + $query = $query->where("status", $data['status']); } if (isset($data['module_network_id']) && $data['module_network_id']) { - $model = $model->where("module_network_id", $data['module_network_id']); + $query->where("module_network_id", $data['module_network_id']); } if (count($withCount) > 0) { - $model = $model->withCount($withCount); + $query->withCount($withCount); } - if (isset($data['page'])) { - return $model->paginate(15); + if ($returnQuery) { + return $query; } - return $model->get(); + + if (!empty($data['paginate'])) { + return $query->paginate( + $data['per_page'] ?? 15 + ); + } + + return $query->get(); } public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []) { diff --git a/app/Repositories/Module/IpAddress/IpAddressRepositoryInterface.php b/app/Repositories/Module/IpAddress/IpAddressRepositoryInterface.php index 3091793..11b8f38 100644 --- a/app/Repositories/Module/IpAddress/IpAddressRepositoryInterface.php +++ b/app/Repositories/Module/IpAddress/IpAddressRepositoryInterface.php @@ -6,9 +6,15 @@ use App\Repositories\BaseRepositoryInterface; interface IpAddressRepositoryInterface extends BaseRepositoryInterface { - public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*']); + public function filter( + array $data = [], + array $relationships = [], + array $withCount = [], + array $select = ['*'], + bool $returnQuery = false + ); public function updateBy(array $condistions = [], array $data = []); - public function findBy(string $key = '',string|int|null $value = '' ); - public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []); + public function findBy(string $key = '', string|int|null $value = ''); + public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []); } diff --git a/resources/views/administrator/pages/block/Group.blade.php b/resources/views/administrator/pages/block/Group.blade.php index eaad5b7..18fc314 100644 --- a/resources/views/administrator/pages/block/Group.blade.php +++ b/resources/views/administrator/pages/block/Group.blade.php @@ -1,10 +1,9 @@ - - Add New Group -
+Add + Group + @csrf - + Import From Excel
- File Import Demo +File Import + Demo diff --git a/resources/views/administrator/pages/package/group/add.blade.php b/resources/views/administrator/pages/package/group/add.blade.php index 3f90976..8f25f8f 100644 --- a/resources/views/administrator/pages/package/group/add.blade.php +++ b/resources/views/administrator/pages/package/group/add.blade.php @@ -1,118 +1,110 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush - -@php - use App\Enums\Status; -@endphp - -@section('breadcrumb') + @section('breadcrumb') + @php + $breadcrumbItems = [ + ['label' => 'Modules'], + ['label' => 'Package vCenter'], + ['label' => 'OS Group', 'url' => route('package.group.index')], + ['label' => 'Edit', 'active' => true] + ]; + @endphp + + @endsection @php - $breadcrumbItems = [ - ['label' => 'Modules'], - ['label' => 'Package vCenter'], - ['label' => 'OS Group'], - ['label' => 'Add New', 'active' => true], - ]; + use App\Enums\Status; @endphp - -@endsection -@section('content') - @if (auth()->guard('admins')->user()->can('add package module')) -
-
- @csrf -
-
-
- {{-- Name --}} -
- -
- + + @section('content') + @if (auth()->guard('admins')->user()->can('add package module')) +
+ + @csrf +
+
+
+ {{-- Name --}} +
+ +
+ +
-
- {{-- Thumbnail --}} -
- -
-
-
- -
-
- + {{-- Thumbnail --}} +
+ +
+
+
+ +
+
+ +
-
- - - - {{-- Status --}} -
- -
- + + + + {{-- Status --}} +
+ +
+ +
-
- - -
- @else -
-
Access Denied - You are not assigned to any Module Package - management department
-
- @endif -@endsection -@push('scripts') - -@endpush - -@push('plugin-scripts') - - - - -@endpush + + @endpush + + @push('plugin-scripts') + @foreach (config('assets.datatable.js') as $datatable) + + @endforeach + @endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/group/edit.blade.php b/resources/views/administrator/pages/package/group/edit.blade.php index 7ce17e1..39df21c 100644 --- a/resources/views/administrator/pages/package/group/edit.blade.php +++ b/resources/views/administrator/pages/package/group/edit.blade.php @@ -1,22 +1,24 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush - -@php - use App\Enums\Status; -@endphp - @section('breadcrumb') @php $breadcrumbItems = [ ['label' => 'Modules'], ['label' => 'Package vCenter'], - ['label' => 'OS Group', 'active' => true], + ['label' => 'OS Group', 'url' => route('package.group.index')], + ['label' => 'Edit', 'active' => true] ]; @endphp @endsection +@php + use App\Enums\Status; +@endphp + @section('content') @if (auth()->guard('admins')->user()->can('add package module'))
@@ -30,8 +32,8 @@
- +
{{-- Thumbnail --}} @@ -87,11 +89,11 @@ @endsection @push('scripts') @endpush @push('plugin-scripts') - - - - + @foreach (config('assets.datatable.js') as $datatable) + + @endforeach @endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/group/index.blade.php b/resources/views/administrator/pages/package/group/index.blade.php index c292a99..599ccd6 100644 --- a/resources/views/administrator/pages/package/group/index.blade.php +++ b/resources/views/administrator/pages/package/group/index.blade.php @@ -1,32 +1,33 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush - @section('breadcrumb') @php - $breadcrumbItems = [ - ['label' => 'Modules'], - ['label' => 'Package vCenter'], - ['label' => 'OS Group', 'active' => true], - ]; +$breadcrumbItems = [ + ['label' => 'Modules'], + ['label' => 'Package vCenter'], + ['label' => 'OS Group', 'active' => true], +]; @endphp @endsection @section('content') @if (auth()->guard('admins')->user()->can('manager package module'))
-
+
@include('administrator.pages.block.Group')
+ ['key' => 'name', 'label' => 'Name'], + ['key' => 'thumbnail', 'label' => 'Thumbnail'], + ['key' => 'module_host_id', 'label' => 'Host'], + ['key' => 'status', 'label' => 'Status'], + ['key' => 'action', 'label' => 'Action'], + ]" />
@else @@ -41,4 +42,4 @@ -@endpush +@endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/ipaddress/index.blade.php b/resources/views/administrator/pages/package/ipaddress/index.blade.php index 92e5adc..50685c3 100644 --- a/resources/views/administrator/pages/package/ipaddress/index.blade.php +++ b/resources/views/administrator/pages/package/ipaddress/index.blade.php @@ -1,18 +1,15 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush - -@php - use App\Enums\Status; -@endphp - @section('breadcrumb') @php $breadcrumbItems = [ ['label' => 'Modules'], ['label' => 'Package vCenter'], - ['label' => 'Datacenter', 'active' => true], + ['label' => 'IP Address', 'active' => true], ]; @endphp @@ -20,74 +17,16 @@ @section('content') @if(auth()->guard('admins')->user()->can("manager package module"))
-
- - Add New IP Address - +
+ Add + IP Address
- - - - - - - - - - - - - - @if($listIP->count()) - @foreach($listIP->all() as $item) - - - - - - - - - - @endforeach - @endif - -
- - VMWare NameIP AddressHost NameStatus
- - - {{ $item->vm_name }} - - {{ $item->ip }} - - {{ $item->Host->name }} - - {!! $item->getStatus() !!} - - - - - -
- @method('delete') - @csrf - -
-
-
-
@else @@ -99,9 +38,7 @@ @endsection @push('plugin-scripts') - - - - -@endpush - + @foreach (config('assets.datatable.js') as $datatable) + + @endforeach +@endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/version/add.blade.php b/resources/views/administrator/pages/package/version/add.blade.php index 8ffc7ab..6de2544 100644 --- a/resources/views/administrator/pages/package/version/add.blade.php +++ b/resources/views/administrator/pages/package/version/add.blade.php @@ -1,22 +1,25 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush -@php - use App\Enums\Status; -@endphp - @section('breadcrumb') @php $breadcrumbItems = [ ['label' => 'Modules'], ['label' => 'Package vCenter'], - ['label' => 'Os Version', 'active' => true], + ['label' => 'Version', 'url' => route('package.version.index')], + ['label' => 'Add Version', 'active' => true], ]; @endphp @endsection + +@php + use App\Enums\Status; +@endphp @section('content') @if (auth()->guard('admins')->user()->can('add package module'))
@@ -49,7 +52,7 @@
- @foreach(Status::getOptions() as $value => $label)
- + Cancel
@csrf @method('DELETE') - + Confirm Delete
@@ -40,10 +34,10 @@ @push('custom-scripts') -@endpush +@endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/version/edit.blade.php b/resources/views/administrator/pages/package/version/edit.blade.php index e354a66..d95886d 100644 --- a/resources/views/administrator/pages/package/version/edit.blade.php +++ b/resources/views/administrator/pages/package/version/edit.blade.php @@ -1,6 +1,8 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush @php @@ -12,7 +14,8 @@ $breadcrumbItems = [ ['label' => 'Modules'], ['label' => 'Package vCenter'], - ['label' => 'Datacenter', 'active' => true], + ['label' => 'Version', 'url' => route('package.version.index')], + ['label' => 'Edit Version', 'active' => true], ]; @endphp @@ -78,12 +81,12 @@ @push('scripts') - - - -@endpush + @foreach (config('assets.datatable.js') as $datatable) + + @endforeach +@endpush \ No newline at end of file diff --git a/resources/views/administrator/pages/package/version/index.blade.php b/resources/views/administrator/pages/package/version/index.blade.php index 56fbd56..3bbd7d2 100644 --- a/resources/views/administrator/pages/package/version/index.blade.php +++ b/resources/views/administrator/pages/package/version/index.blade.php @@ -1,6 +1,8 @@ @extends('administrator.layout.master') @push('plugin-styles') - + @foreach (config('assets.datatable.css') as $datatable) + + @endforeach @endpush @section('breadcrumb') @@ -8,7 +10,7 @@ $breadcrumbItems = [ ['label' => 'Modules'], ['label' => 'Package vCenter'], - ['label' => 'Datacenter', 'active' => true], + ['label' => 'Version', 'active' => true], ]; @endphp @@ -16,10 +18,9 @@ @section('content') @if (auth()->guard('admins')->user()->can('manager package module'))
-
- - Add New Version OS - +
+ Add + Version OS
-
Access Denied - You are not assigned to any Module Package +
Access Denied - You are not assigned to any Module + Package management department
@endif @@ -43,27 +45,9 @@ @include('administrator.pages.package.version.datatable.modal') @endsection -@push('scripts') - -@endpush @push('plugin-scripts') - - - - -@endpush + @foreach (config('assets.datatable.js') as $datatable) + + @endforeach +@endpush \ No newline at end of file diff --git a/resources/views/components/button-c-r-m.blade.php b/resources/views/components/button-c-r-m.blade.php index 2878eb1..2c12882 100644 --- a/resources/views/components/button-c-r-m.blade.php +++ b/resources/views/components/button-c-r-m.blade.php @@ -1,41 +1,41 @@ @php - $tag = 'button'; - $href = null; +$tag = 'button'; +$href = null; - if ($route) { - $href = route($route, $params); - $tag = 'a'; - } elseif ($url) { - $href = $url; - $tag = 'a'; - } elseif ($attributes->has('href')) { - $href = $attributes->get('href'); - $tag = 'a'; - } +if ($route) { + $href = route($route, $params); + $tag = 'a'; +} elseif ($url) { + $href = $url; + $tag = 'a'; +} elseif ($attributes->has('href')) { + $href = $attributes->get('href'); + $tag = 'a'; +} - $baseClasses = 'd-inline-flex gap-2 align-items-center justify-content-center text-white border-0 shadow-md px-2 py-1 rounded-2'; +$baseClasses = 'd-inline-flex gap-2 align-items-center justify-content-center text-white border-0 shadow-md px-2 py-1 rounded-2'; - $variants = [ - 'primary' => 'bg-primary', - 'secondary' => 'bg-secondary', - 'outline' => 'bg-outline', - 'ghost' => 'bg-ghost', - 'link' => 'bg-link', - 'danger' => 'bg-danger', - 'destructive' => 'bg-destructive', - ]; +$variants = [ + 'primary' => 'bg-primary', + 'secondary' => 'bg-secondary', + 'outline' => 'bg-outline', + 'ghost' => 'bg-ghost', + 'link' => 'bg-link', + 'danger' => 'bg-danger', + 'destructive' => 'bg-destructive', +]; - $sizes = [ - 'default' => 'h-10', - 'sm' => 'h-6', - 'lg' => 'h-12', - 'icon' => 'h-10', - ]; +$sizes = [ + 'default' => 'h-10', + 'sm' => 'h-6', + 'lg' => 'h-12', + 'icon' => 'h-10', +]; - $variantClass = $variants[$variant] ?? $variants['primary']; - $sizeClass = $sizes[$size] ?? $sizes['default']; +$variantClass = $variants[$variant] ?? $variants['primary']; +$sizeClass = $sizes[$size] ?? $sizes['default']; - $classes = "{$baseClasses} {$variantClass} {$sizeClass}"; +$classes = "{$baseClasses} {$variantClass} {$sizeClass}"; @endphp @if($tag === 'a') @@ -48,7 +48,7 @@ @else diff --git a/resources/views/components/module/v-center.blade.php b/resources/views/components/module/v-center.blade.php index 2e97b3e..8502ba5 100644 --- a/resources/views/components/module/v-center.blade.php +++ b/resources/views/components/module/v-center.blade.php @@ -24,54 +24,45 @@ @push('custom-scripts') -@endpush - - +@endpush \ No newline at end of file diff --git a/routes/admin.php b/routes/admin.php index a2cf27d..bb107a3 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -318,6 +318,7 @@ Route::prefix('administrator')->group(function () { Route::get('edit/{id}', 'edit')->name('edit'); Route::put('edit/{id}', 'update')->name('update'); Route::delete('remove-ip-address/{id}', 'destroy')->name('destroy'); + Route::get('datatable', 'datatable')->name('datatable'); });