Flasksite1 / templates /philosophie.html
Docfile's picture
Update templates/philosophie.html
fc4bc7e verified
raw
history blame
11.9 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Assistant de Philosophie (Vue.js)</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kalam&family=Lato:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #4f46e5; /* Indigo */
--primary-hover: #4338ca;
--text-color: #374151; /* Gris foncé */
--background-color: #f8f9fa;
--container-bg: #ffffff;
--border-color: #e5e7eb;
}
body {
font-family: 'Lato', sans-serif;
background-color: var(--background-color);
margin: 0;
padding: 2rem;
color: var(--text-color);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.container {
max-width: 960px;
margin: 0 auto;
background: var(--container-bg);
padding: 40px;
border-radius: 12px;
box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}
h1 {
text-align: center;
color: #111827;
margin-bottom: 0.5em;
}
.type-indicator {
text-align: center;
color: #6b7280;
font-size: 1.1em;
margin-bottom: 2em;
font-weight: bold;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 700;
color: #4b5563;
}
textarea, .form-select {
width: 100%;
padding: 15px;
border-radius: 8px;
border: 1px solid var(--border-color);
min-height: 58px;
font-size: 16px;
line-height: 1.6;
transition: border-color 0.3s, box-shadow 0.3s;
background-color: #fff;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
box-sizing: border-box;
}
.form-select {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
background-position: right 0.75rem center;
background-repeat: no-repeat;
background-size: 1.5em 1.5em;
padding-right: 2.5rem;
}
textarea {
min-height: 100px;
}
textarea:focus, .form-select:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}
button {
display: block;
box-sizing: border-box;
width: 100%;
padding: 16px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 8px;
font-size: 18px;
font-weight: 700;
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
}
button:hover:not(:disabled) {
background-color: var(--primary-hover);
transform: translateY(-2px);
}
button:disabled {
background-color: #9ca3af;
cursor: not-allowed;
}
.download-container {
margin-top: 15px;
}
.secondary-button {
background-color: #f3f4f6;
color: #374151;
border: 1px solid #d1d5db;
}
.secondary-button:hover:not(:disabled) {
background-color: #e5e7eb;
border-color: #9ca3af;
}
.loader {
display: block;
border: 8px solid #f3f3f3;
border-top: 8px solid var(--primary-color);
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 30px auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.error {
color: #ef4444;
background-color: #fee2e2;
text-align: center;
margin-top: 20px;
padding: 15px;
border-radius: 8px;
font-weight: bold;
}
/* Styles de la feuille de dissertation */
.dissertation-paper {
font-family: 'Kalam', cursive;
font-size: 20px;
color: #1a2a4c;
background-color: #fdfaf4;
line-height: 2;
background-image: linear-gradient(transparent 97%, #d8e2ee 98%);
background-size: 100% 40px;
border-left: 3px solid #ffaaab;
padding-left: 4em;
margin: 40px -40px -40px -40px;
padding-top: 30px;
padding-bottom: 40px;
padding-right: 30px;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
.dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.5em; }
.dissertation-paper h3 { font-size: 1.2em; margin-top: 3em; margin-bottom: 1.5em; text-transform: uppercase; text-decoration: underline; }
.dissertation-paper .development-block { margin-top: 3em; }
.dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
.dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 2em; }
.dissertation-paper .indented { text-indent: 3em; }
.dissertation-paper .transition { margin-top: 2em; margin-bottom: 2em; font-style: italic; color: #4a6a9c; }
.dissertation-paper, .dissertation-paper * { box-sizing: border-box; }
.avoid-page-break { page-break-inside: avoid; break-inside: avoid; }
</style>
</head>
<body>
<div id="app" class="container">
<h1>Assistant de Dissertation Philosophique</h1>
<p class="type-indicator">Méthodologie : [[ dissertationTypeLabel ]]</p>
<form @submit.prevent="generateDissertation">
<div class="form-group">
<label for="dissertation-type">Choisir la méthodologie</label>
<select id="dissertation-type" v-model="dissertationType" class="form-select">
<option value="type1">Type 1 (Problématique en deux questions)</option>
<option value="type2">Type 2 (Introduction autour d'une citation)</option>
</select>
</div>
<div class="form-group">
<label for="course-context">Choisir un cours comme contexte (optionnel)</label>
<select id="course-context" v-model="selectedCourse" class="form-select">
<option value="">-- Aucun cours en contexte --</option>
<option v-for="course in courses" :key="course.id" :value="course.id">
[[ course.title ]]
</option>
</select>
</div>
<div class="form-group">
<label for="question">Entrez votre sujet de dissertation</label>
<textarea id="question" v-model="question" placeholder="Entrez votre sujet ou la citation à analyser ici..."></textarea>
</div>
<button type="submit" :disabled="isLoading">
[[ isLoading ? 'Génération en cours...' : 'Générer la dissertation' ]]
</button>
</form>
<div v-if="dissertation" class="download-container" data-html2canvas-ignore="true">
<button class="secondary-button" @click="generatePDF">Télécharger la dissertation en PDF</button>
</div>
<div v-if="isLoading" class="loader"></div>
<p v-if="errorMessage" class="error">[[ errorMessage ]]</p>
<div v-if="dissertation" id="dissertation-content" class="dissertation-paper">
<h2>Sujet : [[ dissertation.sujet ]]</h2>
<p class="prof">Prof : [[ dissertation.prof ]]</p>
<h3>Introduction</h3>
<p class="indented">[[ dissertation.introduction ]]</p>
<div v-for="partie in dissertation.parties" :key="partie.chapeau" class="avoid-page-break">
<div class="development-block">
<p class="indented">[[ partie.chapeau ]]</p>
<p v-for="(arg, idx) in partie.arguments" :key="idx" class="indented">
[[ arg.paragraphe_argumentatif ]]
</p>
</div>
<p v-if="partie.transition" class="indented transition">[[ partie.transition ]]</p>
</div>
<h3>Conclusion</h3>
<p class="indented">[[ dissertation.conclusion ]]</p>
</div>
</div>
<script>
const { createApp } = Vue;
const app = createApp({
data() {
return {
question: '',
dissertationType: 'type1',
courses: [], // Pour stocker la liste des cours
selectedCourse: '', // Pour stocker l'ID du cours sélectionné
isLoading: false,
errorMessage: null,
dissertation: null
}
},
computed: {
dissertationTypeLabel() {
return this.dissertationType === 'type1' ? 'Type 1' : 'Type 2';
}
},
mounted() {
// Au chargement du composant, on récupère la liste des cours
this.fetchCourses();
},
methods: {
async fetchCourses() {
try {
const response = await fetch('/api/philosophy/courses');
if (!response.ok) throw new Error('Impossible de charger les cours. Vérifiez la connexion à la base de données.');
const data = await response.json();
if (data.error) throw new Error(data.error);
this.courses = data;
} catch (error) {
this.errorMessage = error.message;
console.error("Erreur de chargement des cours:", error);
}
},
async generateDissertation() {
if (!this.question.trim()) {
this.errorMessage = "Veuillez entrer un sujet de dissertation.";
return;
}
this.isLoading = true;
this.errorMessage = null;
this.dissertation = null;
try {
const response = await fetch('/api/generate_dissertation', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
question: this.question,
type: this.dissertationType,
courseId: this.selectedCourse // On envoie l'ID du cours sélectionné
})
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || "Une erreur inconnue est survenue.");
}
this.dissertation = data;
} catch (error) {
this.errorMessage = error.message;
} finally {
this.isLoading = false;
}
},
async generatePDF() {
const element = document.getElementById('dissertation-content');
if (!element) {
this.errorMessage = "Contenu introuvable pour le PDF.";
return;
}
try {
if (document.fonts && document.fonts.ready) {
await document.fonts.ready;
}
window.scrollTo(0, 0);
const options = {
margin: [15, 15, 15, 15],
filename: 'dissertation-philosophie.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {
scale: 2,
useCORS: true,
logging: true,
backgroundColor: null,
},
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
await html2pdf().set(options).from(element).save();
} catch (err) {
console.error('Erreur html2pdf:', err);
this.errorMessage = "Erreur lors de la génération du PDF. Voir la console pour les détails.";
}
}
}
});
// ⚠️ Changer les délimiteurs pour éviter le conflit avec Jinja2
app.config.compilerOptions.delimiters = ['[[', ']]'];
app.mount('#app');
</script>
</body>
</html>