Spaces:
Sleeping
Sleeping
Update templates/gestion.html
Browse files3 unmodified lines4567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216223 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Gestion des Dissertations - Mariam AI</title><script src="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.js"></script><style>@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');body {font-family: 'Inter', sans-serif;background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);min-height: 100vh;}.glass {background: rgba(255, 255, 255, 0.1);backdrop-filter: blur(10px);border: 1px solid rgba(255, 255, 255, 0.2);}.card-hover {transition: all 0.3s ease;}.card-hover:hover {transform: translateY(-2px);box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);}.table-row:hover {background: rgba(255, 255, 255, 0.1);}.loading-spinner {border: 3px solid rgba(255, 255, 255, 0.3);border-radius: 50%;border-top: 3px solid white;width: 20px;height: 20px;animation: spin 1s linear infinite;}@keyframes spin {0% { transform: rotate(0deg); }100% { transform: rotate(360deg); }}.fade-in {animation: fadeIn 0.5s ease-in-out;}@keyframes fadeIn {from { opacity: 0; transform: translateY(20px); }to { opacity: 1; transform: translateY(0); }}</style></head><body class="min-h-screen"><div class="container mx-auto px-4 py-8"><!-- Header --><div class="text-center mb-8"><h1 class="text-4xl font-bold text-white mb-4">🎓 Gestion des Dissertations</h1><p class="text-white/80 text-lg">Tableau de bord administrateur - Mariam AI</p></div><!-- Stats Cards --><div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8"><div class="glass rounded-xl p-6 text-center card-hover"><div class="text-3xl font-bold text-white" id="totalDissertations">-</div><div class="text-white/80">Total Dissertations</div></div><div class="glass rounded-xl p-6 text-center card-hover"><div class="text-3xl font-bold text-white" id="todayCount">-</div><div class="text-white/80">Aujourd'hui</div></div><div class="glass rounded-xl p-6 text-center card-hover"><div class="text-3xl font-bold text-white" id="type1Count">-</div><div class="text-white/80">Type 1</div></div><div class="glass rounded-xl p-6 text-center card-hover"><div class="text-3xl font-bold text-white" id="type2Count">-</div><div class="text-white/80">Type 2</div></div></div><!-- Search and Filters --><div class="glass rounded-xl p-6 mb-6"><div class="flex flex-col md:flex-row gap-4 mb-4"><div class="flex-1"><input type="text"id="searchInput"placeholder="Rechercher par question ou cours..."class="w-full px-4 py-2 rounded-lg bg-white/20 border border-white/30 text-white placeholder-white/60 focus:outline-none focus:border-white/60"></div><div><select id="typeFilter" class="px-4 py-2 rounded-lg bg-white/20 border border-white/30 text-white focus:outline-none"><option value="">Tous les types</option><option value="type1">Type 1</option><option value="type2">Type 2</option></select></div><div><button id="searchBtn" class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">🔍 Rechercher</button></div></div></div><!-- Dissertations Table --><div class="glass rounded-xl overflow-hidden"><div class="p-6 border-b border-white/20"><h2 class="text-xl font-semibold text-white">📚 Liste des Dissertations</h2></div><div id="loadingIndicator" class="p-8 text-center"><div class="loading-spinner mx-auto mb-4"></div><p class="text-white/80">Chargement des données...</p></div><div id="dissertationsContainer" class="hidden"><div class="overflow-x-auto"><table class="w-full"><thead class="bg-white/10"><tr class="text-white/90 text-left"><th class="p-4 font-medium">Date</th><th class="p-4 font-medium">Question</th><th class="p-4 font-medium">Type</th><th class="p-4 font-medium">Cours</th><th class="p-4 font-medium">IP Utilisateur</th><th class="p-4 font-medium">Actions</th></tr></thead><tbody id="dissertationsTable" class="text-white/80"><!-- Les lignes seront ajoutées dynamiquement --></tbody></table></div><!-- Pagination --><div id="paginationContainer" class="p-4 border-t border-white/20 flex justify-between items-center"><div class="text-white/80"><span id="paginationInfo">Affichage de 0 à 0 sur 0 résultats</span></div><div class="flex gap-2"><button id="prevBtn" class="px-4 py-2 bg-white/20 hover:bg-white/30 text-white rounded-lg transition-colors disabled:opacity-50">← Précédent</button><span id="pageNumbers" class="flex gap-1"></span><button id="nextBtn" class="px-4 py-2 bg-white/20 hover:bg-white/30 text-white rounded-lg transition-colors disabled:opacity-50">Suivant →</button></div></div></div></div></div><!-- Modal de détail --><div id="detailModal" class="hidden fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50"><div class="glass rounded-xl max-w-4xl max-h-full overflow-y-auto"><div class="p-6 border-b border-white/20 flex justify-between items-center"><h3 class="text-xl font-semibold text-white">📄 Détail de la Dissertation</h3><button id="closeModal" class="text-white/60 hover:text-white text-2xl">×</button></div><div id="modalContent" class="p-6 text-white"><!-- Contenu du modal ajouté dynamiquement --></div></div></div><!-- Modal de confirmation de suppression --><div id="deleteModal" class="hidden fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50"><div class="glass rounded-xl p-6 max-w-md"><h3 class="text-lg font-semibold text-white mb-4">⚠️ Confirmer la suppression</h3><p class="text-white/80 mb-6">Êtes-vous sûr de vouloir supprimer cette dissertation ? Cette action est irréversible.</p><div class="flex gap-4 justify-end"><button id="cancelDelete" class="px-4 py-2 bg-gray-500 hover:bg-gray-600 text-white rounded-lg transition-colors">Annuler</button><button id="confirmDelete" class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors">Supprimer</button></div></div></div><script>let currentPage = 1;let currentSearch = '';let currentType = '';let deleteId = null;// Initialisationdocument.addEventListener('DOMContentLoaded', function() {loadDissertations();setupEventListeners();});function setupEventListeners() {// Recherchedocument.getElementById('searchBtn').addEventListener('click', performSearch);document.getElementById('searchInput').addEventListener('keypress', function(e) {if (e.key === 'Enter') performSearch();});// Modal handlersdocument.getElementById('closeModal').addEventListener('click', closeModal);document.getElementById('cancelDelete').addEventListener('click', closeDeleteModal);document.getElementById('confirmDelete').addEventListener('click', confirmDelete);// Click outside modal to closedocument.getElementById('detailModal').addEventListener('click', function(e) {if (e.target === this) closeModal();});document.getElementById('deleteModal').addEventListener('click', function(e) {if (e.target === this) closeDeleteModal();});}function performSearch() {currentSearch = document.getElementById('searchInput').value.trim();currentType = document.getElementById('typeFilter').value;currentPage = 1;loadDissertations();}async function loadDissertations() {try {showLoading();const params = new URLSearchParams({page: currentPage,per_page: 10,search: currentSearch,type: currentType});const response = await fetch(`/api/dissertations?${params}`);const data = await response.json();if (response.ok) {displayDissertations(data);updateStats(data);} else {throw new Error(data.error || 'Erreur lors du chargement');}} catch (error) {console.error('Erreur:', error);showError('Erreur lors du chargement des données');} finally {hideLoading();}}function showLoading() {document.getElementById('loadingIndicator').classList.remove('hidden');document.getElementById('dissertationsContainer').classList.add('hidden');}function hideLoading() {document.getElementById('loadingIndicator').classList.add('hidden');document.getElementById('dissertationsContainer').classList.remove('hidden');}function displayDissertations(data) {const tbody = document.getElementById('dissertationsTable');tbody.innerHTML = '';data.dissertations.forEach(dissertation => {const row = createDissertationRow(dissertation);tbody.appendChild(row);});updatePagination(data);}function createDissertationRow(dissertation) {const row = document.createElement('tr');row.className = 'table-row border-b border-white/10';const date = new Date(dissertation.created_at).toLocaleDateString('fr-FR', {year: 'numeric',month: 'short',day: 'numeric',hour: '2-digit',minute: '2-digit'});row.innerHTML = `<td class="p-4">${date}</td><td class="p-4"><div class="max-w-xs truncate" title="${dissertation.question}">${dissertation.question}</div></td><td class="p-4"><span class="px-2 py-1 rounded text-xs ${dissertation.dissertation_type === 'type1' ? 'bg-blue-500/20 text-blue-300' : 'bg-green-500/20 text-green-300'}">${dissertation.dissertation_type.toUpperCase()}</span></td><td class="p-4"><div class="max-w-xs truncate" title="${dissertation.course_title || 'Aucun'}">${dissertation.course_title || '-'}</div></td><td class="p-4">${dissertation.user_ip}</td><td class="p-4"><div class="flex gap-2"><button onclick="viewDissertation(${dissertation.id})"class="px-3 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded text-sm transition-colors">👁️ Voir</button><button onclick="deleteDissertation(${dissertation.id})"class="px-3 py-1 bg-red-600 hover:bg-red-700 text-white rounded text-sm transition-colors">🗑️ Suppr.</button></div></td>`;return row;}function updatePagination(data) {const { page, total_pages, total, per_page } = data;const start = (page - 1) * per_page + 1;const end = Math.min(page * per_page, total);document.getElementById('paginationInfo').textContent =`Affichage de ${start} à ${end} sur ${total} résultats`;// Boutons précédent/suivantconst prevBtn = document.getElementById('prevBtn');const nextBtn = document.getElementById('nextBtn');prevBtn.disabled = page <= 1;nextBtn.disabled = page >= total_pages;prevBtn.onclick = () => { if (page > 1) { currentPage = page - 1; loadDissertations(); } };nextBtn.onclick = () => { if (page < total_pages) { currentPage = page + 1; loadDissertations(); } };// Numéros de pageconst pageNumbers = document.getElementById('pageNumbers');pageNumbers.innerHTML = '';const maxVisible = 5;let startPage = Math.max(1, page - Math.floor(maxVisible / 2));let endPage = Math.min(total_pages, startPage + maxVisible - 1);if (endPage - startPage + 1 < maxVisible) {startPage = Math.max(1, endPage - maxVisible + 1);}for (let i = startPage; i <= endPage; i++) {const pageBtn = document.createElement('button');pageBtn.className = `px-3 py-2 rounded-lg transition-colors ${i === page? 'bg-white/30 text-white': 'bg-white/10 hover:bg-white/20 text-white/80'}`;pageBtn.textContent = i;pageBtn.onclick = () => { currentPage = i; loadDissertations(); };pageNumbers.appendChild(pageBtn);}}function updateStats(data) {// Simuler des stats basiques (vous pouvez créer une API dédiée pour des stats plus précises)document.getElementById('totalDissertations').textContent = data.total;// Compter les types dans la page actuelle (approximation)const type1Count = data.dissertations.filter(d => d.dissertation_type === 'type1').length;const type2Count = data.dissertations.filter(d => d.dissertation_type === 'type2').length;document.getElementById('type1Count').textContent = type1Count;document.getElementById('type2Count').textContent = type2Count;// Compter aujourd'hui (approximation basée sur la page actuelle)const today = new Date().toDateString();const todayCount = data.dissertations.filter(d =>new Date(d.created_at).toDateString() === today).length;document.getElementById('todayCount').textContent = todayCount;}async function viewDissertation(id) {try {const response = await fetch(`/api/dissertations/${id}`);const data = await response.json();if (response.ok) {showDissertationModal(data);} else {throw new Error(data.error || 'Erreur lors du chargement');}} catch (error) {console.error('Erreur:', error);showError('Erreur lors du chargement du détail');}}function showDissertationModal(dissertation) {const content = dissertation.generated_content;const modalContent = document.getElementById('modalContent');modalContent.innerHTML = `<div class="space-y-6"><!-- Info générales --><div class="grid grid-cols-1 md:grid-cols-2 gap-4 p-4 bg-white/10 rounded-lg"><div><strong class="text-white/90">Question:</strong><p class="text-white/80 mt-1">${dissertation.question}</p></div><div><strong class="text-white/90">Type:</strong><span class="ml-2 px-2 py-1 rounded text-xs ${dissertation.dissertation_type === 'type1'? 'bg-blue-500/20 text-blue-300': 'bg-green-500/20 text-green-300'}">${dissertation.dissertation_type.toUpperCase()}</span></div><div><strong class="text-white/90">Cours:</strong><p class="text-white/80 mt-1">${dissertation.course_title || 'Aucun cours spécifique'}</p></div><div><strong class="text-white/90">Date:</strong><p class="text-white/80 mt-1">${new Date(dissertation.created_at).toLocaleString('fr-FR')}</p></div><div><strong class="text-white/90">IP Utilisateur:</strong><p class="text-white/80 mt-1">${dissertation.user_ip}</p></div><div><strong class="text-white/90">User Agent:</strong><p class="text-white/80 mt-1 text-xs truncate" title="${dissertation.user_agent}">${dissertation.user_agent}</p></div></div><!-- Contenu de la dissertation --><div class="bg-white/5 rounded-lg p-4"><h4 class="text-lg font-semibold text-white mb-4">📝 Contenu de la Dissertation</h4><!-- Introduction --><div class="mb-6"><h5 class="font-medium text-white/90 mb-2">Introduction</h5><div class="bg-white/10 rounded p-3 text-white/80 text-sm leading-relaxed">${content.introduction}</div></div><!-- Parties --><div class="space-y-6">${content.parties.map((partie, index) => `<div class="mb-6"><h5 class="font-medium text-white/90 mb-2">Partie ${index + 1}</h5><!-- Chapeau --><div class="bg-blue-500/20 rounded p-3 mb-3"><p class="text-blue-200 text-sm font-medium mb-1">Chapeau:</p><p class="text-white/80 text-sm">${partie.chapeau}</p></div><!-- Arguments --><div class="space-y-2">${partie.arguments.map((arg, argIndex) => `<div class="bg-white/10 rounded p-3"><p class="text-green-300 text-xs mb-1">Argument ${argIndex + 1}:</p><p class="text-white/80 text-sm leading-relaxed">${arg.paragraphe_argumentatif}</p></div>`).join('')}</div><!-- Transition -->${partie.transition ? `<div class="bg-purple-500/20 rounded p-3 mt-3"><p class="text-purple-200 text-sm font-medium mb-1">Transition:</p><p class="text-white/80 text-sm">${partie.transition}</p></div>` : ''}</div>`).join('')}</div><!-- Conclusion --><div class="mt-6"><h5 class="font-medium text-white/90 mb-2">Conclusion</h5><div class="bg-white/10 rounded p-3 text-white/80 text-sm leading-relaxed">${content.conclusion}</div></div></div><!-- Actions --><div class="flex gap-4 pt-4"><button onclick="generatePDF(${dissertation.id})"class="px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg transition-colors">📄 Générer PDF</button><button onclick="copyToClipboard(${JSON.stringify(content).replace(/"/g, '"')})"class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors">📋 Copier le texte</button></div></div>`;document.getElementById('detailModal').classList.remove('hidden');document.body.style.overflow = 'hidden';}function closeModal() {document.getElementById('detailModal').classList.add('hidden');document.body.style.overflow = 'auto';}function deleteDissertation(id) {deleteId = id;document.getElementById('deleteModal').classList.remove('hidden');}function closeDeleteModal() {document.getElementById('deleteModal').classList.add('hidden');deleteId = null;}async function confirmDelete() {if (!deleteId) return;try {const response = await fetch(`/api/dissertations/${deleteId}`, {method: 'DELETE'});const data = await response.json();if (response.ok) {showSuccess('Dissertation supprimée avec succès');closeDeleteModal();loadDissertations(); // Recharger la liste} else {throw new Error(data.error || 'Erreur lors de la suppression');}} catch (error) {console.error('Erreur:', error);showError('Erreur lors de la suppression');}}function generatePDF(dissertationId) {// Placeholder pour la génération PDFshowInfo('Fonctionnalité PDF en développement');}function copyToClipboard(content) {const textContent = formatDissertationText(content);navigator.clipboard.writeText(textContent).then(() => {showSuccess('Texte copié dans le presse-papiers');}).catch(() => {showError('Erreur lors de la copie');});}function formatDissertationText(content) {let text = `DISSERTATION DE PHILOSOPHIE\n`;text += `Sujet: ${content.sujet}\n`;text += `Professeur: ${content.prof}\n\n`;text += `INTRODUCTION\n`;text += `${content.introduction}\n\n`;content.parties.forEach((partie, index) => {text += `PARTIE ${index + 1}\n`;text += `${partie.chapeau}\n\n`;partie.arguments.forEach((arg, argIndex) => {text += `${arg.paragraphe_argumentatif}\n\n`;});if (partie.transition) {text += `${partie.transition}\n\n`;}});text += `CONCLUSION\n`;text += `${content.conclusion}\n`;return text;}function showSuccess(message) {showNotification(message, 'bg-green-500');}function showError(message) {showNotification(message, 'bg-red-500');}function showInfo(message) {showNotification(message, 'bg-blue-500');}function showNotification(message, bgColor) {const notification = document.createElement('div');notification.className = `fixed top-4 right-4 ${bgColor} text-white px-6 py-3 rounded-lg shadow-lg z-50 fade-in`;notification.textContent = message;document.body.appendChild(notification);setTimeout(() => {notification.remove();}, 3000);}</script></body></html>3 unmodified lines4567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464473 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Gestion des Dissertations - Mariam AI</title><script src="https://cdn.tailwindcss.com"></script><script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js" defer></script><style>[x-cloak] { display: none !important; }</style></head><body class="bg-gray-50 min-h-screen"><div x-data="gestionApp()" x-init="loadData()" class="container mx-auto px-4 py-8"><!-- Header --><div class="bg-white rounded-lg shadow-md p-6 mb-8"><div class="flex justify-between items-center"><div><h1 class="text-3xl font-bold text-gray-800">Gestion des Dissertations</h1><p class="text-gray-600 mt-2">Suivi des requêtes et réponses générées par Mariam AI</p></div><div class="flex space-x-4"><a href="/" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition duration-200">← Retour à l'app</a><button @click="confirmClearAll()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg transition duration-200">Vider tout</button></div></div></div><!-- Statistiques --><div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8"><div class="bg-white p-6 rounded-lg shadow-md"><div class="flex items-center"><div class="p-3 rounded-full bg-blue-100 text-blue-500"><svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg></div><div class="ml-4"><p class="text-sm font-medium text-gray-600">Total</p><p class="text-2xl font-semibold text-gray-900" x-text="stats.total"></p></div></div></div><div class="bg-white p-6 rounded-lg shadow-md"><div class="flex items-center"><div class="p-3 rounded-full bg-green-100 text-green-500"><svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg></div><div class="ml-4"><p class="text-sm font-medium text-gray-600">Succès</p><p class="text-2xl font-semibold text-gray-900" x-text="stats.success"></p></div></div></div><div class="bg-white p-6 rounded-lg shadow-md"><div class="flex items-center"><div class="p-3 rounded-full bg-red-100 text-red-500"><svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg></div><div class="ml-4"><p class="text-sm font-medium text-gray-600">Erreurs</p><p class="text-2xl font-semibold text-gray-900" x-text="stats.errors"></p></div></div></div><div class="bg-white p-6 rounded-lg shadow-md"><div class="flex items-center"><div class="p-3 rounded-full bg-purple-100 text-purple-500"><svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg></div><div class="ml-4"><p class="text-sm font-medium text-gray-600">Taux de succès</p><p class="text-2xl font-semibold text-gray-900" x-text="stats.successRate + '%'"></p></div></div></div></div><!-- Filtres --><div class="bg-white rounded-lg shadow-md p-6 mb-8"><div class="flex flex-wrap gap-4 items-center"><div><label class="block text-sm font-medium text-gray-700 mb-2">Filtrer par statut</label><select x-model="filter.status" @change="applyFilters()" class="border border-gray-300 rounded-md px-3 py-2"><option value="">Tous</option><option value="success">Succès</option><option value="error">Erreurs</option></select></div><div><label class="block text-sm font-medium text-gray-700 mb-2">Filtrer par type</label><select x-model="filter.type" @change="applyFilters()" class="border border-gray-300 rounded-md px-3 py-2"><option value="">Tous</option><option value="type1">Type 1</option><option value="type2">Type 2</option></select></div><div><label class="block text-sm font-medium text-gray-700 mb-2">Rechercher</label><input type="text" x-model="filter.search" @input="applyFilters()"placeholder="Rechercher dans les sujets..."class="border border-gray-300 rounded-md px-3 py-2"></div><div class="flex-1"></div><button @click="refreshData()" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-lg transition duration-200">🔄 Actualiser</button></div></div><!-- Messages --><div x-show="message.show" x-cloak:class="message.type === 'success' ? 'bg-green-100 border-green-500 text-green-700' : 'bg-red-100 border-red-500 text-red-700'"class="border-l-4 p-4 mb-6 rounded"><p x-text="message.text"></p></div><!-- Loading --><div x-show="loading" x-cloak class="text-center py-8"><div class="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500"></div><p class="mt-2 text-gray-600">Chargement...</p></div><!-- Liste des dissertations --><div x-show="!loading" x-cloak class="space-y-6"><template x-for="item in filteredData" :key="item.id"><div class="bg-white rounded-lg shadow-md p-6"><div class="flex justify-between items-start mb-4"><div class="flex-1"><div class="flex items-center gap-3 mb-2"><span class="text-sm text-gray-500" x-text="formatDate(item.timestamp)"></span><span :class="item.success ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'"class="px-2 py-1 rounded-full text-xs font-medium"x-text="item.success ? 'Succès' : 'Erreur'"></span><span class="bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-xs font-medium"x-text="item.input.type"></span></div><h3 class="text-lg font-semibold text-gray-800 mb-2" x-text="item.input.question"></h3></div><button @click="deleteRecord(item.id)"class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded text-sm transition duration-200">Supprimer</button></div><!-- Détails de l'input --><div class="bg-gray-50 rounded-lg p-4 mb-4"><h4 class="font-medium text-gray-700 mb-2">Données d'entrée</h4><div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm"><div><span class="font-medium">Question:</span><p class="text-gray-600 mt-1" x-text="item.input.question"></p></div><div><span class="font-medium">Type:</span><p class="text-gray-600 mt-1" x-text="item.input.type"></p></div><div><span class="font-medium">Cours ID:</span><p class="text-gray-600 mt-1" x-text="item.input.courseId || 'Aucun'"></p></div></div></div><!-- Résultat ou erreur --><div x-show="item.success" x-cloak><div class="border-l-4 border-green-500 bg-green-50 p-4 rounded"><h4 class="font-medium text-green-800 mb-2">Résultat généré</h4><div class="space-y-2 text-sm"><div><strong>Sujet:</strong> <span x-text="item.output?.sujet"></span></div><div><strong>Parties:</strong> <span x-text="item.output?.parties?.length + ' partie(s)'"></span></div><button @click="toggleDetails(item.id)"class="text-green-600 hover:text-green-800 underline"x-text="item.showDetails ? 'Masquer les détails' : 'Voir les détails'"></button><!-- Détails complets --><div x-show="item.showDetails" x-cloak class="mt-4 p-4 bg-white rounded border"><div class="space-y-4 max-h-96 overflow-y-auto"><div><strong class="text-gray-700">Introduction:</strong><p class="mt-1 text-gray-600 text-sm" x-text="item.output?.introduction"></p></div><template x-for="(partie, index) in item.output?.parties" :key="index"><div class="border-l-2 border-blue-200 pl-4"><strong class="text-gray-700" x-text="'Partie ' + (index + 1) + ':'"></strong><p class="mt-1 text-gray-600 text-sm" x-text="partie.chapeau"></p><div class="mt-2"><template x-for="(arg, argIndex) in partie.arguments" :key="argIndex"><p class="mt-2 text-gray-600 text-sm pl-4 border-l border-gray-200"x-text="arg.paragraphe_argumentatif"></p></template></div><p x-show="partie.transition" class="mt-2 text-gray-500 text-sm italic"x-text="partie.transition"></p></div></template><div><strong class="text-gray-700">Conclusion:</strong><p class="mt-1 text-gray-600 text-sm" x-text="item.output?.conclusion"></p></div></div></div></div></div></div><div x-show="!item.success" x-cloak><div class="border-l-4 border-red-500 bg-red-50 p-4 rounded"><h4 class="font-medium text-red-800 mb-2">Erreur</h4><p class="text-red-700 text-sm" x-text="item.error"></p></div></div></div></template><!-- Message si aucune donnée --><div x-show="filteredData.length === 0" x-cloak class="text-center py-12"><div class="text-gray-400 mb-4"><svg class="mx-auto h-12 w-12" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg></div><h3 class="text-lg font-medium text-gray-900">Aucune donnée trouvée</h3><p class="text-gray-500">Aucune dissertation n'a encore été générée ou ne correspond aux filtres.</p></div></div><!-- Modal de confirmation --><div x-show="showConfirmModal" x-cloakclass="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50"><div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white"><div class="mt-3 text-center"><div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-red-100"><svg class="h-6 w-6 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.728-.833-2.498 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"></path></svg></div><h3 class="text-lg leading-6 font-medium text-gray-900 mt-2">Confirmer la suppression</h3><div class="mt-2 px-7 py-3"><p class="text-sm text-gray-500">Êtes-vous sûr de vouloir supprimer toutes les données ? Cette action est irréversible.</p></div><div class="flex justify-center space-x-4 mt-4"><button @click="showConfirmModal = false"class="px-4 py-2 bg-gray-300 text-gray-700 rounded-md hover:bg-gray-400">Annuler</button><button @click="clearAllData()"class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">Supprimer tout</button></div></div></div></div></div><script>function gestionApp() {return {data: [],filteredData: [],loading: false,showConfirmModal: false,filter: {status: '',type: '',search: ''},stats: {total: 0,success: 0,errors: 0,successRate: 0},message: {show: false,text: '',type: 'success'},async loadData() {this.loading = true;try {const response = await fetch('/api/gestion/dissertations');const result = await response.json();if (result.success) {this.data = result.data;this.calculateStats();this.applyFilters();} else {this.showMessage('Erreur lors du chargement des données', 'error');}} catch (error) {console.error('Erreur:', error);this.showMessage('Erreur de connexion', 'error');} finally {this.loading = false;}},async refreshData() {await this.loadData();this.showMessage('Données actualisées', 'success');},calculateStats() {this.stats.total = this.data.length;this.stats.success = this.data.filter(item => item.success).length;this.stats.errors = this.data.filter(item => !item.success).length;this.stats.successRate = this.stats.total > 0 ?Math.round((this.stats.success / this.stats.total) * 100) : 0;},applyFilters() {let filtered = [...this.data];// Filtre par statutif (this.filter.status) {if (this.filter.status === 'success') {filtered = filtered.filter(item => item.success);} else if (this.filter.status === 'error') {filtered = filtered.filter(item => !item.success);}}// Filtre par typeif (this.filter.type) {filtered = filtered.filter(item => item.input.type === this.filter.type);}// Filtre par rechercheif (this.filter.search) {const searchLower = this.filter.search.toLowerCase();filtered = filtered.filter(item =>item.input.question.toLowerCase().includes(searchLower));}// Trier par date (plus récent d'abord)filtered.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));this.filteredData = filtered;},async deleteRecord(id) {if (!confirm('Êtes-vous sûr de vouloir supprimer cet enregistrement ?')) {return;}try {const response = await fetch(`/api/gestion/dissertations/${id}`, {method: 'DELETE'});const result = await response.json();if (result.success) {await this.loadData();this.showMessage('Enregistrement supprimé', 'success');} else {this.showMessage('Erreur lors de la suppression', 'error');}} catch (error) {console.error('Erreur:', error);this.showMessage('Erreur de connexion', 'error');}},confirmClearAll() {this.showConfirmModal = true;},async clearAllData() {this.showConfirmModal = false;try {const response = await fetch('/api/gestion/dissertations/clear', {method: 'DELETE'});const result = await response.json();if (result.success) {await this.loadData();this.showMessage('Toutes les données ont été supprimées', 'success');} else {this.showMessage('Erreur lors de la suppression', 'error');}} catch (error) {console.error('Erreur:', error);this.showMessage('Erreur de connexion', 'error');}},toggleDetails(id) {const item = this.data.find(item => item.id === id);if (item) {item.showDetails = !item.showDetails;}},formatDate(timestamp) {const date = new Date(timestamp);return date.toLocaleString('fr-FR', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit'});},showMessage(text, type = 'success') {this.message.text = text;this.message.type = type;this.message.show = true;setTimeout(() => {this.message.show = false;}, 3000);}}}</script></body></html>
templates/gestion.html+387-562