Files
sm-bm-plugin/public/assets/QuizView-DM-7Xeii.js
Jakub Zych ebd9117f8c feat: lecturer on class sessions and in the session course ref
The schedule showed a lecturer only where the session notes named one
(Globalizacja), so the student plan had nobody under the other courses.
The session JSON now carries the course lecturer in its course ref and an
optional per-session lecturer (new nullable column, admin field, seed key)
for courses shared between two people. The student app shows the
session's own lecturer or, failing that, the course's.
2026-10-17 11:20:11 +02:00

2 lines
11 KiB
JavaScript

var ne=Object.defineProperty;var le=(m,o,n)=>o in m?ne(m,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):m[o]=n;var c=(m,o,n)=>le(m,typeof o!="symbol"?o+"":o,n);import{_ as oe}from"./PageHead.vue_vue_type_script_setup_true_lang-BJjYuJvl.js";import{_ as ie}from"./LoadState.vue_vue_type_script_setup_true_lang-BD6A8a9g.js";import{q as j,_ as re}from"./quizzes-av2RLNrx.js";import{d as ue,q as de,J as ce,c as i,h as S,i as P,r as v,G as I,o as r,F as k,m as _,t as l,e as h,a as e,y as R,z as ve,x as Z,s as x,K as he,k as pe}from"./index-C9sCss04.js";import{c as ye}from"./format-bcE-cYHJ.js";function me(m,o=Math.random){const n=m.slice();for(let p=n.length-1;p>0;p--){const f=Math.floor(o()*(p+1));[n[p],n[f]]=[n[f],n[p]]}return n}class fe{constructor(o,n=5,p=Math.random){c(this,"cards");c(this,"roundSize");c(this,"rng");c(this,"pool",[]);c(this,"round",[]);c(this,"cur",0);c(this,"roundMarks",[]);c(this,"marks",{});c(this,"order",[]);c(this,"review",!1);c(this,"phase","card");this.cards=new Map(o.map(f=>[f.id,f])),this.roundSize=Math.max(1,n),this.rng=p,this.reset()}reset(){this.marks={},this.order=[],this.pool=[...this.cards.keys()],this.draw()}draw(){if(this.review=!1,this.pool.length===0){this.round=[],this.roundMarks=[],this.cur=0,this.phase="final";return}const o=[];for(;o.length<this.roundSize&&this.pool.length;)o.push(this.pool.splice(Math.floor(this.rng()*this.pool.length),1)[0]);this.startRound(o)}startRound(o){this.round=o,this.roundMarks=o.map(()=>null),this.cur=0,this.phase="card"}get current(){const o=this.round[this.cur];return o===void 0?null:this.cards.get(o)??null}get isLastInRound(){return this.cur===this.round.length-1}get answeredCount(){return this.order.length}get remaining(){return this.pool.length}get total(){return this.cards.size}mark(o){const n=this.round[this.cur];n===void 0||this.phase!=="card"||(this.roundMarks[this.cur]=o,n in this.marks||this.order.push(n),this.marks[n]=o)}next(){this.phase==="card"&&(this.cur++,this.cur>=this.round.length&&(this.phase=this.review||this.pool.length===0?"final":"round"))}finish(){this.phase="final"}ids(o){return this.order.filter(n=>this.marks[n]===o)}get missed(){return this.ids("n")}get known(){return this.ids("y")}get tally(){return{y:this.known.length,n:this.missed.length}}startReview(){const o=this.missed;o.length!==0&&(this.review=!0,this.startRound(me(o,this.rng)))}}const ge={key:0,class:"muted"},ke={class:"card accent","aria-labelledby":"start-h"},_e={class:"small muted"},we={key:0,class:"chips wrap",role:"group","aria-label":"Kategoria"},be=["aria-pressed"],ze=["aria-pressed","onClick"],xe={class:"btn-row",style:{"margin-top":"12px"}},Ce=["disabled"],Me={key:1,class:"section","aria-labelledby":"hist-h"},qe={class:"card"},je={class:"quiz-bar"},Ne={class:"score"},$e={class:"y"},We={class:"n"},Re={class:"count"},Se={class:"btn-row"},Le=["disabled"],Be=["disabled"],Pe={class:"step","aria-live":"polite"},Ze={key:0},Ke={key:1,class:"qcard"},Te={class:"q"},Ve={key:1,class:"answer","aria-live":"polite"},De={class:"qactions"},Qe=["aria-pressed","disabled"],Ee=["aria-pressed","disabled"],Ae=["disabled"],Fe={key:2,class:"error-text",role:"alert"},He={key:2,class:"qcard sum"},Ie={class:"tag"},Oe={class:"qactions"},Ge={key:3,class:"qcard sum"},Je={class:"qactions",style:{margin:"0 0 18px"}},Ue={key:0,class:"grp miss"},Xe={class:"tag"},Ye={key:1,class:"grp ok"},et={class:"tag"},tt={key:2,class:"muted small mono",style:{margin:"14px 0 0"}},ut=ue({__name:"QuizView",props:{slug:{}},setup(m){const o=m,n=v(null),p=v(""),f=v([]),y=v(null),d=v(null),g=v(null),w=v(!1),N=v({}),C=v(!1),$=v(""),b=v(null),K=v(null);async function T(){p.value="";try{n.value=await j.quiz(o.slug),V()}catch(t){p.value=I(t)}}async function V(){try{f.value=(await j.attempts(o.slug)).data}catch{}}de(T),ce(()=>{g.value&&!w.value&&d.value?.answeredCount&&j.finish(g.value.id).catch(()=>{})});const D=x(()=>{const t=new Map;for(const a of n.value?.questions??[])a.category&&t.set(a.category,(t.get(a.category)??0)+1);return[...t].sort(([a],[M])=>a.localeCompare(M,"pl"))}),Q=x(()=>(n.value?.questions??[]).filter(t=>!y.value||t.category===y.value).length);function O(){const t=(n.value?.questions??[]).filter(a=>a.type==="self_check"&&(!y.value||a.category===y.value)).map(a=>({id:a.id,text:a.text,category:a.category,answer:a.answer_text??""}));d.value=new fe(t,n.value?.round_size??5),g.value=null,w.value=!1,N.value={},$.value="",b.value=null}async function G(){return g.value||(g.value=await j.start(o.slug,y.value),w.value=!1),g.value}async function E(t){const a=d.value,M=a?.current;if(!(!a||!M||C.value)){C.value=!0,$.value="";try{const u=await G();await j.answer(u.id,{question_id:M.id,known:t==="y"}),a.mark(t),await he(),K.value?.focus()}catch(u){$.value=`Nie udało się zapisać odpowiedzi. ${I(u)}`}finally{C.value=!1}}}function J(){const t=d.value?.current?.id;t!==void 0&&(N.value={...N.value,[t]:!0})}function U(){const t=d.value;t&&(t.next(),t.phase==="final"&&W())}function A(){d.value?.draw(),d.value?.phase==="final"&&W()}function F(){d.value?.finish(),W()}async function W(){const t=g.value;if(!(!t||w.value)){w.value=!0;try{b.value=await j.finish(t.id)}catch{}V()}}function X(){const t=d.value;t&&(t.startReview(),g.value=null,w.value=!1,b.value=null)}function Y(){d.value?.reset(),g.value=null,w.value=!1,N.value={},b.value=null,d.value?.phase==="final"&&W()}function ee(){W(),d.value=null}const s=x(()=>d.value),z=x(()=>s.value?.current??null),L=x(()=>z.value?s.value?.roundMarks[s.value.cur]??null:null),H=t=>s.value?.cards.get(t)?.answer??"",te=t=>s.value?.roundMarks[t]??(t===s.value?.cur?"cur":""),se=x(()=>{const t=s.value;return t?t.isLastInRound?t.review?"Wynik powtórki":t.remaining?"Koniec rundy":"Podsumowanie":"Dalej":""}),B=t=>ye(t,"pytanie","pytania","pytań"),ae=x(()=>{const t=s.value;return t?t.phase==="round"?"Koniec rundy":t.phase==="final"?t.review?"Wynik po powtórce":t.remaining?"Podsumowanie sesji":"Cała pula za Tobą":`${t.review?"Powtórka · ":""}Pytanie ${t.cur+1} z ${t.round.length}`:""});return(t,a)=>{const M=pe("router-link");return r(),i("div",null,[S(ie,{ready:!!n.value,error:p.value,onRetry:a[3]||(a[3]=u=>T())},{default:P(()=>[n.value?(r(),i(k,{key:0},[S(oe,{eyebrow:"Quiz",title:n.value.title},{default:P(()=>[S(M,{class:"btn small ghost",to:"/quizy"},{default:P(()=>[...a[4]||(a[4]=[_("← Quizy",-1)])]),_:1})]),_:1},8,["title"]),s.value?(r(),i(k,{key:1},[e("div",je,[e("div",null,[e("div",Ne,[e("span",$e,[a[7]||(a[7]=_("Wiem ",-1)),e("b",null,l(s.value.tally.y),1)]),e("span",We,[a[8]||(a[8]=_("Nie wiem ",-1)),e("b",null,l(s.value.tally.n),1)])]),e("span",Re,[_(l(B(s.value.total))+" w puli · "+l(s.value.remaining)+" jeszcze nie padło",1),y.value?(r(),i(k,{key:0},[_(" · "+l(y.value),1)],64)):h("",!0)])]),e("div",Se,[e("button",{class:"btn small",type:"button",disabled:s.value.phase==="final",onClick:A},"Losuj "+l(n.value.round_size??5)+" nowych",9,Le),e("button",{class:"btn small primary",type:"button",disabled:s.value.answeredCount===0||s.value.phase==="final",onClick:F},"Zakończ",8,Be)])]),s.value.phase!=="final"?(r(),i("div",{key:0,class:"round-progress",style:ve({gridTemplateColumns:`repeat(${s.value.round.length}, 1fr)`}),"aria-hidden":"true"},[(r(!0),i(k,null,R(s.value.round,(u,q)=>(r(),i("span",{key:q,class:Z(te(q))},null,2))),128))],4)):h("",!0),e("div",Pe,[e("span",null,l(ae.value),1),s.value.phase==="card"&&z.value?.category?(r(),i("span",Ze,l(z.value.category),1)):h("",!0)]),s.value.phase==="card"&&z.value?(r(),i("div",Ke,[e("p",Te,l(z.value.text),1),N.value[z.value.id]?(r(),i("div",Ve,[a[9]||(a[9]=e("span",{class:"tag"},"Odpowiedź",-1)),_(" "+l(z.value.answer),1)])):(r(),i("button",{key:0,class:"reveal",type:"button",onClick:J},"odpowiedź")),e("div",De,[e("button",{class:"btn yes",type:"button","aria-pressed":L.value==="y",disabled:C.value,onClick:a[1]||(a[1]=u=>E("y"))},"Wiem!",8,Qe),e("button",{class:"btn no",type:"button","aria-pressed":L.value==="n",disabled:C.value,onClick:a[2]||(a[2]=u=>E("n"))},"Nie wiem",8,Ee),e("button",{ref_key:"nextBtn",ref:K,class:"btn primary next",type:"button",disabled:!L.value||C.value,onClick:U},l(se.value),9,Ae)]),$.value?(r(),i("p",Fe,l($.value),1)):h("",!0)])):s.value.phase==="round"?(r(),i("div",He,[e("h2",null,"Wiem "+l(s.value.roundMarks.filter(u=>u==="y").length)+" z "+l(s.value.round.length),1),a[10]||(a[10]=e("p",null,"Pytania „Nie wiem” trafiają do powtórki. Zbierzesz je przyciskiem „Zakończ”.",-1)),e("ol",null,[(r(!0),i(k,null,R(s.value.round,(u,q)=>(r(),i("li",{key:u,class:Z(s.value.roundMarks[q])},[e("span",Ie,l(s.value.cards.get(u)?.category),1),_(" "+l(s.value.cards.get(u)?.text)+" ",1),e("small",null,l(H(u)),1)],2))),128))]),e("div",Oe,[e("button",{class:"btn primary",type:"button",onClick:A},"Losuj "+l(n.value.round_size??5)+" nowych",1),e("button",{class:"btn",type:"button",onClick:F},"Zakończ")])])):(r(),i("div",Ge,[e("h2",null,"Wiem "+l(s.value.known.length)+" z "+l(s.value.answeredCount),1),e("p",null,l(s.value.missed.length?`Do powtórki: ${s.value.missed.length}.`:s.value.answeredCount?"Wszystko umiesz. Nie ma nic do powtórki.":"Nie udzielono żadnej odpowiedzi."),1),e("div",Je,[s.value.missed.length?(r(),i("button",{key:0,class:"btn primary",type:"button",onClick:X},"Powtórz "+l(B(s.value.missed.length)),1)):h("",!0),e("button",{class:Z(["btn",{primary:!s.value.missed.length}]),type:"button",onClick:Y},"Nowa sesja",2),e("button",{class:"btn ghost",type:"button",onClick:ee},"Wróć do quizu")]),s.value.missed.length?(r(),i("div",Ue,[a[11]||(a[11]=e("h3",null,"Nie wiem",-1)),e("ol",null,[(r(!0),i(k,null,R(s.value.missed,u=>(r(),i("li",{key:u,class:"n"},[e("span",Xe,l(s.value.cards.get(u)?.category),1),_(" "+l(s.value.cards.get(u)?.text)+" ",1),e("small",null,l(H(u)),1)]))),128))])])):h("",!0),s.value.known.length?(r(),i("div",Ye,[a[12]||(a[12]=e("h3",null,"Wiem",-1)),e("ol",null,[(r(!0),i(k,null,R(s.value.known,u=>(r(),i("li",{key:u,class:"y"},[e("span",et,l(s.value.cards.get(u)?.category),1),_(" "+l(s.value.cards.get(u)?.text),1)]))),128))])])):h("",!0),b.value?(r(),i("p",tt,"Zapisano w historii: "+l(Math.round(b.value.score_points))+"/"+l(Math.round(b.value.max_points)),1)):h("",!0)]))],64)):(r(),i(k,{key:0},[n.value.description?(r(),i("p",ge,l(n.value.description),1)):h("",!0),e("section",ke,[a[5]||(a[5]=e("h2",{id:"start-h",style:{"margin-bottom":"8px"}},"Nowa sesja",-1)),e("p",_e,"Rundy po "+l(n.value.round_size??5)+" losowych pytań, które jeszcze nie padły. Każdą odpowiedź zapisujemy na koncie.",1),D.value.length?(r(),i("div",we,[e("button",{class:"chip",type:"button","aria-pressed":y.value===null,onClick:a[0]||(a[0]=u=>y.value=null)},"Wszystkie",8,be),(r(!0),i(k,null,R(D.value,([u,q])=>(r(),i("button",{key:u,class:"chip",type:"button","aria-pressed":y.value===u,onClick:st=>y.value=u},l(u)+" · "+l(q),9,ze))),128))])):h("",!0),e("div",xe,[e("button",{class:"btn primary",type:"button",disabled:Q.value===0,onClick:O},"Zacznij · "+l(B(Q.value)),9,Ce)])]),f.value.length?(r(),i("section",Me,[a[6]||(a[6]=e("div",{class:"section-head"},[e("h2",{id:"hist-h"},"Historia podejść")],-1)),e("div",qe,[S(re,{attempts:f.value},null,8,["attempts"])])])):h("",!0)],64))],64)):h("",!0)]),_:1},8,["ready","error"])])}}});export{ut as default};