Fix machines display on overview; disable inline PDF thumbnails
This commit is contained in:
@@ -12,12 +12,6 @@
|
|||||||
loading="lazy"
|
loading="lazy"
|
||||||
decoding="async"
|
decoding="async"
|
||||||
>
|
>
|
||||||
<iframe
|
|
||||||
v-else-if="canRenderPdf"
|
|
||||||
:src="previewSrc"
|
|
||||||
class="h-full w-full border-0 bg-white"
|
|
||||||
title="Aperçu PDF"
|
|
||||||
/>
|
|
||||||
<component
|
<component
|
||||||
v-else
|
v-else
|
||||||
:is="icon.component"
|
:is="icon.component"
|
||||||
@@ -54,8 +48,6 @@ const props = defineProps<{
|
|||||||
alt?: string;
|
alt?: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const PDF_PREVIEW_MAX_BYTES = 5 * 1024 * 1024;
|
|
||||||
|
|
||||||
const normalizedDocument = computed(() => props.document ?? null);
|
const normalizedDocument = computed(() => props.document ?? null);
|
||||||
|
|
||||||
const canRenderImage = computed(() => {
|
const canRenderImage = computed(() => {
|
||||||
@@ -64,14 +56,9 @@ const canRenderImage = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const canRenderPdf = computed(() => {
|
const canRenderPdf = computed(() => {
|
||||||
const doc = normalizedDocument.value;
|
// Rendering many PDF iframes in a list is very heavy for the browser.
|
||||||
if (!doc || !isPdfDocument(doc) || !doc.path) {
|
// We intentionally disable inline PDF previews and fall back to an icon.
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if (typeof doc.size === 'number' && doc.size > PDF_PREVIEW_MAX_BYTES) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const appendPdfViewerParams = (src: string) => {
|
const appendPdfViewerParams = (src: string) => {
|
||||||
|
|||||||
@@ -472,10 +472,11 @@ import IconLucideChevronDown from '~icons/lucide/chevron-down'
|
|||||||
import IconLucideSettings2 from '~icons/lucide/settings-2'
|
import IconLucideSettings2 from '~icons/lucide/settings-2'
|
||||||
import IconLucideTag from '~icons/lucide/tag'
|
import IconLucideTag from '~icons/lucide/tag'
|
||||||
import { formatPhone } from '~/utils/formatters/phone'
|
import { formatPhone } from '~/utils/formatters/phone'
|
||||||
|
import { extractRelationId } from '~/shared/apiRelations'
|
||||||
|
|
||||||
const { sites, loading, loadSites, createSite } = useSites()
|
const { sites, loading, loadSites, createSite } = useSites()
|
||||||
const { machineTypes, loadMachineTypes } = useMachineTypesApi()
|
const { machineTypes, loadMachineTypes } = useMachineTypesApi()
|
||||||
const { createMachineFromType, deleteMachine } = useMachines()
|
const { machines, loadMachines, createMachineFromType, deleteMachine } = useMachines()
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
const showAddSiteModal = ref(false)
|
const showAddSiteModal = ref(false)
|
||||||
@@ -517,8 +518,50 @@ const categories = computed(() => {
|
|||||||
return Array.from(cats)
|
return Array.from(cats)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const machinesWithType = computed(() => {
|
||||||
|
return machines.value.map((machine) => {
|
||||||
|
const resolvedTypeMachineId = machine.typeMachineId || extractRelationId(machine.typeMachine)
|
||||||
|
const resolvedTypeMachine = resolvedTypeMachineId
|
||||||
|
? machineTypes.value.find(type => type.id === resolvedTypeMachineId) || null
|
||||||
|
: null
|
||||||
|
|
||||||
|
return {
|
||||||
|
...machine,
|
||||||
|
typeMachineId: resolvedTypeMachineId || machine.typeMachineId,
|
||||||
|
typeMachine:
|
||||||
|
machine.typeMachine && typeof machine.typeMachine === 'object'
|
||||||
|
? machine.typeMachine
|
||||||
|
: resolvedTypeMachine
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const machinesBySiteId = computed(() => {
|
||||||
|
const map = new Map()
|
||||||
|
|
||||||
|
machinesWithType.value.forEach((machine) => {
|
||||||
|
const siteId = machine.siteId || extractRelationId(machine.site)
|
||||||
|
if (!siteId) { return }
|
||||||
|
|
||||||
|
if (!map.has(siteId)) {
|
||||||
|
map.set(siteId, [])
|
||||||
|
}
|
||||||
|
|
||||||
|
map.get(siteId).push(machine)
|
||||||
|
})
|
||||||
|
|
||||||
|
return map
|
||||||
|
})
|
||||||
|
|
||||||
|
const sitesWithMachines = computed(() => {
|
||||||
|
return sites.value.map((site) => ({
|
||||||
|
...site,
|
||||||
|
machines: machinesBySiteId.value.get(site.id) || []
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
const totalMachines = computed(() => {
|
const totalMachines = computed(() => {
|
||||||
return sites.value.reduce((total, site) => {
|
return sitesWithMachines.value.reduce((total, site) => {
|
||||||
return total + (site.machines?.length || 0)
|
return total + (site.machines?.length || 0)
|
||||||
}, 0)
|
}, 0)
|
||||||
})
|
})
|
||||||
@@ -532,7 +575,7 @@ const formatPhoneDisplay = (value) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const filteredSites = computed(() => {
|
const filteredSites = computed(() => {
|
||||||
let filtered = sites.value
|
let filtered = sitesWithMachines.value
|
||||||
|
|
||||||
// Filtrer par terme de recherche
|
// Filtrer par terme de recherche
|
||||||
if (searchTerm.value) {
|
if (searchTerm.value) {
|
||||||
@@ -551,9 +594,11 @@ const filteredSites = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const machineMatches = site.machines?.some(
|
const machineMatches = site.machines?.some(
|
||||||
machine =>
|
machine => {
|
||||||
machine.name.toLowerCase().includes(lowerTerm) ||
|
const name = (machine.name || '').toLowerCase()
|
||||||
machine.reference?.toLowerCase().includes(lowerTerm)
|
const reference = (machine.reference || '').toLowerCase()
|
||||||
|
return name.includes(lowerTerm) || reference.includes(lowerTerm)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return siteMatches || machineMatches
|
return siteMatches || machineMatches
|
||||||
@@ -637,6 +682,7 @@ const handleCreateMachine = async () => {
|
|||||||
newMachine.typeMachineId = ''
|
newMachine.typeMachineId = ''
|
||||||
newMachine.reference = ''
|
newMachine.reference = ''
|
||||||
showAddMachineModal.value = false
|
showAddMachineModal.value = false
|
||||||
|
await loadMachines()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,6 +717,7 @@ const confirmDeleteMachine = async (machine) => {
|
|||||||
const result = await deleteMachine(machine.id)
|
const result = await deleteMachine(machine.id)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
showSuccess(`Machine "${machine.name}" supprimée avec succès`)
|
showSuccess(`Machine "${machine.name}" supprimée avec succès`)
|
||||||
|
await loadMachines()
|
||||||
} else {
|
} else {
|
||||||
showError(`Erreur lors de la suppression: ${result.error}`)
|
showError(`Erreur lors de la suppression: ${result.error}`)
|
||||||
}
|
}
|
||||||
@@ -698,6 +745,6 @@ const getCategoryBadgeClass = (category) => {
|
|||||||
|
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await Promise.all([loadSites(), loadMachineTypes()])
|
await Promise.all([loadSites(), loadMachineTypes(), loadMachines()])
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user