forked from ScoDoc/ScoDoc
143 lines
4.9 KiB
JavaScript
143 lines
4.9 KiB
JavaScript
|
|
const studentsdemo = [
|
|
{ "name": "Alice", "wait": 500, "sems": [0, 2] },
|
|
{ "name": "Bob", "wait": 500, "sems": [1, 2, 3]}
|
|
];
|
|
const semsdemo = [
|
|
{ "id": 0, "wait": 4, "notes": {"Alice": 13 } },
|
|
{ "id": 1, "wait": 3, "notes": {"Bob": 6 } },
|
|
{ "id": 2, "wait": 8, "notes": {"Alice": 11, "Bob": 18 } },
|
|
{ "id": 3, "wait": 7, "notes": {"Bob": 17 } },
|
|
];
|
|
|
|
/*
|
|
getStudents <= [ "Alice", #Bob" ]
|
|
getSems("Alice") <= [ 1, 3]
|
|
getSems("Bob") <= [ 2, 3, 4]
|
|
getMarks(1) <= {"Alice": 13 }
|
|
getMarks(2) <= {"Alice": 13 }...
|
|
getMarks(3) <= {"Alice": 13 }
|
|
getMarks(4) <= {"Alice": 13 }
|
|
*/
|
|
|
|
|
|
async function do_export(api_root, formsemstre_id) {
|
|
console.log('***************** start *****************');
|
|
const students = await api.getStudents(api_root, formsemstre_id);
|
|
console.log('***************** got students *****************');
|
|
console.log(students)
|
|
console.log('***************** seeking sems *****************');
|
|
const student_requests = students.map((student) => {
|
|
return api.getStudentSems(api_root, student.id);
|
|
});
|
|
const sems = await Promise.all(student_requests);
|
|
debugger;
|
|
console.log('***************** got sems *****************');
|
|
const set_sem = new Set(sems.flat());
|
|
console.log(set_sem)
|
|
console.log('***************** seeking marks *****************');
|
|
const studentsGrades = await Promise.all([...set_sem].map(sem => api.getMarks(sem)));
|
|
debugger;
|
|
// Expected output: "resolved"
|
|
}
|
|
|
|
|
|
const api = {
|
|
getStudents(api_root, formsemestre_id) {
|
|
return fetch(`${api_root}/formsemestre/${formsemestre_id}/etudiants`)
|
|
.then(response => response.json())
|
|
},
|
|
getStudentSems(api_root, etudid) {
|
|
return fetch(`${api_root}/etudiant/etudid/${etudid}/formsemestres`)
|
|
.then(response => response.json())
|
|
},
|
|
getMarks(sem_id) {
|
|
return new Promise(
|
|
resolve => { setTimeout(resolve, semsdemo[sem_id].wait, semsdemo[sem_id].notes ); }
|
|
)
|
|
}
|
|
}
|
|
|
|
// let loaded_sems = [];
|
|
//
|
|
// async function doit() {
|
|
// getStudents()
|
|
// .then(students => {
|
|
// return Promise.all(students.map(student => {
|
|
// api.getStudentSems(student)
|
|
// .then(sems_id => {
|
|
// sem_requests = []
|
|
// sems_id.forEach(sem_id => {
|
|
// if (typeof sem_requests[sem_id] === 'undefined') {
|
|
// sem_requests[sem_id](api.getMarks(sem_id));
|
|
// });
|
|
// });
|
|
// then(allMarks => {
|
|
// console.log(allMarks);
|
|
// });
|
|
// });
|
|
// }
|
|
|
|
/*
|
|
let dataSrc = "/ScoDoc/{{dept}}/api/formsemestre/{{formsemestre.id}}/etudiants/long";
|
|
let formsemestres = [];
|
|
fetch(dataSrc)
|
|
.then(r => { return r.json(); })
|
|
.then(json => {
|
|
let etudiants = json;
|
|
promises_etud_semestres = []
|
|
promises_semestres = []
|
|
etudiants.forEach((etudiant) => {
|
|
let url =`/ScoDoc/{{dept}}/api/etudiant/nip/${etudiant.code_nip}/formsemestres`;
|
|
console.log(url);
|
|
promises_etud_semestres.push(
|
|
fetch(url)
|
|
.then(r => { return r.json(); })
|
|
.then(semestre => {
|
|
formsemestre_id = semestre.formsemestre_id;
|
|
|
|
})
|
|
)
|
|
// etudiant.formsemestres_id = [];
|
|
fetch(url)
|
|
.then(r => {return r.json; })
|
|
.then(json => {
|
|
let forms = json;
|
|
console.log(etudiant.code_nip + " " + forms.formsemestre_id);
|
|
// forms.forEach((formsem) => {
|
|
// if (formsem.is_apc) {
|
|
// etudiant.formsemestres_id.push(formsem.formsemestre_id);
|
|
// if (formsem.formsemestre_id in_array()) {
|
|
// }
|
|
// }
|
|
// });
|
|
});
|
|
});
|
|
//let releve = document.querySelector("releve-but");
|
|
//releve.showData = json;
|
|
// Style custom à ajouter
|
|
// let style = document.createElement("style");
|
|
// style.textContent = `
|
|
// .module>div,
|
|
// .dateInscription,
|
|
// .numerosEtudiant,
|
|
// .dateNaissance{
|
|
// display: none;
|
|
// }`;
|
|
//releve.shadowRoot.appendChild(style);
|
|
})
|
|
.catch(error => { console.log(error)});
|
|
// .catch(error => {
|
|
// let div = document.createElement("div");
|
|
// div.innerText = "Une erreur s'est produite lors du transfert des données.";
|
|
// div.style.fontSize = "24px";
|
|
// div.style.color = "#d93030";
|
|
|
|
// let releve = document.querySelector("releve-but");
|
|
// releve.after(div);
|
|
// releve.remove();
|
|
|
|
// throw 'Fin du script - données invalides';
|
|
// });
|
|
*/
|