printer-manager-admin/app/Filament/Resources/PrinterResource.php
2023-11-01 22:27:44 +01:00

98 lines
3.4 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PrinterResource\Pages;
use App\Filament\Resources\PrinterResource\RelationManagers;
use App\Models\Printer;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class PrinterResource extends Resource
{
protected static ?string $model = Printer::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('Printer Information')->columns(2)
->schema([
Forms\Components\TextInput::make('name'),
Forms\Components\Select::make('printer_type')->options([
'klippy' => 'Klippy',
]),
Forms\Components\Select::make('driver')->options([
'moonraker' => 'Moonraker',
'octaprint' => 'Octaprint',
]),
Forms\Components\Section::make('Config')->columns(3)->schema([
Forms\Components\TextInput::make('config.host')->label("Host"),
Forms\Components\TextInput::make('config.port')->label("Port")->type('number'),
Forms\Components\TextInput::make('config.ssl_port')->label('SSL Port')->type('number'),
Forms\Components\TextInput::make('config.max_upload_size')->label('Max Upload Size')->type('number'),
]),
Forms\Components\Toggle::make('config.enable_debug_logging')->label('Enable Debug Logging'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('printer_type')
->sortable(),
Tables\Columns\TextColumn::make('driver')
->sortable(),
Tables\Columns\TextColumn::make('config')
->sortable()
->label('network')
->formatStateUsing(function ($state) {
return $state->networkFormat();
}),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
protected function shouldPersistTableSortInSession(): bool
{
return true;
}
public static function getPages(): array
{
return [
'index' => Pages\ListPrinters::route('/'),
'create' => Pages\CreatePrinter::route('/create'),
'edit' => Pages\EditPrinter::route('/{record}/edit'),
];
}
}