chore: update frontend configuration
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
import { getFileIcon } from './fileIcons'
|
||||
|
||||
export const getPreviewType = (document) => {
|
||||
if (!document) return null
|
||||
if (!document) { return null }
|
||||
const mime = (document.mimeType || '').toLowerCase()
|
||||
const path = document.path || ''
|
||||
|
||||
const check = (prefix) => mime.startsWith(prefix) || path.startsWith(`data:${prefix}`)
|
||||
const check = prefix => mime.startsWith(prefix) || path.startsWith(`data:${prefix}`)
|
||||
|
||||
if (check('image/')) return 'image'
|
||||
if (mime === 'application/pdf' || path.startsWith('data:application/pdf')) return 'pdf'
|
||||
if (check('audio/')) return 'audio'
|
||||
if (check('video/')) return 'video'
|
||||
if (check('text/') || mime.includes('json') || mime.includes('xml') || path.startsWith('data:application/json')) return 'text'
|
||||
if (check('image/')) { return 'image' }
|
||||
if (mime === 'application/pdf' || path.startsWith('data:application/pdf')) { return 'pdf' }
|
||||
if (check('audio/')) { return 'audio' }
|
||||
if (check('video/')) { return 'video' }
|
||||
if (check('text/') || mime.includes('json') || mime.includes('xml') || path.startsWith('data:application/json')) { return 'text' }
|
||||
return null
|
||||
}
|
||||
|
||||
export const canPreviewDocument = (document = {}) => !!getPreviewType(document)
|
||||
|
||||
export const describeDocument = (document) => {
|
||||
if (!document) return ''
|
||||
if (!document) { return '' }
|
||||
const name = document.filename || document.name || ''
|
||||
const icon = getFileIcon({ name, mime: document.mimeType })
|
||||
return icon.label
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
const formatSize = (size) => {
|
||||
if (size === undefined || size === null) return '—'
|
||||
if (size === 0) return '0 B'
|
||||
if (size === undefined || size === null) { return '—' }
|
||||
if (size === 0) { return '0 B' }
|
||||
const units = ['B', 'KB', 'MB', 'GB']
|
||||
const index = Math.min(units.length - 1, Math.floor(Math.log(size) / Math.log(1024)))
|
||||
const formatted = size / Math.pow(1024, index)
|
||||
@@ -15,9 +13,9 @@ const renderPrintField = (label, value, fallback = '—') => {
|
||||
}
|
||||
|
||||
const renderPrintCustomFields = (fields = [], title, sectionClass = 'print-section') => {
|
||||
if (!fields.length) return ''
|
||||
if (!fields.length) { return '' }
|
||||
const items = fields
|
||||
.map((field) => `<div class="print-field"><label>${field.label}</label><span>${field.value || '—'}</span></div>`)
|
||||
.map(field => `<div class="print-field"><label>${field.label}</label><span>${field.value || '—'}</span></div>`)
|
||||
.join('')
|
||||
return `
|
||||
<div class="${sectionClass}">
|
||||
@@ -30,9 +28,9 @@ const renderPrintCustomFields = (fields = [], title, sectionClass = 'print-secti
|
||||
}
|
||||
|
||||
const renderPrintDocuments = (documents = [], title, sectionClass = 'print-section') => {
|
||||
if (!documents.length) return ''
|
||||
if (!documents.length) { return '' }
|
||||
const rows = documents
|
||||
.map((doc) => `<tr><td>${doc.name}</td><td>${doc.type}</td><td>${doc.size}</td></tr>`)
|
||||
.map(doc => `<tr><td>${doc.name}</td><td>${doc.type}</td><td>${doc.size}</td></tr>`)
|
||||
.join('')
|
||||
return `
|
||||
<div class="${sectionClass}">
|
||||
@@ -54,9 +52,9 @@ const renderPrintDocuments = (documents = [], title, sectionClass = 'print-secti
|
||||
const renderPrintPieces = (
|
||||
pieces = [],
|
||||
title = 'Pièces indépendantes',
|
||||
sectionClass = 'print-section print-section--pieces',
|
||||
sectionClass = 'print-section print-section--pieces'
|
||||
) => {
|
||||
if (!pieces.length) return ''
|
||||
if (!pieces.length) { return '' }
|
||||
|
||||
const cards = pieces
|
||||
.map((piece, idx) => {
|
||||
@@ -66,14 +64,14 @@ const renderPrintPieces = (
|
||||
: ''
|
||||
|
||||
const customFields = (piece.customFields || [])
|
||||
.filter((field) => field.value && field.value !== '—' && field.value !== '')
|
||||
.filter(field => field.value && field.value !== '—' && field.value !== '')
|
||||
.map(
|
||||
(field) => `
|
||||
field => `
|
||||
<li>
|
||||
<span class="print-list-label">${field.label}</span>
|
||||
<span class="print-list-value">${field.value}</span>
|
||||
</li>
|
||||
`,
|
||||
`
|
||||
)
|
||||
.join('')
|
||||
|
||||
@@ -83,7 +81,7 @@ const renderPrintPieces = (
|
||||
|
||||
const documentsBlock = (piece.documents || []).length
|
||||
? `<div class="print-piece-section"><h4>Documents</h4><ul class="print-list">${piece.documents
|
||||
.map((doc) => `<li>${doc.name} <span class="print-list-hint">(${doc.type} • ${doc.size})</span></li>`)
|
||||
.map(doc => `<li>${doc.name} <span class="print-list-hint">(${doc.type} • ${doc.size})</span></li>`)
|
||||
.join('')}</ul></div>`
|
||||
: ''
|
||||
|
||||
@@ -126,7 +124,7 @@ const renderPrintPieces = (
|
||||
}
|
||||
|
||||
const renderPrintComponents = (components = [], depth = 0, indexPath = []) => {
|
||||
if (!components.length) return ''
|
||||
if (!components.length) { return '' }
|
||||
return components
|
||||
.map((component, idx) => {
|
||||
const badges = []
|
||||
@@ -143,21 +141,21 @@ const renderPrintComponents = (components = [], depth = 0, indexPath = []) => {
|
||||
<span>Composant : ${component.name}</span>
|
||||
</h3>
|
||||
${component.description ? `<p class="print-muted">${component.description}</p>` : ''}
|
||||
${badges.length ? `<div class="badge-group">${badges.map((badge) => `<span class="print-badge">${badge}</span>`).join('')}</div>` : ''}
|
||||
${badges.length ? `<div class="badge-group">${badges.map(badge => `<span class="print-badge">${badge}</span>`).join('')}</div>` : ''}
|
||||
${renderPrintCustomFields(
|
||||
component.customFields,
|
||||
'Champs personnalisés',
|
||||
'print-section print-subsection print-section--custom-fields',
|
||||
'print-section print-subsection print-section--custom-fields'
|
||||
)}
|
||||
${renderPrintPieces(
|
||||
(component.pieces || []).map((piece, pieceIdx) => ({ ...piece, indexPath: [...currentIndex, pieceIdx + 1] })),
|
||||
'Pièces du composant',
|
||||
'print-section print-subsection print-section--pieces',
|
||||
'print-section print-subsection print-section--pieces'
|
||||
)}
|
||||
${renderPrintDocuments(
|
||||
component.documents,
|
||||
'Documents du composant',
|
||||
'print-section print-subsection print-section--documents',
|
||||
'print-section print-subsection print-section--documents'
|
||||
)}
|
||||
${renderPrintComponents(component.subComponents || [], depth + 1, currentIndex)}
|
||||
</div>
|
||||
@@ -167,31 +165,31 @@ const renderPrintComponents = (components = [], depth = 0, indexPath = []) => {
|
||||
}
|
||||
|
||||
const normalizeDocuments = (docs = []) => {
|
||||
return docs.map((doc) => ({
|
||||
return docs.map(doc => ({
|
||||
id: doc.id,
|
||||
name: doc.name || doc.filename || 'Document',
|
||||
type: doc.mimeType || doc.type || '—',
|
||||
size: formatSize(doc.size),
|
||||
size: formatSize(doc.size)
|
||||
}))
|
||||
}
|
||||
|
||||
const normalizeCustomFields = (values = []) => {
|
||||
return values.map((value) => ({
|
||||
return values.map(value => ({
|
||||
id: value.id,
|
||||
label: value.customField?.name || 'Champ',
|
||||
value: value.value || '—',
|
||||
value: value.value || '—'
|
||||
}))
|
||||
}
|
||||
|
||||
const normalizeConstructeur = (constructeur) => {
|
||||
if (!constructeur) return null
|
||||
if (!constructeur) { return null }
|
||||
return {
|
||||
name: constructeur.name || '—',
|
||||
contact: [constructeur.email, constructeur.phone].filter(Boolean).join(' • ') || '—',
|
||||
contact: [constructeur.email, constructeur.phone].filter(Boolean).join(' • ') || '—'
|
||||
}
|
||||
}
|
||||
|
||||
const normalizePiece = (piece) => ({
|
||||
const normalizePiece = piece => ({
|
||||
id: piece.id,
|
||||
name: piece.name || 'Pièce sans nom',
|
||||
description: piece.description || '',
|
||||
@@ -199,10 +197,10 @@ const normalizePiece = (piece) => ({
|
||||
customFields: normalizeCustomFields(piece.customFieldValues || []),
|
||||
documents: normalizeDocuments(piece.documents || []),
|
||||
constructeur: normalizeConstructeur(piece.constructeur),
|
||||
indexPath: piece.indexPath || null,
|
||||
indexPath: piece.indexPath || null
|
||||
})
|
||||
|
||||
const normalizeComponent = (component) => ({
|
||||
const normalizeComponent = component => ({
|
||||
id: component.id,
|
||||
name: component.name || 'Composant sans nom',
|
||||
description: component.description || '',
|
||||
@@ -210,7 +208,7 @@ const normalizeComponent = (component) => ({
|
||||
documents: normalizeDocuments(component.documents || []),
|
||||
pieces: (component.pieces || []).map(normalizePiece),
|
||||
subComponents: (component.sousComposants || component.subComponents || []).map(normalizeComponent),
|
||||
constructeur: normalizeConstructeur(component.constructeur),
|
||||
constructeur: normalizeConstructeur(component.constructeur)
|
||||
})
|
||||
|
||||
export const buildMachinePrintContext = ({
|
||||
@@ -219,7 +217,7 @@ export const buildMachinePrintContext = ({
|
||||
machineReference,
|
||||
machinePieces = [],
|
||||
components = [],
|
||||
selection,
|
||||
selection
|
||||
}) => {
|
||||
const selectionState = selection || {}
|
||||
const machineSelection = selectionState.machine || {}
|
||||
@@ -231,7 +229,7 @@ export const buildMachinePrintContext = ({
|
||||
const includeMachineDocuments = machineSelection.documents !== false
|
||||
|
||||
const isComponentSelected = (id) => {
|
||||
if (!id) return true
|
||||
if (!id) { return true }
|
||||
if (Object.prototype.hasOwnProperty.call(componentSelection, id)) {
|
||||
return componentSelection[id]
|
||||
}
|
||||
@@ -239,7 +237,7 @@ export const buildMachinePrintContext = ({
|
||||
}
|
||||
|
||||
const isPieceSelected = (id) => {
|
||||
if (!id) return true
|
||||
if (!id) { return true }
|
||||
if (Object.prototype.hasOwnProperty.call(pieceSelection, id)) {
|
||||
return pieceSelection[id]
|
||||
}
|
||||
@@ -259,16 +257,16 @@ export const buildMachinePrintContext = ({
|
||||
|
||||
const normalizedPieces = machinePieces
|
||||
.map(normalizePiece)
|
||||
.filter((piece) => isPieceSelected(piece.id))
|
||||
.filter(piece => isPieceSelected(piece.id))
|
||||
.map((piece, idx) => ({
|
||||
...piece,
|
||||
indexPath: [idx + 1],
|
||||
indexPath: [idx + 1]
|
||||
}))
|
||||
|
||||
const normalizedComponents = components.map(normalizeComponent)
|
||||
|
||||
const filterComponentTree = (component) => {
|
||||
const filteredPieces = (component.pieces || []).filter((piece) => isPieceSelected(piece.id))
|
||||
const filteredPieces = (component.pieces || []).filter(piece => isPieceSelected(piece.id))
|
||||
const filteredSubComponents = (component.subComponents || [])
|
||||
.map(filterComponentTree)
|
||||
.filter(Boolean)
|
||||
@@ -283,7 +281,7 @@ export const buildMachinePrintContext = ({
|
||||
return {
|
||||
...component,
|
||||
pieces: filteredPieces,
|
||||
subComponents: filteredSubComponents,
|
||||
subComponents: filteredSubComponents
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,17 +307,17 @@ export const buildMachinePrintContext = ({
|
||||
: [],
|
||||
documents: includeMachineDocuments
|
||||
? normalizeDocuments(machine?.documents || [])
|
||||
: [],
|
||||
: []
|
||||
},
|
||||
components: filteredComponents,
|
||||
pieces: normalizedPieces,
|
||||
pieces: normalizedPieces
|
||||
}
|
||||
}
|
||||
|
||||
export const buildMachinePrintHtml = (context, styles) => {
|
||||
const title = context.machine.name ? `Impression - ${context.machine.name}` : 'Impression machine'
|
||||
const badgesHtml = context.machine.badges
|
||||
.map((badge) => `<span class="print-badge">${badge}</span>`)
|
||||
.map(badge => `<span class="print-badge">${badge}</span>`)
|
||||
.join('')
|
||||
const sections = []
|
||||
|
||||
@@ -357,7 +355,7 @@ export const buildMachinePrintHtml = (context, styles) => {
|
||||
const customFieldsSection = renderPrintCustomFields(
|
||||
context.machine.customFields,
|
||||
'Champs personnalisés de la machine',
|
||||
'print-section print-section--custom-fields',
|
||||
'print-section print-section--custom-fields'
|
||||
)
|
||||
if (customFieldsSection) {
|
||||
sections.push(customFieldsSection)
|
||||
@@ -366,7 +364,7 @@ export const buildMachinePrintHtml = (context, styles) => {
|
||||
const documentsSection = renderPrintDocuments(
|
||||
context.machine.documents,
|
||||
'Documents liés à la machine',
|
||||
'print-section print-section--documents',
|
||||
'print-section print-section--documents'
|
||||
)
|
||||
if (documentsSection) {
|
||||
sections.push(documentsSection)
|
||||
@@ -380,7 +378,7 @@ export const buildMachinePrintHtml = (context, styles) => {
|
||||
const piecesSection = renderPrintPieces(
|
||||
context.pieces,
|
||||
'Pièces indépendantes',
|
||||
'print-section print-section--pieces',
|
||||
'print-section print-section--pieces'
|
||||
)
|
||||
if (piecesSection) {
|
||||
sections.push(piecesSection)
|
||||
|
||||
Reference in New Issue
Block a user