Security config (3.1): - config/session.ts: cookie.secure now follows app.inProduction instead of being hardcoded to false - config/shield.ts: enable CSP with baseline directives compatible with Vite dev server and Inertia (self + @viteDevUrl/@viteHmrUrl) Frontend typing (3.2): - Replace 'any' props with concrete types (Computer, Component, ComponentType, ComputerState) across computers/*.vue and components/*.vue, using the existing inertia/pages/types/UITypes.ts definitions - Fix UITypes.ts: export ComponentType/ComputerState, switch from interface to type (interfaces are never assignable to Inertia's ComponentProps index signature), drop the stale componentTypeId/componentStateId fields that didn't match the actual Lucid schema (real field is typeId, no component state exists) - Add an asPageProp() boundary cast in the two controllers: Lucid's serialize() returns a loosely typed ModelObject that isn't structurally assignable to the concrete page prop shapes (and the inertia/** tree is excluded from the backend tsconfig, so real types can't be imported directly across that boundary) UTF-8 mojibake fixes (3.3): - Repair broken accented characters (├®/├á/├┤ -> é/à/ô, Ôé¼ -> €) left over from a bad encoding during the GWT->Inertia migration, across ComponentEditor.vue, ComputerComponentsTable.vue, SimpleGallery.vue, TableComponent.vue, isAdminMode.ts and the custom directives Misc cleanup (3.5): - computer.ts: replace console.warn with the app logger (includes computerId) when .cost is accessed without preloading components
129 lines
4.2 KiB
Vue
129 lines
4.2 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
cooler,
|
|
cpu,
|
|
defaultIcon,
|
|
fan,
|
|
graphicCard,
|
|
hardDrive,
|
|
memory,
|
|
motherboard,
|
|
pcCase,
|
|
powerSupply,
|
|
ssd,
|
|
trashIcon,
|
|
wiFiCard,
|
|
} from '~/assets/icons'
|
|
import { router } from '@inertiajs/vue3'
|
|
import { useAdminMode } from '~/composables/isAdminMode'
|
|
import type Component from '#models/component'
|
|
|
|
const props = defineProps<{
|
|
components: Component[]
|
|
}>()
|
|
|
|
const { isAdminActive } = useAdminMode()
|
|
|
|
function getIconPath(typeName: string): string {
|
|
const typeToIconMap: Record<string, string> = {
|
|
'Motherboard': motherboard,
|
|
'Processor': cpu,
|
|
'Memory': memory,
|
|
'HDD': hardDrive,
|
|
'SSD': ssd,
|
|
'Cooler': cooler,
|
|
'Graphic Card': graphicCard,
|
|
'Power Supply': powerSupply,
|
|
'Fan': fan,
|
|
'WiFi-Card': wiFiCard,
|
|
'Case': pcCase,
|
|
}
|
|
return typeToIconMap[typeName] || defaultIcon // Utilisez une icône par défaut si nécessaire
|
|
}
|
|
|
|
function goToDetail(id: number) {
|
|
router.get(`/components/${id}`)
|
|
}
|
|
|
|
function deleteComponent(id: number) {
|
|
router.delete(`/components/${id}`)
|
|
}
|
|
</script>
|
|
<template>
|
|
<div class="flex flex-col mt-8">
|
|
<div class="py-2 -my-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
|
|
<div
|
|
class="inline-block min-w-full overflow-hidden align-middle border-b border-gray-200 shadow sm:rounded-lg"
|
|
>
|
|
<table class="min-w-full">
|
|
<thead>
|
|
<tr>
|
|
<th
|
|
class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50"
|
|
>
|
|
Type
|
|
</th>
|
|
<th
|
|
class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50"
|
|
>
|
|
Name
|
|
</th>
|
|
<th
|
|
v-if="isAdminActive"
|
|
class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50"
|
|
>
|
|
Price
|
|
</th>
|
|
<th
|
|
class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50"
|
|
>
|
|
Purchase Date
|
|
</th>
|
|
<th
|
|
class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-gray-500 uppercase border-b border-gray-200 bg-gray-50"
|
|
>
|
|
Action
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white">
|
|
<tr
|
|
v-for="component in components"
|
|
:key="component.id"
|
|
@click.stop.prevent="goToDetail(component.id)"
|
|
class="cursor-pointer hover:bg-indigo-600/50"
|
|
:class="[component.computerId !== null ? 'used bg-gray-400' : 'bg-white']"
|
|
>
|
|
<td class="px-6 py-4 border-b border-gray-200 whitespace-nowrap">
|
|
<img
|
|
:src="getIconPath(component.type.name)"
|
|
:alt="`${component.type.name} Icon`"
|
|
style="width: 32px; height: 32px"
|
|
/>
|
|
</td>
|
|
<td class="px-6 py-4 border-b border-gray-200 whitespace-nowrap">
|
|
{{ component.name }}
|
|
</td>
|
|
<td v-if="isAdminActive" class="px-6 py-4 border-b border-gray-200 whitespace-nowrap">
|
|
€{{ component.price }}
|
|
</td>
|
|
<td class="px-6 py-4 border-b border-gray-200 whitespace-nowrap">
|
|
{{ component.purchaseDate }}
|
|
</td>
|
|
<td class="px-6 py-4 border-b border-gray-200 whitespace-nowrap">
|
|
<button
|
|
v-delete-confirm="() => deleteComponent(component.id)"
|
|
class="px-4 py-2 bg-gray-300 text-white rounded hover:bg-red-500 transition inline-flex items-center justify-center"
|
|
>
|
|
<img :src="trashIcon" alt="Delete" class="h-5 w-5" />
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<style scoped></style>
|