Refactor code structure for improved readability and maintainability
@@ -0,0 +1,157 @@
|
|||||||
|
<?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'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ModelloResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ModelloResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateModello extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = ModelloResource::class;
|
||||||
|
|
||||||
|
protected function getRedirectUrl(): string
|
||||||
|
{
|
||||||
|
return $this->getResource()::getUrl('index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ModelloResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ModelloResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditModello extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = ModelloResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRedirectUrl(): string
|
||||||
|
{
|
||||||
|
return $this->getResource()::getUrl('index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ModelloResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ModelloResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListModelli extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = ModelloResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Resources\SistemaResource\Pages;
|
||||||
|
use App\Models\Sistema;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class SistemaResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Sistema::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
protected static ?string $slug = 'sistemi';
|
||||||
|
|
||||||
|
protected static ?string $navigationGroup = 'Prodotti';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Sistemi';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'sistema';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'sistemi';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 10;
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form->schema([
|
||||||
|
Forms\Components\Section::make()
|
||||||
|
->columns(2)
|
||||||
|
->schema([
|
||||||
|
Forms\Components\TextInput::make('codice')
|
||||||
|
->label('Codice')
|
||||||
|
->helperText('Usato dal configuratore nel parametro ?sistema= (es. pvc).')
|
||||||
|
->required()
|
||||||
|
->maxLength(50)
|
||||||
|
->alphaDash()
|
||||||
|
->unique(ignoreRecord: true),
|
||||||
|
Forms\Components\TextInput::make('nome')
|
||||||
|
->label('Nome')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
Forms\Components\TextInput::make('ordine')
|
||||||
|
->label('Ordine')
|
||||||
|
->numeric()
|
||||||
|
->minValue(0)
|
||||||
|
->default(0),
|
||||||
|
Forms\Components\Toggle::make('attivo')
|
||||||
|
->label('Attivo nel configuratore')
|
||||||
|
->default(true)
|
||||||
|
->inline(false),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->defaultSort('ordine')
|
||||||
|
->reorderable('ordine')
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('codice')->label('Codice')->searchable(),
|
||||||
|
Tables\Columns\TextColumn::make('nome')->label('Nome')->searchable(),
|
||||||
|
Tables\Columns\TextColumn::make('modelli_count')->label('Modelli')->counts('modelli'),
|
||||||
|
Tables\Columns\IconColumn::make('attivo')->label('Attivo')->boolean(),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\Action::make('modelli')
|
||||||
|
->label('Modelli')
|
||||||
|
->icon('heroicon-o-squares-2x2')
|
||||||
|
->color('gray')
|
||||||
|
->url(fn (Sistema $record) => ModelloResource::getUrl('index', [
|
||||||
|
'tableFilters' => ['sistema' => ['value' => $record->getKey()]],
|
||||||
|
])),
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
Tables\Actions\DeleteAction::make()
|
||||||
|
->modalDescription('Verrà eliminato definitivamente il sistema insieme a tutti i suoi modelli.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListSistemi::route('/'),
|
||||||
|
'create' => Pages\CreateSistema::route('/create'),
|
||||||
|
'edit' => Pages\EditSistema::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\SistemaResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\SistemaResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateSistema extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = SistemaResource::class;
|
||||||
|
|
||||||
|
protected function getRedirectUrl(): string
|
||||||
|
{
|
||||||
|
return $this->getResource()::getUrl('index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\SistemaResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\SistemaResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditSistema extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = SistemaResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make()
|
||||||
|
->modalDescription('Verrà eliminato definitivamente il sistema insieme a tutti i suoi modelli.'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRedirectUrl(): string
|
||||||
|
{
|
||||||
|
return $this->getResource()::getUrl('index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\SistemaResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\SistemaResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListSistemi extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = SistemaResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Modello;
|
||||||
|
use App\Models\Sistema;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class CatalogoController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* GET /api/sistemi
|
||||||
|
* Sistemi attivi con i rispettivi modelli attivi, nell'ordine del menu.
|
||||||
|
*/
|
||||||
|
public function sistemi(): JsonResponse
|
||||||
|
{
|
||||||
|
$sistemi = Sistema::attivi()
|
||||||
|
->with(['modelli' => fn ($q) => $q->attivi()])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return response()->json($sistemi->map(fn (Sistema $s) => $this->sistema($s))->values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/sistemi/{codice}
|
||||||
|
*/
|
||||||
|
public function sistemaPerCodice(string $codice): JsonResponse
|
||||||
|
{
|
||||||
|
$sistema = Sistema::attivi()
|
||||||
|
->where('codice', $codice)
|
||||||
|
->with(['modelli' => fn ($q) => $q->attivi()])
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
return response()->json($this->sistema($sistema));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sistema(Sistema $sistema): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'codice' => $sistema->codice,
|
||||||
|
'nome' => $sistema->nome,
|
||||||
|
'modelli' => $sistema->modelli->map(fn (Modello $m) => $this->modello($m))->values(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stessa forma del vecchio modelli.json (id, nome, cartella, modello, ...) più descrizione e icona.
|
||||||
|
private function modello(Modello $modello): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $modello->codice,
|
||||||
|
'nome' => $modello->nome,
|
||||||
|
'descrizione' => $modello->descrizione,
|
||||||
|
'icona' => $modello->icona_url,
|
||||||
|
'cartella' => $modello->cartella,
|
||||||
|
'modello' => $modello->file_modello,
|
||||||
|
'categoria' => $modello->categoria,
|
||||||
|
'cartella_texture' => $modello->cartella_texture,
|
||||||
|
'moduli' => $modello->moduli ?? [],
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class Modello extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'modelli';
|
||||||
|
|
||||||
|
// Categorie usate dal configuratore (es. per scegliere altezza_maniglia_<categoria>.json).
|
||||||
|
public const CATEGORIE = [
|
||||||
|
'finestre' => 'Finestre',
|
||||||
|
'porte' => 'Porte',
|
||||||
|
'scorrevoli' => 'Scorrevoli',
|
||||||
|
'scuretti' => 'Scuretti',
|
||||||
|
'accessori' => 'Accessori',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Moduli dati caricati dal configuratore per il modello.
|
||||||
|
public const MODULI = [
|
||||||
|
'listino' => 'Listino',
|
||||||
|
'modello' => 'Finiture',
|
||||||
|
'maniglia' => 'Maniglia',
|
||||||
|
'altezza_maniglia' => 'Altezza maniglia',
|
||||||
|
'vetro' => 'Vetro',
|
||||||
|
'cerniere' => 'Cerniere',
|
||||||
|
'telaio' => 'Telaio',
|
||||||
|
'avvolgibile' => 'Avvolgibile',
|
||||||
|
'select_finiture' => 'Select finiture',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'sistema_id', 'codice', 'nome', 'descrizione', 'icona', 'ordine', 'attivo',
|
||||||
|
'cartella', 'file_modello', 'categoria', 'cartella_texture', 'moduli',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'ordine' => 'integer',
|
||||||
|
'attivo' => 'boolean',
|
||||||
|
'moduli' => 'array',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function sistema(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Sistema::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeAttivi(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where('attivo', true)->orderBy('ordine')->orderBy('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIconaUrlAttribute(): ?string
|
||||||
|
{
|
||||||
|
return $this->icona ? Storage::disk('public')->url($this->icona) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
// Rimuove il file dell'icona sostituita o del modello eliminato.
|
||||||
|
static::updated(function (Modello $modello): void {
|
||||||
|
$vecchia = $modello->getOriginal('icona');
|
||||||
|
if ($modello->wasChanged('icona') && $vecchia) {
|
||||||
|
Storage::disk('public')->delete($vecchia);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
static::deleted(function (Modello $modello): void {
|
||||||
|
if ($modello->icona) {
|
||||||
|
Storage::disk('public')->delete($modello->icona);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class Sistema extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'sistemi';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'codice', 'nome', 'ordine', 'attivo',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'ordine' => 'integer',
|
||||||
|
'attivo' => 'boolean',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function modelli(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Modello::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeAttivi(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where('attivo', true)->orderBy('ordine')->orderBy('id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('sistemi', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
// Codice usato dal configuratore nel parametro ?sistema= (es. "pvc").
|
||||||
|
$table->string('codice', 50)->unique();
|
||||||
|
$table->string('nome');
|
||||||
|
$table->unsignedInteger('ordine')->default(0);
|
||||||
|
$table->boolean('attivo')->default(true);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('sistemi');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('modelli', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('sistema_id')->constrained('sistemi')->cascadeOnDelete();
|
||||||
|
// Codice interno: è anche il ?type= del configuratore.
|
||||||
|
$table->string('codice', 100);
|
||||||
|
// Etichetta mostrata nella lista modelli del configuratore.
|
||||||
|
$table->string('nome');
|
||||||
|
// Descrizione d'ordine (es. "FINESTRA 1 ANTA, A/R").
|
||||||
|
$table->string('descrizione')->nullable();
|
||||||
|
$table->string('icona')->nullable();
|
||||||
|
$table->unsignedInteger('ordine')->default(0);
|
||||||
|
$table->boolean('attivo')->default(true);
|
||||||
|
|
||||||
|
// Configurazione 3D letta dal configuratore.
|
||||||
|
$table->string('cartella')->nullable();
|
||||||
|
$table->string('file_modello')->nullable();
|
||||||
|
$table->string('categoria', 50)->nullable();
|
||||||
|
$table->string('cartella_texture')->nullable();
|
||||||
|
$table->json('moduli')->nullable();
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['sistema_id', 'codice']);
|
||||||
|
$table->index(['sistema_id', 'attivo', 'ordine']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('modelli');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Modello;
|
||||||
|
use App\Models\Sistema;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anagrafica iniziale di sistemi e modelli. Idempotente: crea solo i record
|
||||||
|
* mancanti, senza sovrascrivere le modifiche fatte dal pannello admin.
|
||||||
|
*/
|
||||||
|
class CatalogoSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$pvc = Sistema::firstOrCreate(['codice' => 'pvc'], ['nome' => 'PVC', 'ordine' => 1]);
|
||||||
|
|
||||||
|
$this->seedModelli($pvc, require __DIR__.'/data/modelli_pvc.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function seedModelli(Sistema $sistema, array $modelli): void
|
||||||
|
{
|
||||||
|
foreach ($modelli as $ordine => $dati) {
|
||||||
|
$modello = Modello::firstOrCreate(
|
||||||
|
['sistema_id' => $sistema->id, 'codice' => $dati['codice']],
|
||||||
|
$dati + ['ordine' => $ordine + 1]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! $modello->icona) {
|
||||||
|
$modello->icona = $this->copiaIcona($sistema->codice, $modello->codice);
|
||||||
|
$modello->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function copiaIcona(string $sistema, string $codice): ?string
|
||||||
|
{
|
||||||
|
$sorgente = __DIR__."/data/icone/{$sistema}/{$codice}.jpg";
|
||||||
|
if (! is_file($sorgente)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$destinazione = "modelli/icone/{$sistema}/{$codice}.jpg";
|
||||||
|
Storage::disk('public')->put($destinazione, file_get_contents($sorgente));
|
||||||
|
|
||||||
|
return $destinazione;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,5 +21,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
'password' => Hash::make('password'),
|
'password' => Hash::make('password'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->call(CatalogoSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,339 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Anagrafica iniziale dei modelli PVC: codice e descrizione da
|
||||||
|
// reference/OrdineSerramenti_Descrizioni_NuoveOpzioni.xlsx, configurazione 3D
|
||||||
|
// dall'ex src/assets/data/sistemi/pvc/modelli.json. I modelli senza configurazione
|
||||||
|
// 3D (non ancora disponibili nel configuratore) sono disattivi.
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'codice' => 'finestra_1_anta',
|
||||||
|
'nome' => 'Finestra 1 anta',
|
||||||
|
'descrizione' => 'FINESTRA 1 ANTA, A/R',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'finestra_1_anta',
|
||||||
|
'file_modello' => 'finestra_1_anta.glb',
|
||||||
|
'categoria' => 'finestre',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'finestra_2_ante',
|
||||||
|
'nome' => 'Finestra 2 ante',
|
||||||
|
'descrizione' => 'FINESTRA 2 ANTE, A/R',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'finestra_2_ante',
|
||||||
|
'file_modello' => 'finestra_2_ante.glb',
|
||||||
|
'categoria' => 'finestre',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'finestra_3_ante',
|
||||||
|
'nome' => 'Finestra 3 ante',
|
||||||
|
'descrizione' => 'FINESTRA 3 ANTE, A/R',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'finestra_3_ante',
|
||||||
|
'file_modello' => 'finestra_3_ante.glb',
|
||||||
|
'categoria' => 'finestre',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'finestra_anta_fissa',
|
||||||
|
'nome' => 'Finestra Anta Fissa',
|
||||||
|
'descrizione' => 'TELAIO FISSO',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'finestra_anta_fissa',
|
||||||
|
'file_modello' => 'finestra_anta_fissa.glb',
|
||||||
|
'categoria' => 'finestre',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'telaio', 'listino', 'modello', 'vetro', 'select_finiture'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'finestra_vasistas',
|
||||||
|
'nome' => 'Finestra Vasistas',
|
||||||
|
'descrizione' => 'WASISTAS CON MARTELLINA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'finestra_vasistas',
|
||||||
|
'file_modello' => 'finestra_vasistas.glb',
|
||||||
|
'categoria' => 'finestre',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'portafinestra_1_anta',
|
||||||
|
'nome' => 'Portafinestra 1 anta',
|
||||||
|
'descrizione' => 'PORTAFINESTRA 1 ANTA, A/R',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'portafinestra_1_anta',
|
||||||
|
'file_modello' => 'portafinestra_1_anta.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'portafinestra_2_ante',
|
||||||
|
'nome' => 'Portafinestra 2 ante',
|
||||||
|
'descrizione' => 'PORTAFINESTRA 2 ANTE, A/R',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'portafinestra_2_ante',
|
||||||
|
'file_modello' => 'portafinestra_2_ante.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'portafinestra_3_ante',
|
||||||
|
'nome' => 'Portafinestra 3 ante',
|
||||||
|
'descrizione' => 'PORTAFINESTRA 3 ANTE, A/R',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'portafinestra_3_ante',
|
||||||
|
'file_modello' => 'portafinestra_3_ante.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'porta_1_anta',
|
||||||
|
'nome' => 'Porta 1 Anta',
|
||||||
|
'descrizione' => 'PORTA 1 ANTA, CON SERRATURA , SOGLIA RIBASSATA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'porta_1_anta',
|
||||||
|
'file_modello' => 'porta_1_anta.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'porta_1_anta_antipanico',
|
||||||
|
'nome' => 'Porta 1 Anta Antipanico',
|
||||||
|
'descrizione' => 'PORTA 1 ANTA ANTIPANICO_AP ESTERNA, SOGLIA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'porta_1_anta_antipanico',
|
||||||
|
'file_modello' => 'porta_1_anta_antipanico.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'porta_2_ante',
|
||||||
|
'nome' => 'Porta 2 Ante',
|
||||||
|
'descrizione' => 'PORTA 2 ANTE, CON SERRATURA , SOGLIA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'porta_2_ante',
|
||||||
|
'file_modello' => 'porta_2_ante.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'porta_2_ante_antipanico',
|
||||||
|
'nome' => 'Porta 2 Ante Antipanico',
|
||||||
|
'descrizione' => 'PORTA 2 ANTE ANTIPANICO_AP ESTERNA, SOGLIA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'porta_2_ante_antipanico',
|
||||||
|
'file_modello' => 'porta_2_ante_antipanico.glb',
|
||||||
|
'categoria' => 'porte',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_hst_1_anta',
|
||||||
|
'nome' => 'Scorrevole HST 1 Anta',
|
||||||
|
'descrizione' => 'ALZANTE SCORREVOLE 1 ANTA SCORREVOLE_+1 ANTA FISSA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scorrevole_hst_1_anta',
|
||||||
|
'file_modello' => 'scorrevole_hst_1_anta.glb',
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_hst_2_ante',
|
||||||
|
'nome' => 'Scorrevole HST 2 Ante',
|
||||||
|
'descrizione' => 'ALZANTE SCORREVOLE 2 ANTE',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scorrevole_hst_2_ante',
|
||||||
|
'file_modello' => 'scorrevole_hst_2_ante.glb',
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_hst_4_ante',
|
||||||
|
'nome' => 'Scorrevole HST 4 Ante',
|
||||||
|
'descrizione' => 'ALZANTE SCORREVOLE 4 ANTE',
|
||||||
|
'attivo' => false,
|
||||||
|
'cartella' => null,
|
||||||
|
'file_modello' => null,
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => null,
|
||||||
|
'moduli' => null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_sf_1_anta',
|
||||||
|
'nome' => 'Scorrevole SF 1 Anta',
|
||||||
|
'descrizione' => null,
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scorrevole_sf_1_anta',
|
||||||
|
'file_modello' => 'scorrevole_sf_1_anta.glb',
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_sf_2_ante',
|
||||||
|
'nome' => 'Scorrevole SF 2 Ante',
|
||||||
|
'descrizione' => 'SCORREVOLE IN LINEA A 2 ANTE',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scorrevole_sf_2_ante',
|
||||||
|
'file_modello' => 'scorrevole_sf_2_ante.glb',
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_sf_3_ante',
|
||||||
|
'nome' => 'Scorrevole SF 3 Ante',
|
||||||
|
'descrizione' => 'SCORREVOLE IN LINEA A 3 ANTE',
|
||||||
|
'attivo' => false,
|
||||||
|
'cartella' => null,
|
||||||
|
'file_modello' => null,
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => null,
|
||||||
|
'moduli' => null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_sf_4_ante',
|
||||||
|
'nome' => 'Scorrevole SF 4 Ante',
|
||||||
|
'descrizione' => 'SCORREVOLE IN LINEA A 4 ANTE',
|
||||||
|
'attivo' => false,
|
||||||
|
'cartella' => null,
|
||||||
|
'file_modello' => null,
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => null,
|
||||||
|
'moduli' => null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'traslante_scorrevole_1_anta',
|
||||||
|
'nome' => 'Traslante Scorrevole 1 Anta',
|
||||||
|
'descrizione' => 'TRASLANTE SCORREVOLE, 1 ANTA SC.+1ANTA FISSA',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'traslante_scorrevole_1_anta',
|
||||||
|
'file_modello' => 'traslante_scorrevole_1_anta.glb',
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'traslante_scorrevole_1_anta_f',
|
||||||
|
'nome' => 'Traslante Scorrevole 1 Anta + Fisso Laterale',
|
||||||
|
'descrizione' => 'TRASLANTE SCORREVOLE, 1 ANTA SC.+1 FISSO LATERALE',
|
||||||
|
'attivo' => false,
|
||||||
|
'cartella' => null,
|
||||||
|
'file_modello' => null,
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => null,
|
||||||
|
'moduli' => null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scorrevole_parallelo_1_anta',
|
||||||
|
'nome' => 'Scorrevole Parallelo 1 Anta',
|
||||||
|
'descrizione' => null,
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scorrevole_parallelo_1_anta',
|
||||||
|
'file_modello' => 'scorrevole_parallelo_1_anta.glb',
|
||||||
|
'categoria' => 'scorrevoli',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'bilico',
|
||||||
|
'nome' => 'Bilico Orizzontale',
|
||||||
|
'descrizione' => 'BILICO ORIZZONTALE',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'bilico',
|
||||||
|
'file_modello' => 'bilico.glb',
|
||||||
|
'categoria' => 'finestre',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['cerniere', 'listino', 'maniglia', 'altezza_maniglia', 'modello', 'vetro'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scuretto_base',
|
||||||
|
'nome' => 'Scuretto Pannello Base',
|
||||||
|
'descrizione' => 'SCURETTO BASE',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scuretto_base',
|
||||||
|
'file_modello' => 'scuretto_base.glb',
|
||||||
|
'categoria' => 'scuretti',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scuretto_pannello_alessandrite',
|
||||||
|
'nome' => 'Scuretto Pannello Alessandrite',
|
||||||
|
'descrizione' => 'SCURETTO ALESSANDRITE',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scuretto_pannello_alessandrite',
|
||||||
|
'file_modello' => 'scuretto_pannello_alessandrite.glb',
|
||||||
|
'categoria' => 'scuretti',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'scuretto_pannello_malachite',
|
||||||
|
'nome' => 'Scuretto Pannello Malachite',
|
||||||
|
'descrizione' => 'SCURETTO MALACHITE',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'scuretto_pannello_malachite',
|
||||||
|
'file_modello' => 'scuretto_pannello_malachite.glb',
|
||||||
|
'categoria' => 'scuretti',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'cassonetto_80',
|
||||||
|
'nome' => 'Cassonetto Monoblocco 80',
|
||||||
|
'descrizione' => 'CASSONETTO 80mm',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'cassonetto_80',
|
||||||
|
'file_modello' => 'cassonetto_80.glb',
|
||||||
|
'categoria' => 'accessori',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'cassonetto_139',
|
||||||
|
'nome' => 'Cassonetto Monoblocco 139',
|
||||||
|
'descrizione' => 'CASSONETTO 139mm',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'cassonetto_139',
|
||||||
|
'file_modello' => 'cassonetto_139.glb',
|
||||||
|
'categoria' => 'accessori',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'cassonetto_150',
|
||||||
|
'nome' => 'Cassonetto Monoblocco 150',
|
||||||
|
'descrizione' => 'CASSONETTO 150mm',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'cassonetto_150',
|
||||||
|
'file_modello' => 'cassonetto_150.glb',
|
||||||
|
'categoria' => 'accessori',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'codice' => 'celino',
|
||||||
|
'nome' => 'Celino',
|
||||||
|
'descrizione' => 'CIELINO',
|
||||||
|
'attivo' => true,
|
||||||
|
'cartella' => 'celino',
|
||||||
|
'file_modello' => 'celino.glb',
|
||||||
|
'categoria' => 'accessori',
|
||||||
|
'cartella_texture' => 'finestra_2_ante',
|
||||||
|
'moduli' => ['modello', 'listino'],
|
||||||
|
],
|
||||||
|
];
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Api\AuthController;
|
use App\Http\Controllers\Api\AuthController;
|
||||||
use App\Http\Controllers\Api\CarrelloController;
|
use App\Http\Controllers\Api\CarrelloController;
|
||||||
|
use App\Http\Controllers\Api\CatalogoController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
// Espone al configuratore l'URL corrente dell'app cliente (checkout), così il
|
// Espone al configuratore l'URL corrente dell'app cliente (checkout), così il
|
||||||
@@ -10,6 +11,10 @@ Route::get('config', fn () => response()->json([
|
|||||||
'frontend_cliente_url' => config('preventivi.frontend_cliente_url'),
|
'frontend_cliente_url' => config('preventivi.frontend_cliente_url'),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
// Catalogo prodotti (sistemi e modelli con icone) per il configuratore.
|
||||||
|
Route::get('sistemi', [CatalogoController::class, 'sistemi']);
|
||||||
|
Route::get('sistemi/{codice}', [CatalogoController::class, 'sistemaPerCodice']);
|
||||||
|
|
||||||
Route::prefix('auth')->group(function () {
|
Route::prefix('auth')->group(function () {
|
||||||
Route::post('login', [AuthController::class, 'login']);
|
Route::post('login', [AuthController::class, 'login']);
|
||||||
Route::middleware('auth:sanctum')->get('me', [AuthController::class, 'me']);
|
Route::middleware('auth:sanctum')->get('me', [AuthController::class, 'me']);
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ModelloResource;
|
||||||
|
use App\Filament\Resources\ModelloResource\Pages\CreateModello;
|
||||||
|
use App\Filament\Resources\ModelloResource\Pages\EditModello;
|
||||||
|
use App\Filament\Resources\ModelloResource\Pages\ListModelli;
|
||||||
|
use App\Filament\Resources\SistemaResource\Pages\ListSistemi;
|
||||||
|
use App\Models\Modello;
|
||||||
|
use App\Models\Sistema;
|
||||||
|
use App\Models\User;
|
||||||
|
use Database\Seeders\CatalogoSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CatalogoAdminTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Storage::fake('public');
|
||||||
|
$this->seed(CatalogoSeeder::class);
|
||||||
|
$this->actingAs(User::factory()->create());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_le_pagine_admin_del_catalogo_si_aprono(): void
|
||||||
|
{
|
||||||
|
$modello = Modello::where('codice', 'finestra_1_anta')->firstOrFail();
|
||||||
|
|
||||||
|
Livewire::test(ListSistemi::class)->assertOk()->assertSee('PVC');
|
||||||
|
Livewire::test(ListModelli::class)->assertOk()->assertCanSeeTableRecords([$modello]);
|
||||||
|
Livewire::test(CreateModello::class)->assertOk();
|
||||||
|
Livewire::test(EditModello::class, ['record' => $modello->getRouteKey()])
|
||||||
|
->assertOk()
|
||||||
|
->assertFormSet(['codice' => 'finestra_1_anta', 'descrizione' => 'FINESTRA 1 ANTA, A/R']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_dai_sistemi_si_aprono_i_modelli_filtrati_per_sistema(): void
|
||||||
|
{
|
||||||
|
$pvc = Sistema::where('codice', 'pvc')->firstOrFail();
|
||||||
|
$altro = Sistema::create(['codice' => 'legno', 'nome' => 'Legno']);
|
||||||
|
$modelloAltro = Modello::create(['sistema_id' => $altro->id, 'codice' => 'finestra_1_anta', 'nome' => 'Finestra legno', 'attivo' => false]);
|
||||||
|
|
||||||
|
Livewire::test(ListSistemi::class)
|
||||||
|
->assertTableActionHasUrl('modelli', ModelloResource::getUrl('index', [
|
||||||
|
'tableFilters' => ['sistema' => ['value' => $pvc->id]],
|
||||||
|
]), $pvc);
|
||||||
|
|
||||||
|
Livewire::withQueryParams(['tableFilters' => ['sistema' => ['value' => $pvc->id]]])
|
||||||
|
->test(ListModelli::class)
|
||||||
|
->assertCountTableRecords($pvc->modelli()->count())
|
||||||
|
->assertCanNotSeeTableRecords([$modelloAltro]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_un_modello_attivo_richiede_la_configurazione_3d(): void
|
||||||
|
{
|
||||||
|
$sistema = Modello::firstOrFail()->sistema_id;
|
||||||
|
|
||||||
|
Livewire::test(CreateModello::class)
|
||||||
|
->fillForm(['sistema_id' => $sistema, 'codice' => 'nuovo', 'nome' => 'Nuovo', 'attivo' => true])
|
||||||
|
->call('create')
|
||||||
|
->assertHasFormErrors(['cartella' => 'required', 'file_modello' => 'required', 'categoria' => 'required']);
|
||||||
|
|
||||||
|
Livewire::test(CreateModello::class)
|
||||||
|
->fillForm(['sistema_id' => $sistema, 'codice' => 'finestra_1_anta', 'nome' => 'Doppione', 'attivo' => false])
|
||||||
|
->call('create')
|
||||||
|
->assertHasFormErrors(['codice' => 'unique']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Modello;
|
||||||
|
use App\Models\Sistema;
|
||||||
|
use Database\Seeders\CatalogoSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CatalogoApiTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Storage::fake('public');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_il_seeder_carica_anagrafica_pvc_con_icone(): void
|
||||||
|
{
|
||||||
|
$this->seed(CatalogoSeeder::class);
|
||||||
|
|
||||||
|
$pvc = Sistema::where('codice', 'pvc')->firstOrFail();
|
||||||
|
$this->assertSame(30, $pvc->modelli()->count());
|
||||||
|
|
||||||
|
$finestra = $pvc->modelli()->where('codice', 'finestra_1_anta')->firstOrFail();
|
||||||
|
$this->assertSame('FINESTRA 1 ANTA, A/R', $finestra->descrizione);
|
||||||
|
Storage::disk('public')->assertExists($finestra->icona);
|
||||||
|
|
||||||
|
// Modelli presenti solo nell'Excel: senza asset 3D, quindi disattivi.
|
||||||
|
$this->assertFalse($pvc->modelli()->where('codice', 'scorrevole_sf_3_ante')->value('attivo'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_il_seeder_non_sovrascrive_le_modifiche_admin(): void
|
||||||
|
{
|
||||||
|
$this->seed(CatalogoSeeder::class);
|
||||||
|
Modello::where('codice', 'bilico')->update(['nome' => 'Bilico modificato']);
|
||||||
|
|
||||||
|
$this->seed(CatalogoSeeder::class);
|
||||||
|
|
||||||
|
$this->assertSame('Bilico modificato', Modello::where('codice', 'bilico')->value('nome'));
|
||||||
|
$this->assertSame(30, Modello::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_api_sistemi_espone_solo_modelli_attivi_in_ordine(): void
|
||||||
|
{
|
||||||
|
$this->seed(CatalogoSeeder::class);
|
||||||
|
Sistema::create(['codice' => 'legno', 'nome' => 'Legno', 'attivo' => false]);
|
||||||
|
|
||||||
|
$response = $this->getJson('/api/sistemi')->assertOk();
|
||||||
|
|
||||||
|
$response->assertJsonCount(1);
|
||||||
|
$response->assertJsonPath('0.codice', 'pvc');
|
||||||
|
|
||||||
|
$modelli = collect($response->json('0.modelli'));
|
||||||
|
$this->assertSame(26, $modelli->count());
|
||||||
|
$this->assertSame('finestra_1_anta', $modelli->first()['id']);
|
||||||
|
$this->assertNotContains('scorrevole_sf_3_ante', $modelli->pluck('id'));
|
||||||
|
$this->assertStringEndsWith('/storage/modelli/icone/pvc/finestra_1_anta.jpg', $modelli->first()['icona']);
|
||||||
|
$this->assertSame('finestra_1_anta.glb', $modelli->first()['modello']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_api_sistema_inesistente_restituisce_404(): void
|
||||||
|
{
|
||||||
|
$this->getJson('/api/sistemi/inesistente')->assertNotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -229,7 +229,7 @@ const buildListaModelli = (modelli, modello, categoria, sistema) => {
|
|||||||
|
|
||||||
html += `<div class="d-inline btn-categoria">
|
html += `<div class="d-inline btn-categoria">
|
||||||
<a href="./?type=${m.id}&sistema=${sistema}">
|
<a href="./?type=${m.id}&sistema=${sistema}">
|
||||||
<img class="${selected}" src="./assets/data/icone/${m.id}.jpg" alt="${m.id}" />
|
<img class="${selected}" src="${m.icona || ''}" alt="${m.id}" />
|
||||||
</a>
|
</a>
|
||||||
<p>${m.nome}</p>
|
<p>${m.nome}</p>
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ window.GLTFLoader = GLTFLoader; // Used by APP Scripts.
|
|||||||
|
|
||||||
// --- Integrazione backend preventivi ---
|
// --- Integrazione backend preventivi ---
|
||||||
const CART_TOKEN_KEY = 'kreios_cart_token';
|
const CART_TOKEN_KEY = 'kreios_cart_token';
|
||||||
// Ordine dei sistemi come nel menu: il primo è quello di default
|
|
||||||
const SISTEMI = ['pvc', 'alluminio', 'legno', 'acciaio'];
|
|
||||||
|
|
||||||
// URL dell'app cliente (checkout): richiesto all'API invece di essere indovinato, perché la
|
// URL dell'app cliente (checkout): richiesto all'API invece di essere indovinato, perché la
|
||||||
// porta Vite dell'app cliente può cambiare (es. se 5199 è già occupata). Fallback locale se
|
// porta Vite dell'app cliente può cambiare (es. se 5199 è già occupata). Fallback locale se
|
||||||
@@ -138,15 +136,21 @@ $(() => {
|
|||||||
const start = async () => {
|
const start = async () => {
|
||||||
const params = ParamsParser.getQueryParams();
|
const params = ParamsParser.getQueryParams();
|
||||||
|
|
||||||
// Senza sistema in query string si parte dal primo sistema (pvc)
|
// Sistemi e modelli (con icone) sono serviti dal backoffice, già filtrati sui soli attivi
|
||||||
if (!SISTEMI.includes(params.sistema))
|
// e nell'ordine del menu: il primo sistema è quello di default.
|
||||||
params.sistema = SISTEMI[0];
|
const res = await fetch(`${PREVENTIVI_API_BASE}/sistemi`, { headers: { Accept: 'application/json' } });
|
||||||
|
if (!res.ok) throw new Error(`Catalogo non disponibile (HTTP ${res.status})`);
|
||||||
|
const sistemi = await res.json();
|
||||||
|
if (!sistemi.length) throw new Error('Nessun sistema attivo nel catalogo');
|
||||||
|
|
||||||
|
const sistema = sistemi.find(s => s.codice === params.sistema) || sistemi[0];
|
||||||
|
params.sistema = sistema.codice;
|
||||||
|
|
||||||
let data_folder = `./assets/data/sistemi/${params.sistema}`;
|
let data_folder = `./assets/data/sistemi/${params.sistema}`;
|
||||||
let modello_folder = `./assets/data/modelli/${params.sistema}`;
|
let modello_folder = `./assets/data/modelli/${params.sistema}`;
|
||||||
|
|
||||||
|
const modelli = sistema.modelli;
|
||||||
const modelli = await (await fetch(`${data_folder}/modelli.json?rnd=` + Math.random())).json();
|
if (!modelli.length) throw new Error(`Nessun modello attivo per il sistema ${sistema.codice}`);
|
||||||
|
|
||||||
let modello = modelli.find(m => m.id === params.type);
|
let modello = modelli.find(m => m.id === params.type);
|
||||||
|
|
||||||
|
|||||||