mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-29 08:27:23 +08:00
Introduce filament
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\Widget;
|
||||
|
||||
class AccountInfo extends Widget
|
||||
{
|
||||
protected static string $view = 'filament.widgets.account-info';
|
||||
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Torrent;
|
||||
use Closure;
|
||||
use Filament\Tables;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class LatestTorrents extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected function getTableHeading(): string | Closure | null
|
||||
{
|
||||
return __('dashboard.latest_torrent.page_title');
|
||||
}
|
||||
|
||||
protected function isTablePaginationEnabled(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Torrent::query()->orderBy('id', 'desc')->limit(5);
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
Tables\Columns\TextColumn::make('name')->limit(40),
|
||||
Tables\Columns\TextColumn::make('user.username'),
|
||||
Tables\Columns\TextColumn::make('size')->formatStateUsing(fn ($state) => mksize($state)),
|
||||
Tables\Columns\TextColumn::make('added')->dateTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Filament\Tables;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class LatestUsers extends BaseWidget
|
||||
{
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
protected function getTableHeading(): string | Closure | null
|
||||
{
|
||||
return __('dashboard.latest_user.page_title');
|
||||
}
|
||||
|
||||
protected function isTablePaginationEnabled(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return User::query()->orderBy('id', 'desc')->limit(5);
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
Tables\Columns\TextColumn::make('username'),
|
||||
Tables\Columns\TextColumn::make('email'),
|
||||
Tables\Columns\BadgeColumn::make('status')->colors(['success' => 'confirmed', 'danger' => 'pending']),
|
||||
Tables\Columns\TextColumn::make('added')->dateTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Torrent;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Widgets\LineChartWidget;
|
||||
use Flowframe\Trend\Trend;
|
||||
use Flowframe\Trend\TrendValue;
|
||||
|
||||
class TorrentTrend extends LineChartWidget
|
||||
{
|
||||
protected static ?int $sort = 4;
|
||||
|
||||
protected function getHeading(): ?string
|
||||
{
|
||||
return __('dashboard.torrent_trend.page_title');
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Trend::model(Torrent::class)
|
||||
->dateColumn('added')
|
||||
->between(
|
||||
start: now()->subDays(30),
|
||||
end: now(),
|
||||
)
|
||||
->perDay()
|
||||
->count();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Torrent',
|
||||
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
||||
],
|
||||
],
|
||||
'labels' => $data->map(fn (TrendValue $value) => Carbon::parse($value->date)->format('m-d')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Widgets\LineChartWidget;
|
||||
use Flowframe\Trend\Trend;
|
||||
use Flowframe\Trend\TrendValue;
|
||||
|
||||
class UserTrend extends LineChartWidget
|
||||
{
|
||||
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
protected function getHeading(): ?string
|
||||
{
|
||||
return __('dashboard.user_trend.page_title');
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Trend::model(User::class)
|
||||
->dateColumn('added')
|
||||
->between(
|
||||
start: now()->subDays(30),
|
||||
end: now(),
|
||||
)
|
||||
->perDay()
|
||||
->count();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'User',
|
||||
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
||||
],
|
||||
],
|
||||
'labels' => $data->map(fn (TrendValue $value) => Carbon::parse($value->date)->format('m-d')),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user