Docfile commited on
Commit
81b0eb8
·
verified ·
1 Parent(s): 90ca3fe

Update templates/philosophie.html

Browse files
Files changed (1) hide show
  1. templates/philosophie.html +40 -71
templates/philosophie.html CHANGED
@@ -14,9 +14,9 @@
14
 
15
  <style>
16
  :root {
17
- --primary-color: #4f46e5; /* Indigo */
18
  --primary-hover: #4338ca;
19
- --text-color: #374151; /* Gris foncé */
20
  --background-color: #f8f9fa;
21
  --container-bg: #ffffff;
22
  --border-color: #e5e7eb;
@@ -41,18 +41,8 @@
41
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
42
  }
43
 
44
- h1 {
45
- text-align: center;
46
- color: #111827;
47
- margin-bottom: 0.5em;
48
- }
49
-
50
- .type-indicator {
51
- text-align: center;
52
- color: #6b7280;
53
- font-size: 1.1em;
54
- margin-bottom: 2em;
55
- }
56
 
57
  textarea {
58
  width: 100%;
@@ -74,7 +64,6 @@
74
 
75
  button {
76
  display: block;
77
- box-sizing: border-box;
78
  width: 100%;
79
  padding: 16px;
80
  background-color: var(--primary-color);
@@ -96,20 +85,6 @@
96
  background-color: #9ca3af;
97
  cursor: not-allowed;
98
  }
99
-
100
- /* Style pour le bouton de téléchargement */
101
- .download-container {
102
- margin-top: 15px;
103
- }
104
- .secondary-button {
105
- background-color: #f3f4f6; /* Gris clair */
106
- color: #374151; /* Texte foncé */
107
- border: 1px solid #d1d5db; /* Bordure subtile */
108
- }
109
- .secondary-button:hover:not(:disabled) {
110
- background-color: #e5e7eb; /* Gris plus foncé au survol */
111
- border-color: #9ca3af;
112
- }
113
 
114
  .loader {
115
  display: block;
@@ -133,7 +108,16 @@
133
  font-weight: bold;
134
  }
135
 
136
- /* Styles de la feuille de dissertation */
 
 
 
 
 
 
 
 
 
137
  .dissertation-paper {
138
  font-family: 'Kalam', cursive;
139
  font-size: 20px;
@@ -143,23 +127,16 @@
143
  background-image: linear-gradient(transparent 97%, #d8e2ee 98%);
144
  background-size: 100% 40px;
145
  border-left: 3px solid #ffaaab;
146
- padding-left: 4em;
147
- margin: 40px -40px -40px -40px;
148
- padding-top: 30px;
149
- padding-bottom: 40px;
150
- padding-right: 30px;
151
  -webkit-print-color-adjust: exact;
152
  print-color-adjust: exact;
153
  }
154
  .dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.5em; }
155
  .dissertation-paper h3 { font-size: 1.2em; margin-top: 3em; margin-bottom: 1.5em; text-transform: uppercase; text-decoration: underline; }
156
- .dissertation-paper .development-block { margin-top: 3em; }
157
  .dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
158
  .dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 2em; }
159
  .dissertation-paper .indented { text-indent: 3em; }
160
- .dissertation-paper .transition { margin-top: 2em; margin-bottom: 2em; font-style: italic; color: #4a6a9c; }
161
- .dissertation-paper, .dissertation-paper * { box-sizing: border-box; }
162
-
163
  .avoid-page-break { page-break-inside: avoid; break-inside: avoid; }
164
  </style>
165
  </head>
@@ -168,31 +145,25 @@
168
  <h1>Assistant de Dissertation Philosophique</h1>
169
  <p class="type-indicator">Type 1</p>
170
 
171
- <form @submit.prevent="generateDissertation">
 
172
  <textarea v-model="question" placeholder="Entrez votre sujet de dissertation ici..."></textarea>
173
  <button type="submit" :disabled="isLoading">
174
- [[ isLoading ? 'Génération en cours...' : 'Générer la dissertation' ]]
175
  </button>
176
  </form>
177
 
178
- <!-- NOUVEL EMPLACEMENT DU BOUTON PDF -->
179
- <div v-if="dissertation" class="download-container" data-html2canvas-ignore="true">
180
- <button class="secondary-button" @click="generatePDF">Télécharger la dissertation en PDF</button>
181
- </div>
182
-
183
  <div v-if="isLoading" class="loader"></div>
184
  <p v-if="errorMessage" class="error">[[ errorMessage ]]</p>
185
 
186
- <div v-if="dissertation" id="dissertation-content" class="dissertation-paper">
187
-
188
  <h2>Sujet : [[ dissertation.sujet ]]</h2>
189
  <p class="prof">Prof : [[ dissertation.prof ]]</p>
190
-
191
  <h3>Introduction</h3>
192
  <p class="indented">[[ dissertation.introduction ]]</p>
193
-
194
  <div v-for="partie in dissertation.parties" :key="partie.chapeau" class="avoid-page-break">
195
- <div class="development-block">
196
  <p class="indented">[[ partie.chapeau ]]</p>
197
  <p v-for="(arg, idx) in partie.arguments" :key="idx" class="indented">
198
  [[ arg.paragraphe_argumentatif ]]
@@ -200,10 +171,8 @@
200
  </div>
201
  <p v-if="partie.transition" class="indented transition">[[ partie.transition ]]</p>
202
  </div>
203
-
204
  <h3>Conclusion</h3>
205
  <p class="indented">[[ dissertation.conclusion ]]</p>
206
-
207
  </div>
208
  </div>
209
 
@@ -216,11 +185,11 @@
216
  question: '',
217
  isLoading: false,
218
  errorMessage: null,
219
- dissertation: null
220
  }
