2023-05-11 18:05:11 +02:00
|
|
|
function getCurrentScriptPath() {
|
|
|
|
// Get all the script elements on the page
|
|
|
|
var scripts = document.getElementsByTagName('script');
|
|
|
|
|
|
|
|
// Find the last script element (which is the currently executing script)
|
|
|
|
var currentScript = scripts[scripts.length - 1];
|
|
|
|
|
|
|
|
// Retrieve the src attribute of the script element
|
|
|
|
var scriptPath = currentScript.src;
|
|
|
|
|
|
|
|
return scriptPath;
|
|
|
|
}
|
2023-05-11 18:08:02 +02:00
|
|
|
function removeLastTwoComponents(path) {
|
|
|
|
// Split the path into individual components
|
|
|
|
var components = path.split('/');
|
2023-05-11 18:05:11 +02:00
|
|
|
|
2023-05-11 18:08:02 +02:00
|
|
|
// Remove the last two components (filename and enclosing directory)
|
|
|
|
components.splice(-2);
|
|
|
|
|
|
|
|
// Join the remaining components back into a path
|
|
|
|
var newPath = components.join('/');
|
|
|
|
|
|
|
|
return newPath;
|
|
|
|
}
|
2022-01-09 23:13:09 +01:00
|
|
|
class ref_competences extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.shadow = this.attachShadow({ mode: 'open' });
|
|
|
|
|
|
|
|
/* Template de base */
|
|
|
|
this.shadow.innerHTML = `
|
2023-04-13 15:16:14 +02:00
|
|
|
<div class=titre>Cliquer sur un parcours pour afficher ses niveaux de compétences</div>
|
2022-01-09 23:13:09 +01:00
|
|
|
<div class=parcours></div>
|
|
|
|
<div class=competences></div>
|
|
|
|
<div class=ACs></div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
/* Style du module */
|
|
|
|
const styles = document.createElement('link');
|
|
|
|
styles.setAttribute('rel', 'stylesheet');
|
2023-05-11 18:08:02 +02:00
|
|
|
styles.setAttribute('href', removeLastTwoComponents(getCurrentScriptPath()) + '/css/ref-competences.css');
|
2022-01-09 23:13:09 +01:00
|
|
|
|
|
|
|
this.shadow.appendChild(styles);
|
|
|
|
}
|
|
|
|
|
|
|
|
set setData(data) {
|
|
|
|
this.data = data;
|
|
|
|
this.parcours();
|
|
|
|
}
|
|
|
|
|
|
|
|
parcours() {
|
|
|
|
let parcoursDIV = this.shadow.querySelector(".parcours");
|
|
|
|
Object.entries(this.data.parcours).forEach(([cle, parcours]) => {
|
|
|
|
let div = document.createElement("div");
|
2023-04-13 15:16:14 +02:00
|
|
|
div.innerHTML = `<a title="${parcours.libelle}">${parcours.code}</a>`;
|
2022-01-09 23:13:09 +01:00
|
|
|
div.addEventListener("click", (event) => { this.competences(event, cle) })
|
|
|
|
parcoursDIV.appendChild(div);
|
|
|
|
})
|
2022-01-15 15:09:16 +01:00
|
|
|
this.initCompetences();
|
|
|
|
}
|
2022-01-09 23:13:09 +01:00
|
|
|
|
2022-01-15 15:09:16 +01:00
|
|
|
initCompetences() {
|
|
|
|
this.competencesNumber = {};
|
|
|
|
let i = 0;
|
|
|
|
Object.keys(this.data.competences).forEach(competence => {
|
|
|
|
this.competencesNumber[competence] = 1 + i++ % 6;
|
|
|
|
})
|
2022-01-09 23:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
competences(event, cle) {
|
|
|
|
this.shadow.querySelector(".parcours>.focus")?.classList.remove("focus");
|
|
|
|
event.currentTarget.classList.add("focus");
|
2022-01-15 15:09:16 +01:00
|
|
|
let divCompetences = this.shadow.querySelector(".competences");
|
2022-01-09 23:13:09 +01:00
|
|
|
|
|
|
|
this.shadow.querySelector(".competences").innerHTML = "";
|
2022-01-15 15:09:16 +01:00
|
|
|
|
2022-01-17 00:41:57 +01:00
|
|
|
/* Création des compétences */
|
|
|
|
let competencesBucket = [];
|
2022-01-15 15:09:16 +01:00
|
|
|
Object.entries(this.data.parcours[cle].annees).forEach(([annee, dataAnnee]) => {
|
|
|
|
Object.entries(dataAnnee.competences).forEach(([competence, niveauCle]) => {
|
|
|
|
let numComp = this.competencesNumber[competence];
|
2022-01-09 23:13:09 +01:00
|
|
|
let divCompetence = document.createElement("div");
|
2022-01-15 15:09:16 +01:00
|
|
|
divCompetence.innerText = `${competence} ${niveauCle.niveau}`;
|
|
|
|
divCompetence.style.gridRowStart = annee;
|
2022-11-28 18:03:48 +01:00
|
|
|
divCompetence.style.gridColumnStart = competence.replaceAll(" ", "_");
|
2022-01-15 15:09:16 +01:00
|
|
|
divCompetence.className = "comp" + numComp;
|
|
|
|
divCompetence.dataset.competence = `${competence} ${niveauCle.niveau}`;
|
|
|
|
divCompetence.addEventListener("click", (event) => { this.AC(event, competence, niveauCle.niveau, annee, numComp) })
|
|
|
|
divCompetences.appendChild(divCompetence);
|
2022-01-17 00:41:57 +01:00
|
|
|
|
|
|
|
competencesBucket.push(competence);
|
2022-01-15 15:09:16 +01:00
|
|
|
})
|
2022-01-09 23:13:09 +01:00
|
|
|
})
|
2022-01-15 15:09:16 +01:00
|
|
|
|
2022-01-17 00:41:57 +01:00
|
|
|
/* Affectation de la taille des éléments */
|
|
|
|
//divCompetences.style.setProperty("--competence-size", `calc(${100 / competencesBucket.length}% )`);
|
|
|
|
let gridTemplate = "";
|
|
|
|
Object.keys(this.data.competences).forEach(competence => {
|
|
|
|
if (competencesBucket.indexOf(competence) == -1) {
|
2022-11-28 18:03:48 +01:00
|
|
|
gridTemplate += `[${competence.replaceAll(" ", "_")}] 0`;
|
2022-01-17 00:41:57 +01:00
|
|
|
} else {
|
2022-11-28 18:03:48 +01:00
|
|
|
gridTemplate += `[${competence.replaceAll(" ", "_")}] 1fr`;
|
2022-01-17 00:41:57 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
this.shadow.querySelector(".competences").style.gridTemplateColumns = gridTemplate;
|
|
|
|
|
2022-01-15 15:09:16 +01:00
|
|
|
/* Réaffectation des focus */
|
|
|
|
this.shadow.querySelectorAll(".AC").forEach(ac => {
|
|
|
|
this.shadow.querySelector(`[data-competence="${ac.dataset.competence}"]`).classList.add("focus");
|
|
|
|
});
|
2022-01-09 23:13:09 +01:00
|
|
|
}
|
|
|
|
|
2022-01-15 15:09:16 +01:00
|
|
|
AC(event, competence, niveau, annee, numComp) {
|
2022-01-09 23:13:09 +01:00
|
|
|
event.currentTarget.classList.toggle("focus");
|
2022-01-15 15:09:16 +01:00
|
|
|
if (this.shadow.querySelector(`.ACs [data-competence="${competence} ${niveau}"]`)) {
|
|
|
|
this.shadow.querySelector(`.ACs [data-competence="${competence} ${niveau}"]`).remove();
|
2022-01-09 23:13:09 +01:00
|
|
|
} else {
|
|
|
|
let output = `
|
2022-01-15 15:09:16 +01:00
|
|
|
<ul class=AC data-competence="${competence} ${niveau}">
|
|
|
|
<h2 class=comp${numComp}>${competence} ${niveau}</h2>
|
2022-01-09 23:13:09 +01:00
|
|
|
`;
|
|
|
|
Object.entries(this.data.competences[competence].niveaux["BUT" + annee].app_critiques).forEach(([num, contenu]) => {
|
|
|
|
output += `<li><div class=comp${numComp}>${num}</div><div>${contenu.libelle}</div></li>`;
|
|
|
|
})
|
|
|
|
this.shadow.querySelector(".ACs").innerHTML += output + "</ul>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
customElements.define('ref-competences', ref_competences);
|