Update templates/index.html
Browse files- templates/index.html +219 -236
templates/index.html
CHANGED
@@ -5,14 +5,14 @@
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>Mariam AI - Analyse d'Image</title>
|
8 |
-
<!-- CDN pour Tailwind CSS
|
9 |
-
<link href="https://
|
10 |
-
<!-- CDN pour Marked
|
11 |
-
<script src="https://
|
12 |
-
<!-- CDN pour SweetAlert2
|
13 |
-
<script src="https://
|
14 |
-
<!-- CDN pour Moment.js
|
15 |
-
<script src="https://
|
16 |
<style>
|
17 |
/* Styles pour le loader */
|
18 |
.loader {
|
@@ -250,7 +250,6 @@
|
|
250 |
<main class="max-w-7xl mx-auto px-4 py-8 sm:px-6 lg:px-8">
|
251 |
<div class="bg-white rounded-lg shadow p-6 mb-8">
|
252 |
<form id="uploadForm" class="space-y-6">
|
253 |
-
<!-- Zone de téléchargement d'image -->
|
254 |
<div class="upload-zone rounded-lg p-8 text-center">
|
255 |
<input type="file" id="imageInput" accept="image/*" required class="hidden"
|
256 |
onchange="handleImageSelect()">
|
@@ -268,7 +267,6 @@
|
|
268 |
</label>
|
269 |
</div>
|
270 |
|
271 |
-
<!-- Prévisualisation de l'image -->
|
272 |
<div id="imagePreview" class="hidden image-preview-container">
|
273 |
<img id="preview" src="#" alt="Prévisualisation">
|
274 |
<button type="button" class="remove-image" onclick="removeImage()">
|
@@ -279,7 +277,6 @@
|
|
279 |
</button>
|
280 |
</div>
|
281 |
|
282 |
-
<!-- Bouton de soumission du formulaire -->
|
283 |
<div class="flex justify-center">
|
284 |
<button type="submit"
|
285 |
class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-colors duration-200">
|
@@ -289,7 +286,6 @@
|
|
289 |
</form>
|
290 |
</div>
|
291 |
|
292 |
-
<!-- Indicateur de chargement -->
|
293 |
<div id="loading" class="hidden">
|
294 |
<div class="flex flex-col items-center justify-center space-y-4">
|
295 |
<span class="loader"></span>
|
@@ -297,20 +293,17 @@
|
|
297 |
</div>
|
298 |
</div>
|
299 |
|
300 |
-
<!-- Section des résultats -->
|
301 |
<div id="results" class="space-y-8 hidden">
|
302 |
-
<!-- Boutons pour changer d'onglet -->
|
303 |
<div class="tab-buttons">
|
304 |
<button id="showDissertation" class="active">Dissertation</button>
|
305 |
<button id="showTableau">Tableau d'analyse</button>
|
306 |
<button id="showBackups">Sauvegardes</button>
|
307 |
</div>
|
308 |
|
309 |
-
<!-- Onglet Dissertation -->
|
310 |
<div id="dissertationTab" class="tab-content active bg-white rounded-lg shadow p-6">
|
311 |
<h2 class="text-2xl font-bold text-gray-900 mb-4">Dissertation</h2>
|
312 |
<div id="dissertationResult" class="prose max-w-none markdown-content">
|
313 |
-
|
314 |
</div>
|
315 |
<button id="saveDissertation"
|
316 |
class="mt-4 px-6 py-3 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors duration-200">
|
@@ -318,11 +311,10 @@
|
|
318 |
</button>
|
319 |
</div>
|
320 |
|
321 |
-
<!-- Onglet Tableau d'analyse -->
|
322 |
<div id="tableauTab" class="tab-content bg-white rounded-lg shadow p-6 hidden">
|
323 |
<h2 class="text-2xl font-bold text-gray-900 mb-4">Tableau d'analyse</h2>
|
324 |
<div id="tableauResult" class="markdown-content">
|
325 |
-
|
326 |
</div>
|
327 |
<button id="saveTableau"
|
328 |
class="mt-4 px-6 py-3 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors duration-200">
|
@@ -330,23 +322,25 @@
|
|
330 |
</button>
|
331 |
</div>
|
332 |
|
333 |
-
<!-- Onglet Sauvegardes -->
|
334 |
<div id="backupsTab" class="tab-content bg-white rounded-lg shadow p-6 hidden">
|
335 |
<h2 class="text-2xl font-bold text-gray-900 mb-4">Sauvegardes locales</h2>
|
336 |
<ul id="backupList" class="space-y-2">
|
337 |
-
|
338 |
</ul>
|
339 |
</div>
|
|
|
340 |
</div>
|
341 |
</main>
|
342 |
</div>
|
343 |
|
344 |
<script>
|
345 |
-
|
346 |
-
|
347 |
-
|
|
|
|
|
348 |
|
349 |
-
|
350 |
const input = document.getElementById('imageInput');
|
351 |
const preview = document.getElementById('preview');
|
352 |
const previewContainer = document.getElementById('imagePreview');
|
@@ -358,8 +352,7 @@
|
|
358 |
reader.onload = function (e) {
|
359 |
preview.src = e.target.result;
|
360 |
previewContainer.classList.remove('hidden');
|
361 |
-
|
362 |
-
previewContainer.classList.add('fade-in');
|
363 |
};
|
364 |
|
365 |
reader.readAsDataURL(input.files[0]);
|
@@ -367,234 +360,224 @@
|
|
367 |
} else {
|
368 |
removeImage();
|
369 |
}
|
370 |
-
|
371 |
-
|
372 |
-
// Fonction pour supprimer l'image prévisualisée
|
373 |
-
function removeImage() {
|
374 |
-
const input = document.getElementById('imageInput');
|
375 |
-
const preview = document.getElementById('preview');
|
376 |
-
const previewContainer = document.getElementById('imagePreview');
|
377 |
-
const fileName = document.getElementById('fileName');
|
378 |
-
|
379 |
-
input.value = '';
|
380 |
-
preview.src = '#';
|
381 |
-
previewContainer.classList.add('hidden');
|
382 |
-
fileName.textContent = 'Cliquez ou glissez une image ici';
|
383 |
-
}
|
384 |
-
|
385 |
-
// Fonction pour afficher un indicateur de scroll horizontal si nécessaire
|
386 |
-
function showScrollIndicator(container) {
|
387 |
-
if (container.scrollWidth > container.clientWidth) {
|
388 |
-
const indicator = document.createElement('div');
|
389 |
-
indicator.className = 'scroll-indicator visible';
|
390 |
-
indicator.textContent = '← Faites défiler →';
|
391 |
-
container.parentElement.appendChild(indicator);
|
392 |
-
|
393 |
-
setTimeout(() => {
|
394 |
-
indicator.classList.remove('visible');
|
395 |
-
}, 3000);
|
396 |
-
|
397 |
-
container.addEventListener('scroll', () => {
|
398 |
-
if (container.scrollLeft > 0) {
|
399 |
-
indicator.classList.add('visible');
|
400 |
-
} else {
|
401 |
-
indicator.classList.remove('visible');
|
402 |
-
}
|
403 |
-
|
404 |
-
clearTimeout(container.scrollTimeout);
|
405 |
-
container.scrollTimeout = setTimeout(() => {
|
406 |
-
indicator.classList.remove('visible');
|
407 |
-
}, 1000);
|
408 |
-
});
|
409 |
-
}
|
410 |
-
}
|
411 |
-
|
412 |
-
// Gestion des clics sur les onglets
|
413 |
-
document.getElementById('showTableau').addEventListener('click, () => {
|
414 |
-
showTab('tableau');
|
415 |
-
renderTableauContent(); // Rendre le contenu du tableau Markdown
|
416 |
-
});
|
417 |
-
|
418 |
-
document.getElementById('showDissertation').addEventListener('click', () => {
|
419 |
-
showTab('dissertation');
|
420 |
-
});
|
421 |
-
|
422 |
-
document.getElementById('showBackups').addEventListener('click', () => {
|
423 |
-
showTab('backups');
|
424 |
-
updateBackupList(); // Mettre à jour la liste des sauvegardes
|
425 |
-
});
|
426 |
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
document.getElementById(`${tabName}Tab`).classList.add('active');
|
433 |
-
document.getElementById(`show${tabName.charAt(0).toUpperCase() + tabName.slice(1)}`).classList.add('active');
|
434 |
-
}
|
435 |
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
}
|
445 |
-
}
|
446 |
|
447 |
-
|
448 |
-
|
449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
localStorage.setItem('mariamAIBackups', JSON.stringify(backups));
|
451 |
-
updateBackupList();
|
452 |
-
Swal.fire(
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
}
|
479 |
-
|
480 |
-
|
481 |
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
|
486 |
-
|
487 |
-
|
488 |
-
html: marked.parse(backup.content), // Afficher le contenu Markdown
|
489 |
-
width: '90%',
|
490 |
-
customClass: {
|
491 |
-
htmlContainer: 'markdown-content' // Appliquer le style markdown
|
492 |
-
},
|
493 |
-
didRender: () => {
|
494 |
-
const container = document.querySelector('.markdown-content');
|
495 |
-
showScrollIndicator(container);
|
496 |
-
}
|
497 |
|
498 |
-
|
499 |
-
|
500 |
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
icon: 'warning',
|
507 |
-
showCancelButton: true,
|
508 |
-
confirmButtonColor: '#3085d6',
|
509 |
-
cancelButtonColor: '#d33',
|
510 |
-
confirmButtonText: 'Oui, supprimer!'
|
511 |
-
}).then((result) => {
|
512 |
-
if (result.isConfirmed) {
|
513 |
-
backups.splice(index, 1);
|
514 |
-
localStorage.setItem('mariamAIBackups', JSON.stringify(backups));
|
515 |
-
updateBackupList(); // mettre à jour l'affichage
|
516 |
-
Swal.fire(
|
517 |
-
'Supprimé!',
|
518 |
-
'Votre fichier a été supprimé.',
|
519 |
-
'success'
|
520 |
-
)
|
521 |
-
}
|
522 |
-
})
|
523 |
|
|
|
|
|
|
|
|
|
524 |
}
|
525 |
|
|
|
|
|
|
|
526 |
|
|
|
527 |
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
});
|
532 |
-
|
533 |
-
document.getElementById('saveTableau').addEventListener('click', () => {
|
534 |
-
saveBackup('tableau', tableauContent);
|
535 |
-
});
|
536 |
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
const dissertationResult = document.getElementById('dissertationResult');
|
544 |
-
const tableauResult = document.getElementById('tableauResult');
|
545 |
-
|
546 |
-
const formData = new FormData();
|
547 |
-
formData.append('image', document.getElementById('imageInput').files[0]);
|
548 |
-
|
549 |
-
loading.classList.remove('hidden');
|
550 |
-
results.classList.add('hidden');
|
551 |
-
|
552 |
-
try {
|
553 |
-
const response = await fetch('/analyze', { // Remplacez '/analyze' par l'URL de votre endpoint
|
554 |
-
method: 'POST',
|
555 |
-
body: formData
|
556 |
-
});
|
557 |
-
|
558 |
-
const data = await response.json();
|
559 |
-
|
560 |
-
if (response.ok) {
|
561 |
-
dissertationContent = data.dissertation;
|
562 |
-
tableauContent = data.tableau;
|
563 |
-
|
564 |
-
dissertationResult.innerHTML = marked.parse(data.dissertation); // Convertir en HTML
|
565 |
-
// Ne pas afficher le tableau immédiatement, attendre que l'utilisateur clique sur l'onglet
|
566 |
-
|
567 |
-
results.classList.remove('hidden');
|
568 |
-
results.classList.add('fade-in');
|
569 |
-
showTab('dissertation'); // Afficher l'onglet "dissertation" par défaut
|
570 |
-
} else {
|
571 |
-
// Afficher une alerte d'erreur plus informative
|
572 |
-
Swal.fire({
|
573 |
-
icon: 'error',
|
574 |
-
title: 'Erreur lors de l\'analyse',
|
575 |
-
text: data.error || 'Une erreur est survenue lors du traitement de votre image. Veuillez réessayer.',
|
576 |
-
});
|
577 |
-
}
|
578 |
-
} catch (error) {
|
579 |
-
|
580 |
-
Swal.fire({
|
581 |
-
icon: 'error',
|
582 |
-
title: 'Erreur',
|
583 |
-
text: 'Une erreur est survenue lors de la communication avec le serveur. Veuillez vérifier votre connexion internet et réessayer.',
|
584 |
-
});
|
585 |
-
} finally {
|
586 |
-
loading.classList.add('hidden');
|
587 |
-
}
|
588 |
});
|
589 |
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
showScrollIndicator(tableauResult);
|
595 |
-
}
|
596 |
-
}
|
597 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
598 |
</script>
|
599 |
</body>
|
600 |
|
|
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>Mariam AI - Analyse d'Image</title>
|
8 |
+
<!-- CDN pour Tailwind CSS -->
|
9 |
+
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
10 |
+
<!-- CDN pour Marked -->
|
11 |
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
12 |
+
<!-- CDN pour SweetAlert2 -->
|
13 |
+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
14 |
+
<!-- CDN pour Moment.js -->
|
15 |
+
<script src="https://cdn.jsdelivr.net/npm/moment@2.29.1/moment.min.js"></script>
|
16 |
<style>
|
17 |
/* Styles pour le loader */
|
18 |
.loader {
|
|
|
250 |
<main class="max-w-7xl mx-auto px-4 py-8 sm:px-6 lg:px-8">
|
251 |
<div class="bg-white rounded-lg shadow p-6 mb-8">
|
252 |
<form id="uploadForm" class="space-y-6">
|
|
|
253 |
<div class="upload-zone rounded-lg p-8 text-center">
|
254 |
<input type="file" id="imageInput" accept="image/*" required class="hidden"
|
255 |
onchange="handleImageSelect()">
|
|
|
267 |
</label>
|
268 |
</div>
|
269 |
|
|
|
270 |
<div id="imagePreview" class="hidden image-preview-container">
|
271 |
<img id="preview" src="#" alt="Prévisualisation">
|
272 |
<button type="button" class="remove-image" onclick="removeImage()">
|
|
|
277 |
</button>
|
278 |
</div>
|
279 |
|
|
|
280 |
<div class="flex justify-center">
|
281 |
<button type="submit"
|
282 |
class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-colors duration-200">
|
|
|
286 |
</form>
|
287 |
</div>
|
288 |
|
|
|
289 |
<div id="loading" class="hidden">
|
290 |
<div class="flex flex-col items-center justify-center space-y-4">
|
291 |
<span class="loader"></span>
|
|
|
293 |
</div>
|
294 |
</div>
|
295 |
|
|
|
296 |
<div id="results" class="space-y-8 hidden">
|
|
|
297 |
<div class="tab-buttons">
|
298 |
<button id="showDissertation" class="active">Dissertation</button>
|
299 |
<button id="showTableau">Tableau d'analyse</button>
|
300 |
<button id="showBackups">Sauvegardes</button>
|
301 |
</div>
|
302 |
|
|
|
303 |
<div id="dissertationTab" class="tab-content active bg-white rounded-lg shadow p-6">
|
304 |
<h2 class="text-2xl font-bold text-gray-900 mb-4">Dissertation</h2>
|
305 |
<div id="dissertationResult" class="prose max-w-none markdown-content">
|
306 |
+
|
307 |
</div>
|
308 |
<button id="saveDissertation"
|
309 |
class="mt-4 px-6 py-3 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors duration-200">
|
|
|
311 |
</button>
|
312 |
</div>
|
313 |
|
|
|
314 |
<div id="tableauTab" class="tab-content bg-white rounded-lg shadow p-6 hidden">
|
315 |
<h2 class="text-2xl font-bold text-gray-900 mb-4">Tableau d'analyse</h2>
|
316 |
<div id="tableauResult" class="markdown-content">
|
317 |
+
|
318 |
</div>
|
319 |
<button id="saveTableau"
|
320 |
class="mt-4 px-6 py-3 bg-green-600 text-white rounded-md hover:bg-green-700 transition-colors duration-200">
|
|
|
322 |
</button>
|
323 |
</div>
|
324 |
|
|
|
325 |
<div id="backupsTab" class="tab-content bg-white rounded-lg shadow p-6 hidden">
|
326 |
<h2 class="text-2xl font-bold text-gray-900 mb-4">Sauvegardes locales</h2>
|
327 |
<ul id="backupList" class="space-y-2">
|
328 |
+
|
329 |
</ul>
|
330 |
</div>
|
331 |
+
|
332 |
</div>
|
333 |
</main>
|
334 |
</div>
|
335 |
|
336 |
<script>
|
337 |
+
// ...(Le JavaScript de la réponse précédente va ici)
|
338 |
+
|
339 |
+
let tableauContent = '';
|
340 |
+
let dissertationContent = '';
|
341 |
+
let backups = loadBackups();
|
342 |
|
343 |
+
function handleImageSelect() {
|
344 |
const input = document.getElementById('imageInput');
|
345 |
const preview = document.getElementById('preview');
|
346 |
const previewContainer = document.getElementById('imagePreview');
|
|
|
352 |
reader.onload = function (e) {
|
353 |
preview.src = e.target.result;
|
354 |
previewContainer.classList.remove('hidden');
|
355 |
+
previewContainer.classList.add('fade-in');
|
|
|
356 |
};
|
357 |
|
358 |
reader.readAsDataURL(input.files[0]);
|
|
|
360 |
} else {
|
361 |
removeImage();
|
362 |
}
|
363 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
|
365 |
+
function removeImage() {
|
366 |
+
const input = document.getElementById('imageInput');
|
367 |
+
const preview = document.getElementById('preview');
|
368 |
+
const previewContainer = document.getElementById('imagePreview');
|
369 |
+
const fileName = document.getElementById('fileName');
|
|
|
|
|
|
|
370 |
|
371 |
+
input.value = '';
|
372 |
+
preview.src = '#';
|
373 |
+
previewContainer.classList.add('hidden');
|
374 |
+
fileName.textContent = 'Cliquez ou glissez une image ici';
|
375 |
+
}
|
376 |
+
|
377 |
+
function showScrollIndicator(container) {
|
378 |
+
if (container.scrollWidth > container.clientWidth) {
|
379 |
+
const indicator = document.createElement('div');
|
380 |
+
indicator.className = 'scroll-indicator visible';
|
381 |
+
indicator.textContent = '← Faites défiler →';
|
382 |
+
container.parentElement.appendChild(indicator);
|
383 |
+
|
384 |
+
setTimeout(() => {
|
385 |
+
indicator.classList.remove('visible');
|
386 |
+
}, 3000);
|
387 |
+
|
388 |
+
container.addEventListener('scroll', () => {
|
389 |
+
if (container.scrollLeft > 0) {
|
390 |
+
indicator.classList.add('visible');
|
391 |
+
} else {
|
392 |
+
indicator.classList.remove('visible');
|
393 |
}
|
|
|
394 |
|
395 |
+
clearTimeout(container.scrollTimeout);
|
396 |
+
container.scrollTimeout = setTimeout(() => {
|
397 |
+
indicator.classList.remove('visible');
|
398 |
+
}, 1000);
|
399 |
+
});
|
400 |
+
}
|
401 |
+
}
|
402 |
+
|
403 |
+
document.getElementById('showTableau').addEventListener('click', () => {
|
404 |
+
showTab('tableau');
|
405 |
+
renderTableauContent();
|
406 |
+
});
|
407 |
+
|
408 |
+
document.getElementById('showDissertation').addEventListener('click', () => {
|
409 |
+
showTab('dissertation');
|
410 |
+
});
|
411 |
+
|
412 |
+
document.getElementById('showBackups').addEventListener('click', () => {
|
413 |
+
showTab('backups');
|
414 |
+
updateBackupList();
|
415 |
+
});
|
416 |
+
|
417 |
+
function showTab(tabName) {
|
418 |
+
document.querySelectorAll('.tab-content').forEach(tab => tab.classList.remove('active'));
|
419 |
+
document.querySelectorAll('.tab-buttons button').forEach(button => button.classList.remove('active'));
|
420 |
+
|
421 |
+
document.getElementById(`${tabName}Tab`).classList.add('active');
|
422 |
+
document.getElementById(`show${tabName.charAt(0).toUpperCase() + tabName.slice(1)}`).classList.add('active');
|
423 |
+
}
|
424 |
+
|
425 |
+
function loadBackups() {
|
426 |
+
try {
|
427 |
+
const storedBackups = localStorage.getItem('mariamAIBackups');
|
428 |
+
return storedBackups ? JSON.parse(storedBackups) : [];
|
429 |
+
} catch (error) {
|
430 |
+
console.error("Erreur lors du chargement des sauvegardes :", error);
|
431 |
+
return [];
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
function saveBackup(type, content) {
|
436 |
+
const timestamp = moment().format('YYYY-MM-DD HH:mm:ss');
|
437 |
+
backups.push({ timestamp, type, content });
|
438 |
+
localStorage.setItem('mariamAIBackups', JSON.stringify(backups));
|
439 |
+
updateBackupList();
|
440 |
+
Swal.fire({
|
441 |
+
icon: 'success',
|
442 |
+
title: 'Sauvegarde réussie!',
|
443 |
+
});
|
444 |
+
}
|
445 |
+
|
446 |
+
function updateBackupList() {
|
447 |
+
const backupList = document.getElementById('backupList');
|
448 |
+
backupList.innerHTML = '';
|
449 |
+
|
450 |
+
backups.forEach((backup, index) => {
|
451 |
+
const listItem = document.createElement('li');
|
452 |
+
listItem.innerHTML = `
|
453 |
+
<span>${backup.type === 'dissertation' ? 'Dissertation' : 'Tableau'} - ${backup.timestamp}</span>
|
454 |
+
<div>
|
455 |
+
<button data-index="${index}" class="view-backup bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded text-xs">Voir</button>
|
456 |
+
<button data-index="${index}" class="delete-backup bg-red-500 hover:bg-red-700 text-white font-bold py-1 px-2 rounded text-xs">Supprimer</button>
|
457 |
+
</div>
|
458 |
+
`;
|
459 |
+
backupList.appendChild(listItem);
|
460 |
+
|
461 |
+
listItem.querySelector('.view-backup').addEventListener('click', viewBackup);
|
462 |
+
listItem.querySelector('.delete-backup').addEventListener('click', deleteBackup);
|
463 |
+
});
|
464 |
+
}
|
465 |
+
|
466 |
+
function viewBackup(event) {
|
467 |
+
const index = event.target.dataset.index;
|
468 |
+
const backup = backups[index];
|
469 |
+
|
470 |
+
Swal.fire({
|
471 |
+
title: backup.type === 'dissertation' ? 'Dissertation sauvegardée' : 'Tableau sauvegardé',
|
472 |
+
html: marked.parse(backup.content),
|
473 |
+
width: '90%',
|
474 |
+
customClass: {
|
475 |
+
htmlContainer: 'markdown-content'
|
476 |
+
},
|
477 |
+
didRender: () => {
|
478 |
+
const container = document.querySelector('.markdown-content');
|
479 |
+
showScrollIndicator(container);
|
480 |
+
}
|
481 |
+
});
|
482 |
+
}
|
483 |
+
|
484 |
+
function deleteBackup(event) {
|
485 |
+
const index = event.target.dataset.index;
|
486 |
+
Swal.fire({
|
487 |
+
title: 'Êtes-vous sûr?',
|
488 |
+
text: "Vous ne pourrez pas revenir en arrière !",
|
489 |
+
icon: 'warning',
|
490 |
+
showCancelButton: true,
|
491 |
+
confirmButtonColor: '#3085d6',
|
492 |
+
cancelButtonColor: '#d33',
|
493 |
+
confirmButtonText: 'Oui, supprimer!'
|
494 |
+
}).then((result) => {
|
495 |
+
if (result.isConfirmed) {
|
496 |
+
backups.splice(index, 1);
|
497 |
localStorage.setItem('mariamAIBackups', JSON.stringify(backups));
|
498 |
+
updateBackupList();
|
499 |
+
Swal.fire(
|
500 |
+
'Supprimé!',
|
501 |
+
'Votre fichier a été supprimé.',
|
502 |
+
'success'
|
503 |
+
)
|
504 |
+
}
|
505 |
+
});
|
506 |
+
}
|
507 |
+
|
508 |
+
document.getElementById('saveDissertation').addEventListener('click', () => {
|
509 |
+
saveBackup('dissertation', dissertationContent);
|
510 |
+
});
|
511 |
+
|
512 |
+
document.getElementById('saveTableau').addEventListener('click', () => {
|
513 |
+
saveBackup('tableau', tableauContent);
|
514 |
+
});
|
515 |
+
|
516 |
+
document.getElementById('uploadForm').addEventListener('submit', async (e) => {
|
517 |
+
e.preventDefault();
|
518 |
+
|
519 |
+
const imageInput = document.getElementById('imageInput');
|
520 |
+
if (!imageInput.files || !imageInput.files[0]) {
|
521 |
+
Swal.fire({
|
522 |
+
icon: 'error',
|
523 |
+
title: 'Aucune image sélectionnée',
|
524 |
+
text: 'Veuillez sélectionner une image à analyser.',
|
525 |
+
});
|
526 |
+
return;
|
527 |
+
}
|
528 |
|
529 |
+
const loading = document.getElementById('loading');
|
530 |
+
const results = document.getElementById('results');
|
531 |
+
const dissertationResult = document.getElementById('dissertationResult');
|
532 |
|
533 |
+
const formData = new FormData();
|
534 |
+
formData.append('image', imageInput.files[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
535 |
|
536 |
+
loading.classList.remove('hidden');
|
537 |
+
results.classList.add('hidden');
|
538 |
|
539 |
+
try {
|
540 |
+
const response = await fetch('/analyze', {
|
541 |
+
method: 'POST',
|
542 |
+
body: formData
|
543 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
|
545 |
+
if (!response.ok) {
|
546 |
+
const errorData = await response.json();
|
547 |
+
const errorMessage = errorData.error || `Erreur serveur ${response.status}: ${response.statusText}`;
|
548 |
+
throw new Error(errorMessage);
|
549 |
}
|
550 |
|
551 |
+
const data = await response.json();
|
552 |
+
dissertationContent = data.dissertation;
|
553 |
+
tableauContent = data.tableau;
|
554 |
|
555 |
+
dissertationResult.innerHTML = marked.parse(data.dissertation);
|
556 |
|
557 |
+
results.classList.remove('hidden');
|
558 |
+
results.classList.add('fade-in');
|
559 |
+
showTab('dissertation');
|
|
|
|
|
|
|
|
|
|
|
560 |
|
561 |
+
} catch (error) {
|
562 |
+
console.error("Erreur lors de l'analyse :", error);
|
563 |
+
Swal.fire({
|
564 |
+
icon: 'error',
|
565 |
+
title: 'Erreur',
|
566 |
+
text: error.message || 'Une erreur est survenue lors de la communication avec le serveur.',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
567 |
});
|
568 |
|
569 |
+
} finally {
|
570 |
+
loading.classList.add('hidden');
|
571 |
+
}
|
572 |
+
});
|
|
|
|
|
|
|
573 |
|
574 |
+
function renderTableauContent() {
|
575 |
+
const tableauResult = document.getElementById('tableauResult');
|
576 |
+
if (tableauContent) {
|
577 |
+
tableauResult.innerHTML = marked.parse(tableauContent);
|
578 |
+
showScrollIndicator(tableauResult);
|
579 |
+
}
|
580 |
+
}
|
581 |
</script>
|
582 |
</body>
|
583 |
|