Docfile commited on
Commit
be583ae
·
verified ·
1 Parent(s): a8ee996

Update templates/philosophie.html

Browse files
Files changed (1) hide show
  1. templates/philosophie.html +175 -127
templates/philosophie.html CHANGED
@@ -1,141 +1,189 @@
1
  <!DOCTYPE html>
2
  <html lang="fr">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Assistant de Philosophie (Vue.js)</title>
7
-
8
- <script src="https://unpkg.com/vue@3"></script>
9
- <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
10
-
11
- <link rel="preconnect" href="https://fonts.googleapis.com">
12
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
13
- <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Lato:wght@400;700&display=swap" rel="stylesheet">
14
-
15
- <style>
16
- /* Les styles CSS restent identiques, pas besoin de les modifier */
17
- body { font-family: 'Lato', sans-serif; background-color: #f4f4f9; margin: 0; padding: 20px; color: #333; }
18
- .container { max-width: 900px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
19
- h1 { text-align: center; color: #2c3e50; }
20
- textarea { width: 100%; padding: 10px; border-radius: 4px; border: 1px solid #ddd; min-height: 80px; margin-bottom: 10px; font-size: 16px; }
21
- 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; }
22
- button:hover { background-color: #3498db; }
23
- button:disabled { background-color: #95a5a6; cursor: not-allowed; }
24
- .loader { display: block; border: 8px solid #f3f3f3; border-top: 8px solid #3498db; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; }
25
- @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
26
- .error { color: #c0392b; text-align: center; margin-top: 20px; font-weight: bold; }
27
- .dissertation-paper { font-family: 'Kalam', cursive; font-size: 20px; color: #1a2a4c; background-color: #fdfaf4; line-height: 1.8; background-image: linear-gradient(transparent 97%, #d8e2ee 98%); background-size: 100% 36px; border-left: 2px solid #ffaaab; padding-left: 4em; margin: 40px -30px -30px -30px; padding-top: 30px; padding-bottom: 30px; padding-right: 30px; }
28
- .dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.8em; }
29
- .dissertation-paper h3 { font-size: 1.2em; margin-top: 3.6em; margin-bottom: 1.8em; text-transform: uppercase; text-decoration: underline; }
30
- .dissertation-paper .development-block { margin-top: 3.6em; }
31
- .dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
32
- .dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 1.8em; }
33
- .dissertation-paper .indented { text-indent: 3em; }
34
- .dissertation-paper .transition { margin-top: 1.8em; margin-bottom: 1.8em; font-style: italic; color: #4a6a9c; }
35
- .dissertation-paper .pdf-button-container { text-align: center; margin-top: 3.6em; }
36
- .dissertation-paper .pdf-button { font-family: 'Lato', sans-serif; font-size: 16px; padding: 10px 20px; width: auto; }
37
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  </head>
39
  <body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- <div id="app" class="container">
42
- {% raw %}
43
- <!-- Le contenu de l'application Vue commence ici -->
44
-
45
- <h1>Assistant de Dissertation Philosophique</h1>
46
-
47
- <form @submit.prevent="generateDissertation">
48
- <textarea v-model="question" placeholder="Entrez votre sujet de dissertation ici..."></textarea>
49
-
50
- <button type="submit" :disabled="isLoading">
51
- {{ isLoading ? 'Génération en cours...' : 'Générer la dissertation' }}
52
- </button>
53
- </form>
54
-
55
- <div v-if="isLoading" class="loader"></div>
56
- <p v-if="errorMessage" class="error">{{ errorMessage }}</p>
57
-
58
- <div v-if="dissertation" id="dissertation-content" class="dissertation-paper">
59
- <h2>Sujet : {{ dissertation.sujet }}</h2>
60
- <p class="prof">Prof : {{ dissertation.prof }}</p>
61
-
62
- <h3>Introduction</h3>
63
- <p class="indented">{{ dissertation.introduction }}</p>
64
-
65
- <div v-for="partie in dissertation.parties" :key="partie.chapeau">
66
- <div class="development-block">
67
- <p class="indented">{{ partie.chapeau }}</p>
68
- <p v-for="arg in partie.arguments" :key="arg.paragraphe_argumentatif" class="indented">
69
- {{ arg.paragraphe_argumentatif }}
70
- </p>
71
- </div>
72
- <p v-if="partie.transition" class="indented transition">{{ partie.transition }}</p>
73
- </div>
74
-
75
- <h3>Conclusion</h3>
76
- <p class="indented">{{ dissertation.conclusion }}</p>
77
-
78
- <div class="pdf-button-container" data-html2canvas-ignore="true">
79
- <button class="pdf-button" @click="generatePDF">Télécharger en PDF</button>
80
- </div>
81
  </div>
 
 
 
 
 
82
 
83
- <!-- Le contenu de l'application Vue se termine ici -->
84
- {% endraw %}
 
 
85
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
- <script>
88
- const { createApp } = Vue;
89
-
90
- createApp({
91
- data() {
92
- return {
93
- question: '',
94
- isLoading: false,
95
- errorMessage: null,
96
- dissertation: null
97
- }
98
- },
99
- methods: {
100
- async generateDissertation() {
101
- if (!this.question.trim()) {
102
- this.errorMessage = "Veuillez entrer un sujet de dissertation.";
103
- return;
104
- }
105
- this.isLoading = true;
106
- this.errorMessage = null;
107
- this.dissertation = null;
108
- try {
109
- const response = await fetch('/api/generate_dissertation', {
110
- method: 'POST',
111
- headers: { 'Content-Type': 'application/json' },
112
- body: JSON.stringify({ question: this.question })
113
- });
114
- const data = await response.json();
115
- if (!response.ok) {
116
- throw new Error(data.error || "Une erreur inconnue est survenue.");
117
- }
118
- this.dissertation = data;
119
- } catch (error) {
120
- this.errorMessage = error.message;
121
- } finally {
122
- this.isLoading = false;
123
- }
124
- },
125
- generatePDF() {
126
- const element = document.getElementById('dissertation-content');
127
- const options = {
128
- margin: [0.5, 0.5, 0.5, 0.5],
129
- filename: 'dissertation-philosophie.pdf',
130
- image: { type: 'jpeg', quality: 0.98 },
131
- html2canvas: { scale: 2, useCORS: true },
132
- jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
133
- };
134
- html2pdf().set(options).from(element).save();
135
- }
136
  }
137
- }).mount('#app');
138
- </script>
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  </body>
141
  </html>
 
1
  <!DOCTYPE html>
2
  <html lang="fr">
3
  <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6
+ <title>Assistant de Philosophie (Vue.js)</title>
7
+
8
+ <script src="https://unpkg.com/vue@3"></script>
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
10
+
11
+ <!-- Ajout du crossorigin pour aider le chargement des fonts dans html2canvas -->
12
+ <link rel="preconnect" href="https://fonts.googleapis.com">
13
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
14
+ <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Lato:wght@400;700&display=swap" rel="stylesheet" crossorigin="anonymous">
15
+
16
+ <style>
17
+ body { font-family: 'Lato', sans-serif; background-color: #f4f4f9; margin: 0; padding: 20px; color: #333; }
18
+ .container { max-width: 900px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
19
+ h1 { text-align: center; color: #2c3e50; }
20
+ textarea { width: 100%; padding: 10px; border-radius: 4px; border: 1px solid #ddd; min-height: 80px; margin-bottom: 10px; font-size: 16px; }
21
+ 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; }
22
+ button:hover { background-color: #3498db; }
23
+ button:disabled { background-color: #95a5a6; cursor: not-allowed; }
24
+ .loader { display: block; border: 8px solid #f3f3f3; border-top: 8px solid #3498db; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin: 20px auto; }
25
+ @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
26
+ .error { color: #c0392b; text-align: center; margin-top: 20px; font-weight: bold; }
27
+
28
+ /* Paper style */
29
+ .dissertation-paper {
30
+ font-family: 'Kalam', cursive;
31
+ font-size: 20px;
32
+ color: #1a2a4c;
33
+ background-color: #fdfaf4;
34
+ line-height: 1.8;
35
+ background-image: linear-gradient(transparent 97%, #d8e2ee 98%);
36
+ background-size: 100% 36px;
37
+ border-left: 2px solid #ffaaab;
38
+ padding-left: 4em;
39
+ margin: 40px -30px -30px -30px;
40
+ padding-top: 30px;
41
+ padding-bottom: 30px;
42
+ padding-right: 30px;
43
+ /* for better printing */
44
+ -webkit-print-color-adjust: exact;
45
+ print-color-adjust: exact;
46
+ -webkit-font-smoothing: antialiased;
47
+ /* Force white background for canvas capture (avoid transparent PNG-like issues) */
48
+ background-clip: padding-box;
49
+ }
50
+ .dissertation-paper h2 { font-size: 1.5em; text-align: center; margin-bottom: 1.8em; }
51
+ .dissertation-paper h3 { font-size: 1.2em; margin-top: 3.6em; margin-bottom: 1.8em; text-transform: uppercase; text-decoration: underline; }
52
+ .dissertation-paper .development-block { margin-top: 3.6em; }
53
+ .dissertation-paper p { text-align: justify; margin: 0; padding: 0; }
54
+ .dissertation-paper .prof { text-align: center; font-style: italic; margin-bottom: 1.8em; }
55
+ .dissertation-paper .indented { text-indent: 3em; }
56
+ .dissertation-paper .transition { margin-top: 1.8em; margin-bottom: 1.8em; font-style: italic; color: #4a6a9c; }
57
+ .dissertation-paper .pdf-button-container { text-align: center; margin-top: 3.6em; }
58
+ .dissertation-paper .pdf-button { font-family: 'Lato', sans-serif; font-size: 16px; padding: 10px 20px; width: auto; }
59
+
60
+ /* Evite que des blocs soient cassés au mauvais endroit */
61
+ .dissertation-paper, .dissertation-paper * { box-sizing: border-box; }
62
+ .avoid-page-break { page-break-inside: avoid; break-inside: avoid; }
63
+ </style>
64
  </head>
65
  <body>
66
+ <div id="app" class="container">
67
+ <!-- contenu Vue -->
68
+ <h1>Assistant de Dissertation Philosophique</h1>
69
+
70
+ <form @submit.prevent="generateDissertation">
71
+ <textarea v-model="question" placeholder="Entrez votre sujet de dissertation ici..."></textarea>
72
+ <button type="submit" :disabled="isLoading">
73
+ {{ isLoading ? 'Génération en cours...' : 'Générer la dissertation' }}
74
+ </button>
75
+ </form>
76
+
77
+ <div v-if="isLoading" class="loader"></div>
78
+ <p v-if="errorMessage" class="error">{{ errorMessage }}</p>
79
+
80
+ <div v-if="dissertation" id="dissertation-content" class="dissertation-paper">
81
+ <h2>Sujet : {{ dissertation.sujet }}</h2>
82
+ <p class="prof">Prof : {{ dissertation.prof }}</p>
83
 
84
+ <h3>Introduction</h3>
85
+ <p class="indented">{{ dissertation.introduction }}</p>
86
+
87
+ <div v-for="partie in dissertation.parties" :key="partie.chapeau" class="avoid-page-break">
88
+ <div class="development-block">
89
+ <p class="indented">{{ partie.chapeau }}</p>
90
+ <p v-for="(arg, idx) in partie.arguments" :key="idx" class="indented">
91
+ {{ arg.paragraphe_argumentatif }}
92
+ </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  </div>
94
+ <p v-if="partie.transition" class="indented transition">{{ partie.transition }}</p>
95
+ </div>
96
+
97
+ <h3>Conclusion</h3>
98
+ <p class="indented">{{ dissertation.conclusion }}</p>
99
 
100
+ <div class="pdf-button-container" data-html2canvas-ignore="true">
101
+ <!-- data-html2canvas-ignore empêchera le bouton d'être rendu dans le canvas -->
102
+ <button class="pdf-button" @click="generatePDF">Télécharger en PDF</button>
103
+ </div>
104
  </div>
105
+ <!-- fin contenu Vue -->
106
+ </div>
107
+
108
+ <script>
109
+ const { createApp } = Vue;
110
+
111
+ createApp({
112
+ data() {
113
+ return {
114
+ question: '',
115
+ isLoading: false,
116
+ errorMessage: null,
117
+ dissertation: null
118
+ }
119
+ },
120
+ methods: {
121
+ async generateDissertation() {
122
+ if (!this.question.trim()) {
123
+ this.errorMessage = "Veuillez entrer un sujet de dissertation.";
124
+ return;
125
+ }
126
+ this.isLoading = true;
127
+ this.errorMessage = null;
128
+ this.dissertation = null;
129
+ try {
130
+ const response = await fetch('/api/generate_dissertation', {
131
+ method: 'POST',
132
+ headers: { 'Content-Type': 'application/json' },
133
+ body: JSON.stringify({ question: this.question })
134
+ });
135
+ const data = await response.json();
136
+ if (!response.ok) {
137
+ throw new Error(data.error || "Une erreur inconnue est survenue.");
138
+ }
139
+ this.dissertation = data;
140
+ // petit timeout facultatif pour s'assurer que le DOM est posé
141
+ await new Promise(r => setTimeout(r, 50));
142
+ } catch (error) {
143
+ this.errorMessage = error.message;
144
+ } finally {
145
+ this.isLoading = false;
146
+ }
147
+ },
148
+
149
+ async generatePDF() {
150
+ const element = document.getElementById('dissertation-content');
151
+ if (!element) {
152
+ this.errorMessage = "Contenu introuvable pour le PDF.";
153
+ return;
154
+ }
155
 
156
+ try {
157
+ // attendre que les polices web soient chargées (important pour html2canvas)
158
+ if (document.fonts && document.fonts.ready) {
159
+ await document.fonts.ready;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  }
 
 
161
 
162
+ // mettre la page en haut (prévenir offset / découpage)
163
+ window.scrollTo(0, 0);
164
+
165
+ const options = {
166
+ margin: [10, 10, 10, 10], // mm
167
+ filename: 'dissertation-philosophie.pdf',
168
+ image: { type: 'jpeg', quality: 0.98 },
169
+ html2canvas: {
170
+ scale: 2,
171
+ useCORS: true,
172
+ logging: true,
173
+ backgroundColor: '#ffffff' // important si l'élément a un fond semi-transparent
174
+ },
175
+ jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
176
+ };
177
+
178
+ // génération
179
+ await html2pdf().set(options).from(element).save();
180
+ } catch (err) {
181
+ console.error('Erreur html2pdf:', err);
182
+ this.errorMessage = "Erreur lors de la génération du PDF. Vérifiez la console pour plus de détails (CORS / ressources externes).";
183
+ }
184
+ }
185
+ }
186
+ }).mount('#app');
187
+ </script>
188
  </body>
189
  </html>