ADD EV3-473 gyártó admin felület: minimál ProducerResource + alias CRUD
Csak lista + megtekintés a gyártón (nincs create/edit/delete, ahogy eddig sem volt admin felület), az AliasesRelationManager viszont teljes CRUD-ot ad az aliasokon - felvétel a ProducerAliasResolver ütközés-védelmén át, törlés. Felkerült egy "Gyártók" menüpont mindkét navbarba. A Filament panel alapból read-only-vá tesz minden relation managert a View oldalon, mert a ProducerResource-nak nincs Edit oldala - ezt csak a Livewire-teszt buktatta le, az AliasesRelationManager::isReadOnly() explicit felülírással oldva.
This commit is contained in:
parent
80564c87a2
commit
f83ce54e2f
11
app/Filament/Resources/Producers/Pages/ListProducers.php
Normal file
11
app/Filament/Resources/Producers/Pages/ListProducers.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Producers\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Producers\ProducerResource;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListProducers extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = ProducerResource::class;
|
||||||
|
}
|
||||||
11
app/Filament/Resources/Producers/Pages/ViewProducer.php
Normal file
11
app/Filament/Resources/Producers/Pages/ViewProducer.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Producers\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Producers\ProducerResource;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewProducer extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = ProducerResource::class;
|
||||||
|
}
|
||||||
64
app/Filament/Resources/Producers/ProducerResource.php
Normal file
64
app/Filament/Resources/Producers/ProducerResource.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Producers;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Producers\Pages\ListProducers;
|
||||||
|
use App\Filament\Resources\Producers\Pages\ViewProducer;
|
||||||
|
use App\Filament\Resources\Producers\RelationManagers\AliasesRelationManager;
|
||||||
|
use App\Filament\Resources\Producers\Schemas\ProducerInfolist;
|
||||||
|
use App\Filament\Resources\Producers\Tables\ProducersTable;
|
||||||
|
use App\Models\Producer;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Csak lista + megtekintés: gyártó ma is kizárólag árlista importból keletkezik, itt
|
||||||
|
* nincs create/edit/delete. A felület egyetlen célja az aliasok kezelése (lásd
|
||||||
|
* AliasesRelationManager) - EV3-473.
|
||||||
|
*/
|
||||||
|
class ProducerResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Producer::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-building-storefront';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Gyártók';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'Gyártó';
|
||||||
|
|
||||||
|
protected static ?string $pluralLabel = 'Gyártók';
|
||||||
|
|
||||||
|
protected static ?string $breadcrumb = 'Gyártók';
|
||||||
|
|
||||||
|
public static function infolist(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return ProducerInfolist::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return ProducersTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
AliasesRelationManager::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListProducers::route('/'),
|
||||||
|
'view' => ViewProducer::route('/{record}'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canCreate(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Producers\RelationManagers;
|
||||||
|
|
||||||
|
use App\Support\NameNormalizer;
|
||||||
|
use App\Support\ProducerAliasResolver;
|
||||||
|
use Closure;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teljes CRUD az aliasokon (nem a gyártó törzsén) - EV3-473. A gyártónak ma sincs
|
||||||
|
* admin felülete, ez az első; a cél kizárólag az, hogy a régi gyártóneveket kézzel is
|
||||||
|
* fel lehessen venni/törölni, ne csak a producers:dedupe és a backfill parancson át.
|
||||||
|
*/
|
||||||
|
class AliasesRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'aliases';
|
||||||
|
|
||||||
|
protected static ?string $title = 'Aliasok';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A panel alapértelmezése szerint minden ViewRecord oldalra kerülő relation manager
|
||||||
|
* csak olvasható (Panel::hasReadOnlyRelationManagersOnResourceViewPagesByDefault()).
|
||||||
|
* A ProducerResource szándékosan csak View oldalt ad a gyártóhoz (nincs Edit), de az
|
||||||
|
* aliasokon MUST legyen teljes CRUD - ezért ez a manager kivétel a globális alapérték
|
||||||
|
* alól, nem a panel-szintű beállítást lazítjuk (ami minden más View-relation managert
|
||||||
|
* is érintene).
|
||||||
|
*/
|
||||||
|
public function isReadOnly(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema->components([
|
||||||
|
TextInput::make('name')
|
||||||
|
->label('Régi / alternatív gyártónév')
|
||||||
|
->required()
|
||||||
|
->maxLength(255)
|
||||||
|
->rules([
|
||||||
|
fn (): Closure => function (string $attribute, $value, Closure $fail) {
|
||||||
|
try {
|
||||||
|
app(ProducerAliasResolver::class)
|
||||||
|
->assertNameAvailable($value, $this->getOwnerRecord()->id);
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
$fail($e->getMessage());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->recordTitleAttribute('name')
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('name')
|
||||||
|
->label('Név')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('source')
|
||||||
|
->label('Forrás')
|
||||||
|
->badge(),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('Létrehozva')
|
||||||
|
->dateTime('Y-m-d H:i'),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->headerActions([
|
||||||
|
CreateAction::make()
|
||||||
|
->mutateDataUsing(function (array $data): array {
|
||||||
|
$data['normalized_name'] = NameNormalizer::normalize($data['name']);
|
||||||
|
$data['source'] = 'manual';
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
DeleteAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Producers\Schemas;
|
||||||
|
|
||||||
|
use Filament\Infolists\Components\TextEntry;
|
||||||
|
use Filament\Schemas\Components\Section;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class ProducerInfolist
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
Section::make()
|
||||||
|
->columns(2)
|
||||||
|
->schema([
|
||||||
|
TextEntry::make('name')->label('Név'),
|
||||||
|
TextEntry::make('status')->label('Státusz')->badge(),
|
||||||
|
TextEntry::make('note')
|
||||||
|
->label('Megjegyzés')
|
||||||
|
->placeholder('—')
|
||||||
|
->columnSpanFull(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
51
app/Filament/Resources/Producers/Tables/ProducersTable.php
Normal file
51
app/Filament/Resources/Producers/Tables/ProducersTable.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Producers\Tables;
|
||||||
|
|
||||||
|
use App\Enums\DbStatusFieldEnum;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class ProducersTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->modifyQueryUsing(fn ($query) => $query->withCount('aliases'))
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('name')
|
||||||
|
->label('Név')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('status')
|
||||||
|
->label('Státusz')
|
||||||
|
->badge()
|
||||||
|
->color(fn (string $state) => match ($state) {
|
||||||
|
DbStatusFieldEnum::active => 'success',
|
||||||
|
DbStatusFieldEnum::archive => 'gray',
|
||||||
|
DbStatusFieldEnum::deleted => 'danger',
|
||||||
|
default => 'gray',
|
||||||
|
})
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('aliases_count')
|
||||||
|
->label('Aliasok')
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('note')
|
||||||
|
->label('Megjegyzés')
|
||||||
|
->limit(40)
|
||||||
|
->placeholder('—')
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->defaultSort('name')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('status')
|
||||||
|
->label('Státusz')
|
||||||
|
->options(collect(DbStatusFieldEnum::getValues())->mapWithKeys(fn ($v) => [$v => $v])),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,6 +29,7 @@
|
|||||||
['name' => 'statistics', 'displayName' => 'Statisztikák', 'icon' => 'kimutatasok', 'link' => route('legacy.show', ['path' => 'admin/statistics']), 'roles' => ['root','developer','admin']],
|
['name' => 'statistics', 'displayName' => 'Statisztikák', 'icon' => 'kimutatasok', 'link' => route('legacy.show', ['path' => 'admin/statistics']), 'roles' => ['root','developer','admin']],
|
||||||
['name' => 'export', 'displayName' => 'Export', 'icon' => 'export', 'link' => route('legacy.show', ['path' => 'admin/export']), 'roles' => ['root','developer','admin']],
|
['name' => 'export', 'displayName' => 'Export', 'icon' => 'export', 'link' => route('legacy.show', ['path' => 'admin/export']), 'roles' => ['root','developer','admin']],
|
||||||
['name' => 'priceListProcessor', 'displayName' => 'Árlista feldolgozó', 'icon' => 'price_list', 'link' => '/admin/pricelist-files', 'roles' => ['root','developer','admin']],
|
['name' => 'priceListProcessor', 'displayName' => 'Árlista feldolgozó', 'icon' => 'price_list', 'link' => '/admin/pricelist-files', 'roles' => ['root','developer','admin']],
|
||||||
|
['name' => 'producers', 'displayName' => 'Gyártók', 'icon' => 'supplier', 'link' => '/admin/producers', 'roles' => ['root','developer','admin']],
|
||||||
['name' => 'delivery', 'displayName' => 'Szállítás', 'icon' => 'timetable3', 'roles' => ['root','admin','developer'], 'children' => $deliveryChildren],
|
['name' => 'delivery', 'displayName' => 'Szállítás', 'icon' => 'timetable3', 'roles' => ['root','admin','developer'], 'children' => $deliveryChildren],
|
||||||
['name' => 'calendarTest', 'displayName' => 'Naptár Teszt', 'icon' => 'idopontok', 'link' => \App\Filament\Pages\CalendarTest::getUrl(), 'roles' => ['root','developer','admin']],
|
['name' => 'calendarTest', 'displayName' => 'Naptár Teszt', 'icon' => 'idopontok', 'link' => \App\Filament\Pages\CalendarTest::getUrl(), 'roles' => ['root','developer','admin']],
|
||||||
];
|
];
|
||||||
|
|||||||
@ -129,6 +129,14 @@
|
|||||||
'noAjax' => true,
|
'noAjax' => true,
|
||||||
'roles' => ['developer','admin'],
|
'roles' => ['developer','admin'],
|
||||||
],
|
],
|
||||||
|
'producers' => [
|
||||||
|
'name' => 'producers',
|
||||||
|
'DisplayName' => 'Gyártók',
|
||||||
|
'icon' => 'supplier',
|
||||||
|
'link' => '/admin/producers',
|
||||||
|
'noAjax' => true,
|
||||||
|
'roles' => ['developer','admin'],
|
||||||
|
],
|
||||||
'delivery' => [
|
'delivery' => [
|
||||||
'name' => 'delivery',
|
'name' => 'delivery',
|
||||||
'DisplayName' => 'Szállítás',
|
'DisplayName' => 'Szállítás',
|
||||||
|
|||||||
@ -33,6 +33,7 @@ public function test_developer_sees_correct_speedbuttons(): void
|
|||||||
->assertVisible('.iconholderModulstatistics')
|
->assertVisible('.iconholderModulstatistics')
|
||||||
->assertVisible('.iconholderModulexport')
|
->assertVisible('.iconholderModulexport')
|
||||||
->assertVisible('.iconholderModulpriceListProcessor')
|
->assertVisible('.iconholderModulpriceListProcessor')
|
||||||
|
->assertVisible('.iconholderModulproducers')
|
||||||
// Buttons that should NOT be visible for 'developer' role
|
// Buttons that should NOT be visible for 'developer' role
|
||||||
->assertMissing('.iconholderModulorder')
|
->assertMissing('.iconholderModulorder')
|
||||||
// EV3-473: a legacy árlista-import elérési pontja szándékosan eltűnt
|
// EV3-473: a legacy árlista-import elérési pontja szándékosan eltűnt
|
||||||
|
|||||||
110
tests/Feature/ProducerAdminUiTest.php
Normal file
110
tests/Feature/ProducerAdminUiTest.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\DbStatusFieldEnum;
|
||||||
|
use App\Filament\Resources\Producers\Pages\ListProducers;
|
||||||
|
use App\Filament\Resources\Producers\Pages\ViewProducer;
|
||||||
|
use App\Filament\Resources\Producers\ProducerResource;
|
||||||
|
use App\Filament\Resources\Producers\RelationManagers\AliasesRelationManager;
|
||||||
|
use App\Models\Producer;
|
||||||
|
use App\Models\ProducerAlias;
|
||||||
|
use App\Models\Role;
|
||||||
|
use App\Models\User;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
uses(TestCase::class, RefreshDatabase::class);
|
||||||
|
|
||||||
|
function actAsDeveloperForProducers(): User
|
||||||
|
{
|
||||||
|
$devRole = Role::firstOrCreate(['name' => 'developer'], ['display_name' => 'Developer']);
|
||||||
|
$developer = User::factory()->create();
|
||||||
|
$developer->addRole($devRole);
|
||||||
|
|
||||||
|
return $developer;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('a gyártó lista oldal renderel', function () {
|
||||||
|
$this->actingAs(actAsDeveloperForProducers());
|
||||||
|
|
||||||
|
Producer::create(['name' => 'Danone', 'status' => DbStatusFieldEnum::active, 'canSee' => 1]);
|
||||||
|
|
||||||
|
Livewire::test(ListProducers::class)->assertSuccessful();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a gyártó megtekintő oldal az alias relation managerrel együtt renderel', function () {
|
||||||
|
$this->actingAs(actAsDeveloperForProducers());
|
||||||
|
|
||||||
|
$producer = Producer::create(['name' => 'Danone', 'status' => DbStatusFieldEnum::active, 'canSee' => 1]);
|
||||||
|
ProducerAlias::create([
|
||||||
|
'producer_id' => $producer->id,
|
||||||
|
'name' => 'Danone ',
|
||||||
|
'normalized_name' => 'DANONE',
|
||||||
|
'source' => 'backfill',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Livewire::test(ViewProducer::class, ['record' => $producer->getRouteKey()])
|
||||||
|
->assertSuccessful()
|
||||||
|
->assertSee('Danone ');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a relation manageren keresztül felvett alias ütközését a form visszautasítja', function () {
|
||||||
|
$this->actingAs(actAsDeveloperForProducers());
|
||||||
|
|
||||||
|
Producer::create(['name' => 'Bonduelle', 'status' => DbStatusFieldEnum::active, 'canSee' => 1]);
|
||||||
|
$producer = Producer::create(['name' => 'Danone', 'status' => DbStatusFieldEnum::active, 'canSee' => 1]);
|
||||||
|
|
||||||
|
Livewire::test(AliasesRelationManager::class, [
|
||||||
|
'ownerRecord' => $producer,
|
||||||
|
'pageClass' => ViewProducer::class,
|
||||||
|
])
|
||||||
|
->callTableAction(CreateAction::class, data: ['name' => 'Bonduelle'])
|
||||||
|
->assertHasTableActionErrors(['name']);
|
||||||
|
|
||||||
|
expect(ProducerAlias::count())->toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a relation manageren keresztül felvett alias létrejön és a normalizált név is elmentődik', function () {
|
||||||
|
$this->actingAs(actAsDeveloperForProducers());
|
||||||
|
|
||||||
|
$producer = Producer::create(['name' => 'Danone', 'status' => DbStatusFieldEnum::active, 'canSee' => 1]);
|
||||||
|
|
||||||
|
Livewire::test(AliasesRelationManager::class, [
|
||||||
|
'ownerRecord' => $producer,
|
||||||
|
'pageClass' => ViewProducer::class,
|
||||||
|
])->callTableAction(CreateAction::class, data: ['name' => 'Danone Kft']);
|
||||||
|
|
||||||
|
$alias = ProducerAlias::where('producer_id', $producer->id)->sole();
|
||||||
|
|
||||||
|
expect($alias->name)->toBe('Danone Kft')
|
||||||
|
->and($alias->normalized_name)->toBe('DANONE KFT')
|
||||||
|
->and($alias->source)->toBe('manual');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a relation managerben az alias törölhető', function () {
|
||||||
|
$this->actingAs(actAsDeveloperForProducers());
|
||||||
|
|
||||||
|
$producer = Producer::create(['name' => 'Danone', 'status' => DbStatusFieldEnum::active, 'canSee' => 1]);
|
||||||
|
$alias = ProducerAlias::create([
|
||||||
|
'producer_id' => $producer->id,
|
||||||
|
'name' => 'Danone Kft',
|
||||||
|
'normalized_name' => 'DANONE KFT',
|
||||||
|
'source' => 'backfill',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Livewire::test(AliasesRelationManager::class, [
|
||||||
|
'ownerRecord' => $producer,
|
||||||
|
'pageClass' => ViewProducer::class,
|
||||||
|
])->callTableAction(DeleteAction::class, record: $alias);
|
||||||
|
|
||||||
|
expect(ProducerAlias::count())->toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('csak azoknak a szerepköröknek látszik a menüpont, akik elérik az admin felületet', function () {
|
||||||
|
$developer = actAsDeveloperForProducers();
|
||||||
|
|
||||||
|
$this->actingAs($developer);
|
||||||
|
$this->get(ProducerResource::getUrl())->assertOk();
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user