feat(machines) : allow category-only links on machine structure

Enable adding a component, piece, or product to a machine by selecting
only the category (ModelType) without a specific entity. The link
displays a red "À remplir" badge; clicking it reopens the modal
pre-filled with the category so the user can associate an item later.

Backend: entity FKs made nullable on the 3 link tables, modelType FK
added, controller/audit/version/MCP normalization adapted for null
entities.

Frontend: modal accepts category-only confirm, page handles fill mode,
hierarchy builder creates pending nodes, display components show
clickable badge with event propagation through the full hierarchy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 10:15:47 +02:00
parent 342ae37762
commit 1c3b566923
20 changed files with 452 additions and 77 deletions

View File

@@ -623,17 +623,21 @@ class MachineStructureController extends AbstractController
{
return array_map(function (MachineComponentLink $link): array {
$composant = $link->getComposant();
$modelType = $link->getModelType();
$parentLink = $link->getParentLink();
return [
'id' => $link->getId(),
'linkId' => $link->getId(),
'machineId' => $link->getMachine()->getId(),
'composantId' => $composant->getId(),
'composant' => $this->normalizeComposant($composant),
'composantId' => $composant?->getId(),
'composant' => $composant ? $this->normalizeComposant($composant) : null,
'modelTypeId' => $modelType?->getId(),
'modelType' => $modelType ? $this->normalizeModelType($modelType) : null,
'pendingEntity' => null === $composant,
'parentLinkId' => $parentLink?->getId(),
'parentComponentLinkId' => $parentLink?->getId(),
'parentComponentId' => $parentLink?->getComposant()->getId(),
'parentComponentId' => $parentLink?->getComposant()?->getId(),
'overrides' => $this->normalizeOverrides($link),
'childLinks' => [],
'pieceLinks' => [],
@@ -645,19 +649,23 @@ class MachineStructureController extends AbstractController
{
return array_map(function (MachinePieceLink $link): array {
$piece = $link->getPiece();
$modelType = $link->getModelType();
$parentLink = $link->getParentLink();
return [
'id' => $link->getId(),
'linkId' => $link->getId(),
'machineId' => $link->getMachine()->getId(),
'pieceId' => $piece->getId(),
'piece' => $this->normalizePiece($piece),
'pieceId' => $piece?->getId(),
'piece' => $piece ? $this->normalizePiece($piece) : null,
'modelTypeId' => $modelType?->getId(),
'modelType' => $modelType ? $this->normalizeModelType($modelType) : null,
'pendingEntity' => null === $piece,
'parentLinkId' => $parentLink?->getId(),
'parentComponentLinkId' => $parentLink?->getId(),
'parentComponentId' => $parentLink?->getComposant()->getId(),
'parentComponentId' => $parentLink?->getComposant()?->getId(),
'overrides' => $this->normalizeOverrides($link),
'quantity' => $this->resolvePieceQuantity($link),
'quantity' => $piece ? $this->resolvePieceQuantity($link) : 1,
];
}, $links);
}
@@ -665,13 +673,16 @@ class MachineStructureController extends AbstractController
private function resolvePieceQuantity(MachinePieceLink $link): int
{
$parentLink = $link->getParentLink();
$piece = $link->getPiece();
if (!$parentLink) {
if (!$parentLink || !$piece) {
return $link->getQuantity();
}
$composant = $parentLink->getComposant();
$piece = $link->getPiece();
if (!$composant) {
return $link->getQuantity();
}
foreach ($composant->getPieceSlots() as $slot) {
if ($slot->getSelectedPiece()?->getId() === $piece->getId()) {
@@ -685,14 +696,18 @@ class MachineStructureController extends AbstractController
private function normalizeProductLinks(array $links): array
{
return array_map(function (MachineProductLink $link): array {
$product = $link->getProduct();
$product = $link->getProduct();
$modelType = $link->getModelType();
return [
'id' => $link->getId(),
'linkId' => $link->getId(),
'machineId' => $link->getMachine()->getId(),
'productId' => $product->getId(),
'product' => $this->normalizeProduct($product),
'productId' => $product?->getId(),
'product' => $product ? $this->normalizeProduct($product) : null,
'modelTypeId' => $modelType?->getId(),
'modelType' => $modelType ? $this->normalizeModelType($modelType) : null,
'pendingEntity' => null === $product,
'parentLinkId' => $link->getParentLink()?->getId(),
'parentComponentLinkId' => $link->getParentComponentLink()?->getId(),
'parentPieceLinkId' => $link->getParentPieceLink()?->getId(),