Compare commits
5 Commits
cc70fe2b29
...
v1.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a98ab8c275 | ||
|
|
e22463874c | ||
|
|
256039264e | ||
|
|
e459da7c20 | ||
|
|
e84b5cf674 |
212
app/components/CommentSection.vue
Normal file
212
app/components/CommentSection.vue
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
<template>
|
||||||
|
<div class="space-y-4">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<h3 class="text-lg font-semibold flex items-center gap-2">
|
||||||
|
<IconLucideMessageSquare class="w-5 h-5" />
|
||||||
|
Commentaires
|
||||||
|
<span v-if="openComments.length" class="badge badge-warning badge-sm">
|
||||||
|
{{ openComments.length }}
|
||||||
|
</span>
|
||||||
|
</h3>
|
||||||
|
<button
|
||||||
|
v-if="showResolved && resolvedComments.length"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-ghost btn-xs"
|
||||||
|
@click="showResolvedList = !showResolvedList"
|
||||||
|
>
|
||||||
|
{{ showResolvedList ? 'Masquer résolus' : `Voir résolus (${resolvedComments.length})` }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Formulaire d'ajout -->
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<textarea
|
||||||
|
v-model="newContent"
|
||||||
|
class="textarea textarea-bordered flex-1 text-sm"
|
||||||
|
rows="2"
|
||||||
|
placeholder="Ajouter un commentaire..."
|
||||||
|
:disabled="submitting"
|
||||||
|
@keydown.ctrl.enter="handleSubmit"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-primary btn-sm self-end"
|
||||||
|
:disabled="!newContent.trim() || submitting"
|
||||||
|
@click="handleSubmit"
|
||||||
|
>
|
||||||
|
<span v-if="submitting" class="loading loading-spinner loading-xs" />
|
||||||
|
<IconLucideSend v-else class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Liste des commentaires ouverts -->
|
||||||
|
<div v-if="loadingComments" class="flex justify-center py-4">
|
||||||
|
<span class="loading loading-spinner loading-sm" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="openComments.length === 0" class="text-sm text-base-content/50 py-2">
|
||||||
|
Aucun commentaire ouvert.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="space-y-3">
|
||||||
|
<div
|
||||||
|
v-for="comment in openComments"
|
||||||
|
:key="comment.id"
|
||||||
|
class="bg-base-200 rounded-lg p-3 space-y-2"
|
||||||
|
>
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="flex-1">
|
||||||
|
<p class="text-sm whitespace-pre-wrap">{{ comment.content }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between text-xs text-base-content/60">
|
||||||
|
<span>
|
||||||
|
{{ comment.authorName }} — {{ formatCommentDate(comment.createdAt) }}
|
||||||
|
</span>
|
||||||
|
<div v-if="canEdit" class="flex gap-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-success btn-xs gap-1"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="handleResolve(comment.id)"
|
||||||
|
>
|
||||||
|
<IconLucideCheck class="w-3 h-3" />
|
||||||
|
Résoudre
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-ghost btn-xs text-error"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="handleDelete(comment.id)"
|
||||||
|
>
|
||||||
|
<IconLucideTrash2 class="w-3 h-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Commentaires résolus -->
|
||||||
|
<div v-if="showResolvedList && resolvedComments.length" class="space-y-2">
|
||||||
|
<div class="divider text-xs text-base-content/40">
|
||||||
|
Résolus
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="comment in resolvedComments"
|
||||||
|
:key="comment.id"
|
||||||
|
class="bg-base-200/50 rounded-lg p-3 opacity-60 space-y-1"
|
||||||
|
>
|
||||||
|
<p class="text-sm whitespace-pre-wrap">{{ comment.content }}</p>
|
||||||
|
<div class="flex items-center justify-between text-xs text-base-content/50">
|
||||||
|
<span>{{ comment.authorName }} — {{ formatCommentDate(comment.createdAt) }}</span>
|
||||||
|
<span v-if="comment.resolvedByName">
|
||||||
|
Résolu par {{ comment.resolvedByName }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
import { useComments, type Comment } from '~/composables/useComments'
|
||||||
|
import { usePermissions } from '~/composables/usePermissions'
|
||||||
|
import IconLucideMessageSquare from '~icons/lucide/message-square'
|
||||||
|
import IconLucideSend from '~icons/lucide/send'
|
||||||
|
import IconLucideCheck from '~icons/lucide/check'
|
||||||
|
import IconLucideTrash2 from '~icons/lucide/trash-2'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
entityType: string
|
||||||
|
entityId: string
|
||||||
|
entityName?: string
|
||||||
|
showResolved?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { canEdit } = usePermissions()
|
||||||
|
const {
|
||||||
|
loading,
|
||||||
|
fetchComments,
|
||||||
|
createComment,
|
||||||
|
resolveComment,
|
||||||
|
deleteComment,
|
||||||
|
} = useComments()
|
||||||
|
|
||||||
|
const comments = ref<Comment[]>([])
|
||||||
|
const newContent = ref('')
|
||||||
|
const submitting = ref(false)
|
||||||
|
const loadingComments = ref(false)
|
||||||
|
const showResolvedList = ref(false)
|
||||||
|
|
||||||
|
const openComments = computed(() =>
|
||||||
|
comments.value.filter(c => c.status === 'open'),
|
||||||
|
)
|
||||||
|
|
||||||
|
const resolvedComments = computed(() =>
|
||||||
|
comments.value.filter(c => c.status === 'resolved'),
|
||||||
|
)
|
||||||
|
|
||||||
|
const formatCommentDate = (dateStr: string): string => {
|
||||||
|
const date = new Date(dateStr)
|
||||||
|
if (Number.isNaN(date.getTime())) return '—'
|
||||||
|
return new Intl.DateTimeFormat('fr-FR', {
|
||||||
|
day: '2-digit',
|
||||||
|
month: '2-digit',
|
||||||
|
year: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
}).format(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadComments = async () => {
|
||||||
|
loadingComments.value = true
|
||||||
|
const [openResult, resolvedResult] = await Promise.all([
|
||||||
|
fetchComments(props.entityType, props.entityId, 'open'),
|
||||||
|
props.showResolved
|
||||||
|
? fetchComments(props.entityType, props.entityId, 'resolved')
|
||||||
|
: Promise.resolve({ success: true, data: [] as Comment[] }),
|
||||||
|
])
|
||||||
|
const open = openResult.success ? (openResult.data ?? []) : []
|
||||||
|
const resolved = resolvedResult.success ? (resolvedResult.data ?? []) : []
|
||||||
|
comments.value = [...open, ...resolved]
|
||||||
|
loadingComments.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const content = newContent.value.trim()
|
||||||
|
if (!content) return
|
||||||
|
submitting.value = true
|
||||||
|
const result = await createComment(
|
||||||
|
props.entityType,
|
||||||
|
props.entityId,
|
||||||
|
content,
|
||||||
|
props.entityName,
|
||||||
|
)
|
||||||
|
submitting.value = false
|
||||||
|
if (result.success) {
|
||||||
|
newContent.value = ''
|
||||||
|
await loadComments()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResolve = async (commentId: string) => {
|
||||||
|
const result = await resolveComment(commentId)
|
||||||
|
if (result.success) {
|
||||||
|
await loadComments()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDelete = async (commentId: string) => {
|
||||||
|
const result = await deleteComment(commentId)
|
||||||
|
if (result.success) {
|
||||||
|
comments.value = comments.value.filter(c => c.id !== commentId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.entityId) {
|
||||||
|
loadComments()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -20,16 +20,16 @@
|
|||||||
</button>
|
</button>
|
||||||
<div
|
<div
|
||||||
v-if="openDropdown"
|
v-if="openDropdown"
|
||||||
class="absolute z-20 mt-1 w-full max-h-48 overflow-y-auto bg-base-100 border border-base-200 rounded-box shadow-lg flex flex-col"
|
class="absolute z-20 mt-1 w-full max-h-60 overflow-y-auto bg-base-100 border border-base-200 rounded-box shadow-lg flex flex-col"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-if="options.length === 0"
|
v-if="filteredOptions.length === 0"
|
||||||
class="px-3 py-2 text-xs text-gray-500"
|
class="px-3 py-2 text-xs text-gray-500"
|
||||||
>
|
>
|
||||||
Aucun fournisseur trouvé
|
Aucun fournisseur trouvé
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
v-for="option in options"
|
v-for="option in filteredOptions"
|
||||||
:key="option.id"
|
:key="option.id"
|
||||||
type="button"
|
type="button"
|
||||||
class="w-full text-left px-3 py-2 hover:bg-base-200 focus:bg-base-200 focus:outline-none"
|
class="w-full text-left px-3 py-2 hover:bg-base-200 focus:bg-base-200 focus:outline-none"
|
||||||
@@ -164,8 +164,7 @@ const openCreateModal = ref(false)
|
|||||||
const creating = ref(false)
|
const creating = ref(false)
|
||||||
const options = ref<ConstructeurSummary[]>([])
|
const options = ref<ConstructeurSummary[]>([])
|
||||||
const selectedIds = ref<string[]>([])
|
const selectedIds = ref<string[]>([])
|
||||||
let searchTimeout: ReturnType<typeof setTimeout> | null = null
|
|
||||||
let lastSearchTerm = ''
|
|
||||||
|
|
||||||
const uniqueOptions = (items: ConstructeurSummary[] = []) => {
|
const uniqueOptions = (items: ConstructeurSummary[] = []) => {
|
||||||
const seen = new Map<string, ConstructeurSummary>()
|
const seen = new Map<string, ConstructeurSummary>()
|
||||||
@@ -182,32 +181,22 @@ const normalizedInitialOptions = computed(() =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
const applyOptions = (items: ConstructeurSummary[] = []) => {
|
const applyOptions = (items: ConstructeurSummary[] = []) => {
|
||||||
const normalized = uniqueOptions([
|
options.value = uniqueOptions([
|
||||||
...normalizedInitialOptions.value,
|
...normalizedInitialOptions.value,
|
||||||
...items,
|
...items,
|
||||||
])
|
])
|
||||||
const limited = normalized.slice(0, 10)
|
|
||||||
|
|
||||||
selectedIds.value.forEach((id) => {
|
|
||||||
if (!limited.some((item) => item.id === id)) {
|
|
||||||
const match =
|
|
||||||
normalized.find((item) => item.id === id) ||
|
|
||||||
constructeurs.value.find((item) => item.id === id)
|
|
||||||
if (match) {
|
|
||||||
if (limited.length >= 10) {
|
|
||||||
limited.pop()
|
|
||||||
}
|
|
||||||
limited.unshift(match)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
options.value = uniqueOptions([
|
|
||||||
...normalizedInitialOptions.value,
|
|
||||||
...limited,
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filteredOptions = computed(() => {
|
||||||
|
const term = searchTerm.value.trim().toLowerCase()
|
||||||
|
if (!term) return options.value
|
||||||
|
return options.value.filter((option) =>
|
||||||
|
(option.name ?? '').toLowerCase().includes(term)
|
||||||
|
|| (option.email && option.email.toLowerCase().includes(term))
|
||||||
|
|| (option.phone && option.phone.toLowerCase().includes(term))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const createForm = ref({
|
const createForm = ref({
|
||||||
name: '',
|
name: '',
|
||||||
email: '',
|
email: '',
|
||||||
@@ -257,46 +246,20 @@ const extractDataArray = (data: unknown): ConstructeurSummary[] => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ensureOptionsLoaded = async (force = false) => {
|
const ensureOptionsLoaded = async (force = false) => {
|
||||||
if (!force && !searchTerm.value && constructeurs.value.length) {
|
if (!force && constructeurs.value.length) {
|
||||||
applyOptions(constructeurs.value as ConstructeurSummary[])
|
applyOptions(constructeurs.value as ConstructeurSummary[])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force && searchTerm.value === lastSearchTerm && options.value.length) {
|
const result = await searchConstructeurs('')
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.value.length && !force) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await searchConstructeurs(searchTerm.value)
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
applyOptions(extractDataArray(result.data))
|
applyOptions(extractDataArray(result.data))
|
||||||
lastSearchTerm = searchTerm.value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onSearch = () => {
|
const onSearch = () => {
|
||||||
openDropdown.value = true
|
openDropdown.value = true
|
||||||
if (searchTimeout) {
|
ensureOptionsLoaded()
|
||||||
clearTimeout(searchTimeout)
|
|
||||||
}
|
|
||||||
searchTimeout = setTimeout(async () => {
|
|
||||||
if (!searchTerm.value && constructeurs.value.length) {
|
|
||||||
applyOptions(constructeurs.value as ConstructeurSummary[])
|
|
||||||
lastSearchTerm = ''
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (searchTerm.value === lastSearchTerm) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const result = await searchConstructeurs(searchTerm.value)
|
|
||||||
if (result.success) {
|
|
||||||
applyOptions(extractDataArray(result.data))
|
|
||||||
lastSearchTerm = searchTerm.value
|
|
||||||
}
|
|
||||||
}, 250)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleOption = (option: ConstructeurSummary) => {
|
const toggleOption = (option: ConstructeurSummary) => {
|
||||||
@@ -319,9 +282,19 @@ const closeCreateModal = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleCreate = async () => {
|
const handleCreate = async () => {
|
||||||
|
const trimmedName = createForm.value.name.trim()
|
||||||
|
const duplicate = options.value.find(
|
||||||
|
(o) => (o.name ?? '').toLowerCase() === trimmedName.toLowerCase(),
|
||||||
|
)
|
||||||
|
if (duplicate) {
|
||||||
|
emitSelection([...selectedIds.value, duplicate.id])
|
||||||
|
closeCreateModal()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
creating.value = true
|
creating.value = true
|
||||||
const payload: { name: string; email?: string; phone?: string } = {
|
const payload: { name: string; email?: string; phone?: string } = {
|
||||||
name: createForm.value.name,
|
name: trimmedName,
|
||||||
}
|
}
|
||||||
if (createForm.value.email) {
|
if (createForm.value.email) {
|
||||||
payload.email = createForm.value.email
|
payload.email = createForm.value.email
|
||||||
@@ -383,9 +356,6 @@ watch(
|
|||||||
constructeurs,
|
constructeurs,
|
||||||
(list) => {
|
(list) => {
|
||||||
applyOptions((list as ConstructeurSummary[]) || [])
|
applyOptions((list as ConstructeurSummary[]) || [])
|
||||||
if (!searchTerm.value) {
|
|
||||||
lastSearchTerm = ''
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
@@ -405,9 +375,6 @@ onMounted(() => {
|
|||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
window.removeEventListener('click', clickHandler)
|
window.removeEventListener('click', clickHandler)
|
||||||
if (searchTimeout) {
|
|
||||||
clearTimeout(searchTimeout)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|||||||
@@ -55,16 +55,16 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- Champ de type BOOLEAN -->
|
<!-- Champ de type BOOLEAN -->
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="fieldValues[field.id]"
|
v-model="fieldValues[field.id]"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm"
|
||||||
:checked="fieldValues[field.id] === 'true'"
|
:checked="fieldValues[field.id] === 'true'"
|
||||||
@change="updateCustomFieldValue(field.id)"
|
@change="updateCustomFieldValue(field.id)"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ fieldValues[field.id] === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="fieldValues[field.id] === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ fieldValues[field.id] === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
|
|
||||||
<!-- Champ de type DATE -->
|
<!-- Champ de type DATE -->
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -65,6 +65,9 @@
|
|||||||
:class="childLinkClass(child)"
|
:class="childLinkClass(child)"
|
||||||
>
|
>
|
||||||
{{ child.label }}
|
{{ child.label }}
|
||||||
|
<span v-if="child.to === '/comments' && unresolvedCount > 0" class="badge badge-warning badge-xs ml-1">
|
||||||
|
{{ unresolvedCount }}
|
||||||
|
</span>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -142,6 +145,9 @@
|
|||||||
:class="childLinkClass(child)"
|
:class="childLinkClass(child)"
|
||||||
>
|
>
|
||||||
{{ child.label }}
|
{{ child.label }}
|
||||||
|
<span v-if="child.to === '/comments' && unresolvedCount > 0" class="badge badge-warning badge-xs ml-1">
|
||||||
|
{{ unresolvedCount }}
|
||||||
|
</span>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -166,8 +172,14 @@
|
|||||||
<div
|
<div
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
role="button"
|
role="button"
|
||||||
class="btn btn-ghost btn-circle avatar placeholder"
|
class="btn btn-ghost btn-circle avatar placeholder indicator"
|
||||||
>
|
>
|
||||||
|
<span
|
||||||
|
v-if="unresolvedCount > 0"
|
||||||
|
class="indicator-item badge badge-warning badge-xs"
|
||||||
|
>
|
||||||
|
{{ unresolvedCount }}
|
||||||
|
</span>
|
||||||
<div
|
<div
|
||||||
class="bg-secondary text-secondary-content rounded-full w-10 h-10 grid place-items-center"
|
class="bg-secondary text-secondary-content rounded-full w-10 h-10 grid place-items-center"
|
||||||
>
|
>
|
||||||
@@ -185,6 +197,7 @@
|
|||||||
<li class="px-2 py-1 text-sm text-base-content/70">
|
<li class="px-2 py-1 text-sm text-base-content/70">
|
||||||
Connecté en tant que<br />
|
Connecté en tant que<br />
|
||||||
<span class="font-semibold text-base-content">{{ activeProfileLabel }}</span>
|
<span class="font-semibold text-base-content">{{ activeProfileLabel }}</span>
|
||||||
|
<span class="badge badge-sm" :class="roleBadgeClass">{{ roleLabel }}</span>
|
||||||
</li>
|
</li>
|
||||||
<li v-if="isAdmin">
|
<li v-if="isAdmin">
|
||||||
<NuxtLink to="/admin" class="justify-between">
|
<NuxtLink to="/admin" class="justify-between">
|
||||||
@@ -192,6 +205,15 @@
|
|||||||
<IconLucideChevronRight class="w-4 h-4" aria-hidden="true" />
|
<IconLucideChevronRight class="w-4 h-4" aria-hidden="true" />
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<NuxtLink to="/comments" class="justify-between">
|
||||||
|
Commentaires
|
||||||
|
<span v-if="unresolvedCount > 0" class="badge badge-warning badge-xs">
|
||||||
|
{{ unresolvedCount }}
|
||||||
|
</span>
|
||||||
|
<IconLucideChevronRight v-else class="w-4 h-4" aria-hidden="true" />
|
||||||
|
</NuxtLink>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -211,11 +233,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import { useRoute } from '#imports'
|
import { useRoute } from '#imports'
|
||||||
import { useNavDropdown } from '~/composables/useNavDropdown'
|
import { useNavDropdown } from '~/composables/useNavDropdown'
|
||||||
import { usePermissions } from '~/composables/usePermissions'
|
import { usePermissions } from '~/composables/usePermissions'
|
||||||
import { useProfileSession } from '~/composables/useProfileSession'
|
import { useProfileSession } from '~/composables/useProfileSession'
|
||||||
|
import { useComments } from '~/composables/useComments'
|
||||||
import IconLucideMenu from '~icons/lucide/menu'
|
import IconLucideMenu from '~icons/lucide/menu'
|
||||||
import IconLucideSettings from '~icons/lucide/settings'
|
import IconLucideSettings from '~icons/lucide/settings'
|
||||||
import IconLucideChevronRight from '~icons/lucide/chevron-right'
|
import IconLucideChevronRight from '~icons/lucide/chevron-right'
|
||||||
@@ -276,11 +299,12 @@ const navGroups: NavGroup[] = [
|
|||||||
{
|
{
|
||||||
id: 'resources',
|
id: 'resources',
|
||||||
label: 'Ressources liées',
|
label: 'Ressources liées',
|
||||||
activePaths: ['/sites', '/documents', '/constructeurs', '/activity-log'],
|
activePaths: ['/sites', '/documents', '/constructeurs', '/activity-log', '/comments'],
|
||||||
children: [
|
children: [
|
||||||
{ to: '/sites', label: 'Sites' },
|
{ to: '/sites', label: 'Sites' },
|
||||||
{ to: '/documents', label: 'Documents' },
|
{ to: '/documents', label: 'Documents' },
|
||||||
{ to: '/constructeurs', label: 'Fournisseurs' },
|
{ to: '/constructeurs', label: 'Fournisseurs' },
|
||||||
|
{ to: '/comments', label: 'Commentaires' },
|
||||||
{ to: '/activity-log', label: 'Journal d\'activité' },
|
{ to: '/activity-log', label: 'Journal d\'activité' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -289,7 +313,25 @@ const navGroups: NavGroup[] = [
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { openDropdown, setDropdown, scheduleDropdownClose, toggleDropdown } = useNavDropdown()
|
const { openDropdown, setDropdown, scheduleDropdownClose, toggleDropdown } = useNavDropdown()
|
||||||
const { activeProfile } = useProfileSession()
|
const { activeProfile } = useProfileSession()
|
||||||
const { isAdmin } = usePermissions()
|
const { isAdmin, canEdit } = usePermissions()
|
||||||
|
const { fetchUnresolvedCount } = useComments()
|
||||||
|
|
||||||
|
const unresolvedCount = ref(0)
|
||||||
|
let pollInterval: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
const refreshUnresolvedCount = async () => {
|
||||||
|
if (!activeProfile.value) return
|
||||||
|
unresolvedCount.value = await fetchUnresolvedCount()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
refreshUnresolvedCount()
|
||||||
|
pollInterval = setInterval(refreshUnresolvedCount, 60_000)
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (pollInterval) clearInterval(pollInterval)
|
||||||
|
})
|
||||||
|
|
||||||
const isActive = (path: string) => {
|
const isActive = (path: string) => {
|
||||||
if (path === '/') {
|
if (path === '/') {
|
||||||
@@ -320,6 +362,18 @@ const childLinkClass = (child: NavLink) => {
|
|||||||
: 'text-base-content hover:bg-primary/10 hover:text-primary'
|
: 'text-base-content hover:bg-primary/10 hover:text-primary'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const roleLabel = computed(() => {
|
||||||
|
if (isAdmin.value) return 'Admin'
|
||||||
|
if (canEdit.value) return 'Gestionnaire'
|
||||||
|
return 'Lecteur'
|
||||||
|
})
|
||||||
|
|
||||||
|
const roleBadgeClass = computed(() => {
|
||||||
|
if (isAdmin.value) return 'badge-error'
|
||||||
|
if (canEdit.value) return 'badge-warning'
|
||||||
|
return 'badge-info'
|
||||||
|
})
|
||||||
|
|
||||||
const activeProfileLabel = computed(() => {
|
const activeProfileLabel = computed(() => {
|
||||||
if (!activeProfile.value) {
|
if (!activeProfile.value) {
|
||||||
return 'Profil inconnu'
|
return 'Profil inconnu'
|
||||||
|
|||||||
@@ -120,17 +120,16 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
:value="field.value ?? ''"
|
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm"
|
||||||
:checked="String(field.value).toLowerCase() === 'true'"
|
:checked="String(field.value).toLowerCase() === 'true'"
|
||||||
@change="$emit('set-custom-field-value', field, ($event.target as HTMLInputElement).checked ? 'true' : 'false')"
|
@change="$emit('set-custom-field-value', field, ($event.target as HTMLInputElement).checked ? 'true' : 'false')"
|
||||||
@blur="$emit('update-custom-field', field)"
|
@blur="$emit('update-custom-field', field)"
|
||||||
/>
|
>
|
||||||
<span class="text-sm">{{ String(field.value).toLowerCase() === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="String(field.value).toLowerCase() === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ String(field.value).toLowerCase() === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
:value="field.value ?? ''"
|
:value="field.value ?? ''"
|
||||||
|
|||||||
184
app/composables/useComments.ts
Normal file
184
app/composables/useComments.ts
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
import { useApi } from './useApi'
|
||||||
|
import { useToast } from './useToast'
|
||||||
|
import { extractCollection } from '~/shared/utils/apiHelpers'
|
||||||
|
|
||||||
|
export interface Comment {
|
||||||
|
id: string
|
||||||
|
content: string
|
||||||
|
entityType: string
|
||||||
|
entityId: string
|
||||||
|
entityName?: string | null
|
||||||
|
authorId: string
|
||||||
|
authorName: string
|
||||||
|
status: 'open' | 'resolved'
|
||||||
|
resolvedById?: string | null
|
||||||
|
resolvedByName?: string | null
|
||||||
|
resolvedAt?: string | null
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CommentResult {
|
||||||
|
success: boolean
|
||||||
|
data?: Comment | Comment[]
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CommentListResult {
|
||||||
|
success: boolean
|
||||||
|
data?: Comment[]
|
||||||
|
total?: number
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useComments() {
|
||||||
|
const { get, post, patch, delete: del } = useApi()
|
||||||
|
const { showSuccess, showError } = useToast()
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const fetchComments = async (
|
||||||
|
entityType: string,
|
||||||
|
entityId: string,
|
||||||
|
status: string = 'open',
|
||||||
|
): Promise<CommentListResult> => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
entityType,
|
||||||
|
entityId,
|
||||||
|
status,
|
||||||
|
'order[createdAt]': 'desc',
|
||||||
|
itemsPerPage: '200',
|
||||||
|
})
|
||||||
|
const result = await get(`/comments?${params.toString()}`)
|
||||||
|
if (result.success) {
|
||||||
|
const items = extractCollection<Comment>(result.data)
|
||||||
|
return { success: true, data: items }
|
||||||
|
}
|
||||||
|
return { success: false, error: result.error }
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as Error
|
||||||
|
return { success: false, error: err.message }
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchAllComments = async (options: {
|
||||||
|
status?: string
|
||||||
|
entityType?: string
|
||||||
|
page?: number
|
||||||
|
itemsPerPage?: number
|
||||||
|
} = {}): Promise<CommentListResult> => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
if (options.status) params.set('status', options.status)
|
||||||
|
if (options.entityType) params.set('entityType', options.entityType)
|
||||||
|
params.set('order[createdAt]', 'desc')
|
||||||
|
params.set('itemsPerPage', String(options.itemsPerPage || 30))
|
||||||
|
params.set('page', String(options.page || 1))
|
||||||
|
|
||||||
|
const result = await get(`/comments?${params.toString()}`)
|
||||||
|
if (result.success) {
|
||||||
|
const items = extractCollection<Comment>(result.data)
|
||||||
|
const raw = result.data as Record<string, unknown> | null
|
||||||
|
const total = Number(raw?.['hydra:totalItems'] ?? raw?.totalItems ?? items.length)
|
||||||
|
return { success: true, data: items, total }
|
||||||
|
}
|
||||||
|
return { success: false, error: result.error }
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as Error
|
||||||
|
return { success: false, error: err.message }
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const createComment = async (
|
||||||
|
entityType: string,
|
||||||
|
entityId: string,
|
||||||
|
content: string,
|
||||||
|
entityName?: string,
|
||||||
|
): Promise<CommentResult> => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const payload: Record<string, string> = { entityType, entityId, content }
|
||||||
|
if (entityName) payload.entityName = entityName
|
||||||
|
const result = await post('/comments', payload)
|
||||||
|
if (result.success) {
|
||||||
|
showSuccess('Commentaire ajouté')
|
||||||
|
return { success: true, data: result.data as Comment }
|
||||||
|
}
|
||||||
|
if (result.error) showError(result.error)
|
||||||
|
return { success: false, error: result.error }
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as Error
|
||||||
|
showError('Impossible d\'ajouter le commentaire')
|
||||||
|
return { success: false, error: err.message }
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolveComment = async (commentId: string): Promise<CommentResult> => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const result = await patch(`/comments/${commentId}/resolve`)
|
||||||
|
if (result.success) {
|
||||||
|
showSuccess('Commentaire résolu')
|
||||||
|
return { success: true, data: result.data as Comment }
|
||||||
|
}
|
||||||
|
if (result.error) showError(result.error)
|
||||||
|
return { success: false, error: result.error }
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as Error
|
||||||
|
showError('Impossible de résoudre le commentaire')
|
||||||
|
return { success: false, error: err.message }
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteComment = async (commentId: string): Promise<CommentResult> => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const result = await del(`/comments/${commentId}`)
|
||||||
|
if (result.success) {
|
||||||
|
showSuccess('Commentaire supprimé')
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
|
if (result.error) showError(result.error)
|
||||||
|
return { success: false, error: result.error }
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as Error
|
||||||
|
showError('Impossible de supprimer le commentaire')
|
||||||
|
return { success: false, error: err.message }
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchUnresolvedCount = async (): Promise<number> => {
|
||||||
|
try {
|
||||||
|
const result = await get<{ count: number }>('/comments/stats/unresolved-count')
|
||||||
|
if (result.success && result.data) {
|
||||||
|
return result.data.count
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
} catch {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
loading,
|
||||||
|
fetchComments,
|
||||||
|
fetchAllComments,
|
||||||
|
createComment,
|
||||||
|
resolveComment,
|
||||||
|
deleteComment,
|
||||||
|
fetchUnresolvedCount,
|
||||||
|
}
|
||||||
|
}
|
||||||
331
app/pages/comments.vue
Normal file
331
app/pages/comments.vue
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
<template>
|
||||||
|
<main class="container mx-auto px-6 py-10 space-y-8">
|
||||||
|
<header>
|
||||||
|
<h1 class="text-3xl font-semibold text-base-content">
|
||||||
|
Commentaires
|
||||||
|
</h1>
|
||||||
|
<p class="text-sm text-gray-500">
|
||||||
|
Liste de tous les commentaires et tickets ouverts sur les fiches.
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="card border border-base-200 bg-base-100 shadow-sm">
|
||||||
|
<div class="card-body space-y-4">
|
||||||
|
<!-- Filtres -->
|
||||||
|
<div class="flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between">
|
||||||
|
<div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<label
|
||||||
|
class="text-xs font-semibold uppercase tracking-wide text-base-content/70"
|
||||||
|
for="comment-status"
|
||||||
|
>
|
||||||
|
Statut
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="comment-status"
|
||||||
|
v-model="statusFilter"
|
||||||
|
class="select select-bordered select-sm"
|
||||||
|
@change="handleFilterChange"
|
||||||
|
>
|
||||||
|
<option value="open">
|
||||||
|
Ouverts
|
||||||
|
</option>
|
||||||
|
<option value="resolved">
|
||||||
|
Résolus
|
||||||
|
</option>
|
||||||
|
<option value="">
|
||||||
|
Tous
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<label
|
||||||
|
class="text-xs font-semibold uppercase tracking-wide text-base-content/70"
|
||||||
|
for="comment-entity-type"
|
||||||
|
>
|
||||||
|
Type
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="comment-entity-type"
|
||||||
|
v-model="entityTypeFilter"
|
||||||
|
class="select select-bordered select-sm"
|
||||||
|
@change="handleFilterChange"
|
||||||
|
>
|
||||||
|
<option value="">
|
||||||
|
Tous
|
||||||
|
</option>
|
||||||
|
<option value="machine">
|
||||||
|
Machine
|
||||||
|
</option>
|
||||||
|
<option value="piece">
|
||||||
|
Pièce
|
||||||
|
</option>
|
||||||
|
<option value="composant">
|
||||||
|
Composant
|
||||||
|
</option>
|
||||||
|
<option value="product">
|
||||||
|
Produit
|
||||||
|
</option>
|
||||||
|
<option value="piece_category">
|
||||||
|
Catégorie pièce
|
||||||
|
</option>
|
||||||
|
<option value="component_category">
|
||||||
|
Catégorie composant
|
||||||
|
</option>
|
||||||
|
<option value="product_category">
|
||||||
|
Catégorie produit
|
||||||
|
</option>
|
||||||
|
<option value="machine_skeleton">
|
||||||
|
Squelette machine
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<label
|
||||||
|
class="text-xs font-semibold uppercase tracking-wide text-base-content/70"
|
||||||
|
for="comment-per-page"
|
||||||
|
>
|
||||||
|
Par page
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="comment-per-page"
|
||||||
|
v-model.number="itemsPerPage"
|
||||||
|
class="select select-bordered select-sm"
|
||||||
|
@change="handleFilterChange"
|
||||||
|
>
|
||||||
|
<option :value="20">
|
||||||
|
20
|
||||||
|
</option>
|
||||||
|
<option :value="50">
|
||||||
|
50
|
||||||
|
</option>
|
||||||
|
<option :value="100">
|
||||||
|
100
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="text-xs text-base-content/50 lg:text-right">
|
||||||
|
{{ comments.length }} / {{ total }} résultat{{ total > 1 ? 's' : '' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Loading -->
|
||||||
|
<div v-if="loadingList" class="flex justify-center py-8">
|
||||||
|
<span class="loading loading-spinner" aria-hidden="true" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Empty states -->
|
||||||
|
<p v-else-if="!comments.length" class="text-sm text-base-content/70 py-4">
|
||||||
|
Aucun commentaire trouvé.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Table -->
|
||||||
|
<template v-else>
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="table table-sm md:table-md">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Contenu</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Item</th>
|
||||||
|
<th>Auteur</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Statut</th>
|
||||||
|
<th v-if="canEdit">
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr
|
||||||
|
v-for="comment in comments"
|
||||||
|
:key="comment.id"
|
||||||
|
class="hover"
|
||||||
|
>
|
||||||
|
<td class="max-w-xs">
|
||||||
|
<span class="line-clamp-2 text-sm">{{ comment.content }}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge badge-outline badge-sm">
|
||||||
|
{{ entityTypeLabel(comment.entityType) }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<NuxtLink
|
||||||
|
v-if="getEntityRoute(comment)"
|
||||||
|
:to="getEntityRoute(comment)!"
|
||||||
|
class="link link-primary text-sm font-medium"
|
||||||
|
>
|
||||||
|
{{ comment.entityName || comment.entityId }}
|
||||||
|
</NuxtLink>
|
||||||
|
<span v-else class="text-sm">
|
||||||
|
{{ comment.entityName || comment.entityId }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-sm">
|
||||||
|
{{ comment.authorName }}
|
||||||
|
</td>
|
||||||
|
<td class="text-sm whitespace-nowrap">
|
||||||
|
{{ formatCommentDate(comment.createdAt) }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span
|
||||||
|
class="badge badge-sm"
|
||||||
|
:class="comment.status === 'open' ? 'badge-warning' : 'badge-success'"
|
||||||
|
>
|
||||||
|
{{ comment.status === 'open' ? 'Ouvert' : 'Résolu' }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td v-if="canEdit" @click.stop>
|
||||||
|
<button
|
||||||
|
v-if="comment.status === 'open'"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-success btn-xs gap-1"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="handleResolve(comment.id)"
|
||||||
|
>
|
||||||
|
<IconLucideCheck class="w-3 h-3" />
|
||||||
|
Résoudre
|
||||||
|
</button>
|
||||||
|
<span v-else class="text-xs text-base-content/50">
|
||||||
|
{{ comment.resolvedByName }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
<div v-if="totalPages > 1" class="flex justify-center gap-2 pt-2">
|
||||||
|
<button
|
||||||
|
class="btn btn-sm"
|
||||||
|
:disabled="page <= 1"
|
||||||
|
@click="goToPage(page - 1)"
|
||||||
|
>
|
||||||
|
Précédent
|
||||||
|
</button>
|
||||||
|
<span class="flex items-center text-sm text-base-content/70">
|
||||||
|
Page {{ page }} / {{ totalPages }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
class="btn btn-sm"
|
||||||
|
:disabled="page >= totalPages"
|
||||||
|
@click="goToPage(page + 1)"
|
||||||
|
>
|
||||||
|
Suivant
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
import { useComments, type Comment } from '~/composables/useComments'
|
||||||
|
import { usePermissions } from '~/composables/usePermissions'
|
||||||
|
import IconLucideCheck from '~icons/lucide/check'
|
||||||
|
|
||||||
|
const { canEdit } = usePermissions()
|
||||||
|
const {
|
||||||
|
loading,
|
||||||
|
fetchAllComments,
|
||||||
|
resolveComment,
|
||||||
|
} = useComments()
|
||||||
|
|
||||||
|
const comments = ref<Comment[]>([])
|
||||||
|
const total = ref(0)
|
||||||
|
const page = ref(1)
|
||||||
|
const itemsPerPage = ref(20)
|
||||||
|
const statusFilter = ref('open')
|
||||||
|
const entityTypeFilter = ref('')
|
||||||
|
const loadingList = ref(false)
|
||||||
|
|
||||||
|
const totalPages = computed(() =>
|
||||||
|
Math.max(1, Math.ceil(total.value / itemsPerPage.value)),
|
||||||
|
)
|
||||||
|
|
||||||
|
const ENTITY_TYPE_LABELS: Record<string, string> = {
|
||||||
|
machine: 'Machine',
|
||||||
|
piece: 'Pièce',
|
||||||
|
composant: 'Composant',
|
||||||
|
product: 'Produit',
|
||||||
|
piece_category: 'Cat. pièce',
|
||||||
|
component_category: 'Cat. composant',
|
||||||
|
product_category: 'Cat. produit',
|
||||||
|
machine_skeleton: 'Squelette',
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityTypeLabel = (type: string): string =>
|
||||||
|
ENTITY_TYPE_LABELS[type] ?? type
|
||||||
|
|
||||||
|
const formatCommentDate = (dateStr: string): string => {
|
||||||
|
const date = new Date(dateStr)
|
||||||
|
if (Number.isNaN(date.getTime())) return '—'
|
||||||
|
return new Intl.DateTimeFormat('fr-FR', {
|
||||||
|
day: '2-digit',
|
||||||
|
month: '2-digit',
|
||||||
|
year: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
}).format(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadComments = async () => {
|
||||||
|
loadingList.value = true
|
||||||
|
const result = await fetchAllComments({
|
||||||
|
status: statusFilter.value || undefined,
|
||||||
|
entityType: entityTypeFilter.value || undefined,
|
||||||
|
page: page.value,
|
||||||
|
itemsPerPage: itemsPerPage.value,
|
||||||
|
})
|
||||||
|
if (result.success) {
|
||||||
|
comments.value = result.data ?? []
|
||||||
|
total.value = result.total ?? 0
|
||||||
|
}
|
||||||
|
loadingList.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleFilterChange = () => {
|
||||||
|
page.value = 1
|
||||||
|
loadComments()
|
||||||
|
}
|
||||||
|
|
||||||
|
const goToPage = (p: number) => {
|
||||||
|
page.value = p
|
||||||
|
loadComments()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResolve = async (commentId: string) => {
|
||||||
|
const result = await resolveComment(commentId)
|
||||||
|
if (result.success) {
|
||||||
|
await loadComments()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ENTITY_ROUTE_MAP: Record<string, (id: string) => string> = {
|
||||||
|
machine: (id: string) => `/machine/${id}`,
|
||||||
|
piece: (id: string) => `/pieces/${id}/edit`,
|
||||||
|
composant: (id: string) => `/component/${id}/edit`,
|
||||||
|
product: (id: string) => `/product/${id}/edit`,
|
||||||
|
piece_category: (id: string) => `/piece-category/${id}/edit`,
|
||||||
|
component_category: (id: string) => `/component-category/${id}/edit`,
|
||||||
|
product_category: (id: string) => `/product-category/${id}/edit`,
|
||||||
|
machine_skeleton: (id: string) => `/type/${id}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
const getEntityRoute = (comment: Comment): string | null => {
|
||||||
|
const builder = ENTITY_ROUTE_MAP[comment.entityType]
|
||||||
|
return builder ? builder(comment.entityId) : null
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadComments()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -35,6 +35,16 @@
|
|||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="component_category"
|
||||||
|
:entity-id="String(route.params.id)"
|
||||||
|
:entity-name="initialData?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -304,17 +304,17 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm md:toggle-md"
|
||||||
true-value="true"
|
true-value="true"
|
||||||
false-value="false"
|
false-value="false"
|
||||||
:disabled="!canEdit || saving"
|
:disabled="!canEdit || saving"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="field.value === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
@@ -512,6 +512,16 @@
|
|||||||
Enregistrer les modifications
|
Enregistrer les modifications
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="composant"
|
||||||
|
:entity-id="String(route.params.id)"
|
||||||
|
:entity-name="component?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -271,17 +271,17 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm md:toggle-md"
|
||||||
true-value="true"
|
true-value="true"
|
||||||
false-value="false"
|
false-value="false"
|
||||||
:disabled="!canEdit || submitting"
|
:disabled="!canEdit || submitting"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="field.value === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
|
|||||||
@@ -195,8 +195,18 @@ const closeModal = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const saveConstructeur = async () => {
|
const saveConstructeur = async () => {
|
||||||
|
const trimmedName = form.value.name.trim()
|
||||||
|
const duplicate = constructeurs.value.find(
|
||||||
|
(c) => c.name.toLowerCase() === trimmedName.toLowerCase()
|
||||||
|
&& c.id !== editingConstructeur.value?.id,
|
||||||
|
)
|
||||||
|
if (duplicate) {
|
||||||
|
showError(`Un fournisseur "${duplicate.name}" existe déjà.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
saving.value = true
|
saving.value = true
|
||||||
const payload = { ...form.value }
|
const payload = { ...form.value, name: trimmedName }
|
||||||
if (!payload.email) { delete payload.email }
|
if (!payload.email) { delete payload.email }
|
||||||
if (!payload.phone) { delete payload.phone }
|
if (!payload.phone) { delete payload.phone }
|
||||||
let result
|
let result
|
||||||
|
|||||||
@@ -108,6 +108,16 @@
|
|||||||
@edit-piece="d.editPiece"
|
@edit-piece="d.editPiece"
|
||||||
@custom-field-update="d.updatePieceCustomField"
|
@custom-field-update="d.updatePieceCustomField"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="machine"
|
||||||
|
:entity-id="String(machineId)"
|
||||||
|
:entity-name="d.machine.value?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
|
|||||||
@@ -35,6 +35,16 @@
|
|||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="piece_category"
|
||||||
|
:entity-id="String(route.params.id)"
|
||||||
|
:entity-name="initialData?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -251,17 +251,17 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm md:toggle-md"
|
||||||
true-value="true"
|
true-value="true"
|
||||||
false-value="false"
|
false-value="false"
|
||||||
:disabled="!canEdit || saving"
|
:disabled="!canEdit || saving"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="field.value === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
@@ -459,6 +459,16 @@
|
|||||||
Enregistrer les modifications
|
Enregistrer les modifications
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="piece"
|
||||||
|
:entity-id="String(route.params.id)"
|
||||||
|
:entity-name="piece?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -223,17 +223,17 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm md:toggle-md"
|
||||||
true-value="true"
|
true-value="true"
|
||||||
false-value="false"
|
false-value="false"
|
||||||
:disabled="!canEdit || submitting"
|
:disabled="!canEdit || submitting"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="field.value === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
|
|||||||
@@ -35,6 +35,16 @@
|
|||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="product_category"
|
||||||
|
:entity-id="String(route.params.id)"
|
||||||
|
:entity-name="initialData?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -175,17 +175,17 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm md:toggle-md"
|
||||||
true-value="true"
|
true-value="true"
|
||||||
false-value="false"
|
false-value="false"
|
||||||
:disabled="!canEdit || saving"
|
:disabled="!canEdit || saving"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="field.value === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
@@ -382,6 +382,16 @@
|
|||||||
<p v-if="product && !requiredCustomFieldsFilled" class="text-xs text-error text-right">
|
<p v-if="product && !requiredCustomFieldsFilled" class="text-xs text-error text-right">
|
||||||
Merci de renseigner tous les champs personnalisés obligatoires.
|
Merci de renseigner tous les champs personnalisés obligatoires.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<!-- Comments -->
|
||||||
|
<div class="mt-4">
|
||||||
|
<CommentSection
|
||||||
|
entity-type="product"
|
||||||
|
:entity-id="String(route.params.id)"
|
||||||
|
:entity-name="product?.name"
|
||||||
|
show-resolved
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -162,17 +162,17 @@
|
|||||||
{{ option }}
|
{{ option }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div v-else-if="field.type === 'boolean'" class="flex items-center gap-2">
|
<label v-else-if="field.type === 'boolean'" class="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="checkbox checkbox-sm"
|
class="toggle toggle-primary toggle-sm md:toggle-md"
|
||||||
true-value="true"
|
true-value="true"
|
||||||
false-value="false"
|
false-value="false"
|
||||||
:disabled="!canEdit || submitting"
|
:disabled="!canEdit || submitting"
|
||||||
>
|
>
|
||||||
<span class="text-sm">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
<span class="text-sm" :class="field.value === 'true' ? 'text-success font-medium' : 'text-base-content/60'">{{ field.value === 'true' ? 'Oui' : 'Non' }}</span>
|
||||||
</div>
|
</label>
|
||||||
<input
|
<input
|
||||||
v-else-if="field.type === 'date'"
|
v-else-if="field.type === 'date'"
|
||||||
v-model="field.value"
|
v-model="field.value"
|
||||||
|
|||||||
@@ -127,6 +127,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Commentaires -->
|
||||||
|
<CommentSection
|
||||||
|
entity-type="machine_skeleton"
|
||||||
|
:entity-id="type.id"
|
||||||
|
:entity-name="type.name"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Error State -->
|
<!-- Error State -->
|
||||||
|
|||||||
17
package-lock.json
generated
17
package-lock.json
generated
@@ -5550,12 +5550,15 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/baseline-browser-mapping": {
|
"node_modules/baseline-browser-mapping": {
|
||||||
"version": "2.8.7",
|
"version": "2.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.7.tgz",
|
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.0.tgz",
|
||||||
"integrity": "sha512-bxxN2M3a4d1CRoQC//IqsR5XrLh0IJ8TCv2x6Y9N0nckNz/rTjZB3//GGscZziZOxmjP55rzxg/ze7usFI9FqQ==",
|
"integrity": "sha512-lIyg0szRfYbiy67j9KN8IyeD7q7hcmqnJ1ddWmNt19ItGpNN64mnllmxUNFIOdOm6by97jlL6wfpTTJrmnjWAA==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"baseline-browser-mapping": "dist/cli.js"
|
"baseline-browser-mapping": "dist/cli.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/binary-extensions": {
|
"node_modules/binary-extensions": {
|
||||||
@@ -5847,9 +5850,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001745",
|
"version": "1.0.30001775",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001745.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001775.tgz",
|
||||||
"integrity": "sha512-ywt6i8FzvdgrrrGbr1jZVObnVv6adj+0if2/omv9cmR2oiZs30zL4DIyaptKcbOrBdOIc74QTMoJvSE2QHh5UQ==",
|
"integrity": "sha512-s3Qv7Lht9zbVKE9XoTyRG6wVDCKdtOFIjBGg3+Yhn6JaytuNKPIjBMTMIY1AnOH3seL5mvF+x33oGAyK3hVt3A==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
|
|||||||
Reference in New Issue
Block a user