dashboard and menu layouts
This commit is contained in:
@@ -4,6 +4,8 @@ namespace Modules\Administration\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\Audit\Models\AuditLog;
|
||||
use Modules\Media\Models\Media;
|
||||
@@ -18,21 +20,63 @@ final class DashboardController extends Controller
|
||||
'roleCount' => Schema::hasTable('roles') ? Role::count() : 0,
|
||||
'mediaCount' => Schema::hasTable('media') ? Media::count() : 0,
|
||||
'auditCount' => Schema::hasTable('audit_logs') ? AuditLog::count() : 0,
|
||||
'recentAudit' => Schema::hasTable('audit_logs') ? AuditLog::query()->latest('created_at')->limit(8)->get() : collect(),
|
||||
'recentAudit' => $this->recentAudit(),
|
||||
'modules' => $this->modules(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function modules(): array
|
||||
private function recentAudit(): LengthAwarePaginator
|
||||
{
|
||||
if (! Schema::hasTable('audit_logs')) {
|
||||
return new LengthAwarePaginator(
|
||||
items: [],
|
||||
total: 0,
|
||||
perPage: 8,
|
||||
currentPage: Paginator::resolveCurrentPage('audit_page'),
|
||||
options: [
|
||||
'path' => request()->url(),
|
||||
'pageName' => 'audit_page',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return AuditLog::query()
|
||||
->latest('created_at')
|
||||
->paginate(8, ['*'], 'audit_page')
|
||||
->withQueryString();
|
||||
}
|
||||
|
||||
private function modules(): LengthAwarePaginator
|
||||
{
|
||||
$statuses = json_decode((string) file_get_contents(base_path('modules_statuses.json')), true) ?: [];
|
||||
$modules = [];
|
||||
|
||||
foreach (glob(base_path('Modules/*/module.json')) ?: [] as $manifest) {
|
||||
$data = json_decode((string) file_get_contents($manifest), true) ?: [];
|
||||
$name = $data['name'] ?? basename(dirname($manifest));
|
||||
$modules[] = ['name' => $name, 'version' => $data['version'] ?? '1.0.0', 'enabled' => (bool) ($statuses[$name] ?? false)];
|
||||
|
||||
$modules[] = [
|
||||
'name' => $name,
|
||||
'version' => $data['version'] ?? '1.0.0',
|
||||
'enabled' => (bool) ($statuses[$name] ?? false),
|
||||
];
|
||||
}
|
||||
usort($modules, fn ($a, $b) => strcasecmp($a['name'], $b['name']));
|
||||
return $modules;
|
||||
|
||||
usort($modules, fn (array $a, array $b): int => strcasecmp($a['name'], $b['name']));
|
||||
|
||||
$pageName = 'modules_page';
|
||||
$perPage = 8;
|
||||
$currentPage = Paginator::resolveCurrentPage($pageName);
|
||||
|
||||
return (new LengthAwarePaginator(
|
||||
items: array_slice($modules, ($currentPage - 1) * $perPage, $perPage),
|
||||
total: count($modules),
|
||||
perPage: $perPage,
|
||||
currentPage: $currentPage,
|
||||
options: [
|
||||
'path' => request()->url(),
|
||||
'pageName' => $pageName,
|
||||
],
|
||||
))->withQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user