Commit 69f7ef2c authored by Romain OZDEN's avatar Romain OZDEN

Lecture des annales + afficher/cacher corrigé

parent 8990c659
const allah = require('alasql');
allah(`
ATTACH FILESTORAGE DATABASE annales("${__dirname}/../../db/db.json");
USE annales;
`);
const router = require('express').Router();
router.get('/getSujetsByMatiere', (req, res) => {
res.send(allah.exec(`select * from Sujet where matiere_id = ${req.query.matiere}`));
});
router.get('/viewSujet', (req, res) => {
res.send(allah.exec(`select * from Sujet where matiere_id = ${req.query.sujet}`));
});
module.exports = router;
\ No newline at end of file
{"tables":{"Specialite":{"columns":[{"columnid":"specialite_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"name","dbtypeid":"STRING"}],"dirty":true},"Annee":{"columns":[{"columnid":"annee_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"name","dbtypeid":"STRING"}],"dirty":true},"Promo":{"columns":[{"columnid":"promo_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"annee_id","dbtypeid":"NUMBER"},{"columnid":"specialite_id","dbtypeid":"NUMBER"}],"dirty":true},"Role":{"columns":[{"columnid":"role_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"nom","dbtypeid":"STRING"}]},"Utilisateur":{"columns":[{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"username","dbtypeid":"STRING","notnull":true},{"columnid":"password","dbtypeid":"STRING","notnull":true},{"columnid":"firstname","dbtypeid":"STRING"},{"columnid":"lastname","dbtypeid":"STRING"},{"columnid":"email","dbtypeid":"STRING"},{"columnid":"role_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Matiere":{"columns":[{"columnid":"matiere_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"name","dbtypeid":"STRING"},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true},{"columnid":"promo_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}],"dirty":true},"Sujet":{"columns":[{"columnid":"sujet_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"nom","dbtypeid":"STRING"},{"columnid":"pdf_sujet","dbtypeid":"STRING"},{"columnid":"pdf_correction","dbtypeid":"STRING"},{"columnid":"verif","dbtypeid":"BOOLEAN"},{"columnid":"date_depot","dbtypeid":"DATE"},{"columnid":"matiere_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Commentaire":{"columns":[{"columnid":"com_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"position","dbtypeid":"NUMBER UNSIGNED"},{"columnid":"message","dbtypeid":"STRING"},{"columnid":"typesujet","dbtypeid":"STRING"},{"columnid":"sujet_id","dbtypeid":"NUMBER UNSIGNED","notnull":true},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Notification":{"columns":[{"columnid":"notif_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Suivre":{"columns":[{"columnid":"matiere_id","dbtypeid":"NUMBER UNSIGNED","notnull":true},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]}},"Specialite":[{"specialite_id":1,"name":"Informatique"},{"specialite_id":2,"name":"ETN"},{"specialite_id":3,"name":"Matériaux"},{"specialite_id":4,"name":"TE"}],"Annee":[{"annee_id":1,"name":"3A"},{"annee_id":2,"name":"4A"},{"annee_id":3,"name":"5A"}],"Promo":[{"promo_id":1,"specialite_id":1,"annee_id":1},{"promo_id":2,"specialite_id":1,"annee_id":2},{"promo_id":3,"specialite_id":1,"annee_id":3},{"promo_id":5,"specialite_id":2,"annee_id":1},{"promo_id":4,"specialite_id":2,"annee_id":2},{"promo_id":6,"specialite_id":2,"annee_id":3},{"promo_id":7,"specialite_id":3,"annee_id":1},{"promo_id":8,"specialite_id":3,"annee_id":2},{"promo_id":9,"specialite_id":3,"annee_id":3},{"promo_id":10,"specialite_id":4,"annee_id":1},{"promo_id":11,"specialite_id":4,"annee_id":2},{"promo_id":12,"specialite_id":4,"annee_id":3}],"Role":[],"Utilisateur":[],"Matiere":[{"matiere_id":1,"name":"C++","promo_id":1},{"matiere_id":2,"name":"Systèmes","promo_id":1},{"matiere_id":3,"name":"Droit","promo_id":1},{"matiere_id":4,"name":"IHM","promo_id":1},{"matiere_id":5,"name":"Outils de gestion","promo_id":1},{"matiere_id":6,"name":"Statistiques I","promo_id":1},{"matiere_id":7,"name":"Statistiques II","promo_id":1},{"matiere_id":8,"name":"Théorie des graphes","promo_id":1},{"matiere_id":9,"name":"Réseau","promo_id":1},{"matiere_id":10,"name":"WEB","promo_id":1}],"Sujet":[],"Commentaire":[],"Notification":[],"Suivre":[]}
\ No newline at end of file
{"tables":{"Specialite":{"columns":[{"columnid":"specialite_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"name","dbtypeid":"STRING"}],"dirty":true},"Annee":{"columns":[{"columnid":"annee_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"name","dbtypeid":"STRING"}],"dirty":true},"Promo":{"columns":[{"columnid":"promo_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"annee_id","dbtypeid":"NUMBER"},{"columnid":"specialite_id","dbtypeid":"NUMBER"}],"dirty":true},"Role":{"columns":[{"columnid":"role_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"nom","dbtypeid":"STRING"}]},"Utilisateur":{"columns":[{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"username","dbtypeid":"STRING","notnull":true},{"columnid":"password","dbtypeid":"STRING","notnull":true},{"columnid":"firstname","dbtypeid":"STRING"},{"columnid":"lastname","dbtypeid":"STRING"},{"columnid":"email","dbtypeid":"STRING"},{"columnid":"role_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Matiere":{"columns":[{"columnid":"matiere_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"name","dbtypeid":"STRING"},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true},{"columnid":"promo_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}],"dirty":true},"Sujet":{"columns":[{"columnid":"sujet_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"nom","dbtypeid":"STRING"},{"columnid":"pdf_sujet","dbtypeid":"STRING"},{"columnid":"pdf_correction","dbtypeid":"STRING"},{"columnid":"verif","dbtypeid":"BOOLEAN"},{"columnid":"date_depot","dbtypeid":"DATE"},{"columnid":"matiere_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}],"dirty":true},"Commentaire":{"columns":[{"columnid":"com_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"position","dbtypeid":"NUMBER UNSIGNED"},{"columnid":"message","dbtypeid":"STRING"},{"columnid":"typesujet","dbtypeid":"STRING"},{"columnid":"sujet_id","dbtypeid":"NUMBER UNSIGNED","notnull":true},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Notification":{"columns":[{"columnid":"notif_id","dbtypeid":"NUMBER UNSIGNED","notnull":true,"identity":{"value":1,"step":1}},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]},"Suivre":{"columns":[{"columnid":"matiere_id","dbtypeid":"NUMBER UNSIGNED","notnull":true},{"columnid":"user_id","dbtypeid":"NUMBER UNSIGNED","notnull":true}]}},"Specialite":[{"specialite_id":1,"name":"Informatique"},{"specialite_id":2,"name":"ETN"},{"specialite_id":3,"name":"Matériaux"},{"specialite_id":4,"name":"TE"}],"Annee":[{"annee_id":1,"name":"3A"},{"annee_id":2,"name":"4A"},{"annee_id":3,"name":"5A"}],"Promo":[{"promo_id":1,"specialite_id":1,"annee_id":1},{"promo_id":2,"specialite_id":1,"annee_id":2},{"promo_id":3,"specialite_id":1,"annee_id":3},{"promo_id":5,"specialite_id":2,"annee_id":1},{"promo_id":4,"specialite_id":2,"annee_id":2},{"promo_id":6,"specialite_id":2,"annee_id":3},{"promo_id":7,"specialite_id":3,"annee_id":1},{"promo_id":8,"specialite_id":3,"annee_id":2},{"promo_id":9,"specialite_id":3,"annee_id":3},{"promo_id":10,"specialite_id":4,"annee_id":1},{"promo_id":11,"specialite_id":4,"annee_id":2},{"promo_id":12,"specialite_id":4,"annee_id":3}],"Role":[],"Utilisateur":[],"Matiere":[{"matiere_id":1,"name":"C++","promo_id":1},{"matiere_id":2,"name":"Systèmes","promo_id":1},{"matiere_id":3,"name":"Droit","promo_id":1},{"matiere_id":4,"name":"IHM","promo_id":1},{"matiere_id":5,"name":"Outils de gestion","promo_id":1},{"matiere_id":6,"name":"Statistiques I","promo_id":1},{"matiere_id":7,"name":"Statistiques II","promo_id":1},{"matiere_id":8,"name":"Théorie des graphes","promo_id":1},{"matiere_id":9,"name":"Réseau","promo_id":1},{"matiere_id":10,"name":"WEB","promo_id":1}],"Sujet":[{"sujet_id":1,"nom":"Annale c++ 2019","pdf_sujet":"exam_cpp_2018_2019_Info3.pdf","pdf_correction":"exam_cpp_2018_2019_Info3.pdf","verif":true,"date_depot":"2020-05-28","matiere_id":1}],"Commentaire":[],"Notification":[],"Suivre":[]}
\ No newline at end of file
......@@ -96,4 +96,7 @@ INSERT INTO Matiere (matiere_id, `name`, promo_id) VALUES
(7, 'Statistiques II', 1),
(8 , 'Théorie des graphes', 1),
(9, 'Réseau', 1),
(10, 'WEB', 1);
\ No newline at end of file
(10, 'WEB', 1);
INSERT INTO Sujet (sujet_id, nom, pdf_sujet, pdf_correction, verif, date_depot, matiere_id) VALUES
(1, 'Annale c++ 2019', 'exam_cpp_2018_2019_Info3.pdf', 'exam_cpp_2018_2019_Info3.pdf', TRUE, "2020-05-28", 1);
\ No newline at end of file
......@@ -15,4 +15,23 @@
.case-lien p + p {
margin-top: 0;
font-size: 12px;
}
.invisible-tab {
display: none;
width: 400px;
}
.verif{
width: 20px;
}
.annale-container {
display: inline-block;
width: 49%;
}
.annale-container iframe {
width: 100%;
height: 100vh;
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Annales</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
<!-- Déclaration de la feuille de style du document-->
<link rel="stylesheet" href="public/css/style.css">
<!-- Polyfills pour le support de fetch dans les vieux navigateurs -->
......
......@@ -99,8 +99,39 @@ page('/selection_annale', async function () {
const promo = window.location.search.split('=')[1];
let matieres = await fetch('api/matiere/getMatieresByPromo?promo=' + promo);
matieres = await matieres.json();
await renderTemplate(templates('public/templates/selection_annale.mustache'), {context, matieres});
const radios = document.querySelectorAll('input[type=radio][name="matiere"]');
async function changeHandler(evt) {
let sujets = await fetch('api/sujet/getSujetsByMatiere?matiere=' + this.value);
sujets = await sujets.json();
let table = document.querySelector('.invisible-tab');
table.style.display = 'none';
if(sujets.length !== 0) {
table.style.display = 'block';
let html = ``;
sujets.forEach(sujet => {
html += `<tr><td><a href="annale?sujet=${sujet.sujet_id}">${sujet.nom}</a></td>`;
if(sujet.verif)
html += `<td><img src="storage/images/vrai.png" class="verif"/></td>`;
else
html += `<td>FAUX</td>`;
html += `</tr>`;
});
document.querySelector('#annales').innerHTML = html;
document.querySelector('#no-annales-message').innerHTML = '';
} else {
document.querySelector('#no-annales-message').innerHTML = `⚠ Pas d'annales pour cette matière`;
}
};
radios.forEach(radio => {
radio.addEventListener('change', changeHandler);
});
//let promo = request.url.split('?')[1];
//requête SQL : SELECT * FROM matiere WHERE promotion=promo;
......@@ -127,7 +158,22 @@ page('/selection_annale', async function () {
});
page('/annale', async function () {
await renderTemplate(templates('public/templates/annale.mustache'), context);
let sujet = window.location.search.split('=')[1];
sujet = await fetch('api/sujet/viewSujet?sujet=' + sujet);
sujet = await sujet.json();
sujet = sujet[0];
await renderTemplate(templates('public/templates/annale.mustache'), {context,sujet});
document.querySelector('#hide-correction').addEventListener('click', (evt) => {
let hide = document.querySelector('#hide-correction');
let correction = document.querySelector('#correction');
if(hide.innerHTML === 'Masquer le corrigé') {
hide.innerHTML = 'Afficher le corrigé';
correction.style.opacity = 0;
} else {
hide.innerHTML = 'Masquer le corrigé';
correction.style.opacity = 1;
}
});
});
page('/connexion', async function () {
......
......@@ -11,7 +11,7 @@
{{#annees}}
<input type="radio" id="{{name}}" name="annee" value="{{annee_id}}" required>
<label for="{{annee_id}}">{{name}}</label>
<label for="{{name}}">{{name}}</label>
{{/annees}}
</fieldset>
......@@ -21,7 +21,7 @@
{{#specialites}}
<input type="radio" id="{{name}}" name="specialite" value="{{specialite_id}}" required>
<label for="{{specialite_id}}">{{name}}</label>
<label for="{{name}}">{{name}}</label>
{{/specialites}}
</fieldset>
......
......@@ -5,16 +5,16 @@
<section>
<h3><!-- titre du corrigé --></h3>
<article>
<article class="annale-container">
<button>Faire un commentaire</button>
<p>Sujet </p>
<embed src="" type='image/pdf'/><!-- prend le fichier pdf contenant l'annale choisie -->
<h2>Sujet </h2>
<iframe src="storage/annales/{{sujet.pdf_sujet}}"></iframe>
</article>
<article>
<article class="annale-container">
<button>Faire un commentaire</button>
<p>Corrigé</p>
<!-- Ou on va avoir un embed qui prend le pdf, ou le pdf est pas trouvé et on fait une chaîne de caractère et un nouveau bouton -->
<button>Masquer le corrigé</button>
<button id="hide-correction">Afficher le corrigé</button>
<h2>Corrigé</h2>
<iframe id="correction"src="storage/annales/{{sujet.pdf_correction}}" style="opacity:0"/></iframe>
</article>
</section>
\ No newline at end of file
......@@ -19,17 +19,17 @@
<fieldset>
<p>2) Choisis ton annale</p>
<input type="radio" id="reseau" name="annale" value="reseau">
<label for="reseau">Profond</label>
<input type="radio" id="WEB" name="annale" value="WEB">
<label for="WEB">Très profond</label>
<input type="radio" id="WEB" name="annale" value="WEB">
<label for="WEB">XXL</label>
<input type="radio" id="WEB" name="annale" value="WEB">
<label for="WEB">Jusqu'à l'épaule</label>
<table class="invisible-tab">
<thead>
<tr>
<td>nom</td>
<td>verif</td>
</tr>
</thead>
<tbody id=annales>
</tbody>
</table>
<p id="no-annales-message"></p>
</fieldset>
</form>
</section>
\ No newline at end of file
......@@ -8,6 +8,7 @@ const matiereRouter = require('./api/matiere/matiere.router');
const anneeRouter = require('./api/annee/annee.router');
const specialiteRouter = require('./api/specialite/specialite.router');
const promoRouter = require('./api/promo/promo.router');
const sujetRouter = require('./api/sujet/sujet.router');
const auth = require('./auth/auth.js');
// on met en place une authentification valide pour toute le site
......@@ -34,6 +35,7 @@ app.use('/api/matiere', matiereRouter);
app.use('/api/annee', anneeRouter);
app.use('/api/specialite', specialiteRouter);
app.use('/api/promo', promoRouter);
app.use('/api/sujet', sujetRouter);
// Pour toutes les autres url (catch all) on renverra l'index.html
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment