mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +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;
|
||||
|
||||
Reference in New Issue
Block a user