with pagination
This commit is contained in:
@@ -4,7 +4,9 @@ namespace mpba\Modules\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use mpba\Modules\Support\DatabaseModuleRegistry;
|
||||
|
||||
@@ -14,10 +16,47 @@ class ModuleControlController extends Controller
|
||||
protected DatabaseModuleRegistry $registry,
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$search = trim((string) $request->query('search', ''));
|
||||
$perPage = 4;
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
|
||||
$allModules = $this->registry->all();
|
||||
|
||||
$filteredModules = $search === ''
|
||||
? $allModules
|
||||
: $allModules->filter(function (array $module) use ($search): bool {
|
||||
$haystack = implode(' ', array_filter([
|
||||
$module['name'] ?? null,
|
||||
$module['alias'] ?? null,
|
||||
$module['description'] ?? null,
|
||||
$module['disk_description'] ?? null,
|
||||
$module['version'] ?? null,
|
||||
$module['database_version'] ?? null,
|
||||
$module['disk_version'] ?? null,
|
||||
$module['path'] ?? null,
|
||||
]));
|
||||
|
||||
return Str::contains(Str::lower($haystack), Str::lower($search));
|
||||
})->values();
|
||||
|
||||
$modules = new LengthAwarePaginator(
|
||||
$filteredModules->forPage($page, $perPage)->values(),
|
||||
$filteredModules->count(),
|
||||
$perPage,
|
||||
$page,
|
||||
[
|
||||
'path' => $request->url(),
|
||||
'query' => $request->query(),
|
||||
]
|
||||
);
|
||||
|
||||
return view('modules-control::index', [
|
||||
'modules' => $this->registry->all(),
|
||||
'modules' => $modules,
|
||||
'allModules' => $allModules,
|
||||
'filteredCount' => $filteredModules->count(),
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/>
|
||||
|
||||
@php
|
||||
$enabledCount = $modules->where('enabled', true)->count();
|
||||
$disabledCount = $modules->count() - $enabledCount;
|
||||
$enabledCount = $allModules->where('enabled', true)->count();
|
||||
$disabledCount = $allModules->count() - $enabledCount;
|
||||
@endphp
|
||||
|
||||
<div class="space-y-6">
|
||||
@@ -20,7 +20,7 @@
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
<div class="rounded-2xl border border-zinc-200 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
|
||||
<div class="text-xs font-semibold uppercase tracking-wide text-zinc-500">Installed</div>
|
||||
<div class="mt-2 text-3xl font-bold text-zinc-900 dark:text-zinc-100">{{ $modules->count() }}</div>
|
||||
<div class="mt-2 text-3xl font-bold text-zinc-900 dark:text-zinc-100">{{ $allModules->count() }}</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-zinc-200 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
|
||||
@@ -34,14 +34,35 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-4 rounded-2xl border border-zinc-200 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900 md:flex-row md:items-center md:justify-between">
|
||||
<div class="flex flex-col gap-4 rounded-2xl border border-zinc-200 bg-white p-5 shadow-sm dark:border-zinc-800 dark:bg-zinc-900 xl:flex-row xl:items-end xl:justify-between">
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-zinc-900 dark:text-zinc-100">Installed modules</h2>
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">
|
||||
Enabled state, sort order, and custom descriptions are stored only in the database.
|
||||
Enabled state, sort order, custom descriptions, and version numbers are stored only in the database.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
<form method="GET" action="{{ route('modules.control.index') }}" class="flex flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<label for="module-search" class="sr-only">Search modules</label>
|
||||
<input
|
||||
id="module-search"
|
||||
type="search"
|
||||
name="search"
|
||||
value="{{ $search }}"
|
||||
placeholder="Search modules..."
|
||||
class="w-full rounded-xl border border-zinc-300 bg-white px-4 py-2 text-sm text-zinc-900 placeholder:text-zinc-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-100 dark:placeholder:text-zinc-500 sm:w-72"
|
||||
/>
|
||||
<button type="submit" class="rounded-xl border border-blue-500/40 bg-blue-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500/30">
|
||||
Search
|
||||
</button>
|
||||
@if ($search !== '')
|
||||
<a href="{{ route('modules.control.index') }}" class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-800 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-100 dark:hover:bg-zinc-800">
|
||||
Clear
|
||||
</a>
|
||||
@endif
|
||||
</form>
|
||||
|
||||
<form method="POST" action="{{ route('modules.control.sync') }}">
|
||||
@csrf
|
||||
<button type="submit" class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-800 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-100 dark:hover:bg-zinc-800">
|
||||
@@ -49,6 +70,17 @@
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1 text-sm text-zinc-500 dark:text-zinc-400 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
Showing {{ $modules->firstItem() ?? 0 }}-{{ $modules->lastItem() ?? 0 }} of {{ $modules->total() }} modules.
|
||||
@if ($search !== '')
|
||||
Search: <span class="font-semibold text-zinc-800 dark:text-zinc-200">{{ $search }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div>4 modules per page</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 xl:grid-cols-2">
|
||||
@forelse ($modules as $module)
|
||||
@@ -148,5 +180,11 @@
|
||||
</div>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
@if ($modules->hasPages())
|
||||
<div class="rounded-2xl border border-zinc-200 bg-white p-4 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
|
||||
{{ $modules->links() }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</x-layouts.app>
|
||||
|
||||
Reference in New Issue
Block a user