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\Validator;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class Group extends Controller
|
||||
{
|
||||
@@ -33,7 +34,7 @@ class Group extends Controller
|
||||
);
|
||||
$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)
|
||||
{
|
||||
@@ -73,7 +74,7 @@ class Group extends Controller
|
||||
{
|
||||
$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)
|
||||
{
|
||||
@@ -98,7 +99,7 @@ class Group extends Controller
|
||||
}
|
||||
$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)
|
||||
{
|
||||
@@ -134,4 +135,50 @@ class Group extends Controller
|
||||
|
||||
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']);
|
||||
$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()
|
||||
{
|
||||
$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)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ class OsVersion extends Controller
|
||||
|
||||
$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)
|
||||
{
|
||||
|
||||
@@ -15,21 +15,34 @@ class OsGroupCachedRepository extends BaseCachedRepository implements OsGroupRep
|
||||
{
|
||||
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([
|
||||
'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->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([
|
||||
'findWithRelationships' => [
|
||||
@@ -37,8 +50,8 @@ class OsGroupCachedRepository extends BaseCachedRepository implements OsGroupRep
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
|
||||
return $this->osGroupRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($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;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['status'])) {
|
||||
$model = $model->where("status", $data['status']);
|
||||
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 (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 = [])
|
||||
{
|
||||
|
||||
@@ -4,8 +4,15 @@ namespace App\Repositories\OsGroup;
|
||||
|
||||
use App\Repositories\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 = []);
|
||||
interface OsGroupRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
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->string('name')->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->timestamps();
|
||||
});
|
||||
|
||||
@@ -1,79 +1,32 @@
|
||||
@php use App\Http\Helpers\Helper; @endphp
|
||||
@extends('admin.main')
|
||||
@extends('administrator.layout.master')
|
||||
@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')
|
||||
@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-header">
|
||||
@include("admin.block.Group")
|
||||
@include('administrator.pages.block.Group')
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-invoice table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<label>
|
||||
<input type="checkbox" name="check" class="check-all">
|
||||
</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() }}
|
||||
<x-datatable id="groupTable" ajax="{{ route('package.group.datatable') }}" :columns="[
|
||||
['key' => 'name', 'label' => 'Name'],
|
||||
['key' => 'thumbnail', 'label' => 'Thumbnail'],
|
||||
['key' => 'module_host_id', 'label' => 'Host'],
|
||||
['key' => 'status', 'label' => 'Status'],
|
||||
['key' => 'action', 'label' => 'Action'],
|
||||
]" />
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
@@ -83,3 +36,9 @@
|
||||
</div>
|
||||
@endif
|
||||
@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::put('edit-group/{id}', 'update')->name('update');
|
||||
Route::delete('remove-group/{id}', 'destroy')->name('destroy');
|
||||
Route::get('datatable', 'datatable')->name('datatable');
|
||||
});
|
||||
Route::group([
|
||||
'prefix' => 'version',
|
||||
|
||||
Reference in New Issue
Block a user