WIP
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
class="text-xs text-base-content/50"
|
class="text-xs text-base-content/50"
|
||||||
>
|
>
|
||||||
{{ constructeur.name }}
|
{{ constructeur.name }}
|
||||||
|
<span v-if="supplierReferenceMap.get(constructeur.id)" class="opacity-70">({{ supplierReferenceMap.get(constructeur.id) }})</span>
|
||||||
</span>
|
</span>
|
||||||
<span v-if="displayProductName" class="badge badge-info badge-xs">
|
<span v-if="displayProductName" class="badge badge-info badge-xs">
|
||||||
{{ displayProductName }}
|
{{ displayProductName }}
|
||||||
@@ -102,6 +103,9 @@
|
|||||||
class="text-base-content"
|
class="text-base-content"
|
||||||
>
|
>
|
||||||
{{ constructeur.name }}
|
{{ constructeur.name }}
|
||||||
|
<span v-if="supplierReferenceMap.get(constructeur.id)" class="text-sm text-base-content/60">
|
||||||
|
— Réf. {{ supplierReferenceMap.get(constructeur.id) }}
|
||||||
|
</span>
|
||||||
<span v-if="formatConstructeurContact(constructeur)" class="text-xs text-base-content/50 block">
|
<span v-if="formatConstructeurContact(constructeur)" class="text-xs text-base-content/50 block">
|
||||||
{{ formatConstructeurContact(constructeur) }}
|
{{ formatConstructeurContact(constructeur) }}
|
||||||
</span>
|
</span>
|
||||||
@@ -292,6 +296,7 @@ import {
|
|||||||
formatConstructeurContact as formatConstructeurContactSummary,
|
formatConstructeurContact as formatConstructeurContactSummary,
|
||||||
resolveConstructeurs,
|
resolveConstructeurs,
|
||||||
uniqueConstructeurIds,
|
uniqueConstructeurIds,
|
||||||
|
parseConstructeurLinksFromApi,
|
||||||
} from '~/shared/constructeurUtils'
|
} from '~/shared/constructeurUtils'
|
||||||
import {
|
import {
|
||||||
formatSize,
|
formatSize,
|
||||||
@@ -391,23 +396,36 @@ const structurePieces = computed(() => allPieces.value.filter((p) => p._structur
|
|||||||
// --- Constructeurs ---
|
// --- Constructeurs ---
|
||||||
const { constructeurs } = useConstructeurs()
|
const { constructeurs } = useConstructeurs()
|
||||||
|
|
||||||
const componentConstructeurIds = computed(() =>
|
const componentConstructeurLinks = computed(() =>
|
||||||
uniqueConstructeurIds(
|
parseConstructeurLinksFromApi(
|
||||||
props.component,
|
|
||||||
Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [],
|
Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [],
|
||||||
props.component.constructeur ? [props.component.constructeur] : [],
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const componentConstructeursDisplay = computed(() =>
|
const supplierReferenceMap = computed(() => {
|
||||||
resolveConstructeurs(
|
const map = new Map()
|
||||||
componentConstructeurIds.value,
|
componentConstructeurLinks.value.forEach(l => {
|
||||||
Array.isArray(props.component.constructeurs) ? props.component.constructeurs : [],
|
if (l.supplierReference) map.set(l.constructeurId, l.supplierReference)
|
||||||
props.component.constructeur ? [props.component.constructeur] : [],
|
})
|
||||||
constructeurs.value,
|
return map
|
||||||
),
|
})
|
||||||
|
|
||||||
|
const componentConstructeurIds = computed(() =>
|
||||||
|
componentConstructeurLinks.value.map(l => l.constructeurId).filter(Boolean),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const componentConstructeursDisplay = computed(() => {
|
||||||
|
// Extract nested constructeur objects from link entries
|
||||||
|
const linkConstructeurs = componentConstructeurLinks.value
|
||||||
|
.filter(l => l.constructeur && l.constructeur.id)
|
||||||
|
.map(l => l.constructeur)
|
||||||
|
return resolveConstructeurs(
|
||||||
|
componentConstructeurIds.value,
|
||||||
|
linkConstructeurs,
|
||||||
|
constructeurs.value,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const formatConstructeurContact = (constructeur) =>
|
const formatConstructeurContact = (constructeur) =>
|
||||||
formatConstructeurContactSummary(constructeur)
|
formatConstructeurContactSummary(constructeur)
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ const getConstructeurContact = (link: ConstructeurLinkEntry): string => {
|
|||||||
|
|
||||||
const updateReference = (index: number, value: string) => {
|
const updateReference = (index: number, value: string) => {
|
||||||
const updated = [...props.modelValue]
|
const updated = [...props.modelValue]
|
||||||
updated[index] = { ...updated[index], supplierReference: value || null }
|
const entry = updated[index]
|
||||||
|
if (!entry) return
|
||||||
|
updated[index] = { ...entry, supplierReference: value || null }
|
||||||
emit('update:modelValue', updated)
|
emit('update:modelValue', updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +88,6 @@ const removeLink = (index: number) => {
|
|||||||
const removed = props.modelValue[index]
|
const removed = props.modelValue[index]
|
||||||
const updated = props.modelValue.filter((_, i) => i !== index)
|
const updated = props.modelValue.filter((_, i) => i !== index)
|
||||||
emit('update:modelValue', updated)
|
emit('update:modelValue', updated)
|
||||||
emit('remove', removed.constructeurId)
|
if (removed) emit('remove', removed.constructeurId)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
<IconLucideEye v-else class="w-5 h-5 mr-2" aria-hidden="true" />
|
<IconLucideEye v-else class="w-5 h-5 mr-2" aria-hidden="true" />
|
||||||
{{ isEditMode ? 'Voir détails' : 'Modifier' }}
|
{{ isEditMode ? 'Voir détails' : 'Modifier' }}
|
||||||
</button>
|
</button>
|
||||||
<NuxtLink :to="backLink" class="btn btn-ghost btn-sm md:btn-md">
|
<button type="button" class="btn btn-ghost btn-sm md:btn-md" @click="goBack">
|
||||||
Retour au catalogue
|
Retour au catalogue
|
||||||
</NuxtLink>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -26,7 +26,9 @@
|
|||||||
import IconLucideSquarePen from '~icons/lucide/square-pen'
|
import IconLucideSquarePen from '~icons/lucide/square-pen'
|
||||||
import IconLucideEye from '~icons/lucide/eye'
|
import IconLucideEye from '~icons/lucide/eye'
|
||||||
|
|
||||||
defineProps<{
|
const router = useRouter()
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
title: string
|
title: string
|
||||||
subtitle?: string
|
subtitle?: string
|
||||||
isEditMode: boolean
|
isEditMode: boolean
|
||||||
@@ -37,4 +39,13 @@ defineProps<{
|
|||||||
defineEmits<{
|
defineEmits<{
|
||||||
'toggle-edit': []
|
'toggle-edit': []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
function goBack() {
|
||||||
|
if (window.history.length > 1) {
|
||||||
|
router.back()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
navigateTo(props.backLink)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -50,6 +50,9 @@
|
|||||||
class="badge badge-outline badge-sm"
|
class="badge badge-outline badge-sm"
|
||||||
>
|
>
|
||||||
{{ constructeur.name }}
|
{{ constructeur.name }}
|
||||||
|
<span v-if="supplierReferenceMap.get(constructeur.id)" class="text-xs opacity-60 ml-0.5">
|
||||||
|
({{ supplierReferenceMap.get(constructeur.id) }})
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<span v-if="pieceData.prix" class="badge badge-primary badge-sm">{{ pieceData.prix }}€</span>
|
<span v-if="pieceData.prix" class="badge badge-primary badge-sm">{{ pieceData.prix }}€</span>
|
||||||
@@ -122,6 +125,9 @@
|
|||||||
>
|
>
|
||||||
<span class="font-medium">
|
<span class="font-medium">
|
||||||
{{ constructeur.name }}
|
{{ constructeur.name }}
|
||||||
|
<span v-if="supplierReferenceMap.get(constructeur.id)" class="text-sm font-normal text-base-content/60">
|
||||||
|
— Réf. {{ supplierReferenceMap.get(constructeur.id) }}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
v-if="formatConstructeurContact(constructeur)"
|
v-if="formatConstructeurContact(constructeur)"
|
||||||
@@ -283,6 +289,7 @@ import {
|
|||||||
formatConstructeurContact as formatConstructeurContactSummary,
|
formatConstructeurContact as formatConstructeurContactSummary,
|
||||||
resolveConstructeurs,
|
resolveConstructeurs,
|
||||||
uniqueConstructeurIds,
|
uniqueConstructeurIds,
|
||||||
|
parseConstructeurLinksFromApi,
|
||||||
} from '~/shared/constructeurUtils'
|
} from '~/shared/constructeurUtils'
|
||||||
import {
|
import {
|
||||||
resolveFieldId,
|
resolveFieldId,
|
||||||
@@ -393,23 +400,36 @@ const toggleCollapse = () => {
|
|||||||
// --- Constructeurs ---
|
// --- Constructeurs ---
|
||||||
const { constructeurs } = useConstructeurs()
|
const { constructeurs } = useConstructeurs()
|
||||||
|
|
||||||
const pieceConstructeurIds = computed(() =>
|
const pieceConstructeurLinks = computed(() =>
|
||||||
uniqueConstructeurIds(
|
parseConstructeurLinksFromApi(
|
||||||
props.piece,
|
|
||||||
Array.isArray(props.piece.constructeurs) ? props.piece.constructeurs : [],
|
Array.isArray(props.piece.constructeurs) ? props.piece.constructeurs : [],
|
||||||
props.piece.constructeur ? [props.piece.constructeur] : [],
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const pieceConstructeursDisplay = computed(() =>
|
const supplierReferenceMap = computed(() => {
|
||||||
resolveConstructeurs(
|
const map = new Map()
|
||||||
pieceConstructeurIds.value,
|
pieceConstructeurLinks.value.forEach(l => {
|
||||||
Array.isArray(props.piece.constructeurs) ? props.piece.constructeurs : [],
|
if (l.supplierReference) map.set(l.constructeurId, l.supplierReference)
|
||||||
props.piece.constructeur ? [props.piece.constructeur] : [],
|
})
|
||||||
constructeurs.value,
|
return map
|
||||||
),
|
})
|
||||||
|
|
||||||
|
const pieceConstructeurIds = computed(() =>
|
||||||
|
pieceConstructeurLinks.value.map(l => l.constructeurId).filter(Boolean),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pieceConstructeursDisplay = computed(() => {
|
||||||
|
// Extract nested constructeur objects from link entries
|
||||||
|
const linkConstructeurs = pieceConstructeurLinks.value
|
||||||
|
.filter(l => l.constructeur && l.constructeur.id)
|
||||||
|
.map(l => l.constructeur)
|
||||||
|
return resolveConstructeurs(
|
||||||
|
pieceConstructeurIds.value,
|
||||||
|
linkConstructeurs,
|
||||||
|
constructeurs.value,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const formatConstructeurContact = (constructeur) =>
|
const formatConstructeurContact = (constructeur) =>
|
||||||
formatConstructeurContactSummary(constructeur)
|
formatConstructeurContactSummary(constructeur)
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
<IconLucidePrinter class="w-5 h-5 mr-2" aria-hidden="true" />
|
<IconLucidePrinter class="w-5 h-5 mr-2" aria-hidden="true" />
|
||||||
Imprimer
|
Imprimer
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm md:btn-md" @click="goBack">
|
||||||
|
Retour aux machines
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -41,6 +44,8 @@ import IconLucideSquarePen from '~icons/lucide/square-pen'
|
|||||||
import IconLucideEye from '~icons/lucide/eye'
|
import IconLucideEye from '~icons/lucide/eye'
|
||||||
import IconLucidePrinter from '~icons/lucide/printer'
|
import IconLucidePrinter from '~icons/lucide/printer'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
title: string
|
title: string
|
||||||
isEditMode: boolean
|
isEditMode: boolean
|
||||||
@@ -50,4 +55,13 @@ defineEmits<{
|
|||||||
'toggle-edit': []
|
'toggle-edit': []
|
||||||
'open-print': []
|
'open-print': []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
function goBack() {
|
||||||
|
if (window.history.length > 1) {
|
||||||
|
router.back()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
navigateTo('/machines')
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
{{ machineReference }}
|
{{ machineReference }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isEditMode || hasMachineConstructeur" class="form-control">
|
<div v-if="isEditMode || hasMachineConstructeur" class="form-control md:col-span-2">
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span class="label-text">Fournisseur</span>
|
<span class="label-text">Fournisseur</span>
|
||||||
</label>
|
</label>
|
||||||
@@ -70,23 +70,15 @@
|
|||||||
placeholder="Rechercher un ou plusieurs fournisseurs..."
|
placeholder="Rechercher un ou plusieurs fournisseurs..."
|
||||||
@update:modelValue="$emit('update:constructeur-ids', $event)"
|
@update:modelValue="$emit('update:constructeur-ids', $event)"
|
||||||
/>
|
/>
|
||||||
<div v-else class="border border-base-300 rounded-btn bg-base-200 px-4 py-2 min-h-12 flex items-center">
|
<ConstructeurLinksTable
|
||||||
<div v-if="machineConstructeursDisplay.length" class="flex flex-wrap gap-2">
|
v-if="constructeurLinks.length"
|
||||||
<span
|
:model-value="constructeurLinks"
|
||||||
v-for="constructeur in machineConstructeursDisplay"
|
:readonly="!isEditMode"
|
||||||
:key="constructeur.id"
|
@update:model-value="$emit('update:constructeur-links', $event)"
|
||||||
class="badge badge-ghost gap-1"
|
@remove="$emit('remove-constructeur-link', $event)"
|
||||||
>
|
/>
|
||||||
{{ constructeur.name }}
|
<div v-else-if="!isEditMode" class="border border-base-300 rounded-btn bg-base-200 px-4 py-2 min-h-12 flex items-center">
|
||||||
<span
|
<span class="text-base-content/50">Non défini</span>
|
||||||
v-if="formatConstructeurContactSummary(constructeur)"
|
|
||||||
class="text-xs opacity-60"
|
|
||||||
>
|
|
||||||
· {{ formatConstructeurContactSummary(constructeur) }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span v-else class="text-base-content/50">Non défini</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -188,12 +180,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { watch } from 'vue'
|
import { watch } from 'vue'
|
||||||
import ConstructeurSelect from '~/components/ConstructeurSelect.vue'
|
import ConstructeurSelect from '~/components/ConstructeurSelect.vue'
|
||||||
|
import ConstructeurLinksTable from '~/components/ConstructeurLinksTable.vue'
|
||||||
import MachineCustomFieldDefEditor from '~/components/machine/MachineCustomFieldDefEditor.vue'
|
import MachineCustomFieldDefEditor from '~/components/machine/MachineCustomFieldDefEditor.vue'
|
||||||
import {
|
|
||||||
formatConstructeurContact as formatConstructeurContactSummary,
|
|
||||||
} from '~/shared/constructeurUtils'
|
|
||||||
import { formatCustomFieldValue } from '~/shared/utils/customFieldUtils'
|
import { formatCustomFieldValue } from '~/shared/utils/customFieldUtils'
|
||||||
import { useMachineCustomFieldDefs } from '~/composables/useMachineCustomFieldDefs'
|
import { useMachineCustomFieldDefs } from '~/composables/useMachineCustomFieldDefs'
|
||||||
|
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
isEditMode: boolean
|
isEditMode: boolean
|
||||||
@@ -205,6 +196,7 @@ const props = defineProps<{
|
|||||||
machineConstructeurIds: string[]
|
machineConstructeurIds: string[]
|
||||||
machineConstructeursDisplay: any[]
|
machineConstructeursDisplay: any[]
|
||||||
hasMachineConstructeur: boolean
|
hasMachineConstructeur: boolean
|
||||||
|
constructeurLinks: ConstructeurLinkEntry[]
|
||||||
visibleCustomFields: any[]
|
visibleCustomFields: any[]
|
||||||
getMachineFieldId: (fieldName: string) => string
|
getMachineFieldId: (fieldName: string) => string
|
||||||
machineId: string
|
machineId: string
|
||||||
@@ -216,6 +208,8 @@ const emit = defineEmits<{
|
|||||||
'update:machine-reference': [value: string]
|
'update:machine-reference': [value: string]
|
||||||
'update:machine-site-id': [value: string]
|
'update:machine-site-id': [value: string]
|
||||||
'update:constructeur-ids': [ids: unknown]
|
'update:constructeur-ids': [ids: unknown]
|
||||||
|
'update:constructeur-links': [links: ConstructeurLinkEntry[]]
|
||||||
|
'remove-constructeur-link': [constructeurId: string]
|
||||||
'set-custom-field-value': [field: any, value: unknown]
|
'set-custom-field-value': [field: any, value: unknown]
|
||||||
'custom-fields-saved': []
|
'custom-fields-saved': []
|
||||||
}>()
|
}>()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useApi } from '~/composables/useApi'
|
import { useApi } from '~/composables/useApi'
|
||||||
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
|
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
|
||||||
|
import { extractCollection } from '~/shared/utils/apiHelpers'
|
||||||
|
|
||||||
type EntityType = 'machine' | 'piece' | 'composant' | 'product'
|
type EntityType = 'machine' | 'piece' | 'composant' | 'product'
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ const ENTITY_PLURALS: Record<EntityType, string> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useConstructeurLinks() {
|
export function useConstructeurLinks() {
|
||||||
const { get, post, patch, del } = useApi()
|
const { get, post, patch, delete: del } = useApi()
|
||||||
|
|
||||||
const fetchLinks = async (
|
const fetchLinks = async (
|
||||||
entityType: EntityType,
|
entityType: EntityType,
|
||||||
@@ -34,11 +35,11 @@ export function useConstructeurLinks() {
|
|||||||
const endpoint = ENDPOINTS[entityType]
|
const endpoint = ENDPOINTS[entityType]
|
||||||
const key = ENTITY_KEYS[entityType]
|
const key = ENTITY_KEYS[entityType]
|
||||||
const plural = ENTITY_PLURALS[entityType]
|
const plural = ENTITY_PLURALS[entityType]
|
||||||
const result = await get(`${endpoint}?${key}=/api/${plural}/${entityId}`)
|
const url = `${endpoint}?${key}=/api/${plural}/${entityId}`
|
||||||
|
const result = await get(url)
|
||||||
if (!result.success || !result.data) return []
|
if (!result.success || !result.data) return []
|
||||||
|
|
||||||
const data = result.data as Record<string, any>
|
const members = extractCollection(result.data)
|
||||||
const members = data['hydra:member'] ?? (Array.isArray(data) ? data : [])
|
|
||||||
if (!Array.isArray(members)) return []
|
if (!Array.isArray(members)) return []
|
||||||
|
|
||||||
return members.map((link: any) => ({
|
return members.map((link: any) => ({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ref, computed, type Ref, type ComputedRef } from 'vue'
|
import { ref, computed, watch, type Ref, type ComputedRef } from 'vue'
|
||||||
import { useUrlState } from './useUrlState'
|
import { useUrlState } from './useUrlState'
|
||||||
import type { DataTableSort, DataTablePagination, DataTableColumnFilters, SortDirection } from '~/shared/types/dataTable'
|
import type { DataTableSort, DataTablePagination, DataTableColumnFilters, SortDirection } from '~/shared/types/dataTable'
|
||||||
|
|
||||||
@@ -22,6 +22,8 @@ export interface UseDataTableOptions {
|
|||||||
persistToUrl?: boolean
|
persistToUrl?: boolean
|
||||||
/** Extra URL state params for page-specific filters */
|
/** Extra URL state params for page-specific filters */
|
||||||
extraParams?: Record<string, { default: string | number; type?: 'string' | 'number' }>
|
extraParams?: Record<string, { default: string | number; type?: 'string' | 'number' }>
|
||||||
|
/** Column filter keys to persist in URL (prefixed with `f.` in query string) */
|
||||||
|
columnFilterKeys?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UseDataTableReturn {
|
export interface UseDataTableReturn {
|
||||||
@@ -56,6 +58,7 @@ export function useDataTable(
|
|||||||
searchDebounceMs = 300,
|
searchDebounceMs = 300,
|
||||||
persistToUrl = true,
|
persistToUrl = true,
|
||||||
extraParams = {},
|
extraParams = {},
|
||||||
|
columnFilterKeys = [],
|
||||||
} = options
|
} = options
|
||||||
|
|
||||||
let searchTerm: Ref<string>
|
let searchTerm: Ref<string>
|
||||||
@@ -64,6 +67,7 @@ export function useDataTable(
|
|||||||
let currentPage: Ref<number>
|
let currentPage: Ref<number>
|
||||||
let itemsPerPage: Ref<number>
|
let itemsPerPage: Ref<number>
|
||||||
const filters: Record<string, Ref<string | number>> = {}
|
const filters: Record<string, Ref<string | number>> = {}
|
||||||
|
const columnFilterRefs: Record<string, Ref<string>> = {}
|
||||||
|
|
||||||
if (persistToUrl) {
|
if (persistToUrl) {
|
||||||
const paramDefs: Record<string, { default: string | number; type?: 'string' | 'number'; debounce?: number }> = {
|
const paramDefs: Record<string, { default: string | number; type?: 'string' | 'number'; debounce?: number }> = {
|
||||||
@@ -75,6 +79,10 @@ export function useDataTable(
|
|||||||
...extraParams,
|
...extraParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const key of columnFilterKeys) {
|
||||||
|
paramDefs[`f.${key}`] = { default: '', debounce: 300 }
|
||||||
|
}
|
||||||
|
|
||||||
const state = useUrlState(paramDefs, {
|
const state = useUrlState(paramDefs, {
|
||||||
onRestore: () => deps.fetchData(),
|
onRestore: () => deps.fetchData(),
|
||||||
})
|
})
|
||||||
@@ -88,6 +96,10 @@ export function useDataTable(
|
|||||||
for (const key of Object.keys(extraParams)) {
|
for (const key of Object.keys(extraParams)) {
|
||||||
filters[key] = (state as Record<string, Ref<string | number>>)[key]!
|
filters[key] = (state as Record<string, Ref<string | number>>)[key]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const key of columnFilterKeys) {
|
||||||
|
columnFilterRefs[key] = (state as Record<string, Ref<string>>)[`f.${key}`]!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
searchTerm = ref('')
|
searchTerm = ref('')
|
||||||
@@ -137,8 +149,31 @@ export function useDataTable(
|
|||||||
deps.fetchData()
|
deps.fetchData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Column filters
|
// Column filters — seed from URL-persisted refs
|
||||||
const columnFilters = ref<DataTableColumnFilters>({})
|
const initialColumnFilters: DataTableColumnFilters = {}
|
||||||
|
for (const [key, r] of Object.entries(columnFilterRefs)) {
|
||||||
|
if (r.value) initialColumnFilters[key] = r.value
|
||||||
|
}
|
||||||
|
const columnFilters = ref<DataTableColumnFilters>(initialColumnFilters)
|
||||||
|
|
||||||
|
// Sync columnFilters → URL refs
|
||||||
|
if (persistToUrl && columnFilterKeys.length > 0) {
|
||||||
|
watch(columnFilters, (val) => {
|
||||||
|
for (const key of columnFilterKeys) {
|
||||||
|
columnFilterRefs[key]!.value = val[key] || ''
|
||||||
|
}
|
||||||
|
}, { deep: true })
|
||||||
|
|
||||||
|
// Sync URL refs → columnFilters (back/forward navigation)
|
||||||
|
for (const key of columnFilterKeys) {
|
||||||
|
watch(columnFilterRefs[key]!, (urlVal) => {
|
||||||
|
const current = columnFilters.value[key] || ''
|
||||||
|
if (current !== urlVal) {
|
||||||
|
columnFilters.value = { ...columnFilters.value, [key]: urlVal }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleColumnFiltersChange = (newFilters: DataTableColumnFilters) => {
|
const handleColumnFiltersChange = (newFilters: DataTableColumnFilters) => {
|
||||||
columnFilters.value = newFilters
|
columnFilters.value = newFilters
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ import {
|
|||||||
resolveConstructeurs,
|
resolveConstructeurs,
|
||||||
uniqueConstructeurIds,
|
uniqueConstructeurIds,
|
||||||
formatConstructeurContact as formatConstructeurContactSummary,
|
formatConstructeurContact as formatConstructeurContactSummary,
|
||||||
|
parseConstructeurLinksFromApi,
|
||||||
|
constructeurIdsFromLinks,
|
||||||
} from '~/shared/constructeurUtils'
|
} from '~/shared/constructeurUtils'
|
||||||
|
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
|
||||||
|
import { useConstructeurLinks } from '~/composables/useConstructeurLinks'
|
||||||
import { useMachineDetailDocuments } from '~/composables/useMachineDetailDocuments'
|
import { useMachineDetailDocuments } from '~/composables/useMachineDetailDocuments'
|
||||||
import { useMachineDetailCustomFields } from '~/composables/useMachineDetailCustomFields'
|
import { useMachineDetailCustomFields } from '~/composables/useMachineDetailCustomFields'
|
||||||
import { useMachineDetailHierarchy } from '~/composables/useMachineDetailHierarchy'
|
import { useMachineDetailHierarchy } from '~/composables/useMachineDetailHierarchy'
|
||||||
@@ -64,6 +68,11 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
const printAreaRef = ref<HTMLElement | null>(null)
|
const printAreaRef = ref<HTMLElement | null>(null)
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
|
|
||||||
|
// Constructeur links
|
||||||
|
const { fetchLinks, syncLinks } = useConstructeurLinks()
|
||||||
|
const constructeurLinks = ref<ConstructeurLinkEntry[]>([])
|
||||||
|
const originalConstructeurLinks = ref<ConstructeurLinkEntry[]>([])
|
||||||
|
|
||||||
// Machine fields
|
// Machine fields
|
||||||
const machineName = ref('')
|
const machineName = ref('')
|
||||||
const machineReference = ref('')
|
const machineReference = ref('')
|
||||||
@@ -78,20 +87,15 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const machineConstructeursDisplay = computed(() => {
|
const machineConstructeursDisplay = computed(() => {
|
||||||
const ids = uniqueConstructeurIds(
|
const ids = machineConstructeurIds.value
|
||||||
machineConstructeurIds.value,
|
if (!ids.length) return [] as any[]
|
||||||
(machine.value as AnyRecord)?.constructeurIds,
|
// Extract nested constructeur objects from link entries as candidate pool
|
||||||
(machine.value as AnyRecord)?.constructeurs,
|
const linkConstructeurs = constructeurLinks.value
|
||||||
(machine.value as AnyRecord)?.constructeur,
|
.filter(l => l.constructeur && l.constructeur.id)
|
||||||
)
|
.map(l => l.constructeur!) as any[]
|
||||||
return resolveConstructeurs(
|
return resolveConstructeurs(
|
||||||
ids,
|
ids,
|
||||||
Array.isArray((machine.value as AnyRecord)?.constructeurs)
|
linkConstructeurs,
|
||||||
? ((machine.value as AnyRecord).constructeurs as any[])
|
|
||||||
: [],
|
|
||||||
(machine.value as AnyRecord)?.constructeur
|
|
||||||
? [(machine.value as AnyRecord).constructeur as any]
|
|
||||||
: [],
|
|
||||||
constructeurs.value as any,
|
constructeurs.value as any,
|
||||||
) as any[]
|
) as any[]
|
||||||
})
|
})
|
||||||
@@ -235,11 +239,12 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
if (machine.value) {
|
if (machine.value) {
|
||||||
machineName.value = (machine.value.name as string) || ''
|
machineName.value = (machine.value.name as string) || ''
|
||||||
machineReference.value = (machine.value.reference as string) || ''
|
machineReference.value = (machine.value.reference as string) || ''
|
||||||
machineConstructeurIds.value = uniqueConstructeurIds(
|
// Parse constructeur links from structure response
|
||||||
machine.value.constructeurIds,
|
const rawLinks = Array.isArray(machine.value.constructeurs) ? machine.value.constructeurs as any[] : []
|
||||||
machine.value.constructeurs,
|
const parsed = parseConstructeurLinksFromApi(rawLinks)
|
||||||
machine.value.constructeur,
|
constructeurLinks.value = parsed
|
||||||
)
|
originalConstructeurLinks.value = parsed.map(l => ({ ...l }))
|
||||||
|
machineConstructeurIds.value = constructeurIdsFromLinks(parsed)
|
||||||
machineSiteId.value = (machine.value.siteId as string) || (machine.value.site as AnyRecord)?.id as string || ''
|
machineSiteId.value = (machine.value.siteId as string) || (machine.value.site as AnyRecord)?.id as string || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,6 +274,8 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
machineReference,
|
machineReference,
|
||||||
machineSiteId,
|
machineSiteId,
|
||||||
machineConstructeurIds,
|
machineConstructeurIds,
|
||||||
|
constructeurLinks,
|
||||||
|
originalConstructeurLinks,
|
||||||
machineDocumentsLoaded,
|
machineDocumentsLoaded,
|
||||||
machineComponentLinks,
|
machineComponentLinks,
|
||||||
machinePieceLinks,
|
machinePieceLinks,
|
||||||
@@ -284,6 +291,7 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
updatePieceApi,
|
updatePieceApi,
|
||||||
apiPatch,
|
apiPatch,
|
||||||
toast,
|
toast,
|
||||||
|
syncLinks,
|
||||||
})
|
})
|
||||||
|
|
||||||
// UI methods
|
// UI methods
|
||||||
@@ -338,6 +346,8 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
const cancelEdition = () => {
|
const cancelEdition = () => {
|
||||||
initMachineFields()
|
initMachineFields()
|
||||||
syncMachineCustomFields()
|
syncMachineCustomFields()
|
||||||
|
constructeurLinks.value = originalConstructeurLinks.value.map(l => ({ ...l }))
|
||||||
|
machineConstructeurIds.value = constructeurIdsFromLinks(constructeurLinks.value)
|
||||||
isEditMode.value = false
|
isEditMode.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,6 +477,7 @@ export function useMachineDetailData(machineId: string) {
|
|||||||
// Machine fields
|
// Machine fields
|
||||||
machineName, machineReference, machineSiteId, machineConstructeurIds, machineConstructeurId,
|
machineName, machineReference, machineSiteId, machineConstructeurIds, machineConstructeurId,
|
||||||
machineConstructeursDisplay, machineConstructeurContact, hasMachineConstructeur,
|
machineConstructeursDisplay, machineConstructeurContact, hasMachineConstructeur,
|
||||||
|
constructeurLinks, originalConstructeurLinks,
|
||||||
sites,
|
sites,
|
||||||
|
|
||||||
// UI state
|
// UI state
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
import { uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
import { uniqueConstructeurIds, constructeurIdsFromLinks } from '~/shared/constructeurUtils'
|
||||||
|
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
|
||||||
|
|
||||||
type AnyRecord = Record<string, unknown>
|
type AnyRecord = Record<string, unknown>
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ export interface UseMachineDetailUpdatesDeps {
|
|||||||
machineReference: Ref<string>
|
machineReference: Ref<string>
|
||||||
machineSiteId: Ref<string>
|
machineSiteId: Ref<string>
|
||||||
machineConstructeurIds: Ref<string[]>
|
machineConstructeurIds: Ref<string[]>
|
||||||
|
constructeurLinks: Ref<ConstructeurLinkEntry[]>
|
||||||
|
originalConstructeurLinks: Ref<ConstructeurLinkEntry[]>
|
||||||
machineDocumentsLoaded: Ref<boolean>
|
machineDocumentsLoaded: Ref<boolean>
|
||||||
machineComponentLinks: Ref<AnyRecord[]>
|
machineComponentLinks: Ref<AnyRecord[]>
|
||||||
machinePieceLinks: Ref<AnyRecord[]>
|
machinePieceLinks: Ref<AnyRecord[]>
|
||||||
@@ -35,6 +38,12 @@ export interface UseMachineDetailUpdatesDeps {
|
|||||||
updatePieceApi: (id: string, data: any) => Promise<unknown>
|
updatePieceApi: (id: string, data: any) => Promise<unknown>
|
||||||
apiPatch: (endpoint: string, data?: unknown) => Promise<any>
|
apiPatch: (endpoint: string, data?: unknown) => Promise<any>
|
||||||
toast: { showInfo: (msg: string) => void }
|
toast: { showInfo: (msg: string) => void }
|
||||||
|
syncLinks: (
|
||||||
|
entityType: 'machine' | 'piece' | 'composant' | 'product',
|
||||||
|
entityId: string,
|
||||||
|
originalLinks: ConstructeurLinkEntry[],
|
||||||
|
formLinks: ConstructeurLinkEntry[],
|
||||||
|
) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
||||||
@@ -44,6 +53,8 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
machineReference,
|
machineReference,
|
||||||
machineSiteId,
|
machineSiteId,
|
||||||
machineConstructeurIds,
|
machineConstructeurIds,
|
||||||
|
constructeurLinks,
|
||||||
|
originalConstructeurLinks,
|
||||||
machineComponentLinks,
|
machineComponentLinks,
|
||||||
machinePieceLinks,
|
machinePieceLinks,
|
||||||
applyMachineLinks,
|
applyMachineLinks,
|
||||||
@@ -56,19 +67,16 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
updatePieceApi,
|
updatePieceApi,
|
||||||
apiPatch,
|
apiPatch,
|
||||||
toast,
|
toast,
|
||||||
|
syncLinks,
|
||||||
} = deps
|
} = deps
|
||||||
|
|
||||||
const updateMachineInfo = async () => {
|
const updateMachineInfo = async () => {
|
||||||
if (!machine.value) return
|
if (!machine.value) return
|
||||||
try {
|
try {
|
||||||
const cIds = uniqueConstructeurIds(machineConstructeurIds.value)
|
|
||||||
machineConstructeurIds.value = cIds
|
|
||||||
|
|
||||||
const result: any = await updateMachineApi(machine.value.id as string, {
|
const result: any = await updateMachineApi(machine.value.id as string, {
|
||||||
name: machineName.value,
|
name: machineName.value,
|
||||||
reference: machineReference.value,
|
reference: machineReference.value,
|
||||||
siteId: machineSiteId.value || undefined,
|
siteId: machineSiteId.value || undefined,
|
||||||
constructeurIds: cIds,
|
|
||||||
} as any)
|
} as any)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const machinePayload =
|
const machinePayload =
|
||||||
@@ -82,11 +90,6 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
documents: machinePayload.documents || machine.value.documents || [],
|
documents: machinePayload.documents || machine.value.documents || [],
|
||||||
customFieldValues: machinePayload.customFieldValues || machine.value.customFieldValues || [],
|
customFieldValues: machinePayload.customFieldValues || machine.value.customFieldValues || [],
|
||||||
}
|
}
|
||||||
machineConstructeurIds.value = uniqueConstructeurIds(
|
|
||||||
machine.value!.constructeurIds,
|
|
||||||
machine.value!.constructeurs,
|
|
||||||
machine.value!.constructeur,
|
|
||||||
)
|
|
||||||
const linksApplied = applyMachineLinks(result.data)
|
const linksApplied = applyMachineLinks(result.data)
|
||||||
if (linksApplied && machine.value) {
|
if (linksApplied && machine.value) {
|
||||||
machine.value.componentLinks = machineComponentLinks.value
|
machine.value.componentLinks = machineComponentLinks.value
|
||||||
@@ -95,6 +98,9 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
loadProductDocuments().catch(() => {})
|
loadProductDocuments().catch(() => {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Sync constructeur links after entity save
|
||||||
|
await syncLinks('machine', machine.value!.id as string, originalConstructeurLinks.value, constructeurLinks.value)
|
||||||
|
originalConstructeurLinks.value = constructeurLinks.value.map(l => ({ ...l }))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur lors de la mise à jour de la machine:', error)
|
console.error('Erreur lors de la mise à jour de la machine:', error)
|
||||||
}
|
}
|
||||||
@@ -209,7 +215,13 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleMachineConstructeurChange = (value: unknown) => {
|
const handleMachineConstructeurChange = (value: unknown) => {
|
||||||
machineConstructeurIds.value = uniqueConstructeurIds(value)
|
const newIds = uniqueConstructeurIds(value)
|
||||||
|
machineConstructeurIds.value = newIds
|
||||||
|
// Sync constructeurLinks: keep existing entries, add new ones
|
||||||
|
const existingMap = new Map(constructeurLinks.value.map(l => [l.constructeurId, l]))
|
||||||
|
constructeurLinks.value = newIds.map(id =>
|
||||||
|
existingMap.get(id) ?? { constructeurId: id, supplierReference: null },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const editComponent = () => {
|
const editComponent = () => {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useToast } from './useToast'
|
import { useToast } from './useToast'
|
||||||
import { useApi, type ApiResponse } from './useApi'
|
import { useApi, type ApiResponse } from './useApi'
|
||||||
import { buildConstructeurRequestPayload } from '~/shared/constructeurUtils'
|
|
||||||
import { extractRelationId, normalizeRelationIds } from '~/shared/apiRelations'
|
import { extractRelationId, normalizeRelationIds } from '~/shared/apiRelations'
|
||||||
import { extractCollection } from '~/shared/utils/apiHelpers'
|
import { extractCollection } from '~/shared/utils/apiHelpers'
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ export function useMachines() {
|
|||||||
const createMachine = async (machineData: Partial<Machine>): Promise<ApiResponse> => {
|
const createMachine = async (machineData: Partial<Machine>): Promise<ApiResponse> => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(machineData))
|
const normalizedPayload = normalizeRelationIds(machineData as Record<string, unknown>)
|
||||||
const result = await post('/machines', normalizedPayload)
|
const result = await post('/machines', normalizedPayload)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const createdMachine = normalizeMachineResponse(result.data) ||
|
const createdMachine = normalizeMachineResponse(result.data) ||
|
||||||
@@ -116,7 +115,7 @@ export function useMachines() {
|
|||||||
const updateMachineData = async (id: string, machineData: Partial<Machine>): Promise<ApiResponse> => {
|
const updateMachineData = async (id: string, machineData: Partial<Machine>): Promise<ApiResponse> => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(machineData))
|
const normalizedPayload = normalizeRelationIds(machineData as Record<string, unknown>)
|
||||||
const result = await patch(`/machines/${id}`, normalizedPayload)
|
const result = await patch(`/machines/${id}`, normalizedPayload)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const updatedMachine = normalizeMachineResponse(result.data) ||
|
const updatedMachine = normalizeMachineResponse(result.data) ||
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ const table = useDataTable(
|
|||||||
status: { default: 'open' },
|
status: { default: 'open' },
|
||||||
entityType: { default: '' },
|
entityType: { default: '' },
|
||||||
},
|
},
|
||||||
|
columnFilterKeys: ['entity'],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ const { componentTypes, loadComponentTypes } = useComponentTypes()
|
|||||||
|
|
||||||
const table = useDataTable(
|
const table = useDataTable(
|
||||||
{ fetchData: fetchComposants },
|
{ fetchData: fetchComposants },
|
||||||
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true },
|
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true, columnFilterKeys: ['typeComposant'] },
|
||||||
)
|
)
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
:machine-constructeur-ids="d.machineConstructeurIds.value"
|
:machine-constructeur-ids="d.machineConstructeurIds.value"
|
||||||
:machine-constructeurs-display="d.machineConstructeursDisplay.value"
|
:machine-constructeurs-display="d.machineConstructeursDisplay.value"
|
||||||
:has-machine-constructeur="d.hasMachineConstructeur.value"
|
:has-machine-constructeur="d.hasMachineConstructeur.value"
|
||||||
|
:constructeur-links="d.constructeurLinks.value"
|
||||||
:visible-custom-fields="d.visibleMachineCustomFields.value"
|
:visible-custom-fields="d.visibleMachineCustomFields.value"
|
||||||
:get-machine-field-id="d.getMachineFieldId"
|
:get-machine-field-id="d.getMachineFieldId"
|
||||||
:machine-id="machineId"
|
:machine-id="machineId"
|
||||||
@@ -72,6 +73,8 @@
|
|||||||
@update:machine-reference="d.machineReference.value = $event"
|
@update:machine-reference="d.machineReference.value = $event"
|
||||||
@update:machine-site-id="d.machineSiteId.value = $event"
|
@update:machine-site-id="d.machineSiteId.value = $event"
|
||||||
@update:constructeur-ids="d.handleMachineConstructeurChange"
|
@update:constructeur-ids="d.handleMachineConstructeurChange"
|
||||||
|
@update:constructeur-links="d.constructeurLinks.value = $event"
|
||||||
|
@remove-constructeur-link="handleRemoveConstructeurLink"
|
||||||
@set-custom-field-value="d.setMachineCustomFieldValue"
|
@set-custom-field-value="d.setMachineCustomFieldValue"
|
||||||
@custom-fields-saved="() => { d.loadMachineData(); refreshVersions() }"
|
@custom-fields-saved="() => { d.loadMachineData(); refreshVersions() }"
|
||||||
/>
|
/>
|
||||||
@@ -196,9 +199,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<h3 class="text-lg font-semibold text-base-content mb-1">Machine non trouvée</h3>
|
<h3 class="text-lg font-semibold text-base-content mb-1">Machine non trouvée</h3>
|
||||||
<p class="text-sm text-base-content/50 mb-6">La machine avec l'ID "{{ machineId }}" n'existe pas ou a été supprimée.</p>
|
<p class="text-sm text-base-content/50 mb-6">La machine avec l'ID "{{ machineId }}" n'existe pas ou a été supprimée.</p>
|
||||||
<NuxtLink to="/machines" class="btn btn-primary">
|
<button type="button" class="btn btn-primary" @click="$router.back()">
|
||||||
Retour aux machines
|
Retour aux machines
|
||||||
</NuxtLink>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
@@ -280,6 +283,11 @@ const openAddModal = (kind) => {
|
|||||||
addModalOpen.value = true
|
addModalOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleRemoveConstructeurLink = (constructeurId) => {
|
||||||
|
const ids = d.machineConstructeurIds.value.filter(id => id !== constructeurId)
|
||||||
|
d.handleMachineConstructeurChange(ids)
|
||||||
|
}
|
||||||
|
|
||||||
const handleAddEntity = async (entityId) => {
|
const handleAddEntity = async (entityId) => {
|
||||||
if (addModalKind.value === 'component') {
|
if (addModalKind.value === 'component') {
|
||||||
await d.addComponentLink(entityId)
|
await d.addComponentLink(entityId)
|
||||||
|
|||||||
@@ -120,11 +120,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, computed, onMounted } from 'vue'
|
import { ref, reactive, computed, onMounted, watch } from 'vue'
|
||||||
import { useMachines } from '~/composables/useMachines'
|
import { useMachines } from '~/composables/useMachines'
|
||||||
import { useSites } from '~/composables/useSites'
|
import { useSites } from '~/composables/useSites'
|
||||||
import { useToast } from '~/composables/useToast'
|
import { useToast } from '~/composables/useToast'
|
||||||
import { humanizeError } from '~/shared/utils/errorMessages'
|
import { humanizeError } from '~/shared/utils/errorMessages'
|
||||||
|
import { useUrlState } from '~/composables/useUrlState'
|
||||||
import IconLucidePlus from '~icons/lucide/plus'
|
import IconLucidePlus from '~icons/lucide/plus'
|
||||||
import IconLucideFactory from '~icons/lucide/factory'
|
import IconLucideFactory from '~icons/lucide/factory'
|
||||||
import IconLucideMapPin from '~icons/lucide/map-pin'
|
import IconLucideMapPin from '~icons/lucide/map-pin'
|
||||||
@@ -135,8 +136,28 @@ const { machines, loading, loadMachines, deleteMachine } = useMachines()
|
|||||||
const { sites, loadSites } = useSites()
|
const { sites, loadSites } = useSites()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
|
||||||
|
const urlState = useUrlState({
|
||||||
|
q: { default: '', debounce: 300 },
|
||||||
|
sites: { default: '' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const searchQuery = urlState.q
|
||||||
const selectedSites = reactive(new Set())
|
const selectedSites = reactive(new Set())
|
||||||
const searchQuery = ref('')
|
|
||||||
|
// Sync URL → selectedSites on load and back/forward
|
||||||
|
watch(urlState.sites, (val) => {
|
||||||
|
selectedSites.clear()
|
||||||
|
if (val) {
|
||||||
|
for (const id of String(val).split(',')) {
|
||||||
|
if (id) selectedSites.add(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
|
||||||
|
// Sync selectedSites → URL
|
||||||
|
watch(() => [...selectedSites], (ids) => {
|
||||||
|
urlState.sites.value = ids.join(',')
|
||||||
|
})
|
||||||
|
|
||||||
// Enrichir les machines avec les objets site complets
|
// Enrichir les machines avec les objets site complets
|
||||||
const enrichedMachines = computed(() => {
|
const enrichedMachines = computed(() => {
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ const loadCategory = async () => {
|
|||||||
category: response.category,
|
category: response.category,
|
||||||
notes: response.notes ?? response.description ?? '',
|
notes: response.notes ?? response.description ?? '',
|
||||||
structure: (response.structure as PieceModelStructure | null) ?? undefined,
|
structure: (response.structure as PieceModelStructure | null) ?? undefined,
|
||||||
|
referenceFormula: response.referenceFormula ?? null,
|
||||||
|
requiredFieldsForReference: response.requiredFieldsForReference ?? null,
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ const { pieceTypes, loadPieceTypes } = usePieceTypes()
|
|||||||
|
|
||||||
const table = useDataTable(
|
const table = useDataTable(
|
||||||
{ fetchData: fetchPieces },
|
{ fetchData: fetchPieces },
|
||||||
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true },
|
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true, columnFilterKeys: ['typePiece'] },
|
||||||
)
|
)
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
|
|||||||
@@ -91,6 +91,10 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ConstructeurLinksTable
|
||||||
|
v-if="constructeurLinks.length"
|
||||||
|
v-model="constructeurLinks"
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
@@ -213,6 +217,7 @@
|
|||||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import { useRoute, useRouter } from '#imports'
|
import { useRoute, useRouter } from '#imports'
|
||||||
import ConstructeurSelect from '~/components/ConstructeurSelect.vue'
|
import ConstructeurSelect from '~/components/ConstructeurSelect.vue'
|
||||||
|
import ConstructeurLinksTable from '~/components/ConstructeurLinksTable.vue'
|
||||||
import DocumentUpload from '~/components/DocumentUpload.vue'
|
import DocumentUpload from '~/components/DocumentUpload.vue'
|
||||||
import ProductSelect from '~/components/ProductSelect.vue'
|
import ProductSelect from '~/components/ProductSelect.vue'
|
||||||
import SearchSelect from '~/components/common/SearchSelect.vue'
|
import SearchSelect from '~/components/common/SearchSelect.vue'
|
||||||
@@ -222,8 +227,11 @@ import { useToast } from '~/composables/useToast'
|
|||||||
import { humanizeError } from '~/shared/utils/errorMessages'
|
import { humanizeError } from '~/shared/utils/errorMessages'
|
||||||
import { useCustomFields } from '~/composables/useCustomFields'
|
import { useCustomFields } from '~/composables/useCustomFields'
|
||||||
import { useDocuments } from '~/composables/useDocuments'
|
import { useDocuments } from '~/composables/useDocuments'
|
||||||
|
import { useConstructeurLinks } from '~/composables/useConstructeurLinks'
|
||||||
|
import { useConstructeurs } from '~/composables/useConstructeurs'
|
||||||
import { formatPieceStructurePreview } from '~/shared/modelUtils'
|
import { formatPieceStructurePreview } from '~/shared/modelUtils'
|
||||||
import { uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
import { constructeurIdsFromLinks } from '~/shared/constructeurUtils'
|
||||||
|
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
|
||||||
import type { PieceModelStructure } from '~/shared/types/inventory'
|
import type { PieceModelStructure } from '~/shared/types/inventory'
|
||||||
import type { ModelType } from '~/services/modelTypes'
|
import type { ModelType } from '~/services/modelTypes'
|
||||||
import {
|
import {
|
||||||
@@ -255,6 +263,8 @@ const { createPiece } = usePieces()
|
|||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { upsertCustomFieldValue, updateCustomFieldValue } = useCustomFields()
|
const { upsertCustomFieldValue, updateCustomFieldValue } = useCustomFields()
|
||||||
const { uploadDocuments } = useDocuments()
|
const { uploadDocuments } = useDocuments()
|
||||||
|
const { syncLinks } = useConstructeurLinks()
|
||||||
|
const { getConstructeurById } = useConstructeurs()
|
||||||
const { canEdit } = usePermissions()
|
const { canEdit } = usePermissions()
|
||||||
|
|
||||||
const initialTypeId = ref<string>(typeof route.query.typeId === 'string' ? route.query.typeId : '')
|
const initialTypeId = ref<string>(typeof route.query.typeId === 'string' ? route.query.typeId : '')
|
||||||
@@ -267,6 +277,7 @@ const creationForm = reactive({
|
|||||||
constructeurIds: [] as string[],
|
constructeurIds: [] as string[],
|
||||||
prix: '' as string,
|
prix: '' as string,
|
||||||
})
|
})
|
||||||
|
const constructeurLinks = ref<ConstructeurLinkEntry[]>([])
|
||||||
const productSelections = ref<(string | null)[]>([])
|
const productSelections = ref<(string | null)[]>([])
|
||||||
|
|
||||||
const lastSuggestedName = ref('')
|
const lastSuggestedName = ref('')
|
||||||
@@ -380,6 +391,7 @@ const clearCreationForm = () => {
|
|||||||
creationForm.description = ''
|
creationForm.description = ''
|
||||||
creationForm.reference = ''
|
creationForm.reference = ''
|
||||||
creationForm.constructeurIds = []
|
creationForm.constructeurIds = []
|
||||||
|
constructeurLinks.value = []
|
||||||
creationForm.prix = ''
|
creationForm.prix = ''
|
||||||
productSelections.value = []
|
productSelections.value = []
|
||||||
lastSuggestedName.value = ''
|
lastSuggestedName.value = ''
|
||||||
@@ -411,8 +423,6 @@ const submitCreation = async () => {
|
|||||||
payload.reference = reference
|
payload.reference = reference
|
||||||
}
|
}
|
||||||
|
|
||||||
payload.constructeurIds = uniqueConstructeurIds(creationForm.constructeurIds)
|
|
||||||
|
|
||||||
const normalizedProductIds = collectNormalizedProductIds(
|
const normalizedProductIds = collectNormalizedProductIds(
|
||||||
productRequirementEntries.value,
|
productRequirementEntries.value,
|
||||||
productSelections.value,
|
productSelections.value,
|
||||||
@@ -448,6 +458,10 @@ const submitCreation = async () => {
|
|||||||
],
|
],
|
||||||
{ customFieldInputs, upsertCustomFieldValue, updateCustomFieldValue, toast },
|
{ customFieldInputs, upsertCustomFieldValue, updateCustomFieldValue, toast },
|
||||||
)
|
)
|
||||||
|
// Sync constructeur links after creation
|
||||||
|
if (constructeurLinks.value.length) {
|
||||||
|
await syncLinks('piece', createdPiece.id, [], constructeurLinks.value)
|
||||||
|
}
|
||||||
if (selectedDocuments.value.length && createdPiece.id) {
|
if (selectedDocuments.value.length && createdPiece.id) {
|
||||||
uploadingDocuments.value = true
|
uploadingDocuments.value = true
|
||||||
const uploadResult = await uploadDocuments(
|
const uploadResult = await uploadDocuments(
|
||||||
@@ -478,6 +492,26 @@ const submitCreation = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync constructeurIds → constructeurLinks when IDs are added via ConstructeurSelect
|
||||||
|
watch(
|
||||||
|
() => creationForm.constructeurIds,
|
||||||
|
(ids) => {
|
||||||
|
const currentIds = new Set(constructeurLinks.value.map(l => l.constructeurId))
|
||||||
|
for (const id of ids) {
|
||||||
|
if (!currentIds.has(id)) {
|
||||||
|
const resolved = getConstructeurById(id)
|
||||||
|
constructeurLinks.value.push({
|
||||||
|
constructeurId: id,
|
||||||
|
constructeur: resolved ? { id: resolved.id, name: resolved.name } : null,
|
||||||
|
supplierReference: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
constructeurLinks.value = constructeurLinks.value.filter(l => ids.includes(l.constructeurId))
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
)
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await loadPieceTypes()
|
await loadPieceTypes()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ const toast = useToast()
|
|||||||
|
|
||||||
const table = useDataTable(
|
const table = useDataTable(
|
||||||
{ fetchData: fetchProducts },
|
{ fetchData: fetchProducts },
|
||||||
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true },
|
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true, columnFilterKeys: ['typeProduct'] },
|
||||||
)
|
)
|
||||||
|
|
||||||
const errorMessage = computed(() => (typeof error.value === 'string' && error.value.length ? error.value : null))
|
const errorMessage = computed(() => (typeof error.value === 'string' && error.value.length ? error.value : null))
|
||||||
|
|||||||
@@ -139,49 +139,3 @@ export const formatConstructeurContact = (
|
|||||||
return [constructeur.email, phone].filter(Boolean).join(' • ');
|
return [constructeur.email, phone].filter(Boolean).join(' • ');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildConstructeurRequestPayload = <T extends Record<string, any>>(
|
|
||||||
payload: T,
|
|
||||||
): T & { constructeurs?: string[] } => {
|
|
||||||
const collected = new Set(uniqueConstructeurIds(
|
|
||||||
payload?.constructeurIds,
|
|
||||||
payload?.constructeurId,
|
|
||||||
payload?.constructeur,
|
|
||||||
payload?.constructeurs,
|
|
||||||
));
|
|
||||||
|
|
||||||
if (!collected.size) {
|
|
||||||
const fallbackLists = [
|
|
||||||
payload?.constructeurIds,
|
|
||||||
payload?.constructeurs,
|
|
||||||
];
|
|
||||||
fallbackLists.forEach((list) => {
|
|
||||||
if (!Array.isArray(list)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
list.forEach((item) => {
|
|
||||||
if (typeof item === 'string') {
|
|
||||||
const id = toStringId(item);
|
|
||||||
if (id) {
|
|
||||||
collected.add(id);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isObject(item) && typeof item.id === 'string') {
|
|
||||||
collected.add(item.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const ids = Array.from(collected);
|
|
||||||
|
|
||||||
const next = { ...payload } as Record<string, any>;
|
|
||||||
delete next.constructeurId;
|
|
||||||
delete next.constructeur;
|
|
||||||
delete next.constructeurs;
|
|
||||||
delete next.constructeurIds;
|
|
||||||
|
|
||||||
next.constructeurs = ids.map((id) => `/api/constructeurs/${id}`);
|
|
||||||
|
|
||||||
return next as T & { constructeurs?: string[] };
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ export default defineNuxtConfig({
|
|||||||
appVersion: appVersion,
|
appVersion: appVersion,
|
||||||
apiTimeout: process.env.NUXT_PUBLIC_API_TIMEOUT || '30000',
|
apiTimeout: process.env.NUXT_PUBLIC_API_TIMEOUT || '30000',
|
||||||
requestTimeout: process.env.NUXT_PUBLIC_REQUEST_TIMEOUT || '10000',
|
requestTimeout: process.env.NUXT_PUBLIC_REQUEST_TIMEOUT || '10000',
|
||||||
enableDebug: process.env.NUXT_PUBLIC_ENABLE_DEBUG || 'true',
|
enableDebug: process.env.NUXT_PUBLIC_ENABLE_DEBUG || 'false',
|
||||||
enableAnalytics: process.env.NUXT_PUBLIC_ENABLE_ANALYTICS || 'false',
|
enableAnalytics: process.env.NUXT_PUBLIC_ENABLE_ANALYTICS || 'false',
|
||||||
csrfToken: process.env.NUXT_PUBLIC_CSRF_TOKEN || '',
|
csrfToken: process.env.NUXT_PUBLIC_CSRF_TOKEN || '',
|
||||||
logLevel: process.env.NUXT_PUBLIC_LOG_LEVEL || 'debug'
|
logLevel: process.env.NUXT_PUBLIC_LOG_LEVEL || 'warn'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
|
|||||||
Reference in New Issue
Block a user