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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Philosophie</title>
|
7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.all.min.js"></script>
|
9 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
|
10 |
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.min.css" rel="stylesheet">
|
11 |
+
<style>
|
12 |
+
.container {
|
13 |
+
max-width: 800px;
|
14 |
+
margin: 0 auto;
|
15 |
+
padding: 20px;
|
16 |
+
}
|
17 |
+
.card {
|
18 |
+
background: white;
|
19 |
+
border-radius: 8px;
|
20 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
21 |
+
padding: 20px;
|
22 |
+
}
|
23 |
+
.form-group {
|
24 |
+
margin-bottom: 20px;
|
25 |
+
}
|
26 |
+
.btn {
|
27 |
+
padding: 10px 20px;
|
28 |
+
border: none;
|
29 |
+
border-radius: 4px;
|
30 |
+
cursor: pointer;
|
31 |
+
margin-right: 10px;
|
32 |
+
font-weight: bold;
|
33 |
+
}
|
34 |
+
.btn-primary {
|
35 |
+
background-color: #4A90E2;
|
36 |
+
color: white;
|
37 |
+
}
|
38 |
+
.btn-secondary {
|
39 |
+
background-color: #6c757d;
|
40 |
+
color: white;
|
41 |
+
}
|
42 |
+
.btn-success {
|
43 |
+
background-color: #28a745;
|
44 |
+
color: white;
|
45 |
+
}
|
46 |
+
.select-wrapper {
|
47 |
+
margin-bottom: 20px;
|
48 |
+
}
|
49 |
+
select, textarea {
|
50 |
+
width: 100%;
|
51 |
+
padding: 8px;
|
52 |
+
border: 1px solid #ddd;
|
53 |
+
border-radius: 4px;
|
54 |
+
margin-top: 5px;
|
55 |
+
}
|
56 |
+
.hidden {
|
57 |
+
display: none;
|
58 |
+
}
|
59 |
+
#loader {
|
60 |
+
text-align: center;
|
61 |
+
padding: 20px;
|
62 |
+
}
|
63 |
+
#response {
|
64 |
+
margin-top: 20px;
|
65 |
+
padding: 15px;
|
66 |
+
background: #f8f9fa;
|
67 |
+
border-radius: 4px;
|
68 |
+
line-height: 1.6;
|
69 |
+
}
|
70 |
+
.course-info {
|
71 |
+
margin-top: 10px;
|
72 |
+
font-size: 0.9em;
|
73 |
+
color: #666;
|
74 |
+
}
|
75 |
+
.course-meta {
|
76 |
+
display: flex;
|
77 |
+
justify-content: space-between;
|
78 |
+
margin-bottom: 10px;
|
79 |
+
padding: 5px;
|
80 |
+
background: #f8f9fa;
|
81 |
+
border-radius: 4px;
|
82 |
+
}
|
83 |
+
.type-label {
|
84 |
+
background: #4A90E2;
|
85 |
+
color: white;
|
86 |
+
padding: 5px 10px;
|
87 |
+
border-radius: 4px;
|
88 |
+
margin-bottom: 15px;
|
89 |
+
display: inline-block;
|
90 |
+
}
|
91 |
+
|
92 |
+
/* Styles Markdown */
|
93 |
+
#response h1 {
|
94 |
+
font-size: 2em;
|
95 |
+
margin-bottom: 0.5em;
|
96 |
+
border-bottom: 2px solid #eee;
|
97 |
+
padding-bottom: 0.3em;
|
98 |
+
}
|
99 |
+
#response h2 {
|
100 |
+
font-size: 1.5em;
|
101 |
+
margin-bottom: 0.5em;
|
102 |
+
border-bottom: 1px solid #eee;
|
103 |
+
padding-bottom: 0.3em;
|
104 |
+
}
|
105 |
+
#response h3 {
|
106 |
+
font-size: 1.3em;
|
107 |
+
margin-bottom: 0.5em;
|
108 |
+
}
|
109 |
+
#response p {
|
110 |
+
margin-bottom: 1em;
|
111 |
+
}
|
112 |
+
#response ul, #response ol {
|
113 |
+
margin-bottom: 1em;
|
114 |
+
padding-left: 2em;
|
115 |
+
}
|
116 |
+
#response li {
|
117 |
+
margin-bottom: 0.5em;
|
118 |
+
}
|
119 |
+
#response blockquote {
|
120 |
+
border-left: 4px solid #ddd;
|
121 |
+
padding-left: 1em;
|
122 |
+
margin-left: 0;
|
123 |
+
color: #666;
|
124 |
+
}
|
125 |
+
#response code {
|
126 |
+
background-color: #f5f5f5;
|
127 |
+
padding: 0.2em 0.4em;
|
128 |
+
border-radius: 3px;
|
129 |
+
font-family: monospace;
|
130 |
+
}
|
131 |
+
#response pre {
|
132 |
+
background-color: #f5f5f5;
|
133 |
+
padding: 1em;
|
134 |
+
border-radius: 4px;
|
135 |
+
overflow-x: auto;
|
136 |
+
margin-bottom: 1em;
|
137 |
+
}
|
138 |
+
#response pre code {
|
139 |
+
background-color: transparent;
|
140 |
+
padding: 0;
|
141 |
+
}
|
142 |
+
#response table {
|
143 |
+
border-collapse: collapse;
|
144 |
+
width: 100%;
|
145 |
+
margin-bottom: 1em;
|
146 |
+
}
|
147 |
+
#response th, #response td {
|
148 |
+
border: 1px solid #ddd;
|
149 |
+
padding: 8px;
|
150 |
+
text-align: left;
|
151 |
+
}
|
152 |
+
#response th {
|
153 |
+
background-color: #f5f5f5;
|
154 |
+
}
|
155 |
+
#response img {
|
156 |
+
max-width: 100%;
|
157 |
+
height: auto;
|
158 |
+
}
|
159 |
+
#response hr {
|
160 |
+
border: none;
|
161 |
+
border-top: 1px solid #ddd;
|
162 |
+
margin: 1em 0;
|
163 |
+
}
|
164 |
+
</style>
|
165 |
+
</head>
|
166 |
+
<body>
|
167 |
+
<div class="container">
|
168 |
+
<div class="card">
|
169 |
+
<h1 class="text-3xl font-bold text-gray-800">Philosophie</h1>
|
170 |
+
|
171 |
+
<!-- Sélection du type de dissertation -->
|
172 |
+
<div class="form-group">
|
173 |
+
<label for="type-select">Type de dissertation :</label>
|
174 |
+
<select id="type-select" class="form-control">
|
175 |
+
<option value="1">Type 1 </option>
|
176 |
+
<option value="2">Type 2 </option>
|
177 |
+
</select>
|
178 |
+
</div>
|
179 |
+
|
180 |
+
<div class="type-label" id="current-type-label">Sujet de type 1</div>
|
181 |
+
|
182 |
+
<!-- Sélection du cours -->
|
183 |
+
<div class="form-group">
|
184 |
+
<label for="course-select">Sélectionner un cours :</label>
|
185 |
+
<select id="course-select" class="form-control">
|
186 |
+
<option value="">Choisir un cours...</option>
|
187 |
+
</select>
|
188 |
+
<div class="course-info">
|
189 |
+
<div class="course-meta hidden">
|
190 |
+
<span id="course-author"></span>
|
191 |
+
<span id="course-date"></span>
|
192 |
+
</div>
|
193 |
+
</div>
|
194 |
+
</div>
|
195 |
+
|
196 |
+
<!-- Zone de texte pour la question -->
|
197 |
+
<div class="form-group">
|
198 |
+
<label for="question">Entrez juste le sujet :</label>
|
199 |
+
<textarea id="question" rows="4" class="form-control"></textarea>
|
200 |
+
</div>
|
201 |
+
|
202 |
+
<!-- Bouton de soumission -->
|
203 |
+
<button id="submit-btn" class="btn btn-success">Soumettre</button>
|
204 |
+
|
205 |
+
<!-- Loader -->
|
206 |
+
<div id="loader" class="hidden">
|
207 |
+
Chargement en cours...
|
208 |
+
</div>
|
209 |
+
|
210 |
+
<!-- Zone de réponse -->
|
211 |
+
<div id="response" class="hidden"></div>
|
212 |
+
|
213 |
+
<!-- Bouton de copie -->
|
214 |
+
<button id="copy-btn" class="btn btn-secondary hidden">Copier la réponse</button>
|
215 |
+
</div>
|
216 |
+
</div>
|
217 |
+
|
218 |
+
<script>
|
219 |
+
$(document).ready(function() {
|
220 |
+
// Configuration de marked
|
221 |
+
marked.setOptions({
|
222 |
+
breaks: true,
|
223 |
+
gfm: true,
|
224 |
+
headerIds: true,
|
225 |
+
langPrefix: 'language-'
|
226 |
+
});
|
227 |
+
|
228 |
+
// Configuration des toasts SweetAlert2
|
229 |
+
const Toast = Swal.mixin({
|
230 |
+
toast: true,
|
231 |
+
position: 'top-end',
|
232 |
+
showConfirmButton: false,
|
233 |
+
timer: 3000,
|
234 |
+
timerProgressBar: true
|
235 |
+
});
|
236 |
+
|
237 |
+
// Gestion du changement de type
|
238 |
+
$('#type-select').change(function() {
|
239 |
+
const type = $(this).val();
|
240 |
+
$('#current-type-label').text(`Sujet de type ${type}`);
|
241 |
+
});
|
242 |
+
|
243 |
+
// Charger les cours depuis la base de données
|
244 |
+
$.ajax({
|
245 |
+
url: '/api/philosophy/courses',
|
246 |
+
method: 'GET',
|
247 |
+
success: function(courses) {
|
248 |
+
const select = $('#course-select');
|
249 |
+
courses.forEach(course => {
|
250 |
+
select.append(`<option value="${course.id}">${course.title}</option>`);
|
251 |
+
});
|
252 |
+
},
|
253 |
+
error: function() {
|
254 |
+
Toast.fire({
|
255 |
+
icon: 'error',
|
256 |
+
title: 'Erreur lors du chargement des cours'
|
257 |
+
});
|
258 |
+
}
|
259 |
+
});
|
260 |
+
|
261 |
+
// Gestion du changement de cours
|
262 |
+
$('#course-select').change(function() {
|
263 |
+
const courseId = $(this).val();
|
264 |
+
if (courseId) {
|
265 |
+
$.ajax({
|
266 |
+
url: `/api/philosophy/courses/${courseId}`,
|
267 |
+
method: 'GET',
|
268 |
+
success: function(course) {
|
269 |
+
$('.course-meta').removeClass('hidden');
|
270 |
+
$('#course-author').text(`Professeur: ${course.author}`);
|
271 |
+
$('#course-date').text(`Mis à jour: ${new Date(course.updated_at).toLocaleDateString()}`);
|
272 |
+
|
273 |
+
Toast.fire({
|
274 |
+
icon: 'success',
|
275 |
+
title: 'Cours chargé avec succès'
|
276 |
+
});
|
277 |
+
},
|
278 |
+
error: function() {
|
279 |
+
Toast.fire({
|
280 |
+
icon: 'error',
|
281 |
+
title: 'Erreur lors du chargement des détails du cours'
|
282 |
+
});
|
283 |
+
}
|
284 |
+
});
|
285 |
+
} else {
|
286 |
+
$('.course-meta').addClass('hidden');
|
287 |
+
}
|
288 |
+
});
|
289 |
+
|
290 |
+
// Gestion de la soumission
|
291 |
+
$('#submit-btn').click(function() {
|
292 |
+
const question = $('#question').val().trim();
|
293 |
+
const type = $('#type-select').val();
|
294 |
+
|
295 |
+
if (!question) {
|
296 |
+
Swal.fire({
|
297 |
+
icon: 'warning',
|
298 |
+
title: 'Attention',
|
299 |
+
text: 'Veuillez saisir une question.'
|
300 |
+
});
|
301 |
+
return;
|
302 |
+
}
|
303 |
+
|
304 |
+
Swal.fire({
|
305 |
+
title: 'Generation en cours',
|
306 |
+
html: 'Veuillez patienter...',
|
307 |
+
allowOutsideClick: false,
|
308 |
+
didOpen: () => {
|
309 |
+
Swal.showLoading();
|
310 |
+
}
|
311 |
+
});
|
312 |
+
|
313 |
+
// Préparation des données
|
314 |
+
const data = {
|
315 |
+
question: question,
|
316 |
+
type: type
|
317 |
+
};
|
318 |
+
|
319 |
+
// Ajout du courseId seulement s'il est sélectionné
|
320 |
+
const courseId = $('#course-select').val();
|
321 |
+
if (courseId) {
|
322 |
+
data.courseId = courseId;
|
323 |
+
}
|
324 |
+
|
325 |
+
$.ajax({
|
326 |
+
url: '/submit_philo',
|
327 |
+
method: 'POST',
|
328 |
+
contentType: 'application/json',
|
329 |
+
data: JSON.stringify(data),
|
330 |
+
success: function(data) {
|
331 |
+
Swal.close();
|
332 |
+
// Conversion du Markdown en HTML
|
333 |
+
const htmlContent = marked.parse(data.response);
|
334 |
+
$('#response').html(htmlContent).removeClass('hidden');
|
335 |
+
$('#copy-btn').removeClass('hidden');
|
336 |
+
|
337 |
+
Toast.fire({
|
338 |
+
icon: 'success',
|
339 |
+
title: 'Réponse générée avec succès'
|
340 |
+
});
|
341 |
+
},
|
342 |
+
error: function(xhr) {
|
343 |
+
Swal.fire({
|
344 |
+
icon: 'error',
|
345 |
+
title: 'Erreur',
|
346 |
+
text: 'Une erreur est survenue lors de la génération de la réponse.'
|
347 |
+
});
|
348 |
+
}
|
349 |
+
});
|
350 |
+
});
|
351 |
+
|
352 |
+
// Gestion de la copie de la réponse
|
353 |
+
$('#copy-btn').click(function() {
|
354 |
+
const response = $('#response').text();
|
355 |
+
navigator.clipboard.writeText(response).then(function() {
|
356 |
+
Toast.fire({
|
357 |
+
icon: 'success',
|
358 |
+
title: 'Réponse copiée avec succès'
|
359 |
+
});
|
360 |
+
}).catch(function() {
|
361 |
+
Toast.fire({
|
362 |
+
icon: 'error',
|
363 |
+
title: 'Erreur lors de la copie'
|
364 |
+
});
|
365 |
+
});
|
366 |
+
});
|
367 |
+
});
|
368 |
+
</script>
|
369 |
+
</body>
|
370 |
+
</html>
|