221
  },
222
  methods: {
223
- async generateDissertation() {
224
  if (!this.question.trim()) {
225
  this.errorMessage = "Veuillez entrer un sujet de dissertation.";
226
  return;
@@ -228,7 +197,9 @@
228
  this.isLoading = true;
229
  this.errorMessage = null;
230
  this.dissertation = null;
 
231
  try {
 
232
  const response = await fetch('/api/generate_dissertation', {
233
  method: 'POST',
234
  headers: { 'Content-Type': 'application/json' },
@@ -239,50 +210,48 @@
239
  throw new Error(data.error || "Une erreur inconnue est survenue.");
240
  }
241
  this.dissertation = data;
 
 
 
 
 
 
 
242
  } catch (error) {
243
  this.errorMessage = error.message;
244
  } finally {
245
  this.isLoading = false;
 
 
246
  }
247
  },
248
 
249
  async generatePDF() {
250
  const element = document.getElementById('dissertation-content');
251
- if (!element) {
252
- this.errorMessage = "Contenu introuvable pour le PDF.";
253
- return;
254
- }
255
  try {
256
- if (document.fonts && document.fonts.ready) {
257
- await document.fonts.ready;
258
- }
259
  window.scrollTo(0, 0);
260
 
261
  const options = {
262
  margin: [15, 15, 15, 15],
263
  filename: 'dissertation-philosophie.pdf',
264
  image: { type: 'jpeg', quality: 0.98 },
265
- html2canvas: {
266
- scale: 2,
267
- useCORS: true,
268
- logging: true,
269
- backgroundColor: null,
270
- },
271
  jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
272
  };
273
 
274
  await html2pdf().set(options).from(element).save();
275
  } catch (err) {
276
  console.error('Erreur html2pdf:', err);
277
- this.errorMessage = "Erreur lors de la génération du PDF. Voir la console pour les détails.";
278
  }
279
  }
280
  }
281
  });
282
 
283
- // ⚠️ Changer les délimiteurs pour éviter le conflit avec Jinja2
284
  app.config.compilerOptions.delimiters = ['[[', ']]'];
285
-
286
  app.mount('#app');
287
  </script>
288
  </body>
 
14
 
15
  <style>
16
  :root {
17
+ --primary-color: #4f46e5;
18
  --primary-hover: #4338ca;
19
+ --text-color: #374151;
20
  --background-color: #f8f9fa;
21
  --container-bg: #ffffff;
22
  --border-color: #e5e7eb;
 
41
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
42
  }
43
 
44
+ h1 { text-align: center; color: #111827; margin-bottom: 0.5em; }
45
+ .type-indicator { text-align: center; color: #6b7280; font-size: 1.1em; margin-bottom: 2em; }
 
 
 
 
 
 
 
 
 
 
46
 
47
  textarea {
48
  width: 100%;
 
64
 
65
  button {
66
  display: block;
 
67
  width: 100%;
68
  padding: 16px;
69
  background-color: var(--primary-color);
 
85
  background-color: #9ca3af;
86
  cursor: not-allowed;
87
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  .loader {
90
  display: block;
 
108
  font-weight: bold;
109
  }
110
 
111
+ /* --- NOUVEAU : Style pour cacher le contenu --- */
112
+ /* On le rend, mais on le place hors de l'écran pour que html2pdf puisse le lire */
113
+ .hidden-for-pdf {
114
+ position: absolute;
115
+ left: -9999px;
116
+ top: -9999px;
117
+ width: 800px; /* Largeur fixe pour aider au rendu PDF */
118
+ }
119
+
120
+ /* Styles de la feuille de dissertation (conservés pour le rendu PDF) */
121
  .dissertation-paper {
122
  font-family: 'Kalam', cursive;
123
  font-size: 20px;
 
127
  background-image: linear-gradient(transparent 97%, #d8e2ee 98%);
128
  background-size: 100% 40px;
129
  border-left: 3px solid #ffaaab;
130
+ padding: 30px 30px 40px 4em;
 
 
 
 
131
  -webkit-print-color-adjust: exact;
132
  print-color-adjust: exact;
133
  }
134
  .dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.5em; }
135
  .dissertation-paper h3 { font-size: 1.2em; margin-top: 3em; margin-bottom: 1.5em; text-transform: uppercase; text-decoration: underline; }
 
136
  .dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
137
  .dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 2em; }
138
  .dissertation-paper .indented { text-indent: 3em; }
139
+ .dissertation-paper .transition { margin: 2em 0; font-style: italic; color: #4a6a9c; }
 
 
140
  .avoid-page-break { page-break-inside: avoid; break-inside: avoid; }
141
  </style>
142
  </head>
 
145
  <h1>Assistant de Dissertation Philosophique</h1>
146
  <p class="type-indicator">Type 1</p>
147
 
148
+ <!-- Le formulaire appelle maintenant la nouvelle méthode -->
149
+ <form @submit.prevent="generateAndDownloadPDF">
150
  <textarea v-model="question" placeholder="Entrez votre sujet de dissertation ici..."></textarea>
151
  <button type="submit" :disabled="isLoading">
152
+ [[ isLoading ? 'Génération en cours...' : 'Générer et Télécharger en PDF' ]]
153
  </button>
154
  </form>
155
 
 
 
 
 
 
156
  <div v-if="isLoading" class="loader"></div>
157
  <p v-if="errorMessage" class="error">[[ errorMessage ]]</p>
158
 
159
+ <!-- CE BLOC SERA RENDU MAIS RESTERA INVISIBLE POUR L'UTILISATEUR -->
160
+ <div v-if="dissertation" id="dissertation-content" class="dissertation-paper hidden-for-pdf">
161
  <h2>Sujet : [[ dissertation.sujet ]]</h2>
162
  <p class="prof">Prof : [[ dissertation.prof ]]</p>
 
163
  <h3>Introduction</h3>
164
  <p class="indented">[[ dissertation.introduction ]]</p>
 
165
  <div v-for="partie in dissertation.parties" :key="partie.chapeau" class="avoid-page-break">
166
+ <div>
167
  <p class="indented">[[ partie.chapeau ]]</p>
168
  <p v-for="(arg, idx) in partie.arguments" :key="idx" class="indented">
169
  [[ arg.paragraphe_argumentatif ]]
 
171
  </div>
172
  <p v-if="partie.transition" class="indented transition">[[ partie.transition ]]</p>
173
  </div>
 
174
  <h3>Conclusion</h3>
175
  <p class="indented">[[ dissertation.conclusion ]]</p>
 
176
  </div>
177
  </div>
178
 
 
185
  question: '',
186
  isLoading: false,
187
  errorMessage: null,
188
+ dissertation: null // Toujours nécessaire pour stocker les données temporairement
189
  }
190
  },
191
  methods: {
192
+ async generateAndDownloadPDF() {
193
  if (!this.question.trim()) {
194
  this.errorMessage = "Veuillez entrer un sujet de dissertation.";
195
  return;
 
197
  this.isLoading = true;
198
  this.errorMessage = null;
199
  this.dissertation = null;
200
+
201
  try {
202
+ // 1. Récupérer les données de la dissertation
203
  const response = await fetch('/api/generate_dissertation', {
204
  method: 'POST',
205
  headers: { 'Content-Type': 'application/json' },
 
210
  throw new Error(data.error || "Une erreur inconnue est survenue.");
211
  }
212
  this.dissertation = data;
213
+
214
+ // 2. Attendre que Vue mette à jour le DOM avec le contenu caché
215
+ await this.$nextTick();
216
+
217
+ // 3. Générer le PDF à partir du contenu maintenant présent (mais caché)
218
+ await this.generatePDF();
219
+
220
  } catch (error) {
221
  this.errorMessage = error.message;
222
  } finally {
223
  this.isLoading = false;
224
+ // 4. (Optionnel) Nettoyer les données pour retirer l'élément caché du DOM
225
+ this.dissertation = null;
226
  }
227
  },
228
 
229
  async generatePDF() {
230
  const element = document.getElementById('dissertation-content');
231
+ if (!element) return; // Pas d'erreur visible si l'élément est introuvable
232
+
 
 
233
  try {
234
+ await document.fonts.ready;
 
 
235
  window.scrollTo(0, 0);
236
 
237
  const options = {
238
  margin: [15, 15, 15, 15],
239
  filename: 'dissertation-philosophie.pdf',
240
  image: { type: 'jpeg', quality: 0.98 },
241
+ html2canvas: { scale: 2, useCORS: true, backgroundColor: null },
 
 
 
 
 
242
  jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
243
  };
244
 
245
  await html2pdf().set(options).from(element).save();
246
  } catch (err) {
247
  console.error('Erreur html2pdf:', err);
248
+ this.errorMessage = "Erreur lors de la génération du PDF. Voir la console.";
249
  }
250
  }
251
  }
252
  });
253
 
 
254
  app.config.compilerOptions.delimiters = ['[[', ']]'];
 
255
  app.mount('#app');
256
  </script>
257
  </body>