147 lines
6.5 KiB
PHP
147 lines
6.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Concerns\SoloSuperadmin;
|
|
use App\Filament\Resources\FinituraResource\Pages;
|
|
use App\Filament\Support\CampiConfiguratore;
|
|
use App\Models\Finitura;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Get;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Validation\Rules\Unique;
|
|
|
|
|
|
class FinituraResource extends Resource
|
|
{
|
|
use SoloSuperadmin;
|
|
|
|
protected static ?string $model = Finitura::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-swatch';
|
|
|
|
protected static ?string $slug = 'finiture';
|
|
|
|
protected static ?string $navigationGroup = 'Configuratore';
|
|
|
|
protected static ?string $navigationLabel = 'Finiture e maniglie';
|
|
|
|
protected static ?string $modelLabel = 'finitura';
|
|
|
|
protected static ?string $pluralModelLabel = 'finiture';
|
|
|
|
protected static ?int $navigationSort = 20;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\Section::make()
|
|
->columns(2)
|
|
->schema([
|
|
CampiConfiguratore::sistema(),
|
|
Forms\Components\Select::make('tipo')
|
|
->label('Tipo')
|
|
->options(Finitura::TIPI)
|
|
->default('profilo')
|
|
->required()
|
|
->live(),
|
|
Forms\Components\TextInput::make('codice')
|
|
->label('Codice')
|
|
->helperText('Identificativo inviato dal configuratore (es. 2, M1).')
|
|
->required()
|
|
->maxLength(50)
|
|
->unique(
|
|
ignoreRecord: true,
|
|
modifyRuleUsing: fn (Unique $rule, Get $get) => $rule
|
|
->where('sistema_id', $get('sistema_id'))
|
|
->where('tipo', $get('tipo')),
|
|
),
|
|
Forms\Components\TextInput::make('descrizione')->label('Descrizione')->required()->maxLength(255),
|
|
Forms\Components\TextInput::make('codice_mazzetta')->label('Codice mazzetta')->maxLength(50),
|
|
CampiConfiguratore::immagine('anteprima', 'Anteprima nel menu', 'finiture/anteprime'),
|
|
Forms\Components\Select::make('lato')
|
|
->label('Lato')
|
|
->helperText('Su quale lato del serramento si può scegliere. Si può cambiare per singolo modello dalla scheda del modello.')
|
|
->options(Finitura::LATI)
|
|
->default('entrambi')
|
|
->required()
|
|
->visible(fn (Get $get) => $get('tipo') === 'profilo'),
|
|
Forms\Components\Toggle::make('predefinita')
|
|
->label('Predefinita')
|
|
->helperText('Selezionata all\'apertura. Per le finiture del profilo: la stessa finitura predefinita su interno ed esterno è il "bianco" senza supplemento.')
|
|
->inline(false),
|
|
Forms\Components\Toggle::make('attivo')
|
|
->label('Attiva nel sistema')
|
|
->helperText('Disattiva: non compare nei modelli, salvo quelli che la attivano nella propria scheda.')
|
|
->default(true)
|
|
->inline(false),
|
|
]),
|
|
CampiConfiguratore::aspetto3d('finiture'),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('ordine')
|
|
->reorderable('ordine')
|
|
->defaultGroup('tipo')
|
|
->groups([
|
|
Tables\Grouping\Group::make('tipo')
|
|
->label('Tipo')
|
|
->getTitleFromRecordUsing(fn (Finitura $record) => Finitura::TIPI[$record->tipo] ?? $record->tipo),
|
|
])
|
|
->columns([
|
|
Tables\Columns\ImageColumn::make('anteprima')->label('Anteprima')->disk('public')->height(40),
|
|
Tables\Columns\TextColumn::make('codice')->label('Codice')->searchable(),
|
|
Tables\Columns\TextColumn::make('descrizione')->label('Descrizione')->searchable()->wrap(),
|
|
Tables\Columns\SelectColumn::make('lato')
|
|
->label('Lato')
|
|
->options(Finitura::LATI)
|
|
->selectablePlaceholder(false)
|
|
->disabled(fn (Finitura $record) => $record->tipo !== 'profilo'),
|
|
Tables\Columns\ColorColumn::make('colore')->label('Colore'),
|
|
Tables\Columns\IconColumn::make('texture')
|
|
->label('Texture')
|
|
->icon(fn (?string $state) => $state ? 'heroicon-o-photo' : null),
|
|
Tables\Columns\IconColumn::make('predefinita')->label('Predefinita')->boolean(),
|
|
Tables\Columns\ToggleColumn::make('attivo')->label('Attiva'),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('sistema')->label('Sistema')->relationship('sistema', 'nome'),
|
|
Tables\Filters\SelectFilter::make('tipo')->label('Tipo')->options(Finitura::TIPI),
|
|
Tables\Filters\SelectFilter::make('lato')->label('Lato')->options(Finitura::LATI),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make()->iconButton(),
|
|
Tables\Actions\DeleteAction::make()->iconButton(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\BulkAction::make('lato')
|
|
->label('Imposta lato')
|
|
->icon('heroicon-o-arrows-right-left')
|
|
->form([
|
|
Forms\Components\Select::make('lato')->label('Lato')->options(Finitura::LATI)->required(),
|
|
])
|
|
->action(fn (Collection $records, array $data) => $records
|
|
->where('tipo', 'profilo')
|
|
->each->update(['lato' => $data['lato']]))
|
|
->deselectRecordsAfterCompletion(),
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ManageFiniture::route('/'),
|
|
];
|
|
}
|
|
}
|