- board.js: fix bug waarbij de opts-parameter (readonly e.d.) nooit bij mountMath aankwam, doordat de registry-wrapper hem liet vallen - math.js/letters.js/ball.js: nieuwe opts.onProgress-callback, aangeroepen bij resp. einde rekenronde, voltooid woord en geknapte ballon - pupil.js: geeft onProgress mee bij het mounten en post het naar /my/progress; alleen actief in leerling-speelmodus, niet bij bewerken
70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
/* teach - leerling-omgeving: toont enkel de widgets die de leerkracht heeft
|
|
klaargezet (via een toewijzing aan de klas of de leerling zelf), in
|
|
speelmodus (readonly) en zonder de sleep/vergroot/sluit-chrome van het bord.
|
|
Geen momentopname: /my/assignment zoekt live in het bord van de leerkracht,
|
|
dus deze pagina pollt periodiek zodat nieuwe woorden vanzelf doorkomen. */
|
|
const PUPIL_WIDGET_CATS = ["taal", "rekenen"];
|
|
const pupilView = document.getElementById("pupilView");
|
|
let pupilPollTimer = null;
|
|
let pupilLastSig = null;
|
|
|
|
function pupilAllowedDefs(){
|
|
return REGISTRY.filter(d => PUPIL_WIDGET_CATS.includes(d.cat));
|
|
}
|
|
|
|
function renderPupilWidgets(widgets){
|
|
pupilView.innerHTML = "";
|
|
const defs = pupilAllowedDefs();
|
|
const usable = widgets
|
|
.map(w => ({ w, def: defs.find(d => d.id === w.id) }))
|
|
.filter(x => x.def);
|
|
if(!usable.length){
|
|
const hint = document.createElement("div");
|
|
hint.className = "pupil-empty";
|
|
hint.textContent = T("pupilEmpty");
|
|
pupilView.appendChild(hint);
|
|
return;
|
|
}
|
|
usable.forEach(({ w, def }, idx)=>{
|
|
const card = document.createElement("div");
|
|
card.className = "widget pupil-card";
|
|
card.style.width = def.w + "px";
|
|
card.style.minHeight = def.h + "px";
|
|
const body = document.createElement("div");
|
|
body.className = "widget-body";
|
|
card.appendChild(body);
|
|
pupilView.appendChild(card);
|
|
/* geen stabiel widget-instantie-id in het bord (alleen het widget-type in
|
|
w.id) - positie in de lijst is de fijnste identiteit die beschikbaar is,
|
|
stabiel zolang de leerkracht de widgets op het bord niet herschikt */
|
|
const widgetId = def.id + ":" + idx;
|
|
def.mount(body, w.state || null, { readonly:true, onProgress: (p)=>{
|
|
api("/my/progress", { method:"POST", body: { widgetId, widgetType: def.id, ...p } }).catch(()=>{});
|
|
}});
|
|
});
|
|
}
|
|
|
|
async function pupilPoll(){
|
|
try{
|
|
const res = await api("/my/assignment");
|
|
const sig = JSON.stringify(res.widgets || []);
|
|
if(sig !== pupilLastSig){
|
|
pupilLastSig = sig;
|
|
renderPupilWidgets(res.widgets || []);
|
|
}
|
|
}catch(e){ /* stille mislukking - volgende poll probeert opnieuw */ }
|
|
}
|
|
|
|
function startPupilView(){
|
|
document.body.classList.add("pupil-mode");
|
|
pupilLastSig = null;
|
|
pupilPoll();
|
|
clearInterval(pupilPollTimer);
|
|
pupilPollTimer = setInterval(pupilPoll, 20000);
|
|
}
|
|
function stopPupilView(){
|
|
document.body.classList.remove("pupil-mode");
|
|
clearInterval(pupilPollTimer);
|
|
pupilPollTimer = null;
|
|
pupilView.innerHTML = "";
|
|
}
|