ScoDoc-PE/app/static/js/releve-but.js

412 lines
12 KiB
JavaScript
Raw Normal View History

2021-12-20 15:39:43 +01:00
/* Module par Seb. L. */
2021-12-18 02:30:47 +01:00
class releveBUT extends HTMLElement {
constructor() {
2021-12-18 02:30:47 +01:00
super();
this.shadow = this.attachShadow({ mode: 'open' });
2021-12-18 02:30:47 +01:00
/* Config par defaut */
this.config = {
showURL: true
};
2021-12-18 02:30:47 +01:00
/* Template du module */
this.shadow.innerHTML = this.template();
2021-12-18 02:30:47 +01:00
/* Style du module */
const styles = document.createElement('link');
styles.setAttribute('rel', 'stylesheet');
if (location.href.split("/")[3] == "ScoDoc") {
styles.setAttribute('href', '/ScoDoc/static/css/releve-but.css'); // Scodoc
} else {
styles.setAttribute('href', '/assets/styles/releve-but.css'); // Passerelle
}
this.shadow.appendChild(styles);
2021-12-18 02:30:47 +01:00
}
listeOnOff() {
2021-12-20 15:39:43 +01:00
this.parentElement.parentElement.classList.toggle("listeOff");
this.parentElement.parentElement.querySelectorAll(".moduleOnOff").forEach(e => {
2021-12-20 15:39:43 +01:00
e.classList.remove("moduleOnOff")
})
}
moduleOnOff() {
2021-12-20 15:39:43 +01:00
this.parentElement.classList.toggle("moduleOnOff");
2021-12-18 02:30:47 +01:00
}
goTo() {
let module = this.dataset.module;
this.parentElement.parentElement.parentElement.parentElement.querySelector("#Module_" + module).scrollIntoView();
}
2021-12-18 02:30:47 +01:00
set setConfig(config) {
2021-12-18 02:30:47 +01:00
this.config.showURL = config.showURL ?? this.config.showURL;
}
set showData(data) {
2021-12-18 02:30:47 +01:00
this.showInformations(data);
this.showSemestre(data);
this.showSynthese(data);
this.showEvaluations(data);
this.showCustom(data);
2021-12-18 02:30:47 +01:00
this.setOptions(data.options);
2021-12-20 15:39:43 +01:00
this.shadow.querySelectorAll(".CTA_Liste").forEach(e => {
e.addEventListener("click", this.listeOnOff)
})
2021-12-20 15:39:43 +01:00
this.shadow.querySelectorAll(".ue, .module").forEach(e => {
e.addEventListener("click", this.moduleOnOff)
})
this.shadow.querySelectorAll(":not(.ueBonus)+.syntheseModule").forEach(e => {
e.addEventListener("click", this.goTo)
})
2021-12-20 15:39:43 +01:00
2021-12-18 02:30:47 +01:00
this.shadow.children[0].classList.add("ready");
}
template() {
2021-12-18 02:30:47 +01:00
return `
<div>
<div class="wait"></div>
<main class="releve">
<!--------------------------->
<!-- Info. étudiant -->
<!--------------------------->
<section class=etudiant>
<img class=studentPic src="" alt="Photo de l'étudiant" width=100 height=120>
<div class=infoEtudiant></div>
</section>
<!--------------------------------------------------------------------------------------->
<!-- Zone spéciale pour que les IUT puisse ajouter des infos locales sur la passerelle -->
<!--------------------------------------------------------------------------------------->
<section class=custom></section>
2021-12-18 02:30:47 +01:00
<!--------------------------->
<!-- Semestre -->
<!--------------------------->
<section>
<h2>Semestre </h2>
2022-01-09 11:36:15 +01:00
<div class=flex>
<div class=infoSemestre></div>
<div>
<div class=decision></div>
2022-01-09 11:36:15 +01:00
<div class=dateInscription>Inscrit le </div>
<em>Les moyennes servent à situer l'étudiant dans la promotion et ne correspondent pas à des validations de compétences ou d'UE.</em>
</div>
</div>
2021-12-18 02:30:47 +01:00
</section>
<!--------------------------->
<!-- Synthèse -->
<!--------------------------->
<section>
<div>
<div>
<h2>Synthèse</h2>
<em>La moyenne des ressources dans une UE dépend des poids donnés aux évaluations.</em>
</div>
<div class=CTA_Liste>
2022-01-09 11:36:15 +01:00
Liste <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2021-12-18 02:30:47 +01:00
<path d="M18 15l-6-6-6 6" />
</svg>
</div>
</div>
<div class=synthese></div>
</section>
<!--------------------------->
<!-- Evaluations -->
<!--------------------------->
<section>
<div>
<h2>Ressources</h2>
<div class=CTA_Liste>
2022-01-09 11:36:15 +01:00
Liste <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2021-12-18 02:30:47 +01:00
<path d="M18 15l-6-6-6 6" />
</svg>
</div>
</div>
<div class=evaluations></div>
</section>
<section>
<div>
<h2>SAÉ</h2>
<div class=CTA_Liste>
2022-01-09 11:36:15 +01:00
Liste <svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2021-12-18 02:30:47 +01:00
<path d="M18 15l-6-6-6 6" />
</svg>
</div>
</div>
<div class=sae></div>
</section>
</main>
</div>`;
}
/********************************/
/* Informations sur l'étudiant */
/********************************/
showInformations(data) {
this.shadow.querySelector(".studentPic").src = data.etudiant.photo_url || "default_Student.svg";
let output = '';
if (this.config.showURL) {
output += `<a href="${data.etudiant.fiche_url}" class=info_etudiant>`;
} else {
output += `<div class=info_etudiant>`;
}
output += `
2021-12-18 02:30:47 +01:00
<div class=civilite>
${this.civilite(data.etudiant.civilite)}
${data.etudiant.nom}
${data.etudiant.prenom}`;
if (data.etudiant.date_naissance) {
2021-12-20 15:39:43 +01:00
output += ` <div class=dateNaissance>né${(data.etudiant.civilite == "F") ? "e" : ""} le ${this.ISOToDate(data.etudiant.date_naissance)}</div>`;
2021-12-18 02:30:47 +01:00
}
output += `
</div>
<div class=numerosEtudiant>
Numéro étudiant : ${data.etudiant.code_nip || "~"} -
Code INE : ${data.etudiant.code_ine || "~"}
2021-12-18 02:30:47 +01:00
</div>
<div>${data.formation.titre}</div>
`;
if (this.config.showURL) {
output += `</a>`;
} else {
output += `</div>`;
}
2021-12-18 02:30:47 +01:00
this.shadow.querySelector(".infoEtudiant").innerHTML = output;
}
/*******************************/
/* Affichage local */
/*******************************/
showCustom(data) {
this.shadow.querySelector(".custom").innerHTML = data.custom || "";
}
2021-12-18 02:30:47 +01:00
/*******************************/
/* Information sur le semestre */
/*******************************/
showSemestre(data) {
this.shadow.querySelector("h2").innerHTML += data.semestre.numero;
this.shadow.querySelector(".dateInscription").innerHTML += this.ISOToDate(data.semestre.inscription);
let output = `
<div>
<div class=enteteSemestre>Moyenne</div><div class=enteteSemestre>${data.semestre.notes.value}</div>
<div class=rang>Rang :</div><div class=rang>${data.semestre.rang.value} / ${data.semestre.rang.total}</div>
<div>Max. promo. :</div><div>${data.semestre.notes.max}</div>
<div>Moy. promo. :</div><div>${data.semestre.notes.moy}</div>
<div>Min. promo. :</div><div>${data.semestre.notes.min}</div>
</div>
<div class=absencesRecap>
<div class=enteteSemestre>Absences</div>
<div class=enteteSemestre>N.J. ${data.semestre.absences?.injustifie ?? "-"}</div>
<div style="grid-column: 2">Total ${data.semestre.absences?.total ?? "-"}</div>
2022-01-09 11:36:15 +01:00
</div>`;
/*${data.semestre.groupes.map(groupe => {
return `
<div>
<div class=enteteSemestre>Groupe</div><div class=enteteSemestre>${groupe.nom}</div>
<div class=rang>Rang :</div><div class=rang>${groupe.rang.value} / ${groupe.rang.total}</div>
<div>Max. groupe :</div><div>${groupe.notes.max}</div>
<div>Moy. groupe :</div><div>${groupe.notes.min}</div>
<div>Min. groupe :</div><div>${groupe.notes.min}</div>
</div>
`;
}).join("")
}*/
2021-12-18 02:30:47 +01:00
this.shadow.querySelector(".infoSemestre").innerHTML = output;
this.shadow.querySelector(".decision").innerHTML = data.semestre.decision?.code || "";
2021-12-18 02:30:47 +01:00
}
/*******************************/
/* Synthèse */
/*******************************/
showSynthese(data) {
let output = ``;
Object.entries(data.ues).forEach(([ue, dataUE]) => {
if (dataUE.type == 1) { // UE Sport / Bonus
output += `
<div>
<div class="ue ueBonus">
<h3>Bonus</h3>
<div>${dataUE.bonus_description}</div>
2021-12-20 15:39:43 +01:00
</div>
${this.ueSport(dataUE.modules)}
</div>
`;
} else {
output += `
<div>
<div class=ue>
<h3>
${ue}${(dataUE.competence) ? " - " + dataUE.competence : ""}
</h3>
<div>
<div class=moyenne>Moyenne&nbsp;:&nbsp;${dataUE.moyenne?.value || "-"}</div>
<div class=info>
Bonus&nbsp;:&nbsp;${dataUE.bonus || 0}&nbsp;-
Malus&nbsp;:&nbsp;${dataUE.malus || 0}
<span class=ects>&nbsp;-
ECTS&nbsp;:&nbsp;${dataUE.ECTS.acquis}&nbsp;/&nbsp;${dataUE.ECTS.total}
</span>
</div>
</div>`;
/*<div class=absences>
<div>Abs&nbsp;N.J.</div><div>${dataUE.absences?.injustifie || 0}</div>
<div>Total</div><div>${dataUE.absences?.total || 0}</div>
</div>*/
output += `
2021-12-18 02:30:47 +01:00
</div>
${this.synthese(data, dataUE.ressources)}
${this.synthese(data, dataUE.saes)}
2021-12-18 02:30:47 +01:00
</div>
`;
}
2021-12-18 02:30:47 +01:00
});
this.shadow.querySelector(".synthese").innerHTML = output;
}
synthese(data, modules) {
let output = "";
Object.entries(modules).forEach(([module, dataModule]) => {
let titre = data.ressources[module]?.titre || data.saes[module]?.titre;
//let url = data.ressources[module]?.url || data.saes[module]?.url;
2021-12-18 02:30:47 +01:00
output += `
<div class=syntheseModule data-module="${module.replace(/[^a-zA-Z0-9]/g, "")}">
<div>${module}&nbsp;- ${titre}</div>
2021-12-18 02:30:47 +01:00
<div>
${dataModule.moyenne}
2021-12-20 15:39:43 +01:00
<em>Coef.&nbsp;${dataModule.coef}</em>
2021-12-18 02:30:47 +01:00
</div>
</div>
`;
})
return output;
}
ueSport(modules) {
let output = "";
Object.values(modules).forEach((module) => {
Object.values(module.evaluations).forEach((evaluation) => {
output += `
<div class=syntheseModule>
<div>${module.titre} - ${evaluation.description}</div>
<div>
${evaluation.note.value ?? "-"}
<em>Coef.&nbsp;${evaluation.coef}</em>
</div>
</div>
`;
})
})
return output;
}
2021-12-18 02:30:47 +01:00
/*******************************/
/* Evaluations */
/*******************************/
showEvaluations(data) {
this.shadow.querySelector(".evaluations").innerHTML = this.module(data.ressources);
this.shadow.querySelector(".sae").innerHTML += this.module(data.saes);
}
module(module) {
let output = "";
Object.entries(module).forEach(([numero, content]) => {
output += `
<div id="Module_${numero.replace(/[^a-zA-Z0-9]/g, "")}">
2021-12-18 02:30:47 +01:00
<div class=module>
<h3>${this.URL(content.url, `${numero} - ${content.titre}`)}</h3>
<div>
<div class=moyenne>Moyenne&nbsp;indicative&nbsp;:&nbsp;${content.moyenne.value}</div>
<div class=info>
Classe&nbsp;:&nbsp;${content.moyenne.moy}&nbsp;-
Max&nbsp;:&nbsp;${content.moyenne.max}&nbsp;-
Min&nbsp;:&nbsp;${content.moyenne.min}
</div>
</div>
<div class=absences>
<div>Abs&nbsp;inj.</div><div>${content.absences?.injustifie || 0}</div>
<div>Total</div><div>${content.absences?.total || 0}</div>
</div>
</div>
${this.evaluation(content.evaluations)}
</div>
`;
})
return output;
}
evaluation(evaluations) {
let output = "";
evaluations.forEach((evaluation) => {
output += `
<div class=eval>
<div>${this.URL(evaluation.url, evaluation.description || "Évaluation")}</div>
2021-12-18 02:30:47 +01:00
<div>
${evaluation.note.value}
2021-12-20 15:39:43 +01:00
<em>Coef.&nbsp;${evaluation.coef}</em>
2021-12-18 02:30:47 +01:00
</div>
<div class=complement>
<div>Coef</div><div>${evaluation.coef}</div>
<div>Max. promo.</div><div>${evaluation.note.max}</div>
<div>Moy. promo.</div><div>${evaluation.note.moy}</div>
<div>Min. promo.</div><div>${evaluation.note.min}</div>
${Object.entries(evaluation.poids).map(([UE, poids]) => {
return `
<div>Poids ${UE}</div>
<div>${poids}</div>
`;
}).join("")}
</div>
</div>
`;
})
return output;
}
/********************/
/* Options */
/********************/
setOptions(options) {
Object.entries(options).forEach(([option, value]) => {
if (value === false) {
document.body.classList.add(option.replace("show", "hide"))
}
})
}
/********************/
/* Fonctions d'aide */
/********************/
URL(href, content) {
if (this.config.showURL) {
2021-12-18 02:30:47 +01:00
return `<a href=${href}>${content}</a>`;
} else {
return content;
}
}
civilite(txt) {
switch (txt) {
case "M": return "M.";
case "F": return "Mme";
default: return "";
}
}
ISOToDate(ISO) {
return ISO.split("-").reverse().join("/");
}
}
customElements.define('releve-but', releveBUT);