Docfile commited on
Commit
9ebe28c
·
verified ·
1 Parent(s): 725f8a8

Update templates/philosophie.html

Browse files
Files changed (1) hide show
  1. templates/philosophie.html +81 -263
templates/philosophie.html CHANGED
@@ -5,12 +5,15 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Assistant de Philosophie</title>
7
 
8
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
 
 
 
9
 
10
  <style>
11
  /* --- Styles Généraux et Interface --- */
12
  body {
13
- font-family: Arial, sans-serif;
14
  background-color: #f4f4f9;
15
  margin: 0;
16
  padding: 20px;
@@ -24,126 +27,46 @@
24
  border-radius: 8px;
25
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
26
  }
27
- h1 {
28
- text-align: center;
29
- color: #2c3e50;
30
- }
31
  textarea {
32
- width: 100%;
33
- padding: 10px;
34
- border-radius: 4px;
35
- border: 1px solid #ddd;
36
- min-height: 80px;
37
- margin-bottom: 10px;
38
- font-size: 16px;
39
- box-sizing: border-box;
40
  }
41
  button {
42
- display: block;
43
- width: 100%;
44
- padding: 15px;
45
- background-color: #2980b9;
46
- color: white;
47
- border: none;
48
- border-radius: 5px;
49
- font-size: 18px;
50
- cursor: pointer;
51
- transition: background-color 0.3s;
52
  }
