diff --git a/app/Http/Controllers/admin/package/OsVersion.php b/app/Http/Controllers/admin/package/OsVersion.php
index 8013224..fc29410 100644
--- a/app/Http/Controllers/admin/package/OsVersion.php
+++ b/app/Http/Controllers/admin/package/OsVersion.php
@@ -15,6 +15,7 @@ use App\Repositories\Os\OsRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
+use Yajra\DataTables\Facades\DataTables;
class OsVersion extends Controller
{
@@ -39,10 +40,10 @@ class OsVersion extends Controller
public function store(OsVersionRequest $request)
{
$validatedData = $request->validated();
-
+
// Remove unnecessary fields
unset($validatedData['vcenter_id'], $validatedData['module_datacenter_id']);
-
+
DB::beginTransaction();
try {
$this->osRepository->create($validatedData);
@@ -55,14 +56,11 @@ class OsVersion extends Controller
}
public function edit(int $id = 0)
{
-
-
$version = $this->osRepository->findWithRelationships($id, ['osGroup.host.datacenter.vCenter']);
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $id);
}
-
$title = "Edit version OS";
return view('administrator.pages.package.version.edit', compact('title', 'version'));
@@ -73,12 +71,12 @@ class OsVersion extends Controller
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $id);
}
-
+
$validatedData = $request->validated();
-
+
// Remove unnecessary fields
unset($validatedData['vcenter_id'], $validatedData['module_datacenter_id']);
-
+
DB::beginTransaction();
try {
$this->osRepository->update($id, $validatedData);
@@ -106,4 +104,36 @@ class OsVersion extends Controller
return back()->with('success', 'Delete success');
}
+
+ public function datatable(Request $request)
+ {
+ $query = $this->osRepository->filter(
+ [],
+ ['osGroup'],
+ [],
+ ['*'],
+ true
+ );
+
+ return DataTables::eloquent($query)
+ ->editColumn('os_group', function ($d) {
+ return $d->osGroup ? $d->osGroup->name . ' - ' . $d->osGroup->host->name : '';
+ })
+ ->editColumn('status', function ($d) {
+ return $d->getStatus();
+ })
+ ->addColumn('action', function ($d) {
+ return '
+ Edit
+ ';
+ })
+ ->filterColumn('host', function ($query, $keyword) {
+ $query->whereHas('host', function ($q) use ($keyword) {
+ $q->where('host', 'like', "%{$keyword}%");
+ });
+ })
+ ->rawColumns(['action', 'status'])
+ ->make(true);
+ }
}
diff --git a/app/Repositories/Os/OsCachedRepository.php b/app/Repositories/Os/OsCachedRepository.php
index 4d1d45a..031d37a 100644
--- a/app/Repositories/Os/OsCachedRepository.php
+++ b/app/Repositories/Os/OsCachedRepository.php
@@ -15,19 +15,32 @@ class OsCachedRepository extends BaseCachedRepository implements OsRepositoryInt
{
return $this->osRepository->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->osRepository
+ ->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->osRepository->filter($data, $relationships, $withCount, $select);
- });
+
+ return Cache::remember(
+ $cacheKey,
+ $this->cacheTime,
+ fn() =>
+ $this->osRepository
+ ->filter($data, $relationships, $withCount, $select, $returnQuery)
+ );
}
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
{
diff --git a/app/Repositories/Os/OsRepository.php b/app/Repositories/Os/OsRepository.php
index 97e18af..f9fb884 100644
--- a/app/Repositories/Os/OsRepository.php
+++ b/app/Repositories/Os/OsRepository.php
@@ -11,34 +11,36 @@ class OsRepository extends BaseRepository implements OsRepositoryInterface
{
return Os::class;
}
- public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
- {
- $model = $this->model->with($relationships)->select($select);
-
- // Apply filters from $data
- if (isset($data['os_id'])) {
- $model = $model->where('os_group_id', $data['os_id']);
+ public function filter(
+ array $data = [],
+ array $relationships = [],
+ array $withCount = [],
+ array $select = ['*'],
+ bool $returnQuery = false
+ ) {
+ $query = $this->model
+ ->select($select)
+ ->with($relationships);
+
+ if (!empty($data['module_host_id'])) {
+ $query->where('module_host_id', $data['module_host_id']);
}
-
- if (isset($data['os_group_id'])) {
- $model = $model->where('os_group_id', $data['os_group_id']);
+
+ if (!empty($withCount)) {
+ $query->withCount($withCount);
}
-
- if (isset($data['module_host_id'])) {
- $model = $model->where('module_host_id', $data['module_host_id']);
+
+ if ($returnQuery) {
+ return $query;
}
-
- if (isset($data['status'])) {
- $model = $model->where('status', $data['status']);
+
+ if (!empty($data['paginate'])) {
+ return $query->paginate(
+ $data['per_page'] ?? 15
+ );
}
-
- if (count($withCount) > 0) {
- $model = $model->withCount($withCount);
- }
- if(isset($data['page'])) {
- return $model->paginate(15);
- }
- return $model->get();
+
+ return $query->get();
}
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
{
diff --git a/app/Repositories/Os/OsRepositoryInterface.php b/app/Repositories/Os/OsRepositoryInterface.php
index d2faf81..f957fc5 100644
--- a/app/Repositories/Os/OsRepositoryInterface.php
+++ b/app/Repositories/Os/OsRepositoryInterface.php
@@ -5,7 +5,13 @@ namespace App\Repositories\Os;
use App\Repositories\BaseRepositoryInterface;
interface OsRepositoryInterface 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 findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []);
}
\ No newline at end of file
diff --git a/app/View/Components/Breabcrumb.php b/app/View/Components/AdminBreadcrumb.php
similarity index 80%
rename from app/View/Components/Breabcrumb.php
rename to app/View/Components/AdminBreadcrumb.php
index da186b0..0853bff 100644
--- a/app/View/Components/Breabcrumb.php
+++ b/app/View/Components/AdminBreadcrumb.php
@@ -6,7 +6,7 @@ use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
-class Breabcrumb extends Component
+class AdminBreadcrumb extends Component
{
/**
* Create a new component instance.
@@ -21,6 +21,6 @@ class Breabcrumb extends Component
*/
public function render(): View|Closure|string
{
- return view('components.breabcrumb');
+ return view('components.admin-breadcrumb');
}
}
diff --git a/database/migrations/2024_02_02_395629_os.php b/database/migrations/2024_02_02_395629_os.php
index fe36563..5cc5643 100644
--- a/database/migrations/2024_02_02_395629_os.php
+++ b/database/migrations/2024_02_02_395629_os.php
@@ -13,12 +13,10 @@ return new class extends Migration {
public function up()
{
Schema::create('os', function (Blueprint $table) {
- $table->id()->autoIncrement();
+ $table->id();
$table->string('version', 100)->nullable();
- $table->string('os_id', 100)->nullable();
- $table->integer('os_group_id')->index()->default(0);
+ $table->foreignId('os_group_id')->constrained('os_group')->index();
$table->string('template_id')->nullable();
- $table->integer('module_host_id')->index()->default(0);
$table->tinyInteger('status')->default(1);
$table->timestamps();
});
diff --git a/resources/views/administrator/pages/package/datacenter/add.blade.php b/resources/views/administrator/pages/package/datacenter/add.blade.php
index d65362f..9532b70 100644
--- a/resources/views/administrator/pages/package/datacenter/add.blade.php
+++ b/resources/views/administrator/pages/package/datacenter/add.blade.php
@@ -10,7 +10,7 @@
['label' => 'Datacenter', 'active' => true],
];
@endphp
-
| - - | -Version | -Group Name | -Host Location | -Status | -- | - |
|---|---|---|---|---|---|---|
| - - | -- {{ $item->version }} - | -- @isset($item->osGroup->name) - {{$item->osGroup->name}} - @endisset - | -- @isset($item->osGroup->host->name) - {{$item->osGroup->host->name}} - @endisset - | -- {!! $item->getStatus() !!} - | -- - - - | -- - | -