refactor(machines) : remove TypeMachine skeleton system, simplify machine creation

- Remove TypeEdit*, TypeInfoDisplay, MachineSkeletonSummary, MachineCreatePreview components
- Remove machine-skeleton pages and type pages
- Remove useMachineTypesApi, useMachineSkeletonEditor, useMachineCreateSelections composables
- Add AddEntityToMachineModal for direct entity linking
- Update machine detail/create pages for direct custom fields
- Fix SearchSelect, category display, and ipartial search filters

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-05 17:25:23 +01:00
parent 6f1bac381d
commit 32d03b480d
49 changed files with 1058 additions and 6093 deletions

View File

@@ -13,7 +13,7 @@
<div class="card bg-base-100 shadow-lg mb-6">
<div class="card-body">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="form-control">
<label class="label">
<span class="label-text">Site</span>
@@ -29,29 +29,14 @@
</div>
<div class="form-control">
<label class="label">
<span class="label-text">Type de machine</span>
<span class="label-text">Recherche</span>
</label>
<select v-model="selectedType" class="select select-bordered">
<option value="">
Tous les types
</option>
<option v-for="type in machineTypes" :key="type.id" :value="type.id">
{{ type.name }}
</option>
</select>
</div>
<div class="form-control">
<label class="label">
<span class="label-text">Catégorie</span>
</label>
<select v-model="selectedCategory" class="select select-bordered">
<option value="">
Toutes les catégories
</option>
<option v-for="category in categories" :key="category" :value="category">
{{ category }}
</option>
</select>
<input
v-model="searchQuery"
type="text"
placeholder="Rechercher par nom ou référence..."
class="input input-bordered"
>
</div>
</div>
</div>
@@ -88,26 +73,14 @@
<h3 class="card-title text-lg">
{{ machine.name }}
</h3>
<div class="badge badge-primary badge-sm">
{{ machine.typeMachine?.category || 'N/A' }}
</div>
</div>
<p class="text-sm text-gray-600 mb-3">
{{ machine.description || machine.typeMachine?.description }}
</p>
<div class="space-y-2 text-sm">
<div class="flex items-center gap-2">
<IconLucideMapPin class="w-4 h-4 text-blue-500" aria-hidden="true" />
<span class="text-gray-600">{{ machine.site?.name || 'Site inconnu' }}</span>
</div>
<div class="flex items-center gap-2">
<IconLucideSettings2 class="w-4 h-4 text-green-500" aria-hidden="true" />
<span class="text-gray-600">{{ machine.typeMachine?.name || 'Type inconnu' }}</span>
</div>
<div v-if="machine.reference" class="flex items-center gap-2">
<IconLucideTag class="w-4 h-4 text-orange-500" aria-hidden="true" />
<span class="text-gray-600">{{ machine.reference }}</span>
@@ -136,44 +109,28 @@
import { ref, computed, onMounted } from 'vue'
import { useMachines } from '~/composables/useMachines'
import { useSites } from '~/composables/useSites'
import { useMachineTypesApi } from '~/composables/useMachineTypesApi'
import { useToast } from '~/composables/useToast'
import { humanizeError } from '~/shared/utils/errorMessages'
import IconLucidePlus from '~icons/lucide/plus'
import IconLucideFactory from '~icons/lucide/factory'
import IconLucideMapPin from '~icons/lucide/map-pin'
import IconLucideSettings2 from '~icons/lucide/settings-2'
import IconLucideTag from '~icons/lucide/tag'
const { canEdit } = usePermissions()
const { machines, loading, loadMachines, deleteMachine } = useMachines()
const { sites, loadSites } = useSites()
const { machineTypes, loadMachineTypes } = useMachineTypesApi()
const toast = useToast()
const selectedSite = ref('')
const selectedType = ref('')
const selectedCategory = ref('')
const searchQuery = ref('')
const categories = computed(() => {
const cats = new Set()
machineTypes.value.forEach((type) => {
if (type.category) {
cats.add(type.category)
}
})
return Array.from(cats)
})
// Enrichir les machines avec les objets site et typeMachine complets
// Enrichir les machines avec les objets site complets
const enrichedMachines = computed(() => {
return machines.value.map((machine) => {
const site = sites.value.find(s => s.id === machine.siteId)
const typeMachine = machineTypes.value.find(t => t.id === machine.typeMachineId)
return {
...machine,
site: site || null,
typeMachine: typeMachine || null
}
})
})
@@ -185,12 +142,12 @@ const filteredMachines = computed(() => {
filtered = filtered.filter(machine => machine.siteId === selectedSite.value)
}
if (selectedType.value) {
filtered = filtered.filter(machine => machine.typeMachineId === selectedType.value)
}
if (selectedCategory.value) {
filtered = filtered.filter(machine => machine.typeMachine?.category === selectedCategory.value)
if (searchQuery.value.trim()) {
const term = searchQuery.value.trim().toLowerCase()
filtered = filtered.filter(machine =>
machine.name?.toLowerCase().includes(term)
|| machine.reference?.toLowerCase().includes(term),
)
}
return filtered
@@ -227,7 +184,6 @@ onMounted(async () => {
await Promise.all([
loadMachines(),
loadSites(),
loadMachineTypes()
])
})
</script>

View File

@@ -1,13 +1,13 @@
<template>
<main class="container mx-auto px-6 py-8">
<div class="max-w-5xl mx-auto">
<div class="max-w-3xl mx-auto">
<div class="flex flex-wrap items-center justify-between gap-3 mb-6">
<div>
<h1 class="text-2xl font-bold">
Nouvelle machine
</h1>
<p class="text-sm text-gray-500">
Renseignez les informations et la configuration avant de créer la machine.
Renseignez les informations de base pour créer la machine.
</p>
</div>
<NuxtLink to="/machines" class="btn btn-ghost">
@@ -15,21 +15,25 @@
</NuxtLink>
</div>
<form class="space-y-6" @submit.prevent="c.finalizeMachineCreation">
<div v-if="c.loading" class="flex justify-center items-center py-12">
<span class="loading loading-spinner loading-lg" />
</div>
<form v-else class="space-y-6" @submit.prevent="c.finalizeMachineCreation">
<div class="card bg-base-100 shadow-lg">
<div class="card-body space-y-6">
<!-- Basic fields -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="form-control">
<label class="label" for="machine-field-name">
<span class="label-text">Nom de la machine</span>
<span class="label-text">Nom de la machine <span class="text-error">*</span></span>
</label>
<input
id="machine-field-name"
v-model="c.newMachine.name"
type="text"
placeholder="Ex: Presse hydraulique #1"
class="input input-bordered"
class="input input-bordered input-sm md:input-md"
:disabled="!canEdit"
required
>
@@ -37,9 +41,15 @@
<div class="form-control">
<label class="label" for="machine-field-site">
<span class="label-text">Site</span>
<span class="label-text">Site <span class="text-error">*</span></span>
</label>
<select id="machine-field-site" v-model="c.newMachine.siteId" class="select select-bordered" :disabled="!canEdit" required>
<select
id="machine-field-site"
v-model="c.newMachine.siteId"
class="select select-bordered select-sm md:select-md"
:disabled="!canEdit"
required
>
<option value="">
Sélectionner un site
</option>
@@ -52,129 +62,43 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="form-control">
<label class="label">
<span class="label-text">Type de machine</span>
<label class="label" for="machine-field-reference">
<span class="label-text">Référence</span>
</label>
<SearchSelect
v-model="c.newMachine.typeMachineId"
:options="c.machineTypes"
:loading="c.machineTypesLoading"
<input
id="machine-field-reference"
v-model="c.newMachine.reference"
type="text"
placeholder="Ex: PRESS-001"
class="input input-bordered input-sm md:input-md"
:disabled="!canEdit"
placeholder="Rechercher un type…"
empty-text="Aucun type trouvé"
:option-label="c.machineTypeLabel"
:option-description="c.machineTypeDescription"
/>
>
</div>
<div class="form-control">
<label class="label">
<span class="label-text">Référence</span>
<span class="label-text">Cloner depuis une machine</span>
</label>
<input
v-model="c.newMachine.reference"
type="text"
placeholder="Ex: PRESS-001"
class="input input-bordered"
<SearchSelect
v-model="c.newMachine.cloneFromMachineId"
:options="c.machines"
:disabled="!canEdit"
>
:clearable="true"
placeholder="Rechercher une machine..."
empty-text="Aucune machine trouvée"
/>
</div>
</div>
<!-- Type structure summary -->
<div v-if="c.selectedMachineType" class="p-4 bg-gray-50 rounded-lg space-y-2 text-sm">
<h4 class="font-semibold text-sm">
Structure du type sélectionné :
</h4>
<div class="flex flex-wrap gap-3">
<span class="inline-flex items-center gap-2">
<span class="font-medium">Familles de composants :</span>
<span class="badge badge-sm">{{ c.selectedMachineType.componentRequirements?.length || 0 }}</span>
</span>
<span class="inline-flex items-center gap-2">
<span class="font-medium">Groupes de pièces :</span>
<span class="badge badge-sm">{{ c.selectedMachineType.pieceRequirements?.length || 0 }}</span>
</span>
<span class="inline-flex items-center gap-2">
<span class="font-medium">Produits requis :</span>
<span class="badge badge-sm">{{ c.selectedMachineType.productRequirements?.length || 0 }}</span>
</span>
<span class="inline-flex items-center gap-2">
<span class="font-medium">Catégorie :</span>
<span class="badge badge-outline badge-sm">{{ c.selectedMachineType.category || 'N/A' }}</span>
</span>
</div>
<p
v-if="(c.selectedMachineType.componentRequirements?.length || 0) === 0 && (c.selectedMachineType.pieceRequirements?.length || 0) === 0 && (c.selectedMachineType.productRequirements?.length || 0) === 0"
class="text-xs text-gray-500"
>
Ce type n'a pas encore de familles configurées. La machine héritera de la structure legacy du type.
</p>
</div>
<!-- Requirement selectors -->
<RequirementComponentSelector
:requirements="c.selectedMachineType?.componentRequirements || []"
:loading="c.composantsLoading"
:get-entries="c.getComponentRequirementEntries"
:get-options="c.getComponentOptions"
:resolve-type-label="c.resolveComponentRequirementTypeLabel"
:find-by-id="c.findComponentById"
:option-label="c.componentOptionLabel"
:option-description="c.componentOptionDescription"
@add-entry="c.addComponentSelectionEntry"
@remove-entry="c.removeComponentSelectionEntry"
@set-component="c.setComponentRequirementComponent"
/>
<RequirementPieceSelector
:requirements="c.selectedMachineType?.pieceRequirements || []"
:loading="c.piecesLoading"
:piece-loading-by-key="c.pieceLoadingByKey"
:get-entries="c.getPieceRequirementEntries"
:get-options="c.getPieceOptions"
:get-piece-key="c.getPieceKey"
:resolve-type-label="c.resolvePieceRequirementTypeLabel"
:find-by-id="c.findPieceById"
:option-label="c.pieceOptionLabel"
:option-description="c.pieceOptionDescription"
@add-entry="c.addPieceSelectionEntry"
@remove-entry="c.removePieceSelectionEntry"
@set-piece="c.setPieceRequirementPiece"
@search="c.fetchPieceOptions"
/>
<RequirementProductSelector
:requirements="c.selectedMachineType?.productRequirements || []"
:products-loading="c.productsLoading"
:get-entries="c.getProductRequirementEntries"
:get-product-options="c.getProductOptions"
:find-by-id="c.findProductById"
@add-entry="c.addProductSelectionEntry"
@remove-entry="c.removeProductSelectionEntry"
@set-product="c.setProductRequirementProduct"
/>
<!-- Preview -->
<MachineCreatePreview :preview="c.machinePreview" />
<!-- Blocking issues warning -->
<div
v-if="c.blockingPreviewIssues.length"
class="text-xs text-error bg-error/10 border border-error/20 rounded-md px-3 py-2"
>
Compléter les informations bloquantes avant de créer la machine.
</div>
<!-- Actions -->
<div class="flex justify-end gap-3 pt-4 border-t border-base-200">
<NuxtLink to="/machines" class="btn btn-outline">
<NuxtLink to="/machines" class="btn btn-outline btn-sm md:btn-md">
Annuler
</NuxtLink>
<button
type="submit"
class="btn btn-primary"
:disabled="!canEdit || !c.canCreateMachine || c.submitting"
class="btn btn-sm md:btn-md btn-primary"
:disabled="!canEdit || !c.newMachine.name?.trim() || c.submitting"
:class="{ loading: c.submitting }"
>
Créer la machine
@@ -191,10 +115,6 @@
import { proxyRefs } from 'vue'
import { useMachineCreatePage } from '~/composables/useMachineCreatePage'
import SearchSelect from '~/components/common/SearchSelect.vue'
import RequirementComponentSelector from '~/components/machine/create/RequirementComponentSelector.vue'
import RequirementPieceSelector from '~/components/machine/create/RequirementPieceSelector.vue'
import RequirementProductSelector from '~/components/machine/create/RequirementProductSelector.vue'
import MachineCreatePreview from '~/components/machine/create/MachineCreatePreview.vue'
const c = proxyRefs(useMachineCreatePage())
const { canEdit } = usePermissions()