158 lines
6.7 KiB
PHP
158 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\ModelloResource\Pages;
|
|
use App\Models\Modello;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Get;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Validation\Rules\Unique;
|
|
|
|
class ModelloResource extends Resource
|
|
{
|
|
protected static ?string $model = Modello::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-squares-2x2';
|
|
|
|
protected static ?string $slug = 'modelli';
|
|
|
|
protected static ?string $navigationGroup = 'Prodotti';
|
|
|
|
protected static ?string $navigationLabel = 'Modelli';
|
|
|
|
protected static ?string $modelLabel = 'modello';
|
|
|
|
protected static ?string $pluralModelLabel = 'modelli';
|
|
|
|
protected static ?int $navigationSort = 11;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\Section::make('Anagrafica')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\Select::make('sistema_id')
|
|
->label('Sistema')
|
|
->relationship('sistema', 'nome')
|
|
->required()
|
|
->preload()
|
|
->live(),
|
|
Forms\Components\TextInput::make('codice')
|
|
->label('Codice interno')
|
|
->helperText('Usato dal configuratore nel parametro ?type=.')
|
|
->required()
|
|
->maxLength(100)
|
|
->alphaDash()
|
|
->unique(
|
|
ignoreRecord: true,
|
|
modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('sistema_id', $get('sistema_id')),
|
|
),
|
|
Forms\Components\TextInput::make('nome')
|
|
->label('Nome')
|
|
->helperText('Etichetta mostrata nella lista modelli del configuratore.')
|
|
->required()
|
|
->maxLength(255),
|
|
Forms\Components\TextInput::make('descrizione')
|
|
->label('Descrizione')
|
|
->maxLength(255),
|
|
Forms\Components\FileUpload::make('icona')
|
|
->label('Icona')
|
|
->image()
|
|
->disk('public')
|
|
->directory('modelli/icone')
|
|
->maxSize(2048),
|
|
Forms\Components\Grid::make(1)
|
|
->columnSpan(1)
|
|
->schema([
|
|
Forms\Components\TextInput::make('ordine')
|
|
->label('Ordine')
|
|
->numeric()
|
|
->minValue(0)
|
|
->default(0),
|
|
Forms\Components\Toggle::make('attivo')
|
|
->label('Visibile nel configuratore')
|
|
->helperText('Richiede la configurazione 3D.')
|
|
->default(true)
|
|
->live(),
|
|
]),
|
|
]),
|
|
Forms\Components\Section::make('Configurazione 3D')
|
|
->description('Asset del configuratore usati per questo modello.')
|
|
->columns(2)
|
|
->collapsible()
|
|
->schema([
|
|
Forms\Components\TextInput::make('cartella')
|
|
->label('Cartella dati')
|
|
->helperText('src/assets/data/modelli/<sistema>/<cartella>/')
|
|
->required(fn (Get $get) => (bool) $get('attivo')),
|
|
Forms\Components\TextInput::make('file_modello')
|
|
->label('File modello 3D')
|
|
->helperText('src/assets/models/<sistema>/<file>.glb')
|
|
->required(fn (Get $get) => (bool) $get('attivo')),
|
|
Forms\Components\Select::make('categoria')
|
|
->label('Categoria')
|
|
->options(Modello::CATEGORIE)
|
|
->required(fn (Get $get) => (bool) $get('attivo')),
|
|
Forms\Components\TextInput::make('cartella_texture')
|
|
->label('Cartella texture')
|
|
->helperText('Se vuota si usa la cartella dati.'),
|
|
Forms\Components\CheckboxList::make('moduli')
|
|
->label('Moduli')
|
|
->options(Modello::MODULI)
|
|
->columns(3)
|
|
->columnSpanFull(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('ordine')
|
|
->reorderable('ordine')
|
|
->defaultGroup('sistema.nome')
|
|
->columns([
|
|
Tables\Columns\ImageColumn::make('icona')->label('Icona')->disk('public')->height(48),
|
|
Tables\Columns\TextColumn::make('codice')->label('Codice')->searchable()->copyable(),
|
|
Tables\Columns\TextColumn::make('nome')->label('Nome')->searchable(),
|
|
Tables\Columns\TextColumn::make('descrizione')->label('Descrizione')->searchable()->wrap()->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('categoria')
|
|
->label('Categoria')
|
|
->badge()
|
|
->formatStateUsing(fn (?string $state) => Modello::CATEGORIE[$state] ?? $state)
|
|
->placeholder('—'),
|
|
Tables\Columns\ToggleColumn::make('attivo')
|
|
->label('Attivo')
|
|
->disabled(fn (Modello $record) => ! $record->attivo && (! $record->cartella || ! $record->file_modello)),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('sistema')->label('Sistema')->relationship('sistema', 'nome'),
|
|
Tables\Filters\SelectFilter::make('categoria')->label('Categoria')->options(Modello::CATEGORIE),
|
|
Tables\Filters\TernaryFilter::make('attivo')->label('Attivo'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\DeleteAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListModelli::route('/'),
|
|
'create' => Pages\CreateModello::route('/create'),
|
|
'edit' => Pages\EditModello::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|