157 lines
5.8 KiB
PHP
157 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\UptimeLab\Admin\Resources;
|
|
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Paymenter\Extensions\Others\UptimeLab\Admin\Resources\UptimeServerResource\Pages;
|
|
use Paymenter\Extensions\Others\UptimeLab\Models\UptimeServer;
|
|
|
|
class UptimeServerResource extends Resource
|
|
{
|
|
protected static ?string $model = UptimeServer::class;
|
|
|
|
// No icon to avoid errors
|
|
// protected static ?string $navigationIcon = 'ri-home';
|
|
// protected static ?string $activeNavigationIcon = 'ri-home-fill';
|
|
|
|
|
|
protected static ?string $navigationGroup = 'Server Uptimes';
|
|
|
|
protected static ?string $navigationLabel = 'Servers';
|
|
protected static ?string $navigationIcon = 'heroicon-o-clock';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Section::make('Server Information')
|
|
->schema([
|
|
Forms\Components\TextInput::make('name')
|
|
->label('Server Name')
|
|
->required()
|
|
->maxLength(255)
|
|
->placeholder('Enter the name of the server'),
|
|
|
|
Forms\Components\Select::make('server_type')
|
|
->label('Fetch Type')
|
|
->required()
|
|
->options([
|
|
'ip' => 'IP Address',
|
|
'subdomain' => 'Subdomain',
|
|
])
|
|
->default('ip')
|
|
->placeholder('Select server type'),
|
|
|
|
Forms\Components\TextInput::make('ip_address')
|
|
->label('IP Address / Subdomain')
|
|
->required()
|
|
->maxLength(255)
|
|
->placeholder('Enter IP address or subdomain'),
|
|
|
|
Forms\Components\TextInput::make('location')
|
|
->label('Server Location')
|
|
->required()
|
|
->maxLength(255)
|
|
->placeholder('Enter server location (e.g., Columbus, Ohio)'),
|
|
|
|
Forms\Components\Toggle::make('is_active')
|
|
->label('Active')
|
|
->default(true)
|
|
->helperText('Enable or disable uptime monitoring for this server'),
|
|
])->columns(2),
|
|
|
|
// Credit Section
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('name')
|
|
->label('Server Name')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('ip_address')
|
|
->label('IP/Subdomain')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('location')
|
|
->label('Location')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Tables\Columns\IconColumn::make('status')
|
|
->label('Status')
|
|
->boolean()
|
|
->trueIcon('ri-checkbox-circle-line')
|
|
->falseIcon('ri-close-circle-line')
|
|
->trueColor('success')
|
|
->falseColor('danger')
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('uptime_percentage')
|
|
->label('Uptime')
|
|
->suffix('%')
|
|
->numeric(
|
|
decimalPlaces: 2,
|
|
decimalSeparator: '.',
|
|
thousandsSeparator: ',',
|
|
)
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('last_check')
|
|
->label('Last Check')
|
|
->dateTime()
|
|
->sortable(),
|
|
|
|
Tables\Columns\IconColumn::make('is_active')
|
|
->label('Active')
|
|
->boolean()
|
|
->sortable(),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('status')
|
|
->options([
|
|
'online' => 'Online',
|
|
'offline' => 'Offline',
|
|
]),
|
|
Tables\Filters\TernaryFilter::make('is_active')
|
|
->label('Active Status'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\Action::make('check_status')
|
|
->label('Check Status')
|
|
->icon('ri-refresh-line')
|
|
->action(function (UptimeServer $record) {
|
|
// This will be implemented in the service
|
|
$record->update([
|
|
'last_check' => now(),
|
|
]);
|
|
}),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListUptimeServers::route('/'),
|
|
'create' => Pages\CreateUptimeServer::route('/create'),
|
|
'edit' => Pages\EditUptimeServer::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|