53
  button:hover { background-color: #3498db; }
54
  button:disabled { background-color: #95a5a6; cursor: not-allowed; }
55
 
56
  .loader {
57
- display: none;
58
- border: 8px solid #f3f3f3;
59
- border-top: 8px solid #3498db;
60
- border-radius: 50%;
61
- width: 50px;
62
- height: 50px;
63
- animation: spin 1s linear infinite;
64
- margin: 20px auto;
65
  }
66
  @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
67
- .error { color: #c0392b; text-align: center; margin-top: 20px; }
68
- .success { color: #27ae60; text-align: center; margin-top: 20px; }
69
 
70
  /* --- Styles du Rendu "Cahier" --- */
71
  .dissertation-paper {
72
- font-family: 'Times New Roman', serif;
73
- font-size: 16px;
74
- color: #1a2a4c;
75
- background-color: #fdfaf4;
76
- line-height: 1.6;
77
- border-left: 3px solid #ffaaab;
78
- padding: 30px;
79
  margin: 40px -30px -30px -30px;
80
- min-height: 500px;
81
- }
82
-
83
- .dissertation-paper h2 {
84
- font-size: 1.4em;
85
- text-align: center;
86
- margin-bottom: 24px;
87
- font-weight: bold;
88
- text-decoration: underline;
89
- }
90
-
91
- .dissertation-paper h3 {
92
- font-size: 1.2em;
93
- margin-top: 32px;
94
- margin-bottom: 20px;
95
- text-transform: uppercase;
96
- text-decoration: underline;
97
- font-weight: bold;
98
- }
99
-
100
- .dissertation-paper .development-block {
101
- margin-top: 24px;
102
- margin-bottom: 24px;
103
- }
104
-
105
- .dissertation-paper p {
106
- text-align: justify;
107
- margin-bottom: 16px;
108
- padding-bottom: 8px;
109
- }
110
-
111
- .dissertation-paper .prof {
112
- text-align: center;
113
- font-style: italic;
114
- margin-bottom: 24px;
115
- font-size: 0.9em;
116
- }
117
-
118
- .dissertation-paper .indented {
119
- text-indent: 2em;
120
- }
121
-
122
- .dissertation-paper .transition {
123
- margin-top: 20px;
124
- margin-bottom: 20px;
125
- font-style: italic;
126
- color: #4a6a9c;
127
- font-weight: 500;
128
- }
129
-
130
- .pdf-button-container {
131
- text-align: center;
132
- margin-top: 40px;
133
- }
134
-
135
- .pdf-button {
136
- font-family: Arial, sans-serif;
137
- font-size: 16px;
138
- padding: 12px 24px;
139
- width: auto;
140
- display: inline-block;
141
- background-color: #27ae60;
142
- }
143
-
144
- .pdf-button:hover {
145
- background-color: #2ecc71;
146
- }
147
  </style>
148
  </head>
149
  <body>
@@ -169,61 +92,36 @@
169
  form.addEventListener('submit', async (event) => {
170
  event.preventDefault();
171
  const question = document.getElementById('question').value.trim();
172
-
173
  if (!question) {
174
  showError("Veuillez entrer un sujet de dissertation.");
175
  return;
176
  }
177
 
178
- simulateGeneration(question);
179
- });
180
-
181
- function simulateGeneration(question) {
182
  submitBtn.disabled = true;
183
  submitBtn.textContent = 'Génération en cours...';
184
  loader.style.display = 'block';
185
  resultContainer.innerHTML = '';
186
 
187
- setTimeout(() => {
188
- const mockData = {
189
- sujet: question,
190
- prof: "M. Dupont",
191
- introduction: "L'introduction de cette dissertation explore les différentes dimensions du sujet proposé. Nous commençons par définir les termes clés et établir la problématique qui guidera notre réflexion. Cette question soulève des enjeux philosophiques fondamentaux que nous devrons examiner avec rigueur.",
192
- parties: [
193
- {
194
- chapeau: "Dans un premier temps, nous examinerons la dimension théorique de cette question.",
195
- arguments: [
196
- {
197
- paragraphe_argumentatif: "Premier argument : Cette perspective nous permet de comprendre les fondements conceptuels du problème. En effet, l'analyse théorique révèle des aspects souvent négligés dans l'approche commune de cette question."
198
- },
199
- {
200
- paragraphe_argumentatif: "Deuxième argument : L'examen des sources philosophiques classiques nous éclaire sur les différentes interprétations possibles. Les penseurs comme Descartes, Kant ou Nietzsche ont chacun apporté des éléments de réponse qui méritent d'être confrontés."
201
- }
202
- ],
203
- transition: "Cependant, cette approche théorique trouve ses limites, ce qui nous amène à considérer une perspective plus pratique."
204
- },
205
- {
206
- chapeau: "Dans un second temps, nous analyserons les implications pratiques et concrètes.",
207
- arguments: [
208
- {
209
- paragraphe_argumentatif: "L'expérience quotidienne nous confronte à des situations qui remettent en question les conclusions purement théoriques. La réalité vécue apporte une richesse d'exemples qui nuancent notre compréhension initiale."
210
- },
211
- {
212
- paragraphe_argumentatif: "Les applications contemporaines de cette réflexion philosophique montrent l'actualité et la pertinence du questionnement. Dans notre société moderne, ces enjeux prennent une dimension particulière qu'il convient d'examiner."
213
- }
214
- ]
215
- }
216
- ],
217
- conclusion: "En conclusion, cette dissertation a permis d'explorer les multiples facettes du sujet proposé. Nous avons vu que l'approche théorique, bien qu'essentielle, doit être complétée par une analyse pratique pour saisir toute la complexité de la question. Cette réflexion ouvre de nouvelles perspectives et invite à poursuivre l'investigation philosophique sur ces thèmes fondamentaux."
218
- };
219
-
220
- renderDissertation(mockData);
221
-
222
  submitBtn.disabled = false;
223
  submitBtn.textContent = 'Générer la dissertation';
224
  loader.style.display = 'none';
225
- }, 2000);
226
- }
227
 
228
  function renderDissertation(data) {
229
  let html = `
@@ -231,145 +129,65 @@
231
  <h2>Sujet : ${data.sujet}</h2>
232
  <p class="prof">Prof : ${data.prof}</p>
233
  <h3>Introduction</h3>
234
- <p class="indented">${data.introduction}</p>
235
  `;
236
-
237
- data.parties.forEach((partie, index) => {
238
  html += `<div class="development-block">`;
239
- html += `<p class="indented">${partie.chapeau}</p>`;
240
  partie.arguments.forEach(arg => {
241
- html += `<p class="indented">${arg.paragraphe_argumentatif}</p>`;
242
  });
243
  html += `</div>`;
244
-
245
  if (partie.transition) {
246
- html += `<p class="indented transition">${partie.transition}</p>`;
247
  }
248
  });
249
-
250
  html += `
251
  <h3>Conclusion</h3>
252
- <p class="indented">${data.conclusion}</p>
253
- </div>
254
- <div class="pdf-button-container">
255
- <button class="pdf-button" id="download-pdf">Télécharger en PDF</button>
256
  </div>
257
  `;
258
-
259
  resultContainer.innerHTML = html;
260
-
261
- // Stocker les données pour le PDF
262
- window.currentDissertation = data;
263
  document.getElementById('download-pdf').addEventListener('click', generatePDF);
264
  }
265
 
266
  function generatePDF() {
267
- const { jsPDF } = window.jspdf;
268
- const doc = new jsPDF();
269
-
270
- const data = window.currentDissertation;
271
- let yPosition = 20;
272
- const lineHeight = 7;
273
- const maxWidth = 180;
274
- const margin = 15;
275
 
276
- // Configuration des polices et styles
277
- doc.setFont("times", "normal");
278
- doc.setFontSize(12);
279
 
280
- // Fonction pour ajouter du texte avec retour à la ligne automatique
281
- function addText(text, x, y, fontSize = 12, style = "normal") {
282
- doc.setFontSize(fontSize);
283
- doc.setFont("times", style);
 
 
 
 
284
 
285
- const splitText = doc.splitTextToSize(text, maxWidth);
286
- doc.text(splitText, x, y);
287
- return y + (splitText.length * lineHeight);
288
- }
289
-
290
- // Fonction pour centrer du texte
291
- function addCenteredText(text, y, fontSize = 12, style = "normal") {
292
- doc.setFontSize(fontSize);
293
- doc.setFont("times", style);
294
- const textWidth = doc.getTextWidth(text);
295
- const x = (doc.internal.pageSize.width - textWidth) / 2;
296
- doc.text(text, x, y);
297
- return y + lineHeight;
298
- }
299
-
300
- // Titre
301
- yPosition = addCenteredText(`Sujet : ${data.sujet}`, yPosition, 16, "bold");
302
- yPosition += 5;
303
- yPosition = addCenteredText(`Prof : ${data.prof}`, yPosition, 10, "italic");
304
- yPosition += 10;
305
-
306
- // Introduction
307
- yPosition = addText("INTRODUCTION", margin, yPosition, 14, "bold");
308
- yPosition += 5;
309
- yPosition = addText(` ${data.introduction}`, margin, yPosition);
310
- yPosition += 10;
311
-
312
- // Parties
313
- data.parties.forEach((partie, index) => {
314
- // Vérifier si on a besoin d'une nouvelle page
315
- if (yPosition > 250) {
316
- doc.addPage();
317
- yPosition = 20;
318
- }
319
-
320
- // Chapeau de partie
321
- yPosition = addText(` ${partie.chapeau}`, margin, yPosition);
322
- yPosition += 5;
323
-
324
- // Arguments
325
- partie.arguments.forEach(arg => {
326
- if (yPosition > 250) {
327
- doc.addPage();
328
- yPosition = 20;
329
- }
330
- yPosition = addText(` ${arg.paragraphe_argumentatif}`, margin, yPosition);
331
- yPosition += 5;
332
  });
333
-
334
- // Transition
335
- if (partie.transition) {
336
- if (yPosition > 250) {
337
- doc.addPage();
338
- yPosition = 20;
339
- }
340
- yPosition = addText(` ${partie.transition}`, margin, yPosition, 12, "italic");
341
- yPosition += 10;
342
- }
343
- });
344
-
345
- // Conclusion
346
- if (yPosition > 230) {
347
- doc.addPage();
348
- yPosition = 20;
349
- }
350
- yPosition = addText("CONCLUSION", margin, yPosition, 14, "bold");
351
- yPosition += 5;
352
- yPosition = addText(` ${data.conclusion}`, margin, yPosition);
353
-
354
- // Sauvegarder le PDF
355
- doc.save('dissertation-philosophie.pdf');
356
- showSuccess("PDF généré avec succès !");
357
  }
358
 
359
  function showError(message) {
360
  resultContainer.innerHTML = `<p class="error">${message}</p>`;
361
  }
362
-
363
- function showSuccess(message) {
364
- const successDiv = document.createElement('div');
365
- successDiv.className = 'success';
366
- successDiv.textContent = message;
367
- resultContainer.appendChild(successDiv);
368
-
369
- setTimeout(() => {
370
- successDiv.remove();
371
- }, 3000);
372
- }
373
  });
374
  </script>
375
 
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Assistant de Philosophie</title>
7
 
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
9
+ <link rel="preconnect" href="https://fonts.googleapis.com">
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11
+ <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Lato:wght@400;700&display=swap" rel="stylesheet">
12
 
13
  <style>
14
  /* --- Styles Généraux et Interface --- */
15
  body {
16
+ font-family: 'Lato', sans-serif;
17
  background-color: #f4f4f9;
18
  margin: 0;
19
  padding: 20px;
 
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 {
32
+ width: 100%; padding: 10px; border-radius: 4px; border: 1px solid #ddd;
33
+ min-height: 80px; margin-bottom: 10px; font-size: 16px; box-sizing: border-box;
 
 
 
 
 
 
34
  }
35
  button {
36
+ display: block; width: 100%; padding: 15px; background-color: #2980b9;
37
+ color: white; border: none; border-radius: 5px; font-size: 18px;
38
+ cursor: pointer; transition: background-color 0.3s;
 
 
 
 
 
 
 
39
  }
40
  button:hover { background-color: #3498db; }
41
  button:disabled { background-color: #95a5a6; cursor: not-allowed; }
42
 
43
  .loader {
44
+ display: none; border: 8px solid #f3f3f3; border-top: 8px solid #3498db;
45
+ border-radius: 50%; width: 50px; height: 50px;
46
+ animation: spin 1s linear infinite; margin: 20px auto;
 
 
 
 
 
47
  }
48
  @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
49
+ .error { color: #c0392b; text-align: center; margin-top: 20px; font-weight: bold; }
 
50
 
51
  /* --- Styles du Rendu "Cahier" --- */
52
  .dissertation-paper {
53
+ font-family: 'Kalam', cursive; font-size: 20px; color: #1a2a4c;
54
+ background-color: #fdfaf4; line-height: 1.8;
55
+ background-image: linear-gradient(transparent 97%, #d8e2ee 98%);
56
+ background-size: 100% 36px;
57
+ border-left: 2px solid #ffaaab; padding-left: 4em;
 
 
58
  margin: 40px -30px -30px -30px;
59
+ padding-top: 30px; padding-bottom: 30px; padding-right: 30px;
60
+ }
61
+ .dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.8em; }
62
+ .dissertation-paper h3 { font-size: 1.2em; margin-top: 3.6em; margin-bottom: 1.8em; text-transform: uppercase; text-decoration: underline; }
63
+ .dissertation-paper .development-block { margin-top: 3.6em; }
64
+ .dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
65
+ .dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 1.8em; }
66
+ .dissertation-paper .indented { text-indent: 3em; }
67
+ .dissertation-paper .transition { margin-top: 1.8em; margin-bottom: 1.8em; font-style: italic; color: #4a6a9c; }
68
+ .dissertation-paper .pdf-button-container { text-align: center; margin-top: 3.6em; }
69
+ .dissertation-paper .pdf-button { font-family: 'Lato', sans-serif; font-size: 16px; padding: 10px 20px; width: auto; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  </style>
71
  </head>
72
  <body>
 
92
  form.addEventListener('submit', async (event) => {
93
  event.preventDefault();
94
  const question = document.getElementById('question').value.trim();
 
95
  if (!question) {
96
  showError("Veuillez entrer un sujet de dissertation.");
97
  return;
98
  }
99
 
 
 
 
 
100
  submitBtn.disabled = true;
101
  submitBtn.textContent = 'Génération en cours...';
102
  loader.style.display = 'block';
103
  resultContainer.innerHTML = '';
104
 
105
+ try {
106
+ const response = await fetch('/api/generate_dissertation', {
107
+ method: 'POST',
108
+ headers: { 'Content-Type': 'application/json' },
109
+ body: JSON.stringify({ question: question })
110
+ });
111
+ if (!response.ok) {
112
+ const errorData = await response.json();
113
+ throw new Error(errorData.error || "Une erreur inconnue est survenue.");
114
+ }
115
+ const data = await response.json();
116
+ renderDissertation(data);
117
+ } catch (error) {
118
+ showError(error.message);
119
+ } finally {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  submitBtn.disabled = false;
121
  submitBtn.textContent = 'Générer la dissertation';
122
  loader.style.display = 'none';
123
+ }
124
+ });
125
 
126
  function renderDissertation(data) {
127
  let html = `
 
129
  <h2>Sujet : ${data.sujet}</h2>
130
  <p class="prof">Prof : ${data.prof}</p>
131
  <h3>Introduction</h3>
132
+ <p class="indented">${data.introduction.replace(/\n/g, '<br>')}</p>
133
  `;
134
+ data.parties.forEach((partie) => {
 
135
  html += `<div class="development-block">`;
136
+ html += `<p class="indented">${partie.chapeau.replace(/\n/g, '<br>')}</p>`;
137
  partie.arguments.forEach(arg => {
138
+ html += `<p class="indented">${arg.paragraphe_argumentatif.replace(/\n/g, '<br>')}</p>`;
139
  });
140
  html += `</div>`;
 
141
  if (partie.transition) {
142
+ html += `<p class="indented transition">${partie.transition.replace(/\n/g, '<br>')}</p>`;
143
  }
144
  });
 
145
  html += `
146
  <h3>Conclusion</h3>
147
+ <p class="indented">${data.conclusion.replace(/\n/g, '<br>')}</p>
148
+ <div class="pdf-button-container">
149
+ <button class="pdf-button" id="download-pdf">Télécharger en PDF</button>
150
+ </div>
151
  </div>
152
  `;
 
153
  resultContainer.innerHTML = html;
 
 
 
154
  document.getElementById('download-pdf').addEventListener('click', generatePDF);
155
  }
156
 
157
  function generatePDF() {
158
+ const element = document.getElementById('dissertation-content');
159
+ const pdfButtonContainer = element.querySelector('.pdf-button-container');
160
+ const pdfButton = element.querySelector('.pdf-button');
 
 
 
 
 
161
 
162
+ pdfButton.textContent = 'Préparation du PDF...';
163
+ pdfButton.disabled = true;
 
164
 
165
+ setTimeout(() => {
166
+ pdfButtonContainer.style.display = 'none';
167
+ const options = {
168
+ margin: [0.5, 0.5, 0.5, 0.5], filename: 'dissertation-philosophie.pdf',
169
+ image: { type: 'jpeg', quality: 0.98 },
170
+ html2canvas: { scale: 2, useCORS: true },
171
+ jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
172
+ };
173
 
174
+ html2pdf().set(options).from(element).save().then(() => {
175
+ pdfButtonContainer.style.display = 'block';
176
+ pdfButton.textContent = 'Télécharger en PDF';
177
+ pdfButton.disabled = false;
178
+ }).catch((err) => {
179
+ console.error("Erreur lors de la génération du PDF :", err);
180
+ showError("Une erreur est survenue lors de la création du PDF.");
181
+ pdfButtonContainer.style.display = 'block';
182
+ pdfButton.textContent = 'Télécharger en PDF';
183
+ pdfButton.disabled = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  });
185
+ }, 100);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  }
187
 
188
  function showError(message) {
189
  resultContainer.innerHTML = `<p class="error">${message}</p>`;
190
  }
 
 
 
 
 
 
 
 
 
 
 
191
  });
192
  </script>
193