Commit 8990c659 authored by Romain OZDEN's avatar Romain OZDEN

Choix de matières en dynamique

parent 12c16079
const allah = require('alasql');
allah(`
ATTACH FILESTORAGE DATABASE annales("${__dirname}/../../db/db.json");
USE annales;
`);
const router = require('express').Router();
router.get('/', (req, res) => {
res.send(allah.exec(`select * from Annee`));
});
module.exports = router;
\ No newline at end of file
const router = require('express').Router();
const allah = require('alasql');
allah(`
ATTACH FILESTORAGE DATABASE annales("${__dirname}/../../db/db.json");
USE annales;
`);
router.post('/temp', function (req, res) {
//requete de ouf qui fait des trucs mais on l'a pas encore
let matiere = 'Informatique';
res.redirect('/selection_annale?matiere='+matiere);
});
const router = require('express').Router();
router.get('/getMatieresByPromo', (req, res) => {
res.send(allah.exec(`select * from Matiere where promo_id = ${req.query.promo}`));
})
module.exports = router;
\ No newline at end of file
const allah = require('alasql');
allah(`
ATTACH FILESTORAGE DATABASE annales("${__dirname}/../../db/db.json");
USE annales;
`);
const router = require('express').Router();
router.get('/', (req, res) => {
res.send(allah.exec(`select * from Promo`));
});
router.post('/temp', (req, res) => {
let promo = allah.exec(`SELECT * FROM Promo WHERE annee_id = ${req.body.annee} AND specialite_id = ${req.body.specialite}`)[0].promo_id;
res.redirect('/selection_annale?matiere='+promo);
});
module.exports = router;
\ No newline at end of file
const allah = require('alasql');
allah(`
ATTACH FILESTORAGE DATABASE annales("${__dirname}/../../db/db.json");
USE annales;
`);
const router = require('express').Router();
router.get('/', (req, res) => {
res.send(allah.exec(`select * from Specialite`));
});
module.exports = router;
\ No newline at end of file
{"tables":{}}
\ 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
CREATE TABLE IF NOT EXISTS `Annee` (
`year` number PRIMARY KEY,
CREATE TABLE IF NOT EXISTS Specialite (
specialite_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` string
);
CREATE TABLE IF NOT EXISTS `Specialite` (
specialite_name string PRIMARY KEY,
CREATE TABLE IF NOT EXISTS Annee (
annee_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` string
);
CREATE TABLE IF NOT EXISTS Promo (
promo_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`year` string,
specialite_name string,
CONSTRAINT `fj_promo_annee` FOREIGN KEY (`year`) REFERENCES Annee (`year`),
CONSTRAINT `fk_promo_spec` FOREIGN KEY (specialite_name) REFERENCES Specialite (specialite_name),
annee_id number,
specialite_id number,
CONSTRAINT `fk_promo_spe` FOREIGN KEY (specialite_id) REFERENCES Specialite (specialite_id),
CONSTRAINT `fk_promo_annee` FOREIGN KEY (annee_id) REFERENCES Annee (annee_id)
);
CREATE TABLE IF NOT EXISTS `Role` (
role_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
nom string
);
CREATE TABLE IF NOT EXISTS Utilisateur (
......@@ -21,12 +28,13 @@ CREATE TABLE IF NOT EXISTS Utilisateur (
firstname string,
lastname string,
email string,
`role` string NOT NULL,
role_id number UNSIGNED NOT NULL,
CONSTRAINT `fk_user_role` FOREIGN KEY (role_id) REFERENCES `Role` (role_id)
);
CREATE TABLE IF NOT EXISTS Matiere (
matiere_id number UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
nom string,
`name` string,
`user_id` number UNSIGNED NOT NULL,
promo_id number UNSIGNED NOT NULL,
CONSTRAINT `fj_mat_user` FOREIGN KEY (`user_id`) REFERENCES Utilisateur (`user_id`),
......@@ -68,4 +76,24 @@ CREATE TABLE IF NOT EXISTS `Suivre` (
PRIMARY KEY (matiere_id, `user_id`),
CONSTRAINT `fk_suj_mat` FOREIGN KEY (matiere_id) REFERENCES Matiere (matiere_id),
CONSTRAINT `fk_notif_user` FOREIGN KEY (`user_id`) REFERENCES Utilisateur (`user_id`)
);
\ No newline at end of file
);
INSERT INTO Specialite (specialite_id, `name`) VALUES (1, 'Informatique'), (2, 'ETN'), (3, 'Matériaux'), (4, 'TE');
INSERT INTO Annee (annee_id, `name`) VALUES (1, '3A'), (2, '4A'), (3, '5A');
INSERT INTO Promo (promo_id, specialite_id, annee_id) VALUES
(1, 1, 1),(2, 1, 2),(3, 1, 3),
(5, 2, 1),(4, 2, 2),(6, 2, 3),
(7, 3, 1),(8, 3, 2),(9, 3, 3),
(10, 4, 1),(11, 4, 2),(12, 4, 3);
INSERT INTO Matiere (matiere_id, `name`, promo_id) VALUES
(1, 'C++', 1),
(2, 'Systèmes', 1),
(3, 'Droit', 1),
(4, 'IHM', 1),
(5, 'Outils de gestion', 1),
(6, 'Statistiques I', 1),
(7, 'Statistiques II', 1),
(8 , 'Théorie des graphes', 1),
(9, 'Réseau', 1),
(10, 'WEB', 1);
\ No newline at end of file
.case-lien {
width: 200px;
display: block;
border: 1px solid #C0C0C0;
margin: 10px;
color: #0089BF;
text-decoration: none;
}
.case-lien p {
text-align: center;
margin: 5px;
}
.case-lien p + p {
margin-top: 0;
font-size: 12px;
}
\ No newline at end of file
......@@ -7,8 +7,10 @@
<!-- Pour le responsive sur mobile -->
<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">
<!-- Déclaration de la feuille de style du document-->
<link rel="text/css" href="public/css/style.css">
<link rel="stylesheet" href="public/css/style.css">
<!-- Polyfills pour le support de fetch dans les vieux navigateurs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.0.5/es6-promise.min.js" async></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.1/fetch.min.js" async></script>
......
......@@ -53,7 +53,7 @@ const loadPartials = (() => {
// route pour la page d'authentification des utilisateurs
page('/', async function () {
await renderTemplate(templates('public/templates/signup.mustache'), context);
await renderTemplate(templates('public/templates/accueil.mustache'), context);
});
page('/signup', async function () {
......@@ -65,8 +65,12 @@ page('/login', async function () {
});
page('/accueil', async function () {
await renderTemplate(templates('public/templates/accueil.mustache'), context);
let annees = await fetch('api/annee');
annees = await annees.json();
let specialites = await fetch('api/specialite');
specialites = await specialites.json();
await renderTemplate(templates('public/templates/accueil.mustache'), {...context, annees, specialites});
/*let valide = document.querySelector('#form');
valide.addEventListener('click', function () {
//evt.preventDefault();
......@@ -79,9 +83,6 @@ page('/accueil', async function () {
return false;
})*/
});
/*window.onload = function(){
document.getElementById("form").onsubmit = function(){
window.location.replace(`http://localhost:8080/selection_annale`);
......@@ -92,32 +93,37 @@ page('/accueil', async function () {
/*function matiere() {
}*/
});
page('/selection_annale', async function () {
await renderTemplate(templates('public/templates/selection_annale.mustache'), context);
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});
//let promo = request.url.split('?')[1];
//requête SQL : SELECT * FROM matiere WHERE promotion=promo;
//requête SQL : SELECT * FROM annales WHERE matiere=mat AND year = promo[1] (l'année quoi)
let list_annale; //le résultat de la dernière requête
// let list_annale; //le résultat de la dernière requête
let form=document.getElementById('form');
let fieldset=form.children[1];
// let form=document.getElementById('form');
// let fieldset=form.children[1];
/*while (fieldset.firstChild.nextSibling){
fieldset.removeChild(fieldset.firstChild.nextSibling);
}*/
let input;
let label;
list_annale.forEach(element => {
input = document.createElement('input');
input.type = "radio";
input.name = "annale";
input.id = input.name = input.innerHTML = `${element.name}`;
label = document.createElement('label');
label.for = label.innerHTML = `${element.name}`;
});
// let input;
// let label;
// list_annale.forEach(element => {
// input = document.createElement('input');
// input.type = "radio";
// input.name = "annale";
// input.id = input.name = input.innerHTML = `${element.name}`;
// label = document.createElement('label');
// label.for = label.innerHTML = `${element.name}`;
// });
});
page('/annale', async function () {
......
......@@ -5,34 +5,25 @@
<section>
<h3>Vous êtes un étudiant et vous souhaitez accéder à des annales et/ou proposer des corrigés ?</h3>
<form id="form" action="/api/matiere/temp" method="POST">
<form id="form" action="/api/promo/temp" method="POST">
<fieldset>
<p>1) Choisis d'abord ton année</p>
<input type="radio" id="3A" name="annee" value="3" required>
<label for="3A">3ème année</label>
{{#annees}}
<input type="radio" id="{{name}}" name="annee" value="{{annee_id}}" required>
<label for="{{annee_id}}">{{name}}</label>
{{/annees}}
<input type="radio" id="4A" name="annee" value="4" required>
<label for="4A">4ème année</label>
<input type="radio" id="5A" name="annee" value="5" required>
<label for="5A">5ème année</label>
</fieldset>
<fieldset>
<p>2) Choisis ensuite ta spécialité</p>
<input type="radio" id="INFO" name="specialite" value="INFO" required>
<label for="INFO">Informatique</label>
<input type="radio" id="ETN" name="specialite" value="ETN" required>
<label for="ETN">ETN</label>
<input type="radio" id="MAT" name="specialite" value="MAT" required>
<label for="MAT">Matériaux</label>
{{#specialites}}
<input type="radio" id="{{name}}" name="specialite" value="{{specialite_id}}" required>
<label for="{{specialite_id}}">{{name}}</label>
{{/specialites}}
<input type="radio" id="TE" name="specialite" value="TE" required>
<label for="TE">TE</label>
</fieldset>
<fieldset>
......@@ -42,7 +33,7 @@
</form>
</section>
<a href="http://localhost:8080/connexion/">
<a class="case-lien" href="http://localhost:8080/login">
<p>Vous êtes un enseignant ?</p>
<p>Cliquez ici</p>
</a>
\ No newline at end of file
<img src="/storage/images/logo.png"/>
<!-- image du logo de polytech nantes -->
<h1>Bienvenue sur Polysheet</h1>
<section>
<h3>Espace de connexion enseignants</h3>
<form>
<p>Vous pouvez vous connecter</p>
<input id="login" placeholder="LOGIN:"/>
<input id="MDP" placeholder="MOT DE PASSE:"/>
<button>Valider</button>
</form>
</section>
<section>
<a href="http://localhost:8080/accueil/">
<p>Vous êtes un étudiant ?</p>
<p>Cliquez ici</p>
</a>
<section>
\ No newline at end of file
C'est l'heure de se connecter (☞゚ヮ゚)☞
<img src="/storage/images/logo.png"/>
<!-- image du logo de polytech nantes -->
<h1>Bienvenue sur Polysheet</h1>
<form method="post" action="/api/users/login">
<section>
<h3>Espace de connexion enseignants</h3>
<label for="username">Nom d'utilisateur</label>
<input type="text" id="username" name="username" required>
<form method="post" action="/api/users/login">
<fieldset>
<p>Veuillez vous connecter</p>
<label for="password">Mot de passe</label>
<input type="text" id="password" name="password" required>
<input type="text" id="username" name="username" placeholder="Nom d'utilisateur" required>
<input type="submit" value="Se connecter">
</form>
\ No newline at end of file
<input type="text" id="password" name="password" placeholder="Mot de passe" required>
<button>Se connecter</button>
</fieldset>
</form>
</section>
<section>
<a class="case-lien" href="http://localhost:8080/accueil">
<p>Vous êtes un étudiant ?</p>
<p>Cliquez ici</p>
</a>
<section>
\ No newline at end of file
......@@ -10,33 +10,26 @@
<p>1) Choisis ta matière</p>
<!-- Attention, là c'est statique mais après on importera depuis les données reçues la page précédente -->
<input type="radio" id="IHM" name="matiere" value="IHM">
<label for="IHM">IHM</label>
{{#matieres}}
<input type="radio" id="{{name}}" name="matiere" value="{{matiere_id}}">
<label for="{{name}}">{{name}}</label>
{{/matieres}}
<input type="radio" id="gestion" name="matiere" value="gestion">
<label for="gestion">Outils de gestion</label>
<input type="radio" id="stats1" name="matiere" value="stats1">
<label for="stats1">Statistique I</label>
<input type="radio" id="stats2" name="matiere" value="stats2">
<label for="stats2">Statistique II</label>
<input type="radio" id="graph" name="matiere" value="graph">
<label for="graph">Théorie des graphes</label>
<input type="radio" id="sys" name="matiere" value="sys">
<label for="sys">Systèmes</label>
<input type="radio" id="reseau" name="matiere" value="reseau">
<label for="reseau">Réseau</label>
<input type="radio" id="WEB" name="matiere" value="WEB">
<label for="WEB">WEB</label>
</fieldset>
<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>
</fieldset>
</form>
</section>
\ No newline at end of file
......@@ -5,6 +5,9 @@ const app = express();
const bodyParser = require('body-parser');
const userRouter = require('./api/users/user.router');
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 auth = require('./auth/auth.js');
// on met en place une authentification valide pour toute le site
......@@ -28,6 +31,9 @@ app.use(bodyParser.json());
app.use('/api/users', userRouter(passport));
app.use('/api/matiere', matiereRouter);
app.use('/api/annee', anneeRouter);
app.use('/api/specialite', specialiteRouter);
app.use('/api/promo', promoRouter);
// 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