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 = []);
|
||||
}
|
||||
Reference in New Issue
Block a user