mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-19 00:01:00 +08:00
add filament dashboard
This commit is contained in:
29
app/Filament/Custom/Widgets/StatTable.php
Normal file
29
app/Filament/Custom/Widgets/StatTable.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Custom\Widgets;
|
||||
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Widgets\Widget;
|
||||
|
||||
class StatTable extends Widget
|
||||
{
|
||||
protected static string $view = 'filament.widgets.stat-table';
|
||||
|
||||
protected function getHeader(): string
|
||||
{
|
||||
return nulll;
|
||||
}
|
||||
|
||||
protected function getTableRows(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getViewData(): array
|
||||
{
|
||||
return [
|
||||
'header' => $this->getHeader(),
|
||||
'data' => $this->getTableRows(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,8 @@ class UserResource extends Resource
|
||||
'index' => Pages\ListUsers::route('/'),
|
||||
'create' => Pages\CreateUser::route('/create'),
|
||||
// 'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||
'view' => Pages\ViewUser::route('/{record}'),
|
||||
// 'view' => Pages\ViewUser::route('/{record}'),
|
||||
'view' => Pages\UserProfile::route('/{record}'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\User\UserResource\Pages;
|
||||
|
||||
use App\Filament\Resources\User\UserResource;
|
||||
use Filament\Resources\Pages\Page;
|
||||
|
||||
class UserProfile extends Page
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.user.user-resource.pages.user-profile';
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class LatestTorrents extends BaseWidget
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
Tables\Columns\TextColumn::make('name')->limit(40),
|
||||
Tables\Columns\TextColumn::make('name')->limit(30),
|
||||
Tables\Columns\TextColumn::make('user.username'),
|
||||
Tables\Columns\TextColumn::make('size')->formatStateUsing(fn ($state) => mksize($state)),
|
||||
Tables\Columns\TextColumn::make('added')->dateTime(),
|
||||
|
||||
26
app/Filament/Widgets/SystemInfo.php
Normal file
26
app/Filament/Widgets/SystemInfo.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Custom\Widgets\StatTable;
|
||||
use App\Repositories\DashboardRepository;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class SystemInfo extends StatTable
|
||||
{
|
||||
protected static ?int $sort = 1000;
|
||||
|
||||
protected function getHeader(): string
|
||||
{
|
||||
return nexus_trans('dashboard.system_info.page_title');
|
||||
}
|
||||
|
||||
protected function getTableRows(): array
|
||||
{
|
||||
$dashboardRep = new DashboardRepository();
|
||||
|
||||
return $dashboardRep->getSystemInfo();
|
||||
}
|
||||
|
||||
}
|
||||
26
app/Filament/Widgets/TorrentStat.php
Normal file
26
app/Filament/Widgets/TorrentStat.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Custom\Widgets\StatTable;
|
||||
use App\Repositories\DashboardRepository;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class TorrentStat extends StatTable
|
||||
{
|
||||
protected static ?int $sort = 102;
|
||||
|
||||
protected function getHeader(): string
|
||||
{
|
||||
return nexus_trans('dashboard.torrent.page_title');
|
||||
}
|
||||
|
||||
protected function getTableRows(): array
|
||||
{
|
||||
$dashboardRep = new DashboardRepository();
|
||||
|
||||
return $dashboardRep->statTorrents();
|
||||
}
|
||||
|
||||
}
|
||||
26
app/Filament/Widgets/UserClassStat.php
Normal file
26
app/Filament/Widgets/UserClassStat.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Custom\Widgets\StatTable;
|
||||
use App\Repositories\DashboardRepository;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class UserClassStat extends StatTable
|
||||
{
|
||||
protected static ?int $sort = 101;
|
||||
|
||||
protected function getHeader(): string
|
||||
{
|
||||
return nexus_trans('dashboard.user_class.page_title');
|
||||
}
|
||||
|
||||
protected function getTableRows(): array
|
||||
{
|
||||
$dashboardRep = new DashboardRepository();
|
||||
|
||||
return $dashboardRep->statUserClass();
|
||||
}
|
||||
|
||||
}
|
||||
26
app/Filament/Widgets/UserStat.php
Normal file
26
app/Filament/Widgets/UserStat.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Custom\Widgets\StatTable;
|
||||
use App\Repositories\DashboardRepository;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class UserStat extends StatTable
|
||||
{
|
||||
protected static ?int $sort = 100;
|
||||
|
||||
protected function getHeader(): string
|
||||
{
|
||||
return nexus_trans('dashboard.user.page_title');
|
||||
}
|
||||
|
||||
protected function getTableRows(): array
|
||||
{
|
||||
$dashboardRep = new DashboardRepository();
|
||||
|
||||
return $dashboardRep->statUsers();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,6 @@ class EncryptCookies extends Middleware
|
||||
'c_secure_login',
|
||||
'c_secure_ssl',
|
||||
'c_secure_tracker_ssl',
|
||||
|
||||
'c_lang_folder',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,9 +28,8 @@ class Locale
|
||||
{
|
||||
$user = $request->user();
|
||||
if ($user) {
|
||||
$language = $user->language;
|
||||
$locale = self::$languageMaps[$language->site_lang_folder] ?? 'en';
|
||||
do_log("user: {$user->id}, language: {$language->id}, set locale: $locale");
|
||||
$locale = $user->locale;
|
||||
do_log("user: {$user->id}, set locale: $locale");
|
||||
App::setLocale($locale);
|
||||
Carbon::setLocale($locale);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Nexus\Database\NexusDB;
|
||||
@@ -245,7 +246,20 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
|
||||
public function getLocaleAttribute()
|
||||
{
|
||||
return Locale::$languageMaps[$this->language->site_lang_folder] ?? 'en';
|
||||
$log = "";
|
||||
if (IN_NEXUS) {
|
||||
$lang = get_langfolder_cookie();
|
||||
$log .= ", IN_NEXUS, get_langfolder_cookie(): $lang";
|
||||
} else {
|
||||
$lang = Cookie::get('c_lang_folder');
|
||||
$log .= ", Cookie::get(): $lang";
|
||||
}
|
||||
if (!$lang) {
|
||||
$lang = $this->language->site_lang_folder;
|
||||
$log .= ", [NO_DATA], from database: $lang";
|
||||
}
|
||||
do_log($log);
|
||||
return Locale::$languageMaps[$lang] ?? 'en';
|
||||
}
|
||||
|
||||
public function getSiteLangFolderAttribute()
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\Setting;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DashboardRepository extends BaseRepository
|
||||
@@ -32,6 +33,12 @@ class DashboardRepository extends BaseRepository
|
||||
'text' => nexus_trans("dashboard.system_info.$name"),
|
||||
'value' => \Illuminate\Foundation\Application::VERSION,
|
||||
];
|
||||
$name = 'filament_version';
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
'text' => nexus_trans("dashboard.system_info.$name"),
|
||||
'value' => '2.13.11',
|
||||
];
|
||||
$name = 'php_version';
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
@@ -44,12 +51,12 @@ class DashboardRepository extends BaseRepository
|
||||
'text' => nexus_trans("dashboard.system_info.$name"),
|
||||
'value' => DB::select(DB::raw('select version() as info'))[0]->info,
|
||||
];
|
||||
// $name = 'os';
|
||||
// $result[$name] = [
|
||||
// 'name' => $name,
|
||||
// 'text' => nexus_trans("dashboard.system_info.$name"),
|
||||
// 'value' => PHP_OS,
|
||||
// ];
|
||||
$name = 'os';
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
'text' => nexus_trans("dashboard.system_info.$name"),
|
||||
'value' => PHP_OS,
|
||||
];
|
||||
$name = 'server_software';
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
@@ -100,9 +107,9 @@ class DashboardRepository extends BaseRepository
|
||||
break;
|
||||
}
|
||||
$result[$class] = [
|
||||
'class' => $class,
|
||||
'class_text' => $value['text'],
|
||||
'counts' => $userClasses->has($class) ? $userClasses->get($class) : 0,
|
||||
'name' => $class,
|
||||
'text' => $value['text'],
|
||||
'value' => $userClasses->has($class) ? $userClasses->get($class) : 0,
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
|
||||
@@ -46,6 +46,7 @@ return [
|
||||
'os' => 'OS',
|
||||
'server_software' => 'Web software',
|
||||
'load_average' => 'Server load average',
|
||||
'filament_version' => 'Filament version',
|
||||
],
|
||||
'latest_user' => [
|
||||
'page_title' => 'User latest',
|
||||
|
||||
@@ -46,6 +46,7 @@ return [
|
||||
'os' => '操作系统',
|
||||
'server_software' => 'Web 软件',
|
||||
'load_average' => '服务器平均负载',
|
||||
'filament_version' => 'Filament 版本',
|
||||
],
|
||||
'latest_user' => [
|
||||
'page_title' => '最新用户',
|
||||
|
||||
@@ -46,6 +46,7 @@ return [
|
||||
'os' => '操作系統',
|
||||
'server_software' => 'Web 軟件',
|
||||
'load_average' => '服務器平均負載',
|
||||
'filament_version' => 'Filament 版本',
|
||||
],
|
||||
'latest_user' => [
|
||||
'page_title' => '最新用戶',
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<x-filament::page>
|
||||
|
||||
</x-filament::page>
|
||||
40
resources/views/filament/widgets/stat-table.blade.php
Normal file
40
resources/views/filament/widgets/stat-table.blade.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<x-filament::widget>
|
||||
<x-filament::card>
|
||||
<div class="p-2 space-y-2 bg-white rounded-xl shadow">
|
||||
<div class="space-y-2">
|
||||
<div class="px-4 py-2 space-y-4">
|
||||
<div class="flex items-center justify-between gap-8">
|
||||
<h2 class="text-xl font-semibold tracking-tight filament-card-heading">
|
||||
{{$header}}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div aria-hidden="true" class="border-t filament-hr"></div>
|
||||
|
||||
<div>
|
||||
<table class="w-full text-left rtl:text-right divide-y table-auto filament-tables-table">
|
||||
<tbody class="divide-y whitespace-nowrap">
|
||||
@foreach(array_chunk($data, 2) as $chunk)
|
||||
<tr class="filament-tables-row">
|
||||
@foreach($chunk as $item)
|
||||
<th class="filament-tables-cell"><div class="px-4 py-3 filament-tables-text-column">{{$item['text']}}</div></th>
|
||||
<td class="filament-tables-cell"
|
||||
@if($loop->count == 1)
|
||||
colspan="3"
|
||||
@endif
|
||||
>
|
||||
<div class="px-4 py-3 filament-tables-text-column">{{$item['value']}}</div>
|
||||
</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament::card>
|
||||
</x-filament::widget>
|
||||
Reference in New Issue
Block a user