Spaces:
Sleeping
Sleeping
Update templates/philosophie.html
Browse files- templates/philosophie.html +58 -76
templates/philosophie.html
CHANGED
@@ -27,48 +27,16 @@
|
|
27 |
border-radius: 8px;
|
28 |
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
29 |
}
|
30 |
-
h1 {
|
31 |
-
|
32 |
-
|
33 |
-
}
|
34 |
-
textarea {
|
35 |
-
width: 100%;
|
36 |
-
padding: 10px;
|
37 |
-
border-radius: 4px;
|
38 |
-
border: 1px solid #ddd;
|
39 |
-
min-height: 80px;
|
40 |
-
margin-bottom: 10px;
|
41 |
-
font-size: 16px;
|
42 |
-
}
|
43 |
-
button {
|
44 |
-
display: block;
|
45 |
-
width: 100%;
|
46 |
-
padding: 15px;
|
47 |
-
background-color: #2980b9;
|
48 |
-
color: white;
|
49 |
-
border: none;
|
50 |
-
border-radius: 5px;
|
51 |
-
font-size: 18px;
|
52 |
-
cursor: pointer;
|
53 |
-
transition: background-color 0.3s;
|
54 |
-
}
|
55 |
button:hover { background-color: #3498db; }
|
56 |
button:disabled { background-color: #95a5a6; cursor: not-allowed; }
|
57 |
-
|
58 |
-
.loader {
|
59 |
-
display: none;
|
60 |
-
border: 8px solid #f3f3f3;
|
61 |
-
border-top: 8px solid #3498db;
|
62 |
-
border-radius: 50%;
|
63 |
-
width: 50px;
|
64 |
-
height: 50px;
|
65 |
-
animation: spin 1s linear infinite;
|
66 |
-
margin: 20px auto;
|
67 |
-
}
|
68 |
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
69 |
.error { color: #c0392b; text-align: center; margin-top: 20px; }
|
70 |
|
71 |
-
/* ---
|
72 |
.dissertation-paper {
|
73 |
font-family: 'Kalam', cursive;
|
74 |
font-size: 20px;
|
@@ -79,36 +47,57 @@
|
|
79 |
background-size: 100% 36px;
|
80 |
border-left: 2px solid #ffaaab;
|
81 |
padding-left: 4em;
|
82 |
-
margin: 40px -30px -30px -30px;
|
83 |
padding-top: 30px;
|
84 |
padding-bottom: 30px;
|
85 |
padding-right: 30px;
|
|
|
86 |
}
|
87 |
-
|
88 |
-
|
89 |
-
.dissertation-paper
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
.dissertation-paper .pdf-button-container { text-align: center; margin-top: 3.6em; }
|
95 |
.dissertation-paper .pdf-button { font-family: 'Lato', sans-serif; font-size: 16px; padding: 10px 20px; width: auto; }
|
96 |
</style>
|
97 |
</head>
|
98 |
<body>
|
99 |
-
|
100 |
<div class="container">
|
101 |
<h1>Assistant de Dissertation Philosophique</h1>
|
102 |
<form id="philo-form">
|
103 |
-
<textarea id="question" name="question" placeholder="Entrez votre sujet de dissertation ici...
|
104 |
<button type="submit" id="submit-btn">Générer la dissertation</button>
|
105 |
</form>
|
106 |
-
|
107 |
<div id="loader" class="loader"></div>
|
108 |
<div id="result-container"></div>
|
109 |
</div>
|
110 |
|
111 |
<script>
|
|
|
112 |
document.addEventListener('DOMContentLoaded', () => {
|
113 |
const form = document.getElementById('philo-form');
|
114 |
const submitBtn = document.getElementById('submit-btn');
|
@@ -118,37 +107,23 @@
|
|
118 |
form.addEventListener('submit', async (event) => {
|
119 |
event.preventDefault();
|
120 |
const question = document.getElementById('question').value.trim();
|
121 |
-
|
122 |
-
if (!question) {
|
123 |
-
showError("Veuillez entrer un sujet de dissertation.");
|
124 |
-
return;
|
125 |
-
}
|
126 |
-
|
127 |
-
// UI management
|
128 |
submitBtn.disabled = true;
|
129 |
submitBtn.textContent = 'Génération en cours...';
|
130 |
loader.style.display = 'block';
|
131 |
resultContainer.innerHTML = '';
|
132 |
-
|
133 |
try {
|
134 |
const response = await fetch('/api/generate_dissertation', {
|
135 |
method: 'POST',
|
136 |
headers: { 'Content-Type': 'application/json' },
|
137 |
body: JSON.stringify({ question: question })
|
138 |
});
|
139 |
-
|
140 |
-
if (!response.ok) {
|
141 |
-
const errorData = await response.json();
|
142 |
-
throw new Error(errorData.error || "Une erreur inconnue est survenue.");
|
143 |
-
}
|
144 |
-
|
145 |
const data = await response.json();
|
146 |
renderDissertation(data);
|
147 |
-
|
148 |
} catch (error) {
|
149 |
showError(error.message);
|
150 |
} finally {
|
151 |
-
// Reset UI
|
152 |
submitBtn.disabled = false;
|
153 |
submitBtn.textContent = 'Générer la dissertation';
|
154 |
loader.style.display = 'none';
|
@@ -156,6 +131,7 @@
|
|
156 |
});
|
157 |
|
158 |
function renderDissertation(data) {
|
|
|
159 |
let html = `
|
160 |
<div id="dissertation-content" class="dissertation-paper">
|
161 |
<h2>Sujet : ${data.sujet}</h2>
|
@@ -163,7 +139,6 @@
|
|
163 |
<h3>Introduction</h3>
|
164 |
<p class="indented">${data.introduction.replace(/\n/g, '<br>')}</p>
|
165 |
`;
|
166 |
-
|
167 |
data.parties.forEach((partie, index) => {
|
168 |
html += `<div class="development-block">`;
|
169 |
html += `<p class="indented">${partie.chapeau.replace(/\n/g, '<br>')}</p>`;
|
@@ -171,12 +146,8 @@
|
|
171 |
html += `<p class="indented">${arg.paragraphe_argumentatif.replace(/\n/g, '<br>')}</p>`;
|
172 |
});
|
173 |
html += `</div>`;
|
174 |
-
|
175 |
-
if (partie.transition) {
|
176 |
-
html += `<p class="indented transition">${partie.transition.replace(/\n/g, '<br>')}</p>`;
|
177 |
-
}
|
178 |
});
|
179 |
-
|
180 |
html += `
|
181 |
<h3>Conclusion</h3>
|
182 |
<p class="indented">${data.conclusion.replace(/\n/g, '<br>')}</p>
|
@@ -185,17 +156,21 @@
|
|
185 |
</div>
|
186 |
</div>
|
187 |
`;
|
188 |
-
|
189 |
resultContainer.innerHTML = html;
|
190 |
-
|
191 |
-
// Attach event listener to the newly created button
|
192 |
document.getElementById('download-pdf').addEventListener('click', generatePDF);
|
193 |
}
|
194 |
|
|
|
195 |
function generatePDF() {
|
196 |
const element = document.getElementById('dissertation-content');
|
197 |
-
|
|
|
|
|
198 |
const pdfButtonContainer = element.querySelector('.pdf-button-container');
|
|
|
|
|
|
|
|
|
199 |
pdfButtonContainer.style.display = 'none';
|
200 |
|
201 |
const options = {
|
@@ -204,9 +179,16 @@
|
|
204 |
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
|
205 |
};
|
206 |
|
|
|
207 |
html2pdf().set(options).from(element).save().then(() => {
|
208 |
-
//
|
209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
});
|
211 |
}
|
212 |
|
|
|
27 |
border-radius: 8px;
|
28 |
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
29 |
}
|
30 |
+
h1 { text-align: center; color: #2c3e50; }
|
31 |
+
textarea { width: 100%; padding: 10px; border-radius: 4px; border: 1px solid #ddd; min-height: 80px; margin-bottom: 10px; font-size: 16px; }
|
32 |
+
button { display: block; width: 100%; padding: 15px; background-color: #2980b9; color: white; border: none; border-radius: 5px; font-size: 18px; cursor: pointer; transition: background-color 0.3s; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
button:hover { background-color: #3498db; }
|
34 |
button:disabled { background-color: #95a5a6; cursor: not-allowed; }
|
35 |
+
.loader { display: none; border: 8px solid #f3f3f3; border-top: 8px solid #3498db; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
37 |
.error { color: #c0392b; text-align: center; margin-top: 20px; }
|
38 |
|
39 |
+
/* --- Style "Cahier" pour l'affichage à l'écran --- */
|
40 |
.dissertation-paper {
|
41 |
font-family: 'Kalam', cursive;
|
42 |
font-size: 20px;
|
|
|
47 |
background-size: 100% 36px;
|
48 |
border-left: 2px solid #ffaaab;
|
49 |
padding-left: 4em;
|
50 |
+
margin: 40px -30px -30px -30px;
|
51 |
padding-top: 30px;
|
52 |
padding-bottom: 30px;
|
53 |
padding-right: 30px;
|
54 |
+
box-shadow: 5px 5px 15px rgba(0,0,0,0.2);
|
55 |
}
|
56 |
+
|
57 |
+
/* -- NOUVEAU : Style "PDF" simple et sûr -- */
|
58 |
+
.dissertation-paper-pdf {
|
59 |
+
/* On utilise une police standard et sûre */
|
60 |
+
font-family: 'Times New Roman', Times, serif;
|
61 |
+
font-size: 16px; /* Taille plus classique pour un PDF */
|
62 |
+
color: #000000; /* Noir simple */
|
63 |
+
background: #ffffff; /* Fond blanc simple */
|
64 |
+
line-height: 1.5;
|
65 |
+
|
66 |
+
/* On garde la mise en page importante */
|
67 |
+
border-left: 2px solid #dd0000;
|
68 |
+
padding-left: 2.5em;
|
69 |
+
padding-top: 30px;
|
70 |
+
padding-bottom: 30px;
|
71 |
+
padding-right: 30px;
|
72 |
+
margin: 0;
|
73 |
+
box-shadow: none; /* Pas d'ombre dans le PDF */
|
74 |
+
}
|
75 |
+
|
76 |
+
/* --- Styles Communs aux deux versions --- */
|
77 |
+
.dissertation-paper h2, .dissertation-paper-pdf h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.8em; }
|
78 |
+
.dissertation-paper h3, .dissertation-paper-pdf h3 { font-size: 1.2em; margin-top: 3.6em; margin-bottom: 1.8em; text-transform: uppercase; text-decoration: underline; }
|
79 |
+
.dissertation-paper .development-block, .dissertation-paper-pdf .development-block { margin-top: 3.6em; }
|
80 |
+
.dissertation-paper p, .dissertation-paper-pdf p { text-align: justify; margin: 0; padding: 0; }
|
81 |
+
.dissertation-paper .prof, .dissertation-paper-pdf .prof { text-align: center; font-style: italic; margin-bottom: 1.8em; }
|
82 |
+
.dissertation-paper .indented, .dissertation-paper-pdf .indented { text-indent: 3em; }
|
83 |
+
.dissertation-paper .transition, .dissertation-paper-pdf .transition { margin-top: 1.8em; margin-bottom: 1.8em; font-style: italic; }
|
84 |
.dissertation-paper .pdf-button-container { text-align: center; margin-top: 3.6em; }
|
85 |
.dissertation-paper .pdf-button { font-family: 'Lato', sans-serif; font-size: 16px; padding: 10px 20px; width: auto; }
|
86 |
</style>
|
87 |
</head>
|
88 |
<body>
|
|
|
89 |
<div class="container">
|
90 |
<h1>Assistant de Dissertation Philosophique</h1>
|
91 |
<form id="philo-form">
|
92 |
+
<textarea id="question" name="question" placeholder="Entrez votre sujet de dissertation ici..."></textarea>
|
93 |
<button type="submit" id="submit-btn">Générer la dissertation</button>
|
94 |
</form>
|
|
|
95 |
<div id="loader" class="loader"></div>
|
96 |
<div id="result-container"></div>
|
97 |
</div>
|
98 |
|
99 |
<script>
|
100 |
+
// Le code de la logique de formulaire reste identique...
|
101 |
document.addEventListener('DOMContentLoaded', () => {
|
102 |
const form = document.getElementById('philo-form');
|
103 |
const submitBtn = document.getElementById('submit-btn');
|
|
|
107 |
form.addEventListener('submit', async (event) => {
|
108 |
event.preventDefault();
|
109 |
const question = document.getElementById('question').value.trim();
|
110 |
+
if (!question) { showError("Veuillez entrer un sujet de dissertation."); return; }
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
submitBtn.disabled = true;
|
112 |
submitBtn.textContent = 'Génération en cours...';
|
113 |
loader.style.display = 'block';
|
114 |
resultContainer.innerHTML = '';
|
|
|
115 |
try {
|
116 |
const response = await fetch('/api/generate_dissertation', {
|
117 |
method: 'POST',
|
118 |
headers: { 'Content-Type': 'application/json' },
|
119 |
body: JSON.stringify({ question: question })
|
120 |
});
|
121 |
+
if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || "Une erreur inconnue est survenue."); }
|
|
|
|
|
|
|
|
|
|
|
122 |
const data = await response.json();
|
123 |
renderDissertation(data);
|
|
|
124 |
} catch (error) {
|
125 |
showError(error.message);
|
126 |
} finally {
|
|
|
127 |
submitBtn.disabled = false;
|
128 |
submitBtn.textContent = 'Générer la dissertation';
|
129 |
loader.style.display = 'none';
|
|
|
131 |
});
|
132 |
|
133 |
function renderDissertation(data) {
|
134 |
+
// Le code de rendu HTML reste identique
|
135 |
let html = `
|
136 |
<div id="dissertation-content" class="dissertation-paper">
|
137 |
<h2>Sujet : ${data.sujet}</h2>
|
|
|
139 |
<h3>Introduction</h3>
|
140 |
<p class="indented">${data.introduction.replace(/\n/g, '<br>')}</p>
|
141 |
`;
|
|
|
142 |
data.parties.forEach((partie, index) => {
|
143 |
html += `<div class="development-block">`;
|
144 |
html += `<p class="indented">${partie.chapeau.replace(/\n/g, '<br>')}</p>`;
|
|
|
146 |
html += `<p class="indented">${arg.paragraphe_argumentatif.replace(/\n/g, '<br>')}</p>`;
|
147 |
});
|
148 |
html += `</div>`;
|
149 |
+
if (partie.transition) { html += `<p class="indented transition">${partie.transition.replace(/\n/g, '<br>')}</p>`; }
|
|
|
|
|
|
|
150 |
});
|
|
|
151 |
html += `
|
152 |
<h3>Conclusion</h3>
|
153 |
<p class="indented">${data.conclusion.replace(/\n/g, '<br>')}</p>
|
|
|
156 |
</div>
|
157 |
</div>
|
158 |
`;
|
|
|
159 |
resultContainer.innerHTML = html;
|
|
|
|
|
160 |
document.getElementById('download-pdf').addEventListener('click', generatePDF);
|
161 |
}
|
162 |
|
163 |
+
// --- FONCTION generatePDF() CORRIGÉE ---
|
164 |
function generatePDF() {
|
165 |
const element = document.getElementById('dissertation-content');
|
166 |
+
|
167 |
+
// Sauvegarde des styles originaux
|
168 |
+
const originalClassName = element.className;
|
169 |
const pdfButtonContainer = element.querySelector('.pdf-button-container');
|
170 |
+
const originalButtonDisplay = pdfButtonContainer.style.display;
|
171 |
+
|
172 |
+
// Application des styles simplifiés pour le PDF
|
173 |
+
element.className = 'dissertation-paper-pdf';
|
174 |
pdfButtonContainer.style.display = 'none';
|
175 |
|
176 |
const options = {
|
|
|
179 |
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
|
180 |
};
|
181 |
|
182 |
+
// Génération du PDF
|
183 |
html2pdf().set(options).from(element).save().then(() => {
|
184 |
+
// Restauration des styles originaux une fois le PDF généré
|
185 |
+
element.className = originalClassName;
|
186 |
+
pdfButtonContainer.style.display = originalButtonDisplay;
|
187 |
+
}).catch(err => {
|
188 |
+
// En cas d'erreur, on restaure aussi les styles
|
189 |
+
console.error("Erreur lors de la génération du PDF:", err);
|
190 |
+
element.className = originalClassName;
|
191 |
+
pdfButtonContainer.style.display = originalButtonDisplay;
|
192 |
});
|
193 |
}
|
194 |
|