- board.js: genWidgetId() naar het voorbeeld van genBoardId(); toegekend in makeWidget (bestaand wid uit opgeslagen data wint), bewaard in serializeBoard; dupliceren geeft een nieuw wid; oude borden zonder wid krijgen er vanzelf een bij de eerstvolgende save - /my/assignment stuurt wid mee per widget - pupil.js: voortgang-widgetId gebruikt nu het wid (terugval op positie voor borden van vóór deze versie) Voorbereiding op het delen van één losse widget (roadmap item 8).
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);
|
|
/* borden die vóór de invoering van stabiele widget-ids zijn opgeslagen
|
|
hebben nog geen wid - dan is positie in de lijst de terugval-identiteit,
|
|
stabiel zolang de leerkracht de widgets op het bord niet herschikt */
|
|
const widgetId = w.wid || (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 = "";
|
|
}
|