update os group
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum Status: int
|
||||||
|
{
|
||||||
|
case DEACTIVE = 0;
|
||||||
|
case ACTIVE = 1;
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::DEACTIVE => 'Không hoạt động',
|
||||||
|
self::ACTIVE => 'Hoạt động',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function badge(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::DEACTIVE => '<span class="badge badge-danger">Không hoạt động</span>',
|
||||||
|
self::ACTIVE => '<span class="badge badge-success">Hoạt động</span>',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::DEACTIVE->value => self::DEACTIVE->label(),
|
||||||
|
self::ACTIVE->value => self::ACTIVE->label(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ use Illuminate\Support\Facades\DB;
|
|||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
|
||||||
class Group extends Controller
|
class Group extends Controller
|
||||||
{
|
{
|
||||||
@@ -33,7 +34,7 @@ class Group extends Controller
|
|||||||
);
|
);
|
||||||
$title = 'List all group Os for all datastore';
|
$title = 'List all group Os for all datastore';
|
||||||
|
|
||||||
return view('admin.package.group.index', compact('group', 'title'));
|
return view('administrator.pages.package.group.index', compact('group', 'title'));
|
||||||
}
|
}
|
||||||
public function import(Request $request)
|
public function import(Request $request)
|
||||||
{
|
{
|
||||||
@@ -73,7 +74,7 @@ class Group extends Controller
|
|||||||
{
|
{
|
||||||
$title = 'Add new Group OS';
|
$title = 'Add new Group OS';
|
||||||
|
|
||||||
return view('admin.package.group.add', compact('title'));
|
return view('administrator.pages.package.group.add', compact('title'));
|
||||||
}
|
}
|
||||||
public function store(OsGroupRequest $request)
|
public function store(OsGroupRequest $request)
|
||||||
{
|
{
|
||||||
@@ -98,7 +99,7 @@ class Group extends Controller
|
|||||||
}
|
}
|
||||||
$title = 'Edit Group OS';
|
$title = 'Edit Group OS';
|
||||||
|
|
||||||
return view('admin.package.group.edit', compact('title', 'group'));
|
return view('administrator.pages.package.group.edit', compact('title', 'group'));
|
||||||
}
|
}
|
||||||
public function update(int $id = 0, OsGroupRequest $request)
|
public function update(int $id = 0, OsGroupRequest $request)
|
||||||
{
|
{
|
||||||
@@ -134,4 +135,50 @@ class Group extends Controller
|
|||||||
|
|
||||||
return redirect()->route('package.group.index')->with('success', 'Delete Group success');
|
return redirect()->route('package.group.index')->with('success', 'Delete Group success');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function datatable(Request $request)
|
||||||
|
{
|
||||||
|
$query = $this->osGroupRepository->filter(
|
||||||
|
$request->all(),
|
||||||
|
['host'],
|
||||||
|
[],
|
||||||
|
['*'],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return DataTables::eloquent($query)
|
||||||
|
->editColumn('thumbnail', function ($d) {
|
||||||
|
if (!$d->thumbnail) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<img src="' . $d->thumbnail . '"
|
||||||
|
alt="' . e($d->name) . '"
|
||||||
|
width="50" height="50"
|
||||||
|
style="object-fit: cover; border-radius: 6px;">';
|
||||||
|
})
|
||||||
|
->editColumn('module_host_id', function ($d) {
|
||||||
|
if ($d->host) {
|
||||||
|
return $d->host->name . ' (Host ID: ' . $d->host->host_id . ')';
|
||||||
|
}
|
||||||
|
return '-';
|
||||||
|
})
|
||||||
|
->editColumn('status', function ($d) {
|
||||||
|
return $d->getStatus();
|
||||||
|
})
|
||||||
|
->addColumn('action', function ($d) {
|
||||||
|
return '<a href="' . route('package.group.edit', $d->id) . '"
|
||||||
|
class="btn btn-primary btn-sm">
|
||||||
|
Edit
|
||||||
|
</a>';
|
||||||
|
})
|
||||||
|
->filterColumn('host', function ($query, $keyword) {
|
||||||
|
$query->whereHas('host', function ($q) use ($keyword) {
|
||||||
|
$q->where('host', 'like', "%{$keyword}%");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->rawColumns(['thumbnail', 'action', 'status'])
|
||||||
|
->make(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ class OsVersion extends Controller
|
|||||||
], ['osGroup.host']);
|
], ['osGroup.host']);
|
||||||
$title = 'List all Version OS';
|
$title = 'List all Version OS';
|
||||||
|
|
||||||
return view('admin.package.version.index', compact('versions', 'title'));
|
return view('administrator.pages.package.version.index', compact('versions', 'title'));
|
||||||
}
|
}
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$title = 'Add new Version Os';
|
$title = 'Add new Version Os';
|
||||||
|
|
||||||
return view('admin.package.version.add', compact('title'));
|
return view('administrator.pages.package.version.add', compact('title'));
|
||||||
}
|
}
|
||||||
public function store(OsVersionRequest $request)
|
public function store(OsVersionRequest $request)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ class OsVersion extends Controller
|
|||||||
|
|
||||||
$title = "Edit version OS";
|
$title = "Edit version OS";
|
||||||
|
|
||||||
return view('admin.package.version.edit', compact('title', 'version'));
|
return view('administrator.pages.package.version.edit', compact('title', 'version'));
|
||||||
}
|
}
|
||||||
public function update(int $id = 0, OsVersionRequest $request)
|
public function update(int $id = 0, OsVersionRequest $request)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,21 +15,34 @@ class OsGroupCachedRepository extends BaseCachedRepository implements OsGroupRep
|
|||||||
{
|
{
|
||||||
return $this->osGroupRepository->getModel();
|
return $this->osGroupRepository->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->osGroupRepository
|
||||||
|
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||||
|
}
|
||||||
|
|
||||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||||
'filterItem' => [
|
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||||
'data' => $data,
|
|
||||||
'relationships' => $relationships,
|
|
||||||
'select' => $select,
|
|
||||||
'withCount' => $withCount
|
|
||||||
]
|
|
||||||
])));
|
])));
|
||||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
|
|
||||||
return $this->osGroupRepository->filter($data, $relationships, $withCount, $select);
|
return Cache::remember(
|
||||||
});
|
$cacheKey,
|
||||||
|
$this->cacheTime,
|
||||||
|
fn() =>
|
||||||
|
$this->osGroupRepository
|
||||||
|
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
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([
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||||
'findWithRelationships' => [
|
'findWithRelationships' => [
|
||||||
@@ -37,8 +50,8 @@ class OsGroupCachedRepository extends BaseCachedRepository implements OsGroupRep
|
|||||||
'relationships' => $relationships
|
'relationships' => $relationships
|
||||||
]
|
]
|
||||||
])));
|
])));
|
||||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $withSum) {
|
||||||
return $this->osGroupRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
return $this->osGroupRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,20 +11,36 @@ class OsGroupRepository extends BaseRepository implements OsGroupRepositoryInter
|
|||||||
{
|
{
|
||||||
return OsGroup::class;
|
return OsGroup::class;
|
||||||
}
|
}
|
||||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
public function filter(
|
||||||
{
|
array $data = [],
|
||||||
$model = $this->model->with($relationships)->select($select);
|
array $relationships = [],
|
||||||
|
array $withCount = [],
|
||||||
|
array $select = ['*'],
|
||||||
|
bool $returnQuery = false
|
||||||
|
) {
|
||||||
|
$query = $this->model
|
||||||
|
->select($select)
|
||||||
|
->with($relationships);
|
||||||
|
|
||||||
if (isset($data['status'])) {
|
if (!empty($data['module_host_id'])) {
|
||||||
$model = $model->where("status", $data['status']);
|
$query->where('module_host_id', $data['module_host_id']);
|
||||||
}
|
}
|
||||||
if (count($withCount) > 0) {
|
|
||||||
$model = $model->withCount($withCount);
|
if (!empty($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 = [])
|
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,15 @@ namespace App\Repositories\OsGroup;
|
|||||||
|
|
||||||
use App\Repositories\BaseRepositoryInterface;
|
use App\Repositories\BaseRepositoryInterface;
|
||||||
|
|
||||||
interface OsGroupRepositoryInterface extends BaseRepositoryInterface{
|
interface OsGroupRepositoryInterface extends BaseRepositoryInterface
|
||||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
{
|
||||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []);
|
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 = []);
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ return new class extends Migration
|
|||||||
$table->id()->autoIncrement();
|
$table->id()->autoIncrement();
|
||||||
$table->string('name')->nullable();
|
$table->string('name')->nullable();
|
||||||
$table->string('thumbnail')->nullable();
|
$table->string('thumbnail')->nullable();
|
||||||
$table->bigInteger('module_host_id')->default(0)->index();
|
$table->foreignId('module_host_id')->constrained('module_host')->index()->nullable();
|
||||||
$table->tinyInteger('status')->default(1);
|
$table->tinyInteger('status')->default(1);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,79 +1,32 @@
|
|||||||
@php use App\Http\Helpers\Helper; @endphp
|
@extends('administrator.layout.master')
|
||||||
@extends('admin.main')
|
@push('plugin-styles')
|
||||||
|
<link href="{{ asset('build/plugins/select2/select2.min.css') }}" rel="stylesheet" />
|
||||||
|
@endpush
|
||||||
|
|
||||||
|
@section('breadcrumb')
|
||||||
|
@php
|
||||||
|
$breadcrumbItems = [
|
||||||
|
['label' => 'Modules'],
|
||||||
|
['label' => 'Package vCenter'],
|
||||||
|
['label' => 'Datacenter', 'active' => true],
|
||||||
|
];
|
||||||
|
@endphp
|
||||||
|
<x-breabcrumb :items="$breadcrumbItems" />
|
||||||
|
@endsection
|
||||||
@section('content')
|
@section('content')
|
||||||
@if(auth()->guard('admins')->user()->can("manager package module"))
|
@if (auth()->guard('admins')->user()->can('manager package module'))
|
||||||
<div class="card card-primary card-outline">
|
<div class="card card-primary card-outline">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
@include("admin.block.Group")
|
@include('administrator.pages.block.Group')
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-invoice table-bordered">
|
<x-datatable id="groupTable" ajax="{{ route('package.group.datatable') }}" :columns="[
|
||||||
<thead>
|
['key' => 'name', 'label' => 'Name'],
|
||||||
<tr>
|
['key' => 'thumbnail', 'label' => 'Thumbnail'],
|
||||||
<th>
|
['key' => 'module_host_id', 'label' => 'Host'],
|
||||||
<label>
|
['key' => 'status', 'label' => 'Status'],
|
||||||
<input type="checkbox" name="check" class="check-all">
|
['key' => 'action', 'label' => 'Action'],
|
||||||
</label>
|
]" />
|
||||||
</th>
|
|
||||||
<th>Group Name</th>
|
|
||||||
<th>Thumbnail</th>
|
|
||||||
<th>Host Name</th>
|
|
||||||
<th>Status</th>
|
|
||||||
<th style="width: 40px"></th>
|
|
||||||
<th style="width: 40px"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@if($group->count())
|
|
||||||
@foreach($group->all() as $item)
|
|
||||||
<tr>
|
|
||||||
<td class="text-center">
|
|
||||||
<label for=""></label><input type="checkbox" name="id[]" value="{{ $item->id }}"
|
|
||||||
id="">
|
|
||||||
</td>
|
|
||||||
<td class="text-center">
|
|
||||||
{{ $item->name }}
|
|
||||||
</td>
|
|
||||||
<td class="text-center">
|
|
||||||
<img
|
|
||||||
style="height: 60px"
|
|
||||||
src="{{ $item->thumbnail ?? "" }}"
|
|
||||||
alt="{{ $item->name }}">
|
|
||||||
</td>
|
|
||||||
<td class="text-center">
|
|
||||||
@isset( $item->host->name)
|
|
||||||
{{$item->host->name}}
|
|
||||||
@endisset
|
|
||||||
</td>
|
|
||||||
<td class="text-center">
|
|
||||||
{!! $item->getStatus() !!}
|
|
||||||
</td>
|
|
||||||
<td class="text-center">
|
|
||||||
<a class="btn btn-warning btn-sm"
|
|
||||||
href="{{ route('package.group.edit',['id' => $item->id]) }}">
|
|
||||||
<i class="fas fa-user-edit"></i>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td class="text-center">
|
|
||||||
<form method="post"
|
|
||||||
class="d-inline"
|
|
||||||
action="{{ route('package.group.destroy',['id' => $item->id]) }}">
|
|
||||||
@method('delete')
|
|
||||||
@csrf
|
|
||||||
<button type="submit" data-toggle="tooltip" data-placement="top" title=""
|
|
||||||
class="btn btn-sm btn-danger" data-original-title="Xoá">
|
|
||||||
<i class="fas fa-trash"></i>
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
@endif
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
{{ $group->withQueryString()->links() }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
@@ -83,3 +36,9 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@endsection
|
@endsection
|
||||||
|
@push('plugin-scripts')
|
||||||
|
<script src="{{ asset('build/plugins/jquery/jquery.min.js') }}"></script>
|
||||||
|
<script src="{{ asset('build/plugins/select2/select2.min.js') }}"></script>
|
||||||
|
<script src="{{ asset('build/plugins/datatables.net/dataTables.min.js') }}"></script>
|
||||||
|
<script src="{{ asset('build/plugins/datatables.net-bs5/dataTables.bootstrap5.min.js') }}"></script>
|
||||||
|
@endpush
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ Route::prefix('administrator')->group(function () {
|
|||||||
Route::get('edit/{id}', 'edit')->name('edit');
|
Route::get('edit/{id}', 'edit')->name('edit');
|
||||||
Route::put('edit-group/{id}', 'update')->name('update');
|
Route::put('edit-group/{id}', 'update')->name('update');
|
||||||
Route::delete('remove-group/{id}', 'destroy')->name('destroy');
|
Route::delete('remove-group/{id}', 'destroy')->name('destroy');
|
||||||
|
Route::get('datatable', 'datatable')->name('datatable');
|
||||||
});
|
});
|
||||||
Route::group([
|
Route::group([
|
||||||
'prefix' => 'version',
|
'prefix' => 'version',
|
||||||
|
|||||||
Reference in New Issue
Block a user