Sprint 2 : moteur de documents + sanctuaire

Backend:
- CRUD complet documents/items/versions (update, delete, accept, reject, reorder)
- Service IPFS (upload/retrieve/pin via kubo HTTP API)
- Service sanctuaire : pipeline SHA-256 + IPFS + on-chain (system.remark)
- Verification integrite des entrees sanctuaire
- Recherche par reference (document -> entrees sanctuaire)
- Serialisation deterministe des documents pour archivage
- 14 tests unitaires supplementaires (document service)

Frontend:
- 9 composants : StatusBadge, MarkdownRenderer, DiffView, ItemCard,
  ItemVersionDiff, DocumentList, SanctuaryEntry, IPFSLink, ChainAnchor
- Page detail item avec historique des versions et diff
- Page detail sanctuaire avec verification integrite
- Modal de creation de document + proposition de version
- Archivage document vers sanctuaire depuis la page detail

Documentation:
- API reference mise a jour (9 nouveaux endpoints)
- Guides utilisateur documents et sanctuaire enrichis

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Yvv
2026-02-28 13:08:48 +01:00
parent 25437f24e3
commit 2bdc731639
26 changed files with 3452 additions and 397 deletions

View File

@@ -0,0 +1,51 @@
<script setup lang="ts">
const props = defineProps<{
diff: string
}>()
interface DiffLine {
text: string
type: 'added' | 'removed' | 'header' | 'context'
}
const parsedLines = computed((): DiffLine[] => {
if (!props.diff) return []
return props.diff.split('\n').map((line) => {
if (line.startsWith('@@')) {
return { text: line, type: 'header' as const }
}
if (line.startsWith('+')) {
return { text: line, type: 'added' as const }
}
if (line.startsWith('-')) {
return { text: line, type: 'removed' as const }
}
return { text: line, type: 'context' as const }
})
})
function lineClass(type: DiffLine['type']): string {
switch (type) {
case 'added':
return 'bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-300'
case 'removed':
return 'bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-300'
case 'header':
return 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 font-semibold'
default:
return 'text-gray-700 dark:text-gray-300'
}
}
</script>
<template>
<div class="border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden">
<pre class="text-xs font-mono leading-relaxed overflow-x-auto"><template
v-for="(line, index) in parsedLines"
:key="index"
><div
:class="['px-4 py-0.5', lineClass(line.type)]"
>{{ line.text }}</div></template></pre>
</div>
</template>

View File

@@ -0,0 +1,67 @@
<script setup lang="ts">
const props = defineProps<{
content: string
}>()
/**
* Basic markdown rendering: bold, line breaks, unordered lists.
* Returns sanitized HTML string for v-html usage.
*/
const renderedHtml = computed(() => {
if (!props.content) return ''
let html = props.content
// Escape HTML entities to prevent XSS
html = html
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
// Convert **bold** to <strong>
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
// Convert *italic* to <em>
html = html.replace(/\*(.+?)\*/g, '<em>$1</em>')
// Process lines for list items
const lines = html.split('\n')
const result: string[] = []
let inList = false
for (const line of lines) {
const trimmed = line.trim()
if (trimmed.startsWith('- ')) {
if (!inList) {
result.push('<ul class="list-disc list-inside space-y-1 my-2">')
inList = true
}
result.push(`<li>${trimmed.slice(2)}</li>`)
} else {
if (inList) {
result.push('</ul>')
inList = false
}
if (trimmed === '') {
result.push('<br>')
} else {
result.push(`<p class="my-1">${line}</p>`)
}
}
}
if (inList) {
result.push('</ul>')
}
return result.join('\n')
})
</script>
<template>
<div
class="prose prose-sm dark:prose-invert max-w-none text-gray-700 dark:text-gray-300 leading-relaxed"
v-html="renderedHtml"
/>
</template>

View File

@@ -0,0 +1,61 @@
<script setup lang="ts">
const props = defineProps<{
status: string
type?: 'document' | 'decision' | 'mandate' | 'version' | 'vote'
}>()
const statusConfig: Record<string, Record<string, { color: string; label: string }>> = {
document: {
draft: { color: 'warning', label: 'Brouillon' },
active: { color: 'success', label: 'Actif' },
archived: { color: 'neutral', label: 'Archive' },
},
version: {
proposed: { color: 'info', label: 'Propose' },
voting: { color: 'warning', label: 'En vote' },
accepted: { color: 'success', label: 'Accepte' },
rejected: { color: 'error', label: 'Rejete' },
},
decision: {
draft: { color: 'warning', label: 'Brouillon' },
qualification: { color: 'info', label: 'Qualification' },
review: { color: 'info', label: 'Revue' },
voting: { color: 'primary', label: 'En vote' },
executed: { color: 'success', label: 'Execute' },
closed: { color: 'neutral', label: 'Clos' },
},
mandate: {
draft: { color: 'warning', label: 'Brouillon' },
candidacy: { color: 'info', label: 'Candidature' },
voting: { color: 'primary', label: 'En vote' },
active: { color: 'success', label: 'Actif' },
reporting: { color: 'info', label: 'Rapport' },
completed: { color: 'neutral', label: 'Termine' },
revoked: { color: 'error', label: 'Revoque' },
},
vote: {
open: { color: 'success', label: 'Ouvert' },
closed: { color: 'warning', label: 'Ferme' },
tallied: { color: 'neutral', label: 'Depouille' },
},
}
const resolved = computed(() => {
const typeKey = props.type || 'document'
const typeMap = statusConfig[typeKey]
if (typeMap && typeMap[props.status]) {
return typeMap[props.status]
}
return { color: 'neutral', label: props.status }
})
</script>
<template>
<UBadge
:color="(resolved.color as any)"
variant="subtle"
size="xs"
>
{{ resolved.label }}
</UBadge>
</template>

View File

@@ -0,0 +1,88 @@
<script setup lang="ts">
import type { Document } from '~/stores/documents'
const props = withDefaults(defineProps<{
documents: Document[]
loading?: boolean
}>(), {
loading: false,
})
const typeLabel = (docType: string): string => {
switch (docType) {
case 'licence': return 'Licence'
case 'engagement': return 'Engagement'
case 'reglement': return 'Reglement'
case 'constitution': return 'Constitution'
default: return docType
}
}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'short',
year: 'numeric',
})
}
</script>
<template>
<!-- Loading state -->
<div v-if="loading" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<USkeleton v-for="i in 6" :key="i" class="h-48 w-full" />
</div>
<!-- Empty state -->
<UCard v-else-if="documents.length === 0">
<div class="text-center py-8">
<UIcon name="i-lucide-book-open" class="text-4xl text-gray-400 mb-3" />
<p class="text-gray-500">Aucun document de reference pour le moment</p>
</div>
</UCard>
<!-- Document grid -->
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<UCard
v-for="doc in documents"
:key="doc.id"
class="cursor-pointer hover:ring-2 hover:ring-primary/50 transition-all"
@click="navigateTo(`/documents/${doc.slug}`)"
>
<div class="space-y-3">
<!-- Header -->
<div class="flex items-start justify-between">
<h3 class="font-semibold text-gray-900 dark:text-white text-sm leading-tight">
{{ doc.title }}
</h3>
<CommonStatusBadge :status="doc.status" type="document" />
</div>
<!-- Type + Version -->
<div class="flex items-center gap-2">
<UBadge variant="subtle" color="primary" size="xs">
{{ typeLabel(doc.doc_type) }}
</UBadge>
<span class="text-xs text-gray-500 font-mono">v{{ doc.version }}</span>
</div>
<!-- Description -->
<p
v-if="doc.description"
class="text-xs text-gray-600 dark:text-gray-400 line-clamp-2"
>
{{ doc.description }}
</p>
<!-- Footer -->
<div class="flex items-center justify-between pt-2 border-t border-gray-100 dark:border-gray-800">
<div class="flex items-center gap-1 text-xs text-gray-500">
<UIcon name="i-lucide-list" class="text-sm" />
<span>{{ doc.items_count }} items</span>
</div>
<span class="text-xs text-gray-400">{{ formatDate(doc.updated_at) }}</span>
</div>
</div>
</UCard>
</div>
</template>

View File

@@ -0,0 +1,89 @@
<script setup lang="ts">
import type { DocumentItem } from '~/stores/documents'
const props = withDefaults(defineProps<{
item: DocumentItem
documentSlug: string
showActions?: boolean
}>(), {
showActions: false,
})
const emit = defineEmits<{
propose: [item: DocumentItem]
}>()
const itemTypeLabel = (itemType: string): string => {
switch (itemType) {
case 'clause': return 'Clause'
case 'rule': return 'Regle'
case 'verification': return 'Verification'
case 'preamble': return 'Preambule'
case 'section': return 'Section'
default: return itemType
}
}
function navigateToItem() {
navigateTo(`/documents/${props.documentSlug}/items/${props.item.id}`)
}
</script>
<template>
<UCard
class="cursor-pointer hover:ring-2 hover:ring-primary/50 transition-all"
@click="navigateToItem"
>
<div class="space-y-3">
<!-- Item header -->
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<UBadge variant="solid" color="primary" size="xs">
{{ item.position }}
</UBadge>
<span v-if="item.title" class="text-sm font-semibold text-gray-900 dark:text-white">
{{ item.title }}
</span>
<UBadge variant="subtle" color="neutral" size="xs">
{{ itemTypeLabel(item.item_type) }}
</UBadge>
</div>
<div class="flex items-center gap-2">
<UBadge
v-if="item.voting_protocol_id"
color="info"
variant="subtle"
size="xs"
>
Sous vote
</UBadge>
<UBadge
v-else
color="neutral"
variant="subtle"
size="xs"
>
Pas de vote
</UBadge>
</div>
</div>
<!-- Item text -->
<div class="pl-2">
<CommonMarkdownRenderer :content="item.current_text" />
</div>
<!-- Actions -->
<div v-if="showActions" class="flex justify-end pt-2 border-t border-gray-100 dark:border-gray-800">
<UButton
label="Proposer une modification"
icon="i-lucide-pen-line"
variant="soft"
color="primary"
size="xs"
@click.stop="emit('propose', item)"
/>
</div>
</div>
</UCard>
</template>

View File

@@ -0,0 +1,95 @@
<script setup lang="ts">
import type { ItemVersion } from '~/stores/documents'
const props = defineProps<{
version: ItemVersion
}>()
const emit = defineEmits<{
accept: [versionId: string]
reject: [versionId: string]
}>()
const auth = useAuthStore()
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
}
function truncateAddress(address: string | null): string {
if (!address) return 'Inconnu'
if (address.length <= 16) return address
return address.slice(0, 8) + '...' + address.slice(-6)
}
</script>
<template>
<UCard>
<div class="space-y-4">
<!-- Header -->
<div class="flex items-start justify-between">
<div class="flex items-center gap-3">
<CommonStatusBadge :status="version.status" type="version" />
<span class="text-sm text-gray-500">
Propose par
<span class="font-medium text-gray-700 dark:text-gray-300 font-mono text-xs">
{{ truncateAddress(version.proposed_by) }}
</span>
</span>
</div>
<span class="text-xs text-gray-400">
{{ formatDate(version.created_at) }}
</span>
</div>
<!-- Rationale -->
<div v-if="version.rationale" class="bg-gray-50 dark:bg-gray-800/50 rounded-lg p-3">
<p class="text-xs font-semibold text-gray-500 uppercase mb-1">Justification</p>
<p class="text-sm text-gray-700 dark:text-gray-300">{{ version.rationale }}</p>
</div>
<!-- Diff view -->
<div v-if="version.diff">
<p class="text-xs font-semibold text-gray-500 uppercase mb-2">Modifications</p>
<CommonDiffView :diff="version.diff" />
</div>
<!-- Proposed text (fallback if no diff) -->
<div v-else-if="version.proposed_text">
<p class="text-xs font-semibold text-gray-500 uppercase mb-2">Texte propose</p>
<div class="bg-green-50 dark:bg-green-900/10 border border-green-200 dark:border-green-800 rounded-lg p-3">
<CommonMarkdownRenderer :content="version.proposed_text" />
</div>
</div>
<!-- Actions for authenticated users -->
<div
v-if="auth.isAuthenticated && version.status === 'proposed'"
class="flex items-center gap-3 pt-2 border-t border-gray-100 dark:border-gray-800"
>
<UButton
label="Accepter"
icon="i-lucide-check"
color="success"
variant="soft"
size="xs"
@click="emit('accept', version.id)"
/>
<UButton
label="Rejeter"
icon="i-lucide-x"
color="error"
variant="soft"
size="xs"
@click="emit('reject', version.id)"
/>
</div>
</div>
</UCard>
</template>

View File

@@ -0,0 +1,33 @@
<script setup lang="ts">
const props = defineProps<{
txHash: string | null
block: number | null
}>()
const truncatedHash = computed(() => {
if (!props.txHash) return null
if (props.txHash.length <= 20) return props.txHash
return props.txHash.slice(0, 10) + '...' + props.txHash.slice(-6)
})
</script>
<template>
<template v-if="txHash">
<div class="inline-flex items-center gap-2">
<div class="flex items-center gap-1.5">
<UIcon name="i-lucide-link" class="text-sm text-gray-500" />
<span class="font-mono text-xs text-gray-700 dark:text-gray-300">
{{ truncatedHash }}
</span>
</div>
<UBadge v-if="block" color="neutral" variant="subtle" size="xs">
Bloc #{{ block.toLocaleString('fr-FR') }}
</UBadge>
</div>
</template>
<template v-else>
<UBadge color="warning" variant="subtle" size="xs">
Non ancre
</UBadge>
</template>
</template>

View File

@@ -0,0 +1,38 @@
<script setup lang="ts">
const props = defineProps<{
cid: string | null
}>()
const IPFS_GATEWAY = 'https://ipfs.io/ipfs/'
const truncatedCid = computed(() => {
if (!props.cid) return null
if (props.cid.length <= 20) return props.cid
return props.cid.slice(0, 12) + '...' + props.cid.slice(-6)
})
const gatewayUrl = computed(() => {
if (!props.cid) return null
return `${IPFS_GATEWAY}${props.cid}`
})
</script>
<template>
<template v-if="cid">
<a
:href="gatewayUrl!"
target="_blank"
rel="noopener noreferrer"
class="inline-flex items-center gap-1.5 font-mono text-xs text-primary hover:underline"
>
<UIcon name="i-lucide-hard-drive" class="text-sm" />
<span>{{ truncatedCid }}</span>
<UIcon name="i-lucide-external-link" class="text-sm" />
</a>
</template>
<template v-else>
<UBadge color="neutral" variant="subtle" size="xs">
Non disponible
</UBadge>
</template>
</template>

View File

@@ -0,0 +1,171 @@
<script setup lang="ts">
export interface SanctuaryEntryOut {
id: string
entry_type: string
reference_id: string
title: string | null
content_hash: string
ipfs_cid: string | null
chain_tx_hash: string | null
chain_block: number | null
metadata_json: string | null
created_at: string
}
const props = defineProps<{
entry: SanctuaryEntryOut
}>()
const emit = defineEmits<{
verify: [id: string]
}>()
const typeLabel = (entryType: string): string => {
switch (entryType) {
case 'document': return 'Document'
case 'decision': return 'Decision'
case 'vote_result': return 'Resultat de vote'
default: return entryType
}
}
const typeColor = (entryType: string): string => {
switch (entryType) {
case 'document': return 'primary'
case 'decision': return 'success'
case 'vote_result': return 'info'
default: return 'neutral'
}
}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
}
function truncateHash(hash: string | null, length: number = 16): string {
if (!hash) return '-'
if (hash.length <= length * 2) return hash
return hash.slice(0, length) + '...' + hash.slice(-8)
}
const copied = ref(false)
async function copyHash() {
try {
await navigator.clipboard.writeText(props.entry.content_hash)
copied.value = true
setTimeout(() => { copied.value = false }, 2000)
} catch {
// Clipboard API not available
}
}
</script>
<template>
<UCard
class="cursor-pointer hover:ring-2 hover:ring-primary/50 transition-all"
@click="navigateTo(`/sanctuary/${entry.id}`)"
>
<div class="space-y-4">
<!-- Entry header -->
<div class="flex items-start justify-between">
<div class="flex items-center gap-3">
<UIcon name="i-lucide-shield-check" class="text-xl text-primary" />
<div>
<h3 class="font-semibold text-gray-900 dark:text-white">
{{ entry.title || 'Entree sans titre' }}
</h3>
<p class="text-xs text-gray-500">
{{ formatDate(entry.created_at) }}
</p>
</div>
</div>
<UBadge :color="(typeColor(entry.entry_type) as any)" variant="subtle" size="xs">
{{ typeLabel(entry.entry_type) }}
</UBadge>
</div>
<!-- Hashes and anchors -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Content hash -->
<div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
<div class="flex items-center justify-between mb-1">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-hash" class="text-gray-400 text-sm" />
<span class="text-xs font-semibold text-gray-500 uppercase">SHA-256</span>
</div>
<UButton
:icon="copied ? 'i-lucide-check' : 'i-lucide-copy'"
variant="ghost"
color="neutral"
size="xs"
class="p-0"
@click.stop="copyHash"
/>
</div>
<p class="font-mono text-xs text-gray-700 dark:text-gray-300 break-all">
{{ truncateHash(entry.content_hash) }}
</p>
</div>
<!-- IPFS CID -->
<div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
<div class="flex items-center gap-2 mb-1">
<UIcon name="i-lucide-hard-drive" class="text-gray-400 text-sm" />
<span class="text-xs font-semibold text-gray-500 uppercase">IPFS CID</span>
</div>
<div @click.stop>
<SanctuaryIPFSLink :cid="entry.ipfs_cid" />
</div>
</div>
<!-- Chain anchor -->
<div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
<div class="flex items-center gap-2 mb-1">
<UIcon name="i-lucide-link" class="text-gray-400 text-sm" />
<span class="text-xs font-semibold text-gray-500 uppercase">On-chain</span>
</div>
<SanctuaryChainAnchor :tx-hash="entry.chain_tx_hash" :block="entry.chain_block" />
</div>
</div>
<!-- Verification status indicators -->
<div class="flex items-center justify-between">
<div class="flex items-center gap-4 text-xs">
<div class="flex items-center gap-1">
<UIcon
:name="entry.ipfs_cid ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.ipfs_cid ? 'text-green-500' : 'text-gray-400'"
/>
<span :class="entry.ipfs_cid ? 'text-green-600' : 'text-gray-400'">
IPFS {{ entry.ipfs_cid ? 'epingle' : 'en attente' }}
</span>
</div>
<div class="flex items-center gap-1">
<UIcon
:name="entry.chain_tx_hash ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.chain_tx_hash ? 'text-green-500' : 'text-gray-400'"
/>
<span :class="entry.chain_tx_hash ? 'text-green-600' : 'text-gray-400'">
Chain {{ entry.chain_tx_hash ? 'ancre' : 'en attente' }}
</span>
</div>
</div>
<UButton
label="Verifier"
icon="i-lucide-shield-check"
variant="soft"
color="primary"
size="xs"
@click.stop="emit('verify', entry.id)"
/>
</div>
</div>
</UCard>
</template>

View File

@@ -1,9 +1,14 @@
<script setup lang="ts">
import type { DocumentItem } from '~/stores/documents'
const route = useRoute()
const documents = useDocumentsStore()
const auth = useAuthStore()
const slug = computed(() => route.params.slug as string)
const archiving = ref(false)
onMounted(async () => {
await documents.fetchBySlug(slug.value)
})
@@ -18,24 +23,6 @@ watch(slug, async (newSlug) => {
}
})
const statusColor = (status: string) => {
switch (status) {
case 'active': return 'success'
case 'draft': return 'warning'
case 'archived': return 'neutral'
default: return 'neutral'
}
}
const statusLabel = (status: string) => {
switch (status) {
case 'active': return 'Actif'
case 'draft': return 'Brouillon'
case 'archived': return 'Archive'
default: return status
}
}
const typeLabel = (docType: string) => {
switch (docType) {
case 'licence': return 'Licence'
@@ -46,17 +33,6 @@ const typeLabel = (docType: string) => {
}
}
const itemTypeLabel = (itemType: string) => {
switch (itemType) {
case 'clause': return 'Clause'
case 'rule': return 'Regle'
case 'verification': return 'Verification'
case 'preamble': return 'Preambule'
case 'section': return 'Section'
default: return itemType
}
}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
@@ -64,6 +40,21 @@ function formatDate(dateStr: string): string {
year: 'numeric',
})
}
function handlePropose(item: DocumentItem) {
navigateTo(`/documents/${slug.value}/items/${item.id}`)
}
async function archiveToSanctuary() {
archiving.value = true
try {
await documents.archiveDocument(slug.value)
} catch {
// Error handled in store
} finally {
archiving.value = false
}
}
</script>
<template>
@@ -114,14 +105,24 @@ function formatDate(dateStr: string): string {
<UBadge variant="subtle" color="primary">
{{ typeLabel(documents.current.doc_type) }}
</UBadge>
<UBadge :color="statusColor(documents.current.status)" variant="subtle">
{{ statusLabel(documents.current.status) }}
</UBadge>
<CommonStatusBadge :status="documents.current.status" type="document" />
<span class="text-sm text-gray-500 font-mono">
v{{ documents.current.version }}
</span>
</div>
</div>
<!-- Archive button for authenticated users with active documents -->
<div v-if="auth.isAuthenticated && documents.current.status === 'active'" class="flex items-center gap-2">
<UButton
label="Archiver dans le Sanctuaire"
icon="i-lucide-archive"
color="primary"
variant="soft"
:loading="archiving"
@click="archiveToSanctuary"
/>
</div>
</div>
<!-- Description -->
@@ -153,14 +154,17 @@ function formatDate(dateStr: string): string {
</div>
<div>
<p class="text-gray-500">Ancrage IPFS</p>
<p class="font-medium text-gray-900 dark:text-white">
<template v-if="documents.current.ipfs_cid">
<span class="font-mono text-xs">{{ documents.current.ipfs_cid.slice(0, 16) }}...</span>
</template>
<template v-else>
<span class="text-gray-400">Non ancre</span>
</template>
</p>
<div class="mt-1">
<SanctuaryIPFSLink :cid="documents.current.ipfs_cid" />
</div>
</div>
</div>
<!-- Chain anchor info -->
<div v-if="documents.current.chain_anchor" class="mt-4 pt-4 border-t border-gray-100 dark:border-gray-800">
<div class="flex items-center gap-2">
<p class="text-sm text-gray-500">Ancrage on-chain :</p>
<SanctuaryChainAnchor :tx-hash="documents.current.chain_anchor" :block="null" />
</div>
</div>
</UCard>
@@ -177,52 +181,14 @@ function formatDate(dateStr: string): string {
</div>
<div v-else class="space-y-4">
<UCard
<DocumentsItemCard
v-for="item in documents.items"
:key="item.id"
>
<div class="space-y-3">
<!-- Item header -->
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<span class="text-sm font-mono font-bold text-primary">
{{ item.position }}
</span>
<UBadge variant="subtle" color="neutral" size="xs">
{{ itemTypeLabel(item.item_type) }}
</UBadge>
<span v-if="item.title" class="text-sm font-semibold text-gray-900 dark:text-white">
{{ item.title }}
</span>
</div>
<div class="flex items-center gap-2">
<UBadge
v-if="item.voting_protocol_id"
color="info"
variant="subtle"
size="xs"
>
Sous vote
</UBadge>
<UBadge
v-else
color="neutral"
variant="subtle"
size="xs"
>
Pas de vote
</UBadge>
</div>
</div>
<!-- Item text -->
<div class="pl-8">
<p class="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap leading-relaxed">
{{ item.current_text }}
</p>
</div>
</div>
</UCard>
:item="item"
:document-slug="slug"
:show-actions="auth.isAuthenticated"
@propose="handlePropose"
/>
</div>
</div>
</template>

View File

@@ -0,0 +1,328 @@
<script setup lang="ts">
import type { DocumentItem, VersionProposal } from '~/stores/documents'
const route = useRoute()
const documents = useDocumentsStore()
const auth = useAuthStore()
const slug = computed(() => route.params.slug as string)
const itemId = computed(() => route.params.itemId as string)
const currentItem = computed((): DocumentItem | undefined => {
return documents.items.find(i => i.id === itemId.value)
})
// Modal state for proposing a modification
const showProposeModal = ref(false)
const proposedText = ref('')
const rationale = ref('')
const proposing = ref(false)
// Loading versions
const versionsLoading = ref(false)
onMounted(async () => {
// Fetch document + items if not already loaded
if (!documents.current || documents.current.slug !== slug.value) {
await documents.fetchBySlug(slug.value)
}
// Fetch versions for this item
versionsLoading.value = true
await documents.fetchItemVersions(slug.value, itemId.value)
versionsLoading.value = false
})
onUnmounted(() => {
documents.versions = []
})
watch([slug, itemId], async ([newSlug, newItemId]) => {
if (newSlug && newItemId) {
if (!documents.current || documents.current.slug !== newSlug) {
await documents.fetchBySlug(newSlug)
}
versionsLoading.value = true
await documents.fetchItemVersions(newSlug, newItemId)
versionsLoading.value = false
}
})
function openProposeModal() {
if (currentItem.value) {
proposedText.value = currentItem.value.current_text
}
rationale.value = ''
showProposeModal.value = true
}
async function submitProposal() {
proposing.value = true
try {
const data: VersionProposal = {
proposed_text: proposedText.value,
rationale: rationale.value || null,
}
await documents.proposeVersion(slug.value, itemId.value, data)
showProposeModal.value = false
proposedText.value = ''
rationale.value = ''
} catch {
// Error handled in store
} finally {
proposing.value = false
}
}
async function handleAcceptVersion(versionId: string) {
try {
await documents.acceptVersion(slug.value, itemId.value, versionId)
// Refresh item data
await documents.fetchBySlug(slug.value)
} catch {
// Error handled in store
}
}
async function handleRejectVersion(versionId: string) {
try {
await documents.rejectVersion(slug.value, itemId.value, versionId)
} catch {
// Error handled in store
}
}
const itemTypeLabel = (itemType: string): string => {
switch (itemType) {
case 'clause': return 'Clause'
case 'rule': return 'Regle'
case 'verification': return 'Verification'
case 'preamble': return 'Preambule'
case 'section': return 'Section'
default: return itemType
}
}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
})
}
</script>
<template>
<div class="space-y-6">
<!-- Breadcrumb -->
<nav class="flex items-center gap-2 text-sm text-gray-500">
<NuxtLink to="/documents" class="hover:text-primary transition-colors">
Documents
</NuxtLink>
<UIcon name="i-lucide-chevron-right" class="text-xs" />
<NuxtLink
v-if="documents.current"
:to="`/documents/${slug}`"
class="hover:text-primary transition-colors"
>
{{ documents.current.title }}
</NuxtLink>
<USkeleton v-else class="h-4 w-32" />
<UIcon name="i-lucide-chevron-right" class="text-xs" />
<span v-if="currentItem" class="text-gray-900 dark:text-white font-medium">
Item {{ currentItem.position }}
</span>
<USkeleton v-else class="h-4 w-20" />
</nav>
<!-- Loading state -->
<template v-if="documents.loading && !currentItem">
<div class="space-y-4">
<USkeleton class="h-8 w-96" />
<USkeleton class="h-4 w-64" />
<USkeleton class="h-48 w-full" />
</div>
</template>
<!-- Error state -->
<template v-else-if="documents.error && !currentItem">
<UCard>
<div class="flex items-center gap-3 text-red-500">
<UIcon name="i-lucide-alert-circle" class="text-xl" />
<p>{{ documents.error }}</p>
</div>
</UCard>
</template>
<!-- Item not found -->
<template v-else-if="!currentItem && !documents.loading">
<UCard>
<div class="text-center py-8">
<UIcon name="i-lucide-file-x" class="text-4xl text-gray-400 mb-3" />
<p class="text-gray-500">Item introuvable</p>
<UButton
:to="`/documents/${slug}`"
label="Retour au document"
variant="soft"
color="primary"
class="mt-4"
/>
</div>
</UCard>
</template>
<!-- Item detail -->
<template v-else-if="currentItem">
<!-- Item header -->
<div class="flex items-start justify-between">
<div>
<div class="flex items-center gap-3 mb-2">
<UBadge variant="solid" color="primary" size="sm">
{{ currentItem.position }}
</UBadge>
<UBadge variant="subtle" color="neutral" size="xs">
{{ itemTypeLabel(currentItem.item_type) }}
</UBadge>
<UBadge
v-if="currentItem.voting_protocol_id"
color="info"
variant="subtle"
size="xs"
>
Sous vote
</UBadge>
</div>
<h1
v-if="currentItem.title"
class="text-2xl font-bold text-gray-900 dark:text-white"
>
{{ currentItem.title }}
</h1>
</div>
<!-- Action buttons -->
<div v-if="auth.isAuthenticated" class="flex items-center gap-2">
<UButton
label="Proposer une modification"
icon="i-lucide-pen-line"
color="primary"
variant="soft"
@click="openProposeModal"
/>
</div>
</div>
<!-- Current text -->
<UCard>
<div class="space-y-3">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-file-text" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">Texte en vigueur</h2>
</div>
<CommonMarkdownRenderer :content="currentItem.current_text" />
<div class="flex items-center gap-4 pt-3 border-t border-gray-100 dark:border-gray-800 text-xs text-gray-400">
<span>Cree le {{ formatDate(currentItem.created_at) }}</span>
<span>Mis a jour le {{ formatDate(currentItem.updated_at) }}</span>
</div>
</div>
</UCard>
<!-- Error banner -->
<UCard v-if="documents.error">
<div class="flex items-center gap-3 text-red-500">
<UIcon name="i-lucide-alert-circle" class="text-xl" />
<p>{{ documents.error }}</p>
</div>
</UCard>
<!-- Version history -->
<div>
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">
Historique des versions ({{ documents.versions.length }})
</h2>
<template v-if="versionsLoading">
<div class="space-y-3">
<USkeleton v-for="i in 3" :key="i" class="h-32 w-full" />
</div>
</template>
<template v-else-if="documents.versions.length === 0">
<UCard>
<div class="text-center py-6">
<UIcon name="i-lucide-git-branch" class="text-3xl text-gray-400 mb-2" />
<p class="text-gray-500 text-sm">Aucune version proposee pour cet item</p>
<p class="text-xs text-gray-400 mt-1">
Connectez-vous pour proposer une modification
</p>
</div>
</UCard>
</template>
<div v-else class="space-y-4">
<DocumentsItemVersionDiff
v-for="version in documents.versions"
:key="version.id"
:version="version"
@accept="handleAcceptVersion"
@reject="handleRejectVersion"
/>
</div>
</div>
</template>
<!-- Propose modification modal -->
<UModal v-model:open="showProposeModal">
<template #content>
<div class="p-6 space-y-4">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
Proposer une modification
</h3>
<p class="text-sm text-gray-500">
Modifiez le texte ci-dessous et fournissez une justification pour votre proposition.
</p>
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Texte propose
</label>
<UTextarea
v-model="proposedText"
:rows="8"
placeholder="Saisissez le nouveau texte..."
class="w-full"
/>
</div>
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Justification
</label>
<UTextarea
v-model="rationale"
:rows="3"
placeholder="Expliquez les raisons de cette modification..."
class="w-full"
/>
</div>
<div class="flex items-center justify-end gap-3 pt-2">
<UButton
label="Annuler"
variant="ghost"
color="neutral"
@click="showProposeModal = false"
/>
<UButton
label="Soumettre la proposition"
icon="i-lucide-send"
color="primary"
:loading="proposing"
:disabled="!proposedText.trim()"
@click="submitProposal"
/>
</div>
</div>
</template>
</UModal>
</div>
</template>

View File

@@ -1,5 +1,8 @@
<script setup lang="ts">
import type { DocumentCreate } from '~/stores/documents'
const documents = useDocumentsStore()
const auth = useAuthStore()
const filterType = ref<string | undefined>(undefined)
const filterStatus = ref<string | undefined>(undefined)
@@ -19,13 +22,22 @@ const statusOptions = [
{ label: 'Archive', value: 'archived' },
]
const columns = [
{ key: 'title', label: 'Titre' },
{ key: 'doc_type', label: 'Type' },
{ key: 'version', label: 'Version' },
{ key: 'status', label: 'Statut' },
{ key: 'items_count', label: 'Items' },
{ key: 'updated_at', label: 'Mis a jour' },
// New document modal state
const showNewDocModal = ref(false)
const newDoc = ref<DocumentCreate>({
slug: '',
title: '',
doc_type: 'licence',
description: null,
version: '1.0.0',
})
const creating = ref(false)
const newDocTypeOptions = [
{ label: 'Licence', value: 'licence' },
{ label: 'Engagement', value: 'engagement' },
{ label: 'Reglement', value: 'reglement' },
{ label: 'Constitution', value: 'constitution' },
]
async function loadDocuments() {
@@ -43,40 +55,47 @@ watch([filterType, filterStatus], () => {
loadDocuments()
})
const statusColor = (status: string) => {
switch (status) {
case 'active': return 'success'
case 'draft': return 'warning'
case 'archived': return 'neutral'
default: return 'neutral'
function openNewDocModal() {
newDoc.value = {
slug: '',
title: '',
doc_type: 'licence',
description: null,
version: '1.0.0',
}
showNewDocModal.value = true
}
const statusLabel = (status: string) => {
switch (status) {
case 'active': return 'Actif'
case 'draft': return 'Brouillon'
case 'archived': return 'Archive'
default: return status
}
function generateSlug(title: string): string {
return title
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.slice(0, 64)
}
const typeLabel = (docType: string) => {
switch (docType) {
case 'licence': return 'Licence'
case 'engagement': return 'Engagement'
case 'reglement': return 'Reglement'
case 'constitution': return 'Constitution'
default: return docType
watch(() => newDoc.value.title, (title) => {
if (title) {
newDoc.value.slug = generateSlug(title)
}
}
})
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'short',
year: 'numeric',
})
async function createDocument() {
creating.value = true
try {
const doc = await documents.createDocument(newDoc.value)
showNewDocModal.value = false
if (doc) {
navigateTo(`/documents/${doc.slug}`)
}
} catch {
// Error handled in store
} finally {
creating.value = false
}
}
</script>
@@ -92,6 +111,15 @@ function formatDate(dateStr: string): string {
Documents fondateurs de la communaute Duniter/G1 sous vote permanent
</p>
</div>
<!-- New document button for authenticated users -->
<UButton
v-if="auth.isAuthenticated"
label="Nouveau document"
icon="i-lucide-plus"
color="primary"
@click="openNewDocModal"
/>
</div>
<!-- Filters -->
@@ -110,15 +138,8 @@ function formatDate(dateStr: string): string {
/>
</div>
<!-- Loading state -->
<template v-if="documents.loading">
<div class="space-y-3">
<USkeleton v-for="i in 5" :key="i" class="h-12 w-full" />
</div>
</template>
<!-- Error state -->
<template v-else-if="documents.error">
<template v-if="documents.error">
<UCard>
<div class="flex items-center gap-3 text-red-500">
<UIcon name="i-lucide-alert-circle" class="text-xl" />
@@ -127,65 +148,96 @@ function formatDate(dateStr: string): string {
</UCard>
</template>
<!-- Empty state -->
<template v-else-if="documents.list.length === 0">
<UCard>
<div class="text-center py-8">
<UIcon name="i-lucide-book-open" class="text-4xl text-gray-400 mb-3" />
<p class="text-gray-500">Aucun document de reference pour le moment</p>
</div>
</UCard>
</template>
<!-- Document list component -->
<DocumentsDocumentList
:documents="documents.list"
:loading="documents.loading"
/>
<!-- Documents table -->
<template v-else>
<UCard>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700">
<th v-for="col in columns" :key="col.key" class="text-left px-4 py-3 font-medium text-gray-500 dark:text-gray-400">
{{ col.label }}
</th>
</tr>
</thead>
<tbody>
<tr
v-for="doc in documents.list"
:key="doc.id"
class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50 dark:hover:bg-gray-800/50 cursor-pointer"
@click="navigateTo(`/documents/${doc.slug}`)"
>
<td class="px-4 py-3">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-file-text" class="text-gray-400" />
<span class="font-medium text-gray-900 dark:text-white">{{ doc.title }}</span>
</div>
</td>
<td class="px-4 py-3">
<UBadge variant="subtle" color="primary">
{{ typeLabel(doc.doc_type) }}
</UBadge>
</td>
<td class="px-4 py-3 text-gray-600 dark:text-gray-400 font-mono text-xs">
v{{ doc.version }}
</td>
<td class="px-4 py-3">
<UBadge :color="statusColor(doc.status)" variant="subtle">
{{ statusLabel(doc.status) }}
</UBadge>
</td>
<td class="px-4 py-3 text-gray-600 dark:text-gray-400">
{{ doc.items_count }}
</td>
<td class="px-4 py-3 text-gray-500 text-xs">
{{ formatDate(doc.updated_at) }}
</td>
</tr>
</tbody>
</table>
<!-- New document modal -->
<UModal v-model:open="showNewDocModal">
<template #content>
<div class="p-6 space-y-4">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
Nouveau document de reference
</h3>
<div class="space-y-4">
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Titre
</label>
<UInput
v-model="newDoc.title"
placeholder="Ex: Licence G1"
class="w-full"
/>
</div>
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Slug (identifiant URL)
</label>
<UInput
v-model="newDoc.slug"
placeholder="Ex: licence-g1"
class="w-full font-mono text-sm"
/>
</div>
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Type de document
</label>
<USelect
v-model="newDoc.doc_type"
:items="newDocTypeOptions"
class="w-full"
/>
</div>
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Version
</label>
<UInput
v-model="newDoc.version"
placeholder="1.0.0"
class="w-full font-mono text-sm"
/>
</div>
<div class="space-y-2">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">
Description (optionnelle)
</label>
<UTextarea
v-model="newDoc.description"
:rows="3"
placeholder="Decrivez brievement ce document..."
class="w-full"
/>
</div>
</div>
<div class="flex items-center justify-end gap-3 pt-2">
<UButton
label="Annuler"
variant="ghost"
color="neutral"
@click="showNewDocModal = false"
/>
<UButton
label="Creer le document"
icon="i-lucide-plus"
color="primary"
:loading="creating"
:disabled="!newDoc.title.trim() || !newDoc.slug.trim()"
@click="createDocument"
/>
</div>
</div>
</UCard>
</template>
</template>
</UModal>
</div>
</template>

View File

@@ -0,0 +1,445 @@
<script setup lang="ts">
const route = useRoute()
const { $api } = useApi()
interface SanctuaryEntryDetail {
id: string
entry_type: string
reference_id: string
title: string | null
content_hash: string
ipfs_cid: string | null
chain_tx_hash: string | null
chain_block: number | null
metadata_json: string | null
created_at: string
}
interface VerifyResult {
match: boolean
message: string
}
const entryId = computed(() => route.params.id as string)
const entry = ref<SanctuaryEntryDetail | null>(null)
const loading = ref(true)
const error = ref<string | null>(null)
const verifying = ref(false)
const verifyResult = ref<VerifyResult | null>(null)
const copied = ref<string | null>(null)
async function loadEntry() {
loading.value = true
error.value = null
try {
entry.value = await $api<SanctuaryEntryDetail>(`/sanctuary/${entryId.value}`)
} catch (err: any) {
error.value = err?.data?.detail || err?.message || 'Entree introuvable'
} finally {
loading.value = false
}
}
async function verifyIntegrity() {
verifying.value = true
verifyResult.value = null
try {
verifyResult.value = await $api<VerifyResult>(
`/sanctuary/${entryId.value}/verify`,
)
} catch (err: any) {
verifyResult.value = {
match: false,
message: err?.data?.detail || err?.message || 'Erreur lors de la verification',
}
} finally {
verifying.value = false
}
}
async function copyToClipboard(text: string, field: string) {
try {
await navigator.clipboard.writeText(text)
copied.value = field
setTimeout(() => { copied.value = null }, 2000)
} catch {
// Clipboard API not available
}
}
onMounted(() => {
loadEntry()
})
watch(entryId, () => {
loadEntry()
})
const typeLabel = (entryType: string): string => {
switch (entryType) {
case 'document': return 'Document'
case 'decision': return 'Decision'
case 'vote_result': return 'Resultat de vote'
default: return entryType
}
}
const typeColor = (entryType: string): string => {
switch (entryType) {
case 'document': return 'primary'
case 'decision': return 'success'
case 'vote_result': return 'info'
default: return 'neutral'
}
}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
}
const parsedMetadata = computed(() => {
if (!entry.value?.metadata_json) return null
try {
return JSON.parse(entry.value.metadata_json)
} catch {
return null
}
})
const formattedMetadata = computed(() => {
if (!parsedMetadata.value) return null
return JSON.stringify(parsedMetadata.value, null, 2)
})
const IPFS_GATEWAY = 'https://ipfs.io/ipfs/'
</script>
<template>
<div class="space-y-6">
<!-- Back link -->
<div>
<UButton
to="/sanctuary"
variant="ghost"
color="neutral"
icon="i-lucide-arrow-left"
label="Retour au sanctuaire"
size="sm"
/>
</div>
<!-- Loading state -->
<template v-if="loading">
<div class="space-y-4">
<USkeleton class="h-8 w-96" />
<USkeleton class="h-4 w-64" />
<USkeleton class="h-48 w-full" />
<USkeleton class="h-32 w-full" />
</div>
</template>
<!-- Error state -->
<template v-else-if="error">
<UCard>
<div class="flex items-center gap-3 text-red-500">
<UIcon name="i-lucide-alert-circle" class="text-xl" />
<p>{{ error }}</p>
</div>
</UCard>
</template>
<!-- Entry detail -->
<template v-else-if="entry">
<!-- Header -->
<div class="flex items-start justify-between">
<div>
<div class="flex items-center gap-3 mb-2">
<UIcon name="i-lucide-shield-check" class="text-2xl text-primary" />
<h1 class="text-2xl font-bold text-gray-900 dark:text-white">
{{ entry.title || 'Entree sans titre' }}
</h1>
</div>
<div class="flex items-center gap-3">
<UBadge :color="(typeColor(entry.entry_type) as any)" variant="subtle">
{{ typeLabel(entry.entry_type) }}
</UBadge>
<span class="text-sm text-gray-500">
{{ formatDate(entry.created_at) }}
</span>
</div>
</div>
<!-- Verify button -->
<UButton
label="Verifier l'integrite"
icon="i-lucide-shield-check"
color="primary"
:loading="verifying"
@click="verifyIntegrity"
/>
</div>
<!-- Verification result -->
<UCard v-if="verifyResult">
<div class="flex items-center gap-3">
<UIcon
:name="verifyResult.match ? 'i-lucide-check-circle' : 'i-lucide-alert-triangle'"
:class="verifyResult.match ? 'text-green-500 text-2xl' : 'text-red-500 text-2xl'"
/>
<div>
<p
:class="verifyResult.match
? 'text-green-700 dark:text-green-400 font-semibold'
: 'text-red-700 dark:text-red-400 font-semibold'"
>
{{ verifyResult.match ? 'Integrite verifiee avec succes' : 'Verification echouee' }}
</p>
<p class="text-sm text-gray-500 mt-1">{{ verifyResult.message }}</p>
</div>
</div>
</UCard>
<!-- SHA-256 Hash -->
<UCard>
<div class="space-y-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-hash" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">Hash SHA-256</h2>
</div>
<UButton
:icon="copied === 'hash' ? 'i-lucide-check' : 'i-lucide-copy'"
:label="copied === 'hash' ? 'Copie' : 'Copier'"
variant="ghost"
color="neutral"
size="xs"
@click="copyToClipboard(entry.content_hash, 'hash')"
/>
</div>
<div class="bg-gray-50 dark:bg-gray-800/50 rounded-lg p-4">
<p class="font-mono text-sm text-gray-700 dark:text-gray-300 break-all select-all">
{{ entry.content_hash }}
</p>
</div>
</div>
</UCard>
<!-- IPFS CID -->
<UCard>
<div class="space-y-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-hard-drive" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">IPFS CID</h2>
</div>
<UButton
v-if="entry.ipfs_cid"
:icon="copied === 'ipfs' ? 'i-lucide-check' : 'i-lucide-copy'"
:label="copied === 'ipfs' ? 'Copie' : 'Copier'"
variant="ghost"
color="neutral"
size="xs"
@click="copyToClipboard(entry.ipfs_cid!, 'ipfs')"
/>
</div>
<template v-if="entry.ipfs_cid">
<div class="bg-gray-50 dark:bg-gray-800/50 rounded-lg p-4">
<p class="font-mono text-sm text-gray-700 dark:text-gray-300 break-all select-all">
{{ entry.ipfs_cid }}
</p>
</div>
<a
:href="`${IPFS_GATEWAY}${entry.ipfs_cid}`"
target="_blank"
rel="noopener noreferrer"
class="inline-flex items-center gap-2 text-sm text-primary hover:underline"
>
<UIcon name="i-lucide-external-link" />
<span>Ouvrir sur la passerelle IPFS</span>
</a>
</template>
<template v-else>
<div class="bg-yellow-50 dark:bg-yellow-900/10 rounded-lg p-4">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-clock" class="text-yellow-500" />
<p class="text-sm text-yellow-700 dark:text-yellow-400">
En attente d'epinglage IPFS
</p>
</div>
</div>
</template>
</div>
</UCard>
<!-- Chain Anchor -->
<UCard>
<div class="space-y-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-link" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">Ancrage On-chain</h2>
</div>
<UButton
v-if="entry.chain_tx_hash"
:icon="copied === 'chain' ? 'i-lucide-check' : 'i-lucide-copy'"
:label="copied === 'chain' ? 'Copie' : 'Copier'"
variant="ghost"
color="neutral"
size="xs"
@click="copyToClipboard(entry.chain_tx_hash!, 'chain')"
/>
</div>
<template v-if="entry.chain_tx_hash">
<div class="bg-gray-50 dark:bg-gray-800/50 rounded-lg p-4 space-y-2">
<div>
<p class="text-xs text-gray-500 mb-1">TX Hash</p>
<p class="font-mono text-sm text-gray-700 dark:text-gray-300 break-all select-all">
{{ entry.chain_tx_hash }}
</p>
</div>
<div v-if="entry.chain_block">
<p class="text-xs text-gray-500 mb-1">Numero de bloc</p>
<p class="font-mono text-sm text-gray-700 dark:text-gray-300">
#{{ entry.chain_block.toLocaleString('fr-FR') }}
</p>
</div>
</div>
</template>
<template v-else>
<div class="bg-yellow-50 dark:bg-yellow-900/10 rounded-lg p-4">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-clock" class="text-yellow-500" />
<p class="text-sm text-yellow-700 dark:text-yellow-400">
En attente d'ancrage on-chain via system.remark
</p>
</div>
</div>
</template>
</div>
</UCard>
<!-- Verification status -->
<UCard>
<div class="space-y-3">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-check-circle" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">Statut de verification</h2>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="flex items-center gap-3 p-3 rounded-lg"
:class="entry.content_hash
? 'bg-green-50 dark:bg-green-900/10'
: 'bg-gray-50 dark:bg-gray-800/50'"
>
<UIcon
:name="entry.content_hash ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.content_hash ? 'text-green-500' : 'text-gray-400'"
/>
<div>
<p class="text-sm font-medium" :class="entry.content_hash ? 'text-green-700 dark:text-green-400' : 'text-gray-500'">
Hash SHA-256
</p>
<p class="text-xs text-gray-500">
{{ entry.content_hash ? 'Calcule' : 'En attente' }}
</p>
</div>
</div>
<div class="flex items-center gap-3 p-3 rounded-lg"
:class="entry.ipfs_cid
? 'bg-green-50 dark:bg-green-900/10'
: 'bg-yellow-50 dark:bg-yellow-900/10'"
>
<UIcon
:name="entry.ipfs_cid ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.ipfs_cid ? 'text-green-500' : 'text-yellow-500'"
/>
<div>
<p class="text-sm font-medium" :class="entry.ipfs_cid ? 'text-green-700 dark:text-green-400' : 'text-yellow-700 dark:text-yellow-400'">
IPFS
</p>
<p class="text-xs text-gray-500">
{{ entry.ipfs_cid ? 'Epingle' : 'En attente' }}
</p>
</div>
</div>
<div class="flex items-center gap-3 p-3 rounded-lg"
:class="entry.chain_tx_hash
? 'bg-green-50 dark:bg-green-900/10'
: 'bg-yellow-50 dark:bg-yellow-900/10'"
>
<UIcon
:name="entry.chain_tx_hash ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.chain_tx_hash ? 'text-green-500' : 'text-yellow-500'"
/>
<div>
<p class="text-sm font-medium" :class="entry.chain_tx_hash ? 'text-green-700 dark:text-green-400' : 'text-yellow-700 dark:text-yellow-400'">
On-chain
</p>
<p class="text-xs text-gray-500">
{{ entry.chain_tx_hash ? 'Ancre' : 'En attente' }}
</p>
</div>
</div>
</div>
</div>
</UCard>
<!-- Metadata JSON -->
<UCard v-if="entry.metadata_json">
<div class="space-y-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-braces" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">Metadonnees</h2>
</div>
<UButton
v-if="entry.metadata_json"
:icon="copied === 'metadata' ? 'i-lucide-check' : 'i-lucide-copy'"
:label="copied === 'metadata' ? 'Copie' : 'Copier'"
variant="ghost"
color="neutral"
size="xs"
@click="copyToClipboard(entry.metadata_json!, 'metadata')"
/>
</div>
<div class="bg-gray-50 dark:bg-gray-800/50 rounded-lg p-4 overflow-x-auto">
<pre class="font-mono text-xs text-gray-700 dark:text-gray-300">{{ formattedMetadata || entry.metadata_json }}</pre>
</div>
</div>
</UCard>
<!-- Reference info -->
<UCard>
<div class="space-y-3">
<div class="flex items-center gap-2">
<UIcon name="i-lucide-info" class="text-gray-400" />
<h2 class="text-sm font-semibold text-gray-500 uppercase">Reference</h2>
</div>
<div class="grid grid-cols-2 gap-4 text-sm">
<div>
<p class="text-gray-500">Identifiant</p>
<p class="font-mono text-xs text-gray-700 dark:text-gray-300">{{ entry.id }}</p>
</div>
<div>
<p class="text-gray-500">Reference (document/decision)</p>
<p class="font-mono text-xs text-gray-700 dark:text-gray-300">{{ entry.reference_id }}</p>
</div>
</div>
</div>
</UCard>
</template>
</div>
</template>

View File

@@ -1,20 +1,9 @@
<script setup lang="ts">
import type { SanctuaryEntryOut } from '~/components/sanctuary/SanctuaryEntry.vue'
const { $api } = useApi()
interface SanctuaryEntry {
id: string
entry_type: string
reference_id: string
title: string | null
content_hash: string
ipfs_cid: string | null
chain_tx_hash: string | null
chain_block: number | null
metadata_json: string | null
created_at: string
}
const entries = ref<SanctuaryEntry[]>([])
const entries = ref<SanctuaryEntryOut[]>([])
const loading = ref(true)
const error = ref<string | null>(null)
@@ -27,6 +16,10 @@ const typeOptions = [
{ label: 'Resultat de vote', value: 'vote_result' },
]
// Verification state
const verifying = ref<string | null>(null)
const verifyResult = ref<{ id: string; match: boolean; message: string } | null>(null)
async function loadEntries() {
loading.value = true
error.value = null
@@ -35,7 +28,7 @@ async function loadEntries() {
const query: Record<string, string> = {}
if (filterType.value) query.entry_type = filterType.value
entries.value = await $api<SanctuaryEntry[]>('/sanctuary/', { query })
entries.value = await $api<SanctuaryEntryOut[]>('/sanctuary/', { query })
} catch (err: any) {
error.value = err?.data?.detail || err?.message || 'Erreur lors du chargement des entrees'
} finally {
@@ -43,6 +36,26 @@ async function loadEntries() {
}
}
async function handleVerify(id: string) {
verifying.value = id
verifyResult.value = null
try {
const result = await $api<{ match: boolean; message: string }>(
`/sanctuary/${id}/verify`,
)
verifyResult.value = { id, ...result }
} catch (err: any) {
verifyResult.value = {
id,
match: false,
message: err?.data?.detail || err?.message || 'Erreur lors de la verification',
}
} finally {
verifying.value = null
}
}
onMounted(() => {
loadEntries()
})
@@ -50,40 +63,6 @@ onMounted(() => {
watch(filterType, () => {
loadEntries()
})
const typeLabel = (entryType: string) => {
switch (entryType) {
case 'document': return 'Document'
case 'decision': return 'Decision'
case 'vote_result': return 'Resultat de vote'
default: return entryType
}
}
const typeColor = (entryType: string) => {
switch (entryType) {
case 'document': return 'primary'
case 'decision': return 'success'
case 'vote_result': return 'info'
default: return 'neutral'
}
}
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleDateString('fr-FR', {
day: 'numeric',
month: 'long',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
})
}
function truncateHash(hash: string | null, length: number = 16): string {
if (!hash) return '-'
if (hash.length <= length * 2) return hash
return hash.slice(0, length) + '...' + hash.slice(-8)
}
</script>
<template>
@@ -108,10 +87,35 @@ function truncateHash(hash: string | null, length: number = 16): string {
/>
</div>
<!-- Verification result banner -->
<UCard v-if="verifyResult">
<div class="flex items-center justify-between">
<div class="flex items-center gap-3">
<UIcon
:name="verifyResult.match ? 'i-lucide-check-circle' : 'i-lucide-alert-triangle'"
:class="verifyResult.match ? 'text-green-500 text-xl' : 'text-red-500 text-xl'"
/>
<div>
<p :class="verifyResult.match ? 'text-green-700 dark:text-green-400 font-medium' : 'text-red-700 dark:text-red-400 font-medium'">
{{ verifyResult.match ? 'Integrite verifiee' : 'Verification echouee' }}
</p>
<p class="text-sm text-gray-500">{{ verifyResult.message }}</p>
</div>
</div>
<UButton
icon="i-lucide-x"
variant="ghost"
color="neutral"
size="xs"
@click="verifyResult = null"
/>
</div>
</UCard>
<!-- Loading state -->
<template v-if="loading">
<div class="space-y-3">
<USkeleton v-for="i in 4" :key="i" class="h-24 w-full" />
<USkeleton v-for="i in 4" :key="i" class="h-48 w-full" />
</div>
</template>
@@ -138,104 +142,25 @@ function truncateHash(hash: string | null, length: number = 16): string {
</UCard>
</template>
<!-- Entries list -->
<!-- Entries list using SanctuaryEntry component -->
<template v-else>
<div class="space-y-4">
<UCard
v-for="entry in entries"
:key="entry.id"
>
<div class="space-y-4">
<!-- Entry header -->
<div class="flex items-start justify-between">
<div class="flex items-center gap-3">
<UIcon name="i-lucide-shield-check" class="text-xl text-primary" />
<div>
<h3 class="font-semibold text-gray-900 dark:text-white">
{{ entry.title || 'Entree sans titre' }}
</h3>
<p class="text-xs text-gray-500">
{{ formatDate(entry.created_at) }}
</p>
</div>
</div>
<UBadge :color="typeColor(entry.entry_type)" variant="subtle" size="xs">
{{ typeLabel(entry.entry_type) }}
</UBadge>
</div>
<!-- Hashes and anchors -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Content hash -->
<div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
<div class="flex items-center gap-2 mb-1">
<UIcon name="i-lucide-hash" class="text-gray-400 text-sm" />
<span class="text-xs font-semibold text-gray-500 uppercase">SHA-256</span>
</div>
<p class="font-mono text-xs text-gray-700 dark:text-gray-300 break-all">
{{ truncateHash(entry.content_hash) }}
</p>
</div>
<!-- IPFS CID -->
<div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
<div class="flex items-center gap-2 mb-1">
<UIcon name="i-lucide-hard-drive" class="text-gray-400 text-sm" />
<span class="text-xs font-semibold text-gray-500 uppercase">IPFS CID</span>
</div>
<template v-if="entry.ipfs_cid">
<p class="font-mono text-xs text-gray-700 dark:text-gray-300 break-all">
{{ truncateHash(entry.ipfs_cid) }}
</p>
</template>
<template v-else>
<p class="text-xs text-gray-400 italic">En attente d'epinglage</p>
</template>
</div>
<!-- Chain anchor -->
<div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
<div class="flex items-center gap-2 mb-1">
<UIcon name="i-lucide-link" class="text-gray-400 text-sm" />
<span class="text-xs font-semibold text-gray-500 uppercase">On-chain</span>
</div>
<template v-if="entry.chain_tx_hash">
<p class="font-mono text-xs text-gray-700 dark:text-gray-300 break-all">
{{ truncateHash(entry.chain_tx_hash) }}
</p>
<p v-if="entry.chain_block" class="text-xs text-gray-400 mt-0.5">
Bloc #{{ entry.chain_block.toLocaleString('fr-FR') }}
</p>
</template>
<template v-else>
<p class="text-xs text-gray-400 italic">En attente d'ancrage</p>
</template>
</div>
</div>
<!-- Verification status -->
<div class="flex items-center gap-4 text-xs">
<div class="flex items-center gap-1">
<UIcon
:name="entry.ipfs_cid ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.ipfs_cid ? 'text-green-500' : 'text-gray-400'"
/>
<span :class="entry.ipfs_cid ? 'text-green-600' : 'text-gray-400'">
IPFS {{ entry.ipfs_cid ? 'epingle' : 'en attente' }}
</span>
</div>
<div class="flex items-center gap-1">
<UIcon
:name="entry.chain_tx_hash ? 'i-lucide-check-circle' : 'i-lucide-clock'"
:class="entry.chain_tx_hash ? 'text-green-500' : 'text-gray-400'"
/>
<span :class="entry.chain_tx_hash ? 'text-green-600' : 'text-gray-400'">
Chain {{ entry.chain_tx_hash ? 'ancre' : 'en attente' }}
</span>
</div>
<div v-for="entry in entries" :key="entry.id" class="relative">
<SanctuarySanctuaryEntry
:entry="entry"
@verify="handleVerify"
/>
<!-- Loading overlay for verification -->
<div
v-if="verifying === entry.id"
class="absolute inset-0 bg-white/50 dark:bg-gray-900/50 flex items-center justify-center rounded-lg"
>
<div class="flex items-center gap-2 text-sm text-gray-500">
<UIcon name="i-lucide-loader-2" class="animate-spin" />
<span>Verification en cours...</span>
</div>
</div>
</UCard>
</div>
</div>
</template>

View File

@@ -32,6 +32,20 @@ export interface Document {
items_count: number
}
export interface ItemVersion {
id: string
item_id: string
version_number: number
proposed_text: string
rationale: string | null
diff: string | null
status: string
proposed_by: string | null
reviewed_by: string | null
created_at: string
updated_at: string
}
export interface DocumentCreate {
slug: string
title: string
@@ -40,10 +54,16 @@ export interface DocumentCreate {
version?: string
}
export interface VersionProposal {
proposed_text: string
rationale?: string | null
}
interface DocumentsState {
list: Document[]
current: Document | null
items: DocumentItem[]
versions: ItemVersion[]
loading: boolean
error: string | null
}
@@ -53,6 +73,7 @@ export const useDocumentsStore = defineStore('documents', {
list: [],
current: null,
items: [],
versions: [],
loading: false,
error: null,
}),
@@ -139,11 +160,122 @@ export const useDocumentsStore = defineStore('documents', {
},
/**
* Clear the current document and items.
* Fetch all versions for a specific item within a document.
*/
async fetchItemVersions(slug: string, itemId: string) {
this.loading = true
this.error = null
try {
const { $api } = useApi()
this.versions = await $api<ItemVersion[]>(
`/documents/${slug}/items/${itemId}/versions`,
)
} catch (err: any) {
this.error = err?.data?.detail || err?.message || 'Erreur lors du chargement des versions'
} finally {
this.loading = false
}
},
/**
* Propose a new version for a document item.
*/
async proposeVersion(slug: string, itemId: string, data: VersionProposal) {
this.error = null
try {
const { $api } = useApi()
const version = await $api<ItemVersion>(
`/documents/${slug}/items/${itemId}/versions`,
{
method: 'POST',
body: data,
},
)
this.versions.unshift(version)
return version
} catch (err: any) {
this.error = err?.data?.detail || err?.message || 'Erreur lors de la proposition'
throw err
}
},
/**
* Accept a proposed version.
*/
async acceptVersion(slug: string, itemId: string, versionId: string) {
this.error = null
try {
const { $api } = useApi()
const updated = await $api<ItemVersion>(
`/documents/${slug}/items/${itemId}/versions/${versionId}/accept`,
{ method: 'POST' },
)
const idx = this.versions.findIndex(v => v.id === versionId)
if (idx >= 0) this.versions[idx] = updated
return updated
} catch (err: any) {
this.error = err?.data?.detail || err?.message || 'Erreur lors de l\'acceptation'
throw err
}
},
/**
* Reject a proposed version.
*/
async rejectVersion(slug: string, itemId: string, versionId: string) {
this.error = null
try {
const { $api } = useApi()
const updated = await $api<ItemVersion>(
`/documents/${slug}/items/${itemId}/versions/${versionId}/reject`,
{ method: 'POST' },
)
const idx = this.versions.findIndex(v => v.id === versionId)
if (idx >= 0) this.versions[idx] = updated
return updated
} catch (err: any) {
this.error = err?.data?.detail || err?.message || 'Erreur lors du rejet'
throw err
}
},
/**
* Archive a document into the Sanctuary.
*/
async archiveDocument(slug: string) {
this.error = null
try {
const { $api } = useApi()
const doc = await $api<Document>(
`/documents/${slug}/archive`,
{ method: 'POST' },
)
// Update current if viewing this document
if (this.current?.slug === slug) {
this.current = doc
}
// Update in list
const idx = this.list.findIndex(d => d.slug === slug)
if (idx >= 0) this.list[idx] = doc
return doc
} catch (err: any) {
this.error = err?.data?.detail || err?.message || 'Erreur lors de l\'archivage'
throw err
}
},
/**
* Clear the current document, items and versions.
*/
clearCurrent() {
this.current = null
this.items = []
this.versions = []
},
},
})