diff --git a/VERSION b/VERSION index b401d59..b920c09 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.12-beta +0.3.13-beta diff --git a/public/js/board.js b/public/js/board.js index 443bf36..6cdcd38 100644 --- a/public/js/board.js +++ b/public/js/board.js @@ -66,6 +66,11 @@ function clampWidgetSize(w, h, def){ return { w: fw, h: fh }; } +/* stabiel widget-instantie-id, zelfde patroon als genBoardId() verderop - nodig + zodat een toewijzing van één enkele widget (zie pupil.js/admin.js) die widget + blijft vinden ook als er widgets vóór/na worden toegevoegd of verplaatst */ +function genWidgetId(){ return "w" + Date.now().toString(36) + Math.random().toString(36).slice(2,8); } + function makeWidget(def, saved){ const win = document.createElement("div"); win.className = "widget"; @@ -222,7 +227,7 @@ function makeWidget(def, saved){ const api = def.mount(body, saved ? saved.state : null) || {}; if(saved && saved.min) setMin(true); if(saved && saved.max) setMax(true); - const inst = { def, win, api }; + const inst = { def, win, api, wid: (saved && saved.wid) || genWidgetId() }; dupBtn.title=T("widgetDuplicate");dupBtn.setAttribute("aria-label",dupBtn.title);previewBtn.title=T("widgetPreview");previewBtn.setAttribute("aria-label",previewBtn.title); dupBtn.addEventListener("click",()=>makeWidget(def,{x:win.offsetLeft+28,y:win.offsetTop+28,w:win.offsetWidth,h:win.offsetHeight,wz:+win.dataset.wz||1,state:api.getState?structuredClone(api.getState()):null})); instances.add(inst); @@ -249,6 +254,7 @@ function serializeBoard(){ const max = w.dataset.max === "1"; return { id: inst.def.id, + wid: inst.wid, x: max ? +w.dataset.pmx : w.offsetLeft, y: max ? +w.dataset.pmy : w.offsetTop, w: min ? (+w.dataset.prevW || inst.def.w) : max ? +w.dataset.pmw : w.offsetWidth, diff --git a/public/js/core.js b/public/js/core.js index a19c261..e3371e3 100644 --- a/public/js/core.js +++ b/public/js/core.js @@ -2,7 +2,7 @@ "use strict"; /* version — shown until /api/version resolves (or if the fetch fails, e.g. offline). Kept in sync by hand with the VERSION file at the repo root on every release. */ -const VERSION = "0.3.12-beta"; +const VERSION = "0.3.13-beta"; (function(){ const tag = document.getElementById("verTag"); tag.textContent = "v"+VERSION; diff --git a/public/js/pupil.js b/public/js/pupil.js index 33b8983..6901314 100644 --- a/public/js/pupil.js +++ b/public/js/pupil.js @@ -34,10 +34,10 @@ function renderPupilWidgets(widgets){ 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, + /* 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 = def.id + ":" + idx; + 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(()=>{}); }}); diff --git a/src/api.js b/src/api.js index 636b077..eaf39f6 100644 --- a/src/api.js +++ b/src/api.js @@ -556,7 +556,7 @@ export default async function api(app) { if (!a) return { widgets: [], updatedAt: null }; const t = (await pool.query('SELECT data FROM users WHERE id = $1', [a.teacher_id])).rows[0]; const board = t ? findBoardById(t.data, a.board_id) : null; - const widgets = (board?.data?.widgets || []).map((w) => ({ id: w.id, state: w.state })); + const widgets = (board?.data?.widgets || []).map((w) => ({ id: w.id, wid: w.wid, state: w.state })); return { widgets, updatedAt: a.updated_at }; });