feat: add writing homework feature to workbook
Browse files- Introduced a new topic type "write" for homework, allowing students to write sentences in Arabic.
- Updated the LESSONS and WRITING structures to accommodate the new homework type.
- Enhanced the UI to support writing tasks, including a dialog for input and display of written sentences.
- Implemented functionality to save and retrieve written sentences for students, ensuring data persistence across devices.
- Updated privacy policy to reflect the storage of written homework in Supabase.
- Added tests to verify the new writing functionality and ensure proper handling of homework submissions.
- README.md +27 -0
- app/auth.py +42 -0
- app/main.py +51 -4
- app/workbook.py +19 -2
- ihki.todo +2 -1
- static/index.html +99 -23
- static/privacy.html +1 -1
- tests/test_scoring.py +25 -3
README.md
CHANGED
|
@@ -108,6 +108,33 @@ The page's "ืืืชืงืืืืช ืฉืื" button reads these rows back through `GET /
|
|
| 108 |
|
| 109 |
The course has levels, each with a planned number of lessons (`LEVELS` in `app/workbook.py`: ืจืื 1 and ืจืื 2, 10 lessons each). Every lesson in `LESSONS` is keyed by its level and number, `(level, lesson)`; one outside the plan stops the app at startup. The path shows each level under its name, and the lessons not written yet as "ืืงืจืื". Level 1's lessons keep their first ids ("1", topics "l1-โฆ") so recorded attempts and saved classes still match; later levels' are "2.1", topics "l2.1-โฆ".
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
### Classes
|
| 112 |
|
| 113 |
In the panel the teacher opens a class in five steps, a question each: its name (such as "ืืชืืืืื ืืืงืืืืจ 2026"), its level (the class studies all the level's lessons; one not written yet opens to the class once it is), its students (ticked from the accounts the panel knows, or added by Google email, each with an optional nickname), its homework, and a summary to confirm, which says where all of it is changed later. That is the class's edit dialog ("ืขืจืืื", beside the class in the panel's list of classes): the name, the lessons one by one (by level: a level's box ticks all of it), the homework, and the students, a line each with the Google email and an optional nickname (`dana@gmail.com ืื ื`); the class is deleted there too. A student may be in several classes: after the opening screen the page asks which one they practise in now, and the learning path shows that class's lessons (a teacher, and anyone before the first class, sees every lesson and is not asked). The page shows the class under the app's name, and pressing it lists the class's students, with a button to move to another class; each student appears by their nickname in it or else their Google name (no addresses; `GET /api/classmates`). Once there is a class, only the classes' students and the teachers can sign in; before the first one, any Google account can.
|
|
|
|
| 108 |
|
| 109 |
The course has levels, each with a planned number of lessons (`LEVELS` in `app/workbook.py`: ืจืื 1 and ืจืื 2, 10 lessons each). Every lesson in `LESSONS` is keyed by its level and number, `(level, lesson)`; one outside the plan stops the app at startup. The path shows each level under its name, and the lessons not written yet as "ืืงืจืื". Level 1's lessons keep their first ids ("1", topics "l1-โฆ") so recorded attempts and saved classes still match; later levels' are "2.1", topics "l2.1-โฆ".
|
| 110 |
|
| 111 |
+
A lesson's homework in the workbook, sentences of the student's own, is a topic of the kind `"write"`, the lesson's last ("ืืชืืืช ืืฉืคืืื": `l1-hw`, `l2-hw`). It has no sentences to say: its task and the number of sentences are in `WRITING` in `app/workbook.py`, and on the path it opens a box with the task and a line for each sentence; it is done once every line is filled. Nothing is scored, so the lesson's count of practised sentences leaves it out.
|
| 112 |
+
|
| 113 |
+
What a signed-in student writes is sent to the server as they write (`PUT /api/writing/<topic>`) and kept in the table `writings`, a row per student and topic, so it follows them to any device (`GET /api/writing`). The device keeps a copy too: lines the server did not take stay there and are sent on the next visit, and without sign-in the copy is all there is. Create the table once in the Supabase SQL editor:
|
| 114 |
+
|
| 115 |
+
```sql
|
| 116 |
+
create table public.writings (
|
| 117 |
+
user_id uuid not null default auth.uid() references auth.users (id) on delete cascade,
|
| 118 |
+
topic text not null, -- the topic id, e.g. l1-hw
|
| 119 |
+
lines jsonb not null, -- the sentences as written, "" for one not written yet
|
| 120 |
+
updated_at timestamptz not null default now(),
|
| 121 |
+
primary key (user_id, topic)
|
| 122 |
+
);
|
| 123 |
+
|
| 124 |
+
alter table public.writings enable row level security;
|
| 125 |
+
grant select, insert, update on public.writings to authenticated;
|
| 126 |
+
create policy "students read their own writings" on public.writings
|
| 127 |
+
for select to authenticated using (user_id = auth.uid());
|
| 128 |
+
create policy "students add their own writings" on public.writings
|
| 129 |
+
for insert to authenticated with check (user_id = auth.uid());
|
| 130 |
+
create policy "students change their own writings" on public.writings
|
| 131 |
+
for update to authenticated using (user_id = auth.uid()) with check (user_id = auth.uid());
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
Until the table exists the sentences stay on each student's device and the panel shows none.
|
| 135 |
+
|
| 136 |
+
A writing topic can be the class's homework like any topic, and is the one offered: the new-class steps open with it chosen, and in a class's "ืขืจืืื" setting a day with no topic chosen picks the written homework of the class's last lesson that has one, so the teacher has only the day to set. The panel then counts its sentences ("ื ืืชืื 3 ืืชืื 5") in the homework's summary and column, and a student's own screen lists the sentences they wrote under the topic.
|
| 137 |
+
|
| 138 |
### Classes
|
| 139 |
|
| 140 |
In the panel the teacher opens a class in five steps, a question each: its name (such as "ืืชืืืืื ืืืงืืืืจ 2026"), its level (the class studies all the level's lessons; one not written yet opens to the class once it is), its students (ticked from the accounts the panel knows, or added by Google email, each with an optional nickname), its homework, and a summary to confirm, which says where all of it is changed later. That is the class's edit dialog ("ืขืจืืื", beside the class in the panel's list of classes): the name, the lessons one by one (by level: a level's box ticks all of it), the homework, and the students, a line each with the Google email and an optional nickname (`dana@gmail.com ืื ื`); the class is deleted there too. A student may be in several classes: after the opening screen the page asks which one they practise in now, and the learning path shows that class's lessons (a teacher, and anyone before the first class, sees every lesson and is not asked). The page shows the class under the app's name, and pressing it lists the class's students, with a button to move to another class; each student appears by their nickname in it or else their Google name (no addresses; `GET /api/classmates`). Once there is a class, only the classes' students and the teachers can sign in; before the first one, any Google account can.
|
app/auth.py
CHANGED
|
@@ -23,6 +23,10 @@ Texts: the teacher also adds texts there (a story or a dialogue: a lesson, a tit
|
|
| 23 |
Arabic written in Hebrew letters, and a dialogue's two voices), kept in the Supabase table `texts` and placed among
|
| 24 |
the lesson's topics like the videos. Each is a topic practised line by line (see app/texts.py).
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
Env: SUPABASE_URL (https://<project-ref>.supabase.co)
|
| 27 |
SUPABASE_PUBLISHABLE_KEY (the publishable/anon key; it is public and also goes to the page)
|
| 28 |
TEACHER_EMAILS (optional: the accounts with the management panel, separated by commas or spaces)
|
|
@@ -128,6 +132,44 @@ class SupabaseAuth:
|
|
| 128 |
break
|
| 129 |
return rows
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
def _get(self, path: str, token: str, key: str):
|
| 132 |
req = urllib.request.Request(
|
| 133 |
self.url + path, headers={"Authorization": f"Bearer {token}", "apikey": key, "User-Agent": "ihki/1.0"})
|
|
|
|
| 23 |
Arabic written in Hebrew letters, and a dialogue's two voices), kept in the Supabase table `texts` and placed among
|
| 24 |
the lesson's topics like the videos. Each is a topic practised line by line (see app/texts.py).
|
| 25 |
|
| 26 |
+
Writing: a lesson's written homework (see workbook.py) is kept in the Supabase table `writings`, a row per student
|
| 27 |
+
and topic, written with the student's own token like the attempts, so it follows them to any device. The panel
|
| 28 |
+
reads every student's with the secret key.
|
| 29 |
+
|
| 30 |
Env: SUPABASE_URL (https://<project-ref>.supabase.co)
|
| 31 |
SUPABASE_PUBLISHABLE_KEY (the publishable/anon key; it is public and also goes to the page)
|
| 32 |
TEACHER_EMAILS (optional: the accounts with the management panel, separated by commas or spaces)
|
|
|
|
| 132 |
break
|
| 133 |
return rows
|
| 134 |
|
| 135 |
+
def writings(self, token: str) -> dict[str, list[str]]:
|
| 136 |
+
"""The student's written homework, {topic id: its lines}. Row-level security limits it to the token's student.
|
| 137 |
+
Before the table is created there is none; any other failure is raised, so the page keeps its own copy."""
|
| 138 |
+
try:
|
| 139 |
+
rows = self._get("/rest/v1/writings?select=topic,lines", token, self.key)
|
| 140 |
+
except urllib.error.HTTPError as e:
|
| 141 |
+
if e.code == 404:
|
| 142 |
+
log.warning("the table `writings` is missing (see the README): written homework stays on the device")
|
| 143 |
+
raise AuthUnavailable("the table writings is missing") from e
|
| 144 |
+
raise AuthUnavailable(f"supabase answered {e.code}") from e
|
| 145 |
+
except (urllib.error.URLError, TimeoutError, ValueError) as e:
|
| 146 |
+
raise AuthUnavailable(str(e)) from e
|
| 147 |
+
return {r["topic"]: [str(x) for x in r["lines"]] for r in rows if isinstance(r.get("lines"), list)}
|
| 148 |
+
|
| 149 |
+
def save_writing(self, token: str, user_id: str, topic: str, lines: list[str]) -> None:
|
| 150 |
+
"""Keeps a topic's lines as the student of this token, in place of what they wrote in it before."""
|
| 151 |
+
row = {"user_id": user_id, "topic": topic, "lines": lines, "updated_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}
|
| 152 |
+
req = urllib.request.Request(
|
| 153 |
+
self.url + "/rest/v1/writings?on_conflict=user_id,topic", data=json.dumps(row).encode(), method="POST",
|
| 154 |
+
headers={"Authorization": f"Bearer {token}", "apikey": self.key, "Content-Type": "application/json",
|
| 155 |
+
"Prefer": "resolution=merge-duplicates,return=minimal", "User-Agent": "ihki/1.0"})
|
| 156 |
+
try:
|
| 157 |
+
urllib.request.urlopen(req, timeout=TIMEOUT).close()
|
| 158 |
+
except urllib.error.HTTPError as e:
|
| 159 |
+
raise AuthUnavailable(f"supabase answered {e.code}: {e.read().decode(errors='replace')[:300]}") from e
|
| 160 |
+
except (urllib.error.URLError, TimeoutError) as e:
|
| 161 |
+
raise AuthUnavailable(str(e)) from e
|
| 162 |
+
|
| 163 |
+
def all_writings(self) -> list[dict]:
|
| 164 |
+
"""Every student's written homework, for the panel: user_id, topic, lines. None before the table is created."""
|
| 165 |
+
try:
|
| 166 |
+
return self._admin(f"/rest/v1/writings?select=user_id,topic,lines&limit={PAGE * 10}")
|
| 167 |
+
except AuthUnavailable as e:
|
| 168 |
+
if "answered 404" not in str(e):
|
| 169 |
+
raise
|
| 170 |
+
log.warning("the table `writings` is missing (see the README): the panel shows no written homework")
|
| 171 |
+
return []
|
| 172 |
+
|
| 173 |
def _get(self, path: str, token: str, key: str):
|
| 174 |
req = urllib.request.Request(
|
| 175 |
self.url + path, headers={"Authorization": f"Bearer {token}", "apikey": key, "User-Agent": "ihki/1.0"})
|
app/main.py
CHANGED
|
@@ -89,6 +89,16 @@ def built(row: dict) -> tuple[list[dict], list[str]]:
|
|
| 89 |
def text_bank(rows: list[dict]) -> dict[int, dict]:
|
| 90 |
"""{phrase id: phrase} of the texts' lines."""
|
| 91 |
return {TEXT_BASE + r["id"] * TEXT_SPAN + k: p for r in rows for k, p in enumerate(built(r)[0])}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
TOPIC_LESSON = {c["id"]: c["lesson"] for c in CATEGORIES} # a topic's lesson: homework is a topic of the class's lessons
|
| 93 |
MIGRATE_CLASSES = ("alter table public.classes add column if not exists nicknames jsonb not null default '{}', "
|
| 94 |
"add column if not exists lessons text[] not null default '{}', "
|
|
@@ -283,19 +293,55 @@ def create_app(scorer: Scorer | None = None, tts: SawtakTTS | None = None,
|
|
| 283 |
s = summary(app.state.auth.attempts(user["token"]) if user else [], text_bank(text_rows()))
|
| 284 |
return {k: s[k] for k in ("best", "tries", "recordings", "days")}
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
@app.get("/api/class")
|
| 287 |
def class_progress(a: SupabaseAuth = Depends(teacher_only)):
|
| 288 |
"""The teacher's panel: the classes (with their lessons and homework), and every student's summary (see `summary`) with
|
|
|
|
| 289 |
their classes ({name: nickname}) and, as "since", the same summary for each class ({name: summary}) of the attempts
|
| 290 |
made since the class was opened: a new class starts clean, whatever its students practised before. The students are the classes' accounts, or every account that signed in
|
| 291 |
when there is no class yet; one that never signed in has joined = false."""
|
| 292 |
try:
|
| 293 |
-
classes, users, rows = a.classes(fresh=True), a.users(), a.all_attempts()
|
| 294 |
except AuthUnavailable as e:
|
| 295 |
raise HTTPException(503, str(e))
|
| 296 |
by: dict[str, list[dict]] = {}
|
| 297 |
for r in rows:
|
| 298 |
by.setdefault(r["user_id"], []).append(r)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
member: dict[str, dict[str, str]] = {} # email -> {class name: nickname}
|
| 300 |
for c in classes:
|
| 301 |
for e in c["emails"]:
|
|
@@ -303,12 +349,13 @@ def create_app(scorer: Scorer | None = None, tts: SawtakTTS | None = None,
|
|
| 303 |
opened = {c["name"]: utc(c["created_at"]) for c in classes if c.get("created_at")}
|
| 304 |
bank, lesson_of = text_bank(text_rows()), topics()
|
| 305 |
|
| 306 |
-
def student(email: str, name: str, joined: bool, mine: list[dict]) -> dict:
|
| 307 |
into = member.get(email.lower(), {})
|
| 308 |
since = {n: summary([r for r in mine if n not in opened or utc(r["created_at"]) >= opened[n]], bank) for n in into}
|
| 309 |
-
return {"email": email, "name": name, "joined": joined, "classes": into, "since": since,
|
|
|
|
| 310 |
|
| 311 |
-
students = [student(u["email"], u["name"], True, by.get(u["id"], []))
|
| 312 |
for u in users if not classes or u["email"].lower() in member]
|
| 313 |
missing = member.keys() - {s["email"].lower() for s in students}
|
| 314 |
students += [student(e, "", False, []) for e in sorted(missing)]
|
|
|
|
| 89 |
def text_bank(rows: list[dict]) -> dict[int, dict]:
|
| 90 |
"""{phrase id: phrase} of the texts' lines."""
|
| 91 |
return {TEXT_BASE + r["id"] * TEXT_SPAN + k: p for r in rows for k, p in enumerate(built(r)[0])}
|
| 92 |
+
# The topics the student writes in (see workbook.py): how many sentences each asks for. What is written is kept in
|
| 93 |
+
# the Supabase table `writings`, a row per student and topic.
|
| 94 |
+
WRITE_TOPICS = {c["id"]: c["write"]["lines"] for c in CATEGORIES if "write" in c}
|
| 95 |
+
CREATE_WRITINGS = ("create table public.writings (user_id uuid not null default auth.uid() references auth.users (id) on delete cascade, "
|
| 96 |
+
"topic text not null, lines jsonb not null, updated_at timestamptz not null default now(), primary key (user_id, topic)); "
|
| 97 |
+
"alter table public.writings enable row level security; grant select, insert, update on public.writings to authenticated; "
|
| 98 |
+
'create policy "students read their own writings" on public.writings for select to authenticated using (user_id = auth.uid()); '
|
| 99 |
+
'create policy "students add their own writings" on public.writings for insert to authenticated with check (user_id = auth.uid()); '
|
| 100 |
+
'create policy "students change their own writings" on public.writings for update to authenticated '
|
| 101 |
+
"using (user_id = auth.uid()) with check (user_id = auth.uid());")
|
| 102 |
TOPIC_LESSON = {c["id"]: c["lesson"] for c in CATEGORIES} # a topic's lesson: homework is a topic of the class's lessons
|
| 103 |
MIGRATE_CLASSES = ("alter table public.classes add column if not exists nicknames jsonb not null default '{}', "
|
| 104 |
"add column if not exists lessons text[] not null default '{}', "
|
|
|
|
| 293 |
s = summary(app.state.auth.attempts(user["token"]) if user else [], text_bank(text_rows()))
|
| 294 |
return {k: s[k] for k in ("best", "tries", "recordings", "days")}
|
| 295 |
|
| 296 |
+
@app.get("/api/writing")
|
| 297 |
+
def writing(user: dict | None = Depends(signed_in)):
|
| 298 |
+
"""The signed-in student's written homework, {topic id: its lines}. 503 when it cannot be read (or without
|
| 299 |
+
sign-in): the page then shows the copy it keeps on the device."""
|
| 300 |
+
if not user:
|
| 301 |
+
raise HTTPException(503, "no sign-in: written homework stays on the device")
|
| 302 |
+
try:
|
| 303 |
+
mine = app.state.auth.writings(user["token"])
|
| 304 |
+
except AuthUnavailable as e:
|
| 305 |
+
raise HTTPException(503, f"written homework not available: {e}")
|
| 306 |
+
return {"writing": {t: lines[:WRITE_TOPICS[t]] for t, lines in mine.items() if t in WRITE_TOPICS}}
|
| 307 |
+
|
| 308 |
+
@app.put("/api/writing/{topic}")
|
| 309 |
+
def write(topic: str, body: dict = Body(...), user: dict | None = Depends(signed_in)):
|
| 310 |
+
"""Keeps what the student wrote in a writing topic: {"lines": a string per sentence, an empty one for a
|
| 311 |
+
sentence not written yet}, in place of what was kept before."""
|
| 312 |
+
if topic not in WRITE_TOPICS:
|
| 313 |
+
raise HTTPException(404, "unknown topic")
|
| 314 |
+
lines = body.get("lines")
|
| 315 |
+
if not isinstance(lines, list) or len(lines) > WRITE_TOPICS[topic] or not all(isinstance(x, str) and len(x) <= MAX_LINE for x in lines):
|
| 316 |
+
raise HTTPException(400, f"up to {WRITE_TOPICS[topic]} sentences, each up to {MAX_LINE} characters")
|
| 317 |
+
if not user:
|
| 318 |
+
raise HTTPException(503, "no sign-in: written homework stays on the device")
|
| 319 |
+
try:
|
| 320 |
+
app.state.auth.save_writing(user["token"], user["id"], topic, [" ".join(x.split()) for x in lines])
|
| 321 |
+
except AuthUnavailable as e:
|
| 322 |
+
if "answered 404" in str(e):
|
| 323 |
+
log.warning("the table `writings` is missing. Run in the Supabase SQL editor: %s", CREATE_WRITINGS)
|
| 324 |
+
raise HTTPException(503, f"written homework not kept: {e}")
|
| 325 |
+
return {"ok": True}
|
| 326 |
+
|
| 327 |
@app.get("/api/class")
|
| 328 |
def class_progress(a: SupabaseAuth = Depends(teacher_only)):
|
| 329 |
"""The teacher's panel: the classes (with their lessons and homework), and every student's summary (see `summary`) with
|
| 330 |
+
"written", their written homework ({topic id: its lines}), with
|
| 331 |
their classes ({name: nickname}) and, as "since", the same summary for each class ({name: summary}) of the attempts
|
| 332 |
made since the class was opened: a new class starts clean, whatever its students practised before. The students are the classes' accounts, or every account that signed in
|
| 333 |
when there is no class yet; one that never signed in has joined = false."""
|
| 334 |
try:
|
| 335 |
+
classes, users, rows, wrote = a.classes(fresh=True), a.users(), a.all_attempts(), a.all_writings()
|
| 336 |
except AuthUnavailable as e:
|
| 337 |
raise HTTPException(503, str(e))
|
| 338 |
by: dict[str, list[dict]] = {}
|
| 339 |
for r in rows:
|
| 340 |
by.setdefault(r["user_id"], []).append(r)
|
| 341 |
+
written: dict[str, dict[str, list[str]]] = {} # user id -> {topic: lines}
|
| 342 |
+
for w in wrote:
|
| 343 |
+
if w["topic"] in WRITE_TOPICS and isinstance(w.get("lines"), list):
|
| 344 |
+
written.setdefault(w["user_id"], {})[w["topic"]] = [str(x) for x in w["lines"]]
|
| 345 |
member: dict[str, dict[str, str]] = {} # email -> {class name: nickname}
|
| 346 |
for c in classes:
|
| 347 |
for e in c["emails"]:
|
|
|
|
| 349 |
opened = {c["name"]: utc(c["created_at"]) for c in classes if c.get("created_at")}
|
| 350 |
bank, lesson_of = text_bank(text_rows()), topics()
|
| 351 |
|
| 352 |
+
def student(email: str, name: str, joined: bool, mine: list[dict], wrote: dict | None = None) -> dict:
|
| 353 |
into = member.get(email.lower(), {})
|
| 354 |
since = {n: summary([r for r in mine if n not in opened or utc(r["created_at"]) >= opened[n]], bank) for n in into}
|
| 355 |
+
return {"email": email, "name": name, "joined": joined, "classes": into, "since": since, "written": wrote or {},
|
| 356 |
+
**summary(mine, bank)}
|
| 357 |
|
| 358 |
+
students = [student(u["email"], u["name"], True, by.get(u["id"], []), written.get(u["id"]))
|
| 359 |
for u in users if not classes or u["email"].lower() in member]
|
| 360 |
missing = member.keys() - {s["email"].lower() for s in students}
|
| 361 |
students += [student(e, "", False, []) for e in sorted(missing)]
|
app/workbook.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
"""The course workbook (ืฉืื ื') lesson by lesson: the student picks a lesson, then one of its topics.
|
| 2 |
|
| 3 |
-
A topic is a list of items, each written once as (Hebrew, Arabic), and is one of
|
| 4 |
"say": Hebrew -> Arabic. The usual flow: Hebrew prompt, the student says it in Arabic.
|
| 5 |
"read": Arabic -> Hebrew. The page shows the transliteration, the student reads it aloud (and is
|
| 6 |
scored on it) and checks the translation with "ืืฆื ืชืจืืื".
|
|
|
|
|
|
|
|
|
|
| 7 |
Single words (the pronouns, a verb's past and future) and conjugations are "say" items like the
|
| 8 |
sentences. An ordered topic is shown in the workbook's order; the others are shuffled.
|
| 9 |
|
|
@@ -315,6 +318,7 @@ LESSONS = {
|
|
| 315 |
("ืื ื ืฉืืืชื ืืช ืืื ืฉืื ืื ืืื ืืช ืืืืื? ืืื ืฉืื: \"ืืืื ืืื ืืช ืืืืื\".", "ุงูุง ุณุฃูุช ุงุจูู ู
ูู ุงูู ุงูุฃููุ ุงุจูู: ุงูููุจ ุงูู ุงูุฃูู."),
|
| 316 |
("ืืืืจื ืฉืืื ืืช ืืืืื: \"ืืจืืฆื, ืืื ืืฉืืช ืขื ืืฉืืืื?\"", "ุงูู
ุนููู
ุฉ ุณุฃูุช#f ุงูุจูุช: ูุง ุดุงุทุฑุฉ ููุด ูุนุฏุชู ุนูู ุงูุทูุงููุฉุ"),
|
| 317 |
]),
|
|
|
|
| 318 |
],
|
| 319 |
(1, 2): [
|
| 320 |
("dual", "ืืืืื", "say", True, [(f"{he}, {he2}", f"{ar}ุ {ar2}") for he, he2, ar, ar2 in DUALS]),
|
|
@@ -442,6 +446,7 @@ LESSONS = {
|
|
| 442 |
("ื' ืืฉืืืจ ืืืชื! ืื ื ืืจ ืืฉืืื ื ืฉืื ืขื ืืฉืชื ืืืชื. (ืืืืจ)", "ุงููู ูุฎููููู
! ุงูุง ุณุงูู ูู ุญุงุฑุชู ู
ุน ู
ุฑุชู ูุจูุชู."),
|
| 443 |
("ืื ื ืืืงืืจ ืืืจืืฉืืื ืืื ืืืื ืื ื ืืจ ืืฆืคืื.", "ุงูุง ุงุตูู ู
ู ุงููุฏุณ ุจุณู ุงูููู
ุงูุง ุณุงูู ูู ุงูุดูู
ุงู."),
|
| 444 |
]),
|
|
|
|
| 445 |
],
|
| 446 |
}
|
| 447 |
for _level, _n in LESSONS:
|
|
@@ -467,10 +472,22 @@ STORIES = {"l2-talk": ("ืืืืจ", "ืจืืืฃ")}
|
|
| 467 |
UNITS = {"pron": "ืืืื", "verbs": "ืคืืขื", "dual": "ืืืื", "family": "ืืืื"}
|
| 468 |
TASKS = {"verbs": "ืืืจื ืืช ืืคืืขื ืืขืจืืืช ืืืืืจืช: ืืขืืจ ืืื ืืขืชืื",
|
| 469 |
"dual": "ืืืจื ืืขืจืืืช ืืืืืจืช: ืืืืื ืืื ืืืืื"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
CATEGORIES = [{"id": f"l{lesson_id(*key)}-{tid}", "name": name, "lesson": lesson_id(*key),
|
|
|
|
| 471 |
**({"story": True, "voices": list(STORIES[f"l{lesson_id(*key)}-{tid}"])} if f"l{lesson_id(*key)}-{tid}" in STORIES else {}),
|
| 472 |
**({"unit": UNITS[tid]} if tid in UNITS else {}), **({"task": TASKS[tid]} if tid in TASKS else {})}
|
| 473 |
-
for key, topics in LESSONS.items() for tid, name, *_ in topics]
|
| 474 |
|
| 475 |
|
| 476 |
def _word(token: str) -> tuple[str, str, list[str]]:
|
|
|
|
| 1 |
"""The course workbook (ืฉืื ื') lesson by lesson: the student picks a lesson, then one of its topics.
|
| 2 |
|
| 3 |
+
A topic is a list of items, each written once as (Hebrew, Arabic), and is one of three kinds:
|
| 4 |
"say": Hebrew -> Arabic. The usual flow: Hebrew prompt, the student says it in Arabic.
|
| 5 |
"read": Arabic -> Hebrew. The page shows the transliteration, the student reads it aloud (and is
|
| 6 |
scored on it) and checks the translation with "ืืฆื ืชืจืืื".
|
| 7 |
+
"write": the workbook's homework, sentences of the student's own. It has no items: the page shows its task
|
| 8 |
+
(WRITING) and a line for each sentence. What is written is kept for the student (the Supabase table
|
| 9 |
+
`writings`) and read by the teacher in the panel. Nothing is said or scored.
|
| 10 |
Single words (the pronouns, a verb's past and future) and conjugations are "say" items like the
|
| 11 |
sentences. An ordered topic is shown in the workbook's order; the others are shuffled.
|
| 12 |
|
|
|
|
| 318 |
("ืื ื ืฉืืืชื ืืช ืืื ืฉืื ืื ืืื ืืช ืืืืื? ืืื ืฉืื: \"ืืืื ืืื ืืช ืืืืื\".", "ุงูุง ุณุฃูุช ุงุจูู ู
ูู ุงูู ุงูุฃููุ ุงุจูู: ุงูููุจ ุงูู ุงูุฃูู."),
|
| 319 |
("ืืืืจื ืฉืืื ืืช ืืืืื: \"ืืจืืฆื, ืืื ืืฉืืช ืขื ืืฉืืืื?\"", "ุงูู
ุนููู
ุฉ ุณุฃูุช#f ุงูุจูุช: ูุง ุดุงุทุฑุฉ ููุด ูุนุฏุชู ุนูู ุงูุทูุงููุฉุ"),
|
| 320 |
]),
|
| 321 |
+
("hw", "ืืชืืืช ืืฉืคืืื", "write", True, []),
|
| 322 |
],
|
| 323 |
(1, 2): [
|
| 324 |
("dual", "ืืืืื", "say", True, [(f"{he}, {he2}", f"{ar}ุ {ar2}") for he, he2, ar, ar2 in DUALS]),
|
|
|
|
| 446 |
("ื' ืืฉืืืจ ืืืชื! ืื ื ืืจ ืืฉืืื ื ืฉืื ืขื ืืฉืชื ืืืชื. (ืืืืจ)", "ุงููู ูุฎููููู
! ุงูุง ุณุงูู ูู ุญุงุฑุชู ู
ุน ู
ุฑุชู ูุจูุชู."),
|
| 447 |
("ืื ื ืืืงืืจ ืืืจืืฉืืื ืืื ืืืื ืื ื ืืจ ืืฆืคืื.", "ุงูุง ุงุตูู ู
ู ุงููุฏุณ ุจุณู ุงูููู
ุงูุง ุณุงูู ูู ุงูุดูู
ุงู."),
|
| 448 |
]),
|
| 449 |
+
("hw", "ืืชืืืช ืืฉืคืืื", "write", True, []),
|
| 450 |
],
|
| 451 |
}
|
| 452 |
for _level, _n in LESSONS:
|
|
|
|
| 472 |
UNITS = {"pron": "ืืืื", "verbs": "ืคืืขื", "dual": "ืืืื", "family": "ืืืื"}
|
| 473 |
TASKS = {"verbs": "ืืืจื ืืช ืืคืืขื ืืขืจืืืช ืืืืืจืช: ืืขืืจ ืืื ืืขืชืื",
|
| 474 |
"dual": "ืืืจื ืืขืจืืืช ืืืืืจืช: ืืืืื ืืื ืืืืื"}
|
| 475 |
+
# The topics the student writes in (kind "write"): the task as the workbook gives it, and how many sentences it asks for.
|
| 476 |
+
WRITING = {"l1-hw": ("ืืชืื ืืืืฉื ืืฉืคืืื ืืขืจืืืช ืืขืืจ ืขื ืืคืขืืื, ืืืืคืื, ืฉืืืช ืืขืฆื ืฉืืืื ื.\n"
|
| 477 |
+
"ืืฉืชืืฉื ืืืืืืช ืืืืง: ืึทืข - ืขื, ืึตืื - ืืืคื, ืึดืื - ืื, ืึตืืฉ - ืืืืข, ืคึดื - ื, ืืชืื, ืืฉ, "
|
| 478 |
+
"ืึตืืึฐืชึทื / ืึตืึฐื ึฐืชึทื - ืืชื.", 5),
|
| 479 |
+
"l2-hw": ("ืึตืึฐืึทืึทึฟืืึตืฃ ืึทืึทืจึฐืก ืึตืืึท'ืืึฐ - ืืืฉืืืืช ืืฉืืขืืจ ืืื\n"
|
| 480 |
+
"1. ืคืชืจื ืืช ืื ืืฉืืขืืจ ืืฉื ื.\n"
|
| 481 |
+
"2. ืืชืื 5 ืืฉืคืืื ืคืฉืืืื ืืืืืืช ืืคืขืืื ืฉืืืื ื ืืื ืืืืคืื.\n"
|
| 482 |
+
"ืืฉืชืืฉื ืืืืืืช ืืืืง: ืขึทืึทื โ ื (ืืงืื), ืื, ืขื. ืขึดื ึฐื โ ืืฆื (ืืื), ืืฉ ื. ืคึดื โ ืืฉ, ื, ืืชืื, ืงึทืึตึผื โ ืืคื ื. "
|
| 483 |
+
"ืึทืข โ ืขื, ืึตืื โ ืืืคื, ืึดืื โ ืื, ืึตืืฉ โ ืืืืข. ืึทึผืขึทืึตืื - ืืืจ ืื.\n"
|
| 484 |
+
"ืืฉืชืืฉื ืจืง ืืคืขืืื ืฉืืืื ื: ืึทืึทึผื / ืึนืืึตึผื โ ืืื, ืกึทืึทื / ืึดืกึฐืึทื โ ืฉืื, ืคึทืชึทื / ืึดืคึฐืชึทื โ ืคืชื, "
|
| 485 |
+
"ืงึทืขึทื / ืึปืงึฐืขึนื โ ืืฉื.", 5)}
|
| 486 |
CATEGORIES = [{"id": f"l{lesson_id(*key)}-{tid}", "name": name, "lesson": lesson_id(*key),
|
| 487 |
+
**({"write": dict(zip(("task", "lines"), WRITING[f"l{lesson_id(*key)}-{tid}"]))} if kind == "write" else {}),
|
| 488 |
**({"story": True, "voices": list(STORIES[f"l{lesson_id(*key)}-{tid}"])} if f"l{lesson_id(*key)}-{tid}" in STORIES else {}),
|
| 489 |
**({"unit": UNITS[tid]} if tid in UNITS else {}), **({"task": TASKS[tid]} if tid in TASKS else {})}
|
| 490 |
+
for key, topics in LESSONS.items() for tid, name, kind, *_ in topics]
|
| 491 |
|
| 492 |
|
| 493 |
def _word(token: str) -> tuple[str, str, list[str]]:
|
ihki.todo
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
- community
|
| 2 |
- llm dialoge
|
| 3 |
-
- practice better (e.g. least score)
|
|
|
|
|
|
| 1 |
- community
|
| 2 |
- llm dialoge
|
| 3 |
+
- practice better (e.g. least score)
|
| 4 |
+
- do i lock the lessons ?
|
static/index.html
CHANGED
|
@@ -293,6 +293,11 @@ body:not(.manage) #manage,body.manage #wrap>header,body.manage #path,body.manage
|
|
| 293 |
.vadd input[name=url]{direction:ltr;text-align:left}
|
| 294 |
#videoDlg{width:min(94vw,860px)}
|
| 295 |
#videoBox iframe{display:block;width:100%;aspect-ratio:16/9;border:0;border-radius:10px;background:#000}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
#mClasses{display:flex;flex-direction:column;gap:inherit}
|
| 297 |
#mClasses>.btn{align-self:flex-start}
|
| 298 |
#mClasses .card>.btn{align-self:flex-start}
|
|
@@ -601,6 +606,12 @@ body.quiet :is(#mic,#playMine,#driveBtn),body.driving :is(#quietBtn,#heBtn,.micl
|
|
| 601 |
<div class="dlg-head"><h2 id="videoTitle"></h2><button class="btn" id="videoClose">ืกืืืจื</button></div>
|
| 602 |
<div id="videoBox"></div>
|
| 603 |
</dialog>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
<dialog id="classDlg" aria-labelledby="classTitle">
|
| 605 |
<div class="dlg-head"><h2 id="classTitle"></h2><button class="btn" id="classClose">ืกืืืจื</button></div>
|
| 606 |
<div id="mates"></div>
|
|
@@ -684,12 +695,14 @@ function dueText(due){ // the homework's day in words ("ืขื ืืืจ", "ืขื ื
|
|
| 684 |
}
|
| 685 |
/* The class's homework for the path: the topic (and its lesson), how far the student got in it, and the words of its
|
| 686 |
bubble, which count the days left ("ื ืฉืืจื 3 ืืืื", "ืืืืฉืื ืืืจ!", "ืืืืืืจ ืฉื ืืืืืื"; with no day set, as any topic's).
|
| 687 |
-
`state` colours it: "soon" on the last two days, "late" after them. Null when the
|
| 688 |
function homework(){
|
| 689 |
-
|
|
|
|
|
|
|
| 690 |
if(!c) return null;
|
| 691 |
-
const t=tally(PHRASES.filter(p=>p.listed!==false&&p.cat===c.id)), now=new Date(), days=n=>n===1?"ืืื":n===2?"ืืืืืื":`${n} ืืืื`;
|
| 692 |
-
const left=
|
| 693 |
const msg=left==null?(t.done?"ืืืฉื":"ืืชืืืื"):left<0?`ืืืืืืจ ืฉื ${days(-left)}`:left===0?"ืืืืฉืื ืืืื!":left===1?"ืืืืฉืื ืืืจ!":`ื ืฉืืจื ${days(left)}`;
|
| 694 |
return {c,l:LESSONS.find(l=>l.id===c.lesson),t,msg,state:left==null||left>1?"":left<0?"late":"soon"};
|
| 695 |
}
|
|
@@ -749,10 +762,10 @@ function ball(t,now){ // a topic's button and the disc inside its ring
|
|
| 749 |
}
|
| 750 |
const WAY=/^(.+?):\s*(\S+)\u00a0โ\u00a0(\S+)(.*)$/, SHORT={"ืขืืจืืช":"ืขืืณ","ืขืจืืืช":"ืขืจืณ"};
|
| 751 |
function mark(cls,text,tag="span"){ const m=document.createElement(tag); m.className=cls; m.textContent=text; return m; }
|
| 752 |
-
function count(t){ // "11/70 ืชืืจืืื", or the mark of a finished one
|
| 753 |
const s=document.createElement("small"), n=document.createElement("bdi");
|
| 754 |
if(t.over){ s.textContent=t.gold?"โ
ืืฆืืื":"โ ืืืฉืื"; return s; }
|
| 755 |
-
n.dir="ltr"; n.textContent=`${t.done}/${t.n}`; s.append(n,"
|
| 756 |
}
|
| 757 |
const levelOf=l=>ALL_LEVELS.find(v=>v.id===l.level)||{name:""};
|
| 758 |
const lessonName=l=>l?(ALL_LEVELS.length>1?levelOf(l).name+" ยท ":"")+l.name:"";
|
|
@@ -798,6 +811,55 @@ function playVideo(v,preview){ // preview: the teacher looks at it from the pa
|
|
| 798 |
$("videoClose").onclick=()=>$("videoDlg").close();
|
| 799 |
$("videoDlg").addEventListener("close",()=>{ // without its frame the video stops playing
|
| 800 |
$("videoBox").replaceChildren(); if(home&&!document.body.classList.contains("manage")) drawPath(true); });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
function drawPath(stay){
|
| 802 |
const box=$("path"), listed=PHRASES.filter(p=>p.listed!==false), NS="http://www.w3.org/2000/svg";
|
| 803 |
drawToday();
|
|
@@ -818,14 +880,14 @@ function drawPath(stay){
|
|
| 818 |
const b=mark("chapter soon",""); b.style.top=y+"px"; b.append(mark("",lessonsWord(run)),mark("","ืืงืจืื","small")); box.append(b);
|
| 819 |
y+=52+28; continue;
|
| 820 |
}
|
| 821 |
-
const items=lessonItems(l.id), cats=items.filter(it=>it.c).map(it=>it.c), parts=cats.map(c=>tally(listed.filter(p=>p.cat===c.id)));
|
| 822 |
const whole=tally(listed.filter(p=>cats.some(c=>c.id===p.cat))), now=!whole.over&&next;
|
| 823 |
const todo=Math.max(0,parts.findIndex(t=>!t.over)); // the topic the banner opens
|
| 824 |
if(now) next=false;
|
| 825 |
const head=document.createElement("button");
|
| 826 |
head.className="chapter"+(whole.gold?" gold":""); head.style.top=y+"px"; head.style.setProperty("--p",`${whole.n?whole.done/whole.n*100:0}%`);
|
| 827 |
head.append(mark("",l.name),count(whole),document.createElement("i")); head.title=`${l.name}: ืชืืจืืื ${whole.done} ืืชืื ${whole.n}`;
|
| 828 |
-
head.onclick=()=>
|
| 829 |
y+=64+86; // the banner, room for the bubble, half a button
|
| 830 |
const seat=(b,i)=>{ // a button's place on the road, and its label
|
| 831 |
const label=document.createElement("span"), x=-SWAY[i%8]*amp, right=x<0||(!x&&i%8===0); // the first turn is to the left; the label stands on the other side
|
|
@@ -844,7 +906,7 @@ function drawPath(stay){
|
|
| 844 |
}
|
| 845 |
const i=cats.indexOf(c), t=parts[i], cur=now&&i===todo, [b,dot]=ball(t,cur), [x,label]=seat(b,at);
|
| 846 |
const mine=!!hw&&c===hw.c; // the homework topic: its bubble counts the days left
|
| 847 |
-
dot.textContent=c.story?"๐ฌ":n; // the number stays; a finished topic gets a badge, the one to do now and the homework a bubble
|
| 848 |
if(t.over) dot.before(mark("badge",t.gold?"โ
":"โ"));
|
| 849 |
else if(cur||mine){
|
| 850 |
const tag=mark("tag",mine?"":t.done?"ืืืฉื":"ืืชืืืื");
|
|
@@ -854,9 +916,10 @@ function drawPath(stay){
|
|
| 854 |
const way=c.name.match(WAY); // "ืืฉืคืืื: ืขืืจืืช โ ืขืจืืืช ื'" is drawn as "ืืฉืคืืื ื'" and a chip with the direction
|
| 855 |
label.append(mark("",way?way[1]+way[4]:c.name,"b"));
|
| 856 |
if(way) label.append(mark("way"+(way[2]==="ืขืจืืืช"?" read":""),`${SHORT[way[2]]||way[2]}\u00a0โ\u00a0${SHORT[way[3]]||way[3]}`));
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
b.
|
|
|
|
| 860 |
stops.push({x,y,went:t.over,cur}); y+=STEP;
|
| 861 |
});
|
| 862 |
const cup=document.createElement("div"), x=-SWAY[items.length%8]*amp; // the lesson's end: gold once all of it was practised
|
|
@@ -1726,6 +1789,10 @@ const listedPhrases=()=>PHRASES.filter(p=>p.listed!==false);
|
|
| 1726 |
const lessonPhrases=(l,list)=>{ const cats=ALL_CATS.filter(c=>c.lesson===l.id).map(c=>c.id); return list.filter(p=>cats.includes(p.cat)); };
|
| 1727 |
const stuTally=(s,list)=>{ const got=list.filter(p=>s.best[p.id]!=null), sum=k=>list.reduce((t,p)=>t+(s[k]&&s[k][p.id]||0),0);
|
| 1728 |
return {done:got.length, n:list.length, avg:mean(got.map(p=>s.best[p.id])), tries:sum("tries"), missed:sum("missed")}; }; // missed: recordings that did not match their sentence
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1729 |
const triesText=t=>[t.tries&&`${t.tries} ื ืืกืืื ืืช`,t.missed&&`${t.missed} ืื ืืืื`].filter(Boolean).join(" ยท ");
|
| 1730 |
const ratio=t=>{ const m=document.createElement("small"), n=document.createElement("bdi"); n.dir="ltr"; n.textContent=`${t.done}/${t.n}`; m.append(n); return m; };
|
| 1731 |
const bar=frac=>{ const b=mark("progress",""), f=document.createElement("i"); f.style.width=`${Math.round(frac*100)}%`; b.append(f); return b; };
|
|
@@ -1813,7 +1880,7 @@ function drawContent(){
|
|
| 1813 |
const lines=c?listed.filter(p=>p.cat===c.id).length:0;
|
| 1814 |
if(n){
|
| 1815 |
const row=mark("crow","","li");
|
| 1816 |
-
row.append(mark("",c.story?"๐ฌ":n,"i"),mark("",c.name,"b"),mark("",`${c.story?"ืฉืืื":"ืชืจืืื"} ยท ${lines} ${c.unit==="ืืืื"?"ืืืืื":c.unit==="ืคืืขื"?"ืคืขืืื":"ืืฉืคืืื"}`,"small")); list.append(row); return;
|
| 1817 |
}
|
| 1818 |
const it=v||c, row=mark("crow added","","li"), text=mark("two",""), title=mark("","","b"), t=document.createElement("bdi"), acts=mark("acts","");
|
| 1819 |
const up=mark("btn move","โ","button"), down=mark("btn move","โ","button"), see=mark("btn",v?"ืฆืคืืื":"ืชืจืืื","button"), del=mark("btn danger","ืืืืงื","button");
|
|
@@ -1946,7 +2013,7 @@ function drawHead(klass,students){ // the class's name and its figures; before
|
|
| 1946 |
head.append(tiles);
|
| 1947 |
const hw=klass.homework&&ALL_CATS.find(c=>c.id===klass.homework&&CLASS_LESSONS.some(l=>l.id===c.lesson));
|
| 1948 |
if(hw){ // the homework: how many finished the topic, and who is still to, the furthest from it first
|
| 1949 |
-
const list=listedPhrases()
|
| 1950 |
const due=dueText(klass.due), box=mark("hwsum"+(due.late&&todo.length?" late":""),""), line=mark("",`ืฉืืขืืจื ืืืช: ${hw.name}`,"b");
|
| 1951 |
line.append(mark("",` ยท ${lessonName(ALL_LESSONS.find(l=>l.id===hw.lesson))}`,"small"));
|
| 1952 |
if(due.text) line.append(mark(""," ยท "+due.text,"small"));
|
|
@@ -1994,8 +2061,8 @@ function drawRoster(klass,students,listed){
|
|
| 1994 |
// the same columns however many lessons the class has: the homework topic (when there is one) and all the class's
|
| 1995 |
// sentences; a lesson by itself is on the student's own screen
|
| 1996 |
const hw=klass&&klass.homework&&ALL_CATS.find(c=>c.id===klass.homework&&CLASS_LESSONS.some(l=>l.id===c.lesson));
|
| 1997 |
-
const cols=[...(hw?[{name:"ืฉืืขืืจื ืืืช",title:`ืฉืืขืืจื ืืืช, ${hw.name}`,
|
| 1998 |
-
...(CLASS_LESSONS.length?[{name:"ืื ืืฉืืขืืจืื",title:"ืื ืืฉืืขืืจืื",
|
| 1999 |
const box=$("mRoster"); box.innerHTML=""; box.hidden=false; box.style.setProperty("--cols",["minmax(0,1fr)",...cols.map(()=>"4.2em"),"3em","10px"].join(" ")); // no lesson column when none is ready
|
| 2000 |
const h=mark("","ืชืืืืืื","h2"); h.append(mark("","ืืืืฆื ืขื ืชืืืื ืคืืชืืช ืืช ืืืฃ ืฉืื","small")); box.append(h);
|
| 2001 |
if(!students.length){ box.append(mark("note","ืืื ืขืืืื ืชืืืืืื ืืืืชื ืืื. ืืืกืืคืื ืืืชื ืชืืช โืืืชืืชโ, ืืืคืชืืจ โืขืจืืืโ ืฉื ืืืืชื.","p")); return; }
|
|
@@ -2006,7 +2073,7 @@ function drawRoster(klass,students,listed){
|
|
| 2006 |
const shown=mark("",s.nick||s.name||s.email,"b"); shown.dir="auto"; // an address is cut at its end
|
| 2007 |
who.append(shown,mark("",lastSeen(s)+(s.unmatched?` ยท ${s.unmatched} ืื ืืืื`:""),"small"));
|
| 2008 |
who.title=s.email; row.append(who);
|
| 2009 |
-
for(const col of cols){ const t=
|
| 2010 |
row.append(s.avg!=null?grade(s.avg):mark("none","โ"),mark("go","โน")); // the arrow says the row opens
|
| 2011 |
row.onclick=()=>showStudent(s.email);
|
| 2012 |
box.append(row);
|
|
@@ -2032,11 +2099,11 @@ function drawStudent(klass,s,listed){
|
|
| 2032 |
if(s.unmatched) head.append(mark("note",`${s.unmatched} ืืงืืืืช ืื ืืืื ืืืฉืคื ืฉืขื ืืืกื: ืื ื ืฉืืจื, ืืื ืื ื ืกืคืจืืช ืืืฉืคืืื ืฉืชืืจืืื ืืื ืืฆืืื. ืืื ืื ื ืืฉื ืืืคืืข ืืื ืืืื ืืื ืื.`,"p"));
|
| 2033 |
const hw=klass&&klass.homework&&ALL_CATS.find(c=>c.id===klass.homework&&CLASS_LESSONS.some(l=>l.id===c.lesson));
|
| 2034 |
if(hw){
|
| 2035 |
-
const t=
|
| 2036 |
const sum=mark("hwsum"+(due.late&&!over?" late":""),""), line=mark("",`ืฉืืขืืจื ืืืช: ${hw.name}`,"b");
|
| 2037 |
line.append(mark("",` ยท ${lessonName(ALL_LESSONS.find(l=>l.id===hw.lesson))}`,"small"));
|
| 2038 |
if(due.text) line.append(mark(""," ยท "+due.text,"small"));
|
| 2039 |
-
sum.append(line,mark("",over?`โ ืกืืื/ื: ืื ${t.n} ืืืฉืคืืื
|
| 2040 |
}
|
| 2041 |
box.append(head);
|
| 2042 |
const lessons=mark("card hard",""), lh=mark("","ืฉืืขืืจืื","h2"); lh.append(mark("","ืืืืฆื ืขื ืฉืืขืืจ ืคืืชืืช ืืช ืื ืืฉืืื ืฉืื","small")); lessons.append(lh);
|
|
@@ -2044,8 +2111,11 @@ function drawStudent(klass,s,listed){
|
|
| 2044 |
const t=stuTally(s,lessonPhrases(l,listed)), sec=part(lessons); sec.classList.add("lsum");
|
| 2045 |
sec.firstChild.append(mark("",lessonName(l)),mark("",t.done?`ืชืืจืืื ${t.done} ืืชืื ${t.n} ืืฉืคืืื`:t.missed?`ื ืืกื/ืชื, ืื ืืืื (${t.missed})`:"ืขืื ืื ืืชืืื/ื","small"),t.avg!=null?grade(t.avg):mark("none","โ"),bar(t.n?t.done/t.n:0));
|
| 2046 |
for(const c of ALL_CATS.filter(c=>c.lesson===l.id)){
|
| 2047 |
-
const t=
|
| 2048 |
row.append(mark("",c.name),mark("",triesText(t),"small"),ratio(t),t.avg!=null?grade(t.avg):mark("none","โ")); sec.append(row);
|
|
|
|
|
|
|
|
|
|
| 2049 |
}
|
| 2050 |
}
|
| 2051 |
if(CLASS_SOON.length) lessons.append(mark("note","ืืงืจืื: "+byLevel(CLASS_SOON).map(g=>`${g.level.name}, ${lessonsWord(g.lessons)}`).join(" ยท "),"p"));
|
|
@@ -2088,6 +2158,10 @@ function editClass(c){
|
|
| 2088 |
for(const t of ALL_CATS.filter(t=>t.lesson===l.id)) g.append(new Option(t.name,t.id));
|
| 2089 |
}
|
| 2090 |
hw.value=c&&c.homework||""; $("editDue").value=c&&c.due||"";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2091 |
$("editEmails").value=c?c.emails.map(e=>[e,c.nicknames&&c.nicknames[e]].filter(Boolean).join(" ")).join("\n"):"";
|
| 2092 |
$("editSave").textContent=c?"ืฉืืืจื":"ืคืชืืืช ืืืืชื"; $("editDelete").hidden=!c; $("editMsg").textContent="";
|
| 2093 |
countStudents(); $("editDlg").showModal(); (c?$("editEmails"):$("editName")).focus();
|
|
@@ -2174,6 +2248,7 @@ function wizAdd(){ // the addresses written in the field join the list, ticked
|
|
| 2174 |
}
|
| 2175 |
$("newAdd").onclick=()=>{ wizAdd(); $("newEmail").focus(); };
|
| 2176 |
$("newEmail").onkeydown=e=>{ if(e.key==="Enter"){ e.preventDefault(); wizAdd(); } };
|
|
|
|
| 2177 |
function wizHomework(){ // the topics of the level's ready lessons, under their lessons; the one chosen before stays
|
| 2178 |
const hw=$("newHw"), was=hw.value, ready=wizLessons().filter(l=>!l.soon);
|
| 2179 |
hw.innerHTML=""; hw.add(new Option(ready.length?"ืืื ืฉืืขืืจื ืืืช ืืื ืชืืื":"ืืจืื ืืื ืขืื ืืื ืฉืืขืืจืื ืืืื ืื",""));
|
|
@@ -2181,7 +2256,8 @@ function wizHomework(){ // the topics of the level's ready lessons, under thei
|
|
| 2181 |
const g=document.createElement("optgroup"); g.label=l.name; hw.append(g);
|
| 2182 |
for(const t of ALL_CATS.filter(t=>t.lesson===l.id)) g.append(new Option(t.name,t.id));
|
| 2183 |
}
|
| 2184 |
-
|
|
|
|
| 2185 |
$("newDue").min=new Date().toLocaleDateString("sv"); hw.onchange();
|
| 2186 |
}
|
| 2187 |
$("newHw").onchange=()=>$("newDueBox").hidden=!$("newHw").value;
|
|
@@ -2273,7 +2349,7 @@ if(AUTH_URL){
|
|
| 2273 |
login.onclick=()=>sb.auth.signInWithOAuth({provider:"google",
|
| 2274 |
options:{redirectTo:here,queryParams:{prompt:"select_account"}}});
|
| 2275 |
logout.onclick=$("switchBtn").onclick=async()=>{ // the best scores kept on the device belong to this student
|
| 2276 |
-
await sb.auth.signOut(); store.set("ihki.best2",{}); store.set("ihki.silent",{}); location.reload(); };
|
| 2277 |
sb.auth.onAuthStateChange((_e,session)=>{
|
| 2278 |
login.hidden=mail.hidden=!!session; logout.hidden=!session;
|
| 2279 |
logout.title=session?session.user.email||"":"";
|
|
@@ -2292,7 +2368,7 @@ if(AUTH_URL){
|
|
| 2292 |
if(MY_CLASSES.length===1) MY_CLASS=mine[0];
|
| 2293 |
else{ const last=MY_CLASSES.find(c=>c.name===store.get("ihki.class","")); if(last) useClass(last); } // the class practised in last
|
| 2294 |
start.hidden=!ok||teacher; roles.hidden=$("toManage").hidden=!teacher; denied.hidden=ok;
|
| 2295 |
-
if(ok){ (teacher?$("practiceBtn"):start).focus({preventScroll:true}); loadProgress().then(()=>{ if(PHRASES.length&&$("wrap").inert) startCat(); }); loadContent(); }
|
| 2296 |
},0);
|
| 2297 |
});
|
| 2298 |
}
|
|
|
|
| 293 |
.vadd input[name=url]{direction:ltr;text-align:left}
|
| 294 |
#videoDlg{width:min(94vw,860px)}
|
| 295 |
#videoBox iframe{display:block;width:100%;aspect-ratio:16/9;border:0;border-radius:10px;background:#000}
|
| 296 |
+
#writeTask{white-space:pre-line;margin:0 0 12px}
|
| 297 |
+
#writeLines{margin:0;padding-inline-start:1.5em;display:grid;gap:8px}
|
| 298 |
+
#writeLines input{width:100%;box-sizing:border-box;font:500 17px/1.5 var(--f-body);padding:8px 10px;border-radius:8px;border:1px solid var(--line);background:var(--bg);color:var(--ink)}
|
| 299 |
+
#writeDlg small{display:block;margin-top:12px;color:var(--muted);font-size:14px}
|
| 300 |
+
.wrote{margin:0;padding:0 16px 8px;padding-inline-start:3em;color:var(--muted);font-size:15px}
|
| 301 |
#mClasses{display:flex;flex-direction:column;gap:inherit}
|
| 302 |
#mClasses>.btn{align-self:flex-start}
|
| 303 |
#mClasses .card>.btn{align-self:flex-start}
|
|
|
|
| 606 |
<div class="dlg-head"><h2 id="videoTitle"></h2><button class="btn" id="videoClose">ืกืืืจื</button></div>
|
| 607 |
<div id="videoBox"></div>
|
| 608 |
</dialog>
|
| 609 |
+
<dialog id="writeDlg" aria-labelledby="writeTitle">
|
| 610 |
+
<div class="dlg-head"><h2 id="writeTitle"></h2><button class="btn" id="writeClose">ืกืืืจื</button></div>
|
| 611 |
+
<p id="writeTask"></p>
|
| 612 |
+
<ol id="writeLines"></ol>
|
| 613 |
+
<small id="writeNote" aria-live="polite"></small>
|
| 614 |
+
</dialog>
|
| 615 |
<dialog id="classDlg" aria-labelledby="classTitle">
|
| 616 |
<div class="dlg-head"><h2 id="classTitle"></h2><button class="btn" id="classClose">ืกืืืจื</button></div>
|
| 617 |
<div id="mates"></div>
|
|
|
|
| 695 |
}
|
| 696 |
/* The class's homework for the path: the topic (and its lesson), how far the student got in it, and the words of its
|
| 697 |
bubble, which count the days left ("ื ืฉืืจื 3 ืืืื", "ืืืืฉืื ืืืจ!", "ืืืืืืจ ืฉื ืืืืืื"; with no day set, as any topic's).
|
| 698 |
+
`state` colours it: "soon" on the last two days, "late" after them. Null when none of the student's classes has homework. */
|
| 699 |
function homework(){
|
| 700 |
+
// of the class practised in now, or else of another class of the student's whose topic is on the path: the one due first
|
| 701 |
+
const own=k=>k&&k.homework&&CATS.find(c=>c.id===k.homework);
|
| 702 |
+
const k=own(MY_CLASS)?MY_CLASS:MY_CLASSES.filter(own).sort((a,b)=>(a.due||"9").localeCompare(b.due||"9"))[0], c=own(k);
|
| 703 |
if(!c) return null;
|
| 704 |
+
const t=c.write?wTally(c):tally(PHRASES.filter(p=>p.listed!==false&&p.cat===c.id)), now=new Date(), days=n=>n===1?"ืืื":n===2?"ืืืืืื":`${n} ืืืื`;
|
| 705 |
+
const left=k.due?Math.round((new Date(k.due+"T00:00")-new Date(now.getFullYear(),now.getMonth(),now.getDate()))/864e5):null;
|
| 706 |
const msg=left==null?(t.done?"ืืืฉื":"ืืชืืืื"):left<0?`ืืืืืืจ ืฉื ${days(-left)}`:left===0?"ืืืืฉืื ืืืื!":left===1?"ืืืืฉืื ืืืจ!":`ื ืฉืืจื ${days(left)}`;
|
| 707 |
return {c,l:LESSONS.find(l=>l.id===c.lesson),t,msg,state:left==null||left>1?"":left<0?"late":"soon"};
|
| 708 |
}
|
|
|
|
| 762 |
}
|
| 763 |
const WAY=/^(.+?):\s*(\S+)\u00a0โ\u00a0(\S+)(.*)$/, SHORT={"ืขืืจืืช":"ืขืืณ","ืขืจืืืช":"ืขืจืณ"};
|
| 764 |
function mark(cls,text,tag="span"){ const m=document.createElement(tag); m.className=cls; m.textContent=text; return m; }
|
| 765 |
+
function count(t,what="ืชืืจืืื"){ // "11/70 ืชืืจืืื", or the mark of a finished one
|
| 766 |
const s=document.createElement("small"), n=document.createElement("bdi");
|
| 767 |
if(t.over){ s.textContent=t.gold?"โ
ืืฆืืื":"โ ืืืฉืื"; return s; }
|
| 768 |
+
n.dir="ltr"; n.textContent=`${t.done}/${t.n}`; s.append(n," "+what); return s;
|
| 769 |
}
|
| 770 |
const levelOf=l=>ALL_LEVELS.find(v=>v.id===l.level)||{name:""};
|
| 771 |
const lessonName=l=>l?(ALL_LEVELS.length>1?levelOf(l).name+" ยท ":"")+l.name:"";
|
|
|
|
| 811 |
$("videoClose").onclick=()=>$("videoDlg").close();
|
| 812 |
$("videoDlg").addEventListener("close",()=>{ // without its frame the video stops playing
|
| 813 |
$("videoBox").replaceChildren(); if(home&&!document.body.classList.contains("manage")) drawPath(true); });
|
| 814 |
+
/* A topic the student writes in (its category has `write`: the task, and how many sentences): the workbook's homework.
|
| 815 |
+
It opens in a box over the page, a line for each sentence, and is done once every line has something in it. What is
|
| 816 |
+
written is kept on the device and, for a signed-in student, sent to the server as they write, so it follows them to
|
| 817 |
+
any device and the teacher reads it in the panel. Lines the server did not take stay on the device and are sent on
|
| 818 |
+
the next visit. */
|
| 819 |
+
let written=store.get("ihki.written",{}), unsent=store.get("ihki.unsent",{}); // {topic id: its lines}; the topics whose lines the server does not have yet
|
| 820 |
+
const WRITE_HOW="ืืืชืืื ืืขืจืืืช ืืืืชืืืช ืขืืจืืืช, ืืื ืืืืืจืช.";
|
| 821 |
+
let writeOpen=null, writeTimer=null; // the topic in the box, and its lines waiting to be sent
|
| 822 |
+
const wLines=id=>Array.from(written[id]||[],x=>x||"");
|
| 823 |
+
function wTally(c){ const done=wLines(c.id).filter(x=>x.trim()).length, n=c.write.lines; return {done,n,over:done>=n,gold:false}; }
|
| 824 |
+
async function sendWriting(id){
|
| 825 |
+
if(!sb) return;
|
| 826 |
+
const note=t=>{ if(writeOpen===id) $("writeNote").textContent=`${WRITE_HOW} ${t}`; }, lines=wLines(id);
|
| 827 |
+
unsent[id]=1; store.set("ihki.unsent",unsent); note("ืฉืืืจโฆ");
|
| 828 |
+
try{
|
| 829 |
+
const res=await send(`/api/writing/${id}`,"PUT",{lines});
|
| 830 |
+
if(!res.ok) throw 0;
|
| 831 |
+
if(JSON.stringify(wLines(id))!==JSON.stringify(lines)) return; // written on meanwhile: the next sending says how it went
|
| 832 |
+
delete unsent[id]; store.set("ihki.unsent",unsent); note("โ ื ืฉืืจ ืืืฉืืื ืฉืืื");
|
| 833 |
+
}catch{ note("ืื ื ืฉืืจ ืืฉืจืช: ืืืฉืคืืื ืฉืืืจืื ืืืืฉืืจ ืืื ืืืืฉืืื ืืื ืืกื ืืืื."); }
|
| 834 |
+
}
|
| 835 |
+
async function loadWriting(){ // the server's lines replace the device's, but those of a topic still to be sent
|
| 836 |
+
if(!sb) return;
|
| 837 |
+
try{
|
| 838 |
+
const res=await api("/api/writing"); if(!res.ok) return;
|
| 839 |
+
const d=(await res.json()).writing||{};
|
| 840 |
+
for(const id in unsent) if(written[id]){ d[id]=written[id]; sendWriting(id); }
|
| 841 |
+
written=d; store.set("ihki.written",written);
|
| 842 |
+
if(PHRASES.length&&home&&!document.body.classList.contains("manage")) drawPath(true);
|
| 843 |
+
}catch{}
|
| 844 |
+
}
|
| 845 |
+
function writeTopic(c){
|
| 846 |
+
const lines=Array.from({length:c.write.lines},(_,k)=>wLines(c.id)[k]||"");
|
| 847 |
+
writeOpen=c.id; $("writeTitle").textContent=c.name; $("writeTask").textContent=c.write.task; $("writeLines").replaceChildren();
|
| 848 |
+
$("writeNote").textContent=`${WRITE_HOW} ${!sb?"ืืืฉืคืืื ื ืฉืืจืื ืืืืฉืืจ ืืื ืืืื.":unsent[c.id]?"ืขืื ืื ื ืฉืืจ ืืฉืจืช.":"ืืืฉืคืืื ื ืฉืืจืื ืืืฉืืื ืฉืืื."}`;
|
| 849 |
+
lines.forEach((line,k)=>{
|
| 850 |
+
const li=document.createElement("li"), inp=Object.assign(document.createElement("input"),{value:line,dir:"rtl",autocomplete:"off",maxLength:300});
|
| 851 |
+
inp.setAttribute("aria-label",`ืืฉืคื ${k+1}`);
|
| 852 |
+
inp.oninput=()=>{ lines[k]=inp.value; written[c.id]=lines; store.set("ihki.written",written);
|
| 853 |
+
clearTimeout(writeTimer); writeTimer=setTimeout(()=>{ writeTimer=null; sendWriting(c.id); },800); };
|
| 854 |
+
li.append(inp); $("writeLines").append(li);
|
| 855 |
+
});
|
| 856 |
+
$("writeDlg").showModal();
|
| 857 |
+
}
|
| 858 |
+
$("writeClose").onclick=()=>$("writeDlg").close();
|
| 859 |
+
$("writeDlg").addEventListener("close",()=>{
|
| 860 |
+
if(writeTimer){ clearTimeout(writeTimer); writeTimer=null; sendWriting(writeOpen); } // what was just written is sent at once
|
| 861 |
+
writeOpen=null; if(home&&!document.body.classList.contains("manage")) drawPath(true); });
|
| 862 |
+
const openCat=c=>c.write?writeTopic(c):pickCat(c.id);
|
| 863 |
function drawPath(stay){
|
| 864 |
const box=$("path"), listed=PHRASES.filter(p=>p.listed!==false), NS="http://www.w3.org/2000/svg";
|
| 865 |
drawToday();
|
|
|
|
| 880 |
const b=mark("chapter soon",""); b.style.top=y+"px"; b.append(mark("",lessonsWord(run)),mark("","ืืงืจืื","small")); box.append(b);
|
| 881 |
y+=52+28; continue;
|
| 882 |
}
|
| 883 |
+
const items=lessonItems(l.id), cats=items.filter(it=>it.c).map(it=>it.c), parts=cats.map(c=>c.write?wTally(c):tally(listed.filter(p=>p.cat===c.id)));
|
| 884 |
const whole=tally(listed.filter(p=>cats.some(c=>c.id===p.cat))), now=!whole.over&&next;
|
| 885 |
const todo=Math.max(0,parts.findIndex(t=>!t.over)); // the topic the banner opens
|
| 886 |
if(now) next=false;
|
| 887 |
const head=document.createElement("button");
|
| 888 |
head.className="chapter"+(whole.gold?" gold":""); head.style.top=y+"px"; head.style.setProperty("--p",`${whole.n?whole.done/whole.n*100:0}%`);
|
| 889 |
head.append(mark("",l.name),count(whole),document.createElement("i")); head.title=`${l.name}: ืชืืจืืื ${whole.done} ืืชืื ${whole.n}`;
|
| 890 |
+
head.onclick=()=>openCat(cats[todo]); box.append(head);
|
| 891 |
y+=64+86; // the banner, room for the bubble, half a button
|
| 892 |
const seat=(b,i)=>{ // a button's place on the road, and its label
|
| 893 |
const label=document.createElement("span"), x=-SWAY[i%8]*amp, right=x<0||(!x&&i%8===0); // the first turn is to the left; the label stands on the other side
|
|
|
|
| 906 |
}
|
| 907 |
const i=cats.indexOf(c), t=parts[i], cur=now&&i===todo, [b,dot]=ball(t,cur), [x,label]=seat(b,at);
|
| 908 |
const mine=!!hw&&c===hw.c; // the homework topic: its bubble counts the days left
|
| 909 |
+
dot.textContent=c.story?"๐ฌ":c.write?"โ\uFE0E":n; // the number stays; a finished topic gets a badge, the one to do now and the homework a bubble
|
| 910 |
if(t.over) dot.before(mark("badge",t.gold?"โ
":"โ"));
|
| 911 |
else if(cur||mine){
|
| 912 |
const tag=mark("tag",mine?"":t.done?"ืืืฉื":"ืืชืืืื");
|
|
|
|
| 916 |
const way=c.name.match(WAY); // "ืืฉืคืืื: ืขืืจืืช โ ืขืจืืืช ื'" is drawn as "ืืฉืคืืื ื'" and a chip with the direction
|
| 917 |
label.append(mark("",way?way[1]+way[4]:c.name,"b"));
|
| 918 |
if(way) label.append(mark("way"+(way[2]==="ืขืจืืืช"?" read":""),`${SHORT[way[2]]||way[2]}\u00a0โ\u00a0${SHORT[way[3]]||way[3]}`));
|
| 919 |
+
const did=c.write?"ื ืืชืื":"ืชืืจืืื";
|
| 920 |
+
label.append(mine&&t.over?mark("","โ ืฉืืขืืจื ืืืืช ืืืฉืืื ๐","small"):count(t,did)); b.append(label);
|
| 921 |
+
b.title=(mine&&!t.over?`ืฉืืขืืจื ืืืช, ${hw.msg}. `:"")+`${c.name}: ${did} ${t.done} ืืชืื ${t.n}`; b.setAttribute("aria-label",b.title);
|
| 922 |
+
b.onclick=()=>openCat(c); box.append(b);
|
| 923 |
stops.push({x,y,went:t.over,cur}); y+=STEP;
|
| 924 |
});
|
| 925 |
const cup=document.createElement("div"), x=-SWAY[items.length%8]*amp; // the lesson's end: gold once all of it was practised
|
|
|
|
| 1789 |
const lessonPhrases=(l,list)=>{ const cats=ALL_CATS.filter(c=>c.lesson===l.id).map(c=>c.id); return list.filter(p=>cats.includes(p.cat)); };
|
| 1790 |
const stuTally=(s,list)=>{ const got=list.filter(p=>s.best[p.id]!=null), sum=k=>list.reduce((t,p)=>t+(s[k]&&s[k][p.id]||0),0);
|
| 1791 |
return {done:got.length, n:list.length, avg:mean(got.map(p=>s.best[p.id])), tries:sum("tries"), missed:sum("missed")}; }; // missed: recordings that did not match their sentence
|
| 1792 |
+
// a topic the students write in (see `writeTopic`): the sentences the student wrote, of those it asks for
|
| 1793 |
+
const stuWrote=(s,c)=>{ const lines=((s.written||{})[c.id]||[]).filter(x=>x.trim()); return {done:Math.min(lines.length,c.write.lines), n:c.write.lines, avg:null, tries:0, missed:0, lines}; };
|
| 1794 |
+
const topicTally=(s,c,listed)=>c.write?stuWrote(s,c):stuTally(s,listed.filter(p=>p.cat===c.id));
|
| 1795 |
+
const didWord=c=>c.write?"ื ืืชืื":"ืชืืจืืื";
|
| 1796 |
const triesText=t=>[t.tries&&`${t.tries} ื ืืกืืื ืืช`,t.missed&&`${t.missed} ืื ืืืื`].filter(Boolean).join(" ยท ");
|
| 1797 |
const ratio=t=>{ const m=document.createElement("small"), n=document.createElement("bdi"); n.dir="ltr"; n.textContent=`${t.done}/${t.n}`; m.append(n); return m; };
|
| 1798 |
const bar=frac=>{ const b=mark("progress",""), f=document.createElement("i"); f.style.width=`${Math.round(frac*100)}%`; b.append(f); return b; };
|
|
|
|
| 1880 |
const lines=c?listed.filter(p=>p.cat===c.id).length:0;
|
| 1881 |
if(n){
|
| 1882 |
const row=mark("crow","","li");
|
| 1883 |
+
row.append(mark("",c.story?"๐ฌ":c.write?"โ\uFE0E":n,"i"),mark("",c.name,"b"),mark("",c.write?`ืืชืืื ยท ${c.write.lines} ืืฉืคืืื`:`${c.story?"ืฉืืื":"ืชืจืืื"} ยท ${lines} ${c.unit==="ืืืื"?"ืืืืื":c.unit==="ืคืืขื"?"ืคืขืืื":"ืืฉืคืืื"}`,"small")); list.append(row); return;
|
| 1884 |
}
|
| 1885 |
const it=v||c, row=mark("crow added","","li"), text=mark("two",""), title=mark("","","b"), t=document.createElement("bdi"), acts=mark("acts","");
|
| 1886 |
const up=mark("btn move","โ","button"), down=mark("btn move","โ","button"), see=mark("btn",v?"ืฆืคืืื":"ืชืจืืื","button"), del=mark("btn danger","ืืืืงื","button");
|
|
|
|
| 2013 |
head.append(tiles);
|
| 2014 |
const hw=klass.homework&&ALL_CATS.find(c=>c.id===klass.homework&&CLASS_LESSONS.some(l=>l.id===c.lesson));
|
| 2015 |
if(hw){ // the homework: how many finished the topic, and who is still to, the furthest from it first
|
| 2016 |
+
const list=listedPhrases(), todo=students.map(s=>({s,t:topicTally(s,hw,list)})).filter(x=>x.t.done<x.t.n).sort((a,b)=>a.t.done-b.t.done);
|
| 2017 |
const due=dueText(klass.due), box=mark("hwsum"+(due.late&&todo.length?" late":""),""), line=mark("",`ืฉืืขืืจื ืืืช: ${hw.name}`,"b");
|
| 2018 |
line.append(mark("",` ยท ${lessonName(ALL_LESSONS.find(l=>l.id===hw.lesson))}`,"small"));
|
| 2019 |
if(due.text) line.append(mark(""," ยท "+due.text,"small"));
|
|
|
|
| 2061 |
// the same columns however many lessons the class has: the homework topic (when there is one) and all the class's
|
| 2062 |
// sentences; a lesson by itself is on the student's own screen
|
| 2063 |
const hw=klass&&klass.homework&&ALL_CATS.find(c=>c.id===klass.homework&&CLASS_LESSONS.some(l=>l.id===c.lesson));
|
| 2064 |
+
const cols=[...(hw?[{name:"ืฉืืขืืจื ืืืช",title:`ืฉืืขืืจื ืืืช, ${hw.name}`,did:didWord(hw),of:s=>topicTally(s,hw,listed)}]:[]),
|
| 2065 |
+
...(CLASS_LESSONS.length?[{name:"ืื ืืฉืืขืืจืื",title:"ืื ืืฉืืขืืจืื",did:"ืชืืจืืื",of:s=>stuTally(s,listed)}]:[])];
|
| 2066 |
const box=$("mRoster"); box.innerHTML=""; box.hidden=false; box.style.setProperty("--cols",["minmax(0,1fr)",...cols.map(()=>"4.2em"),"3em","10px"].join(" ")); // no lesson column when none is ready
|
| 2067 |
const h=mark("","ืชืืืืืื","h2"); h.append(mark("","ืืืืฆื ืขื ืชืืืื ืคืืชืืช ืืช ืืืฃ ืฉืื","small")); box.append(h);
|
| 2068 |
if(!students.length){ box.append(mark("note","ืืื ืขืืืื ืชืืืืืื ืืืืชื ืืื. ืืืกืืคืื ืืืชื ืชืืช โืืืชืืชโ, ืืืคืชืืจ โืขืจืืืโ ืฉื ืืืืชื.","p")); return; }
|
|
|
|
| 2073 |
const shown=mark("",s.nick||s.name||s.email,"b"); shown.dir="auto"; // an address is cut at its end
|
| 2074 |
who.append(shown,mark("",lastSeen(s)+(s.unmatched?` ยท ${s.unmatched} ืื ืืืื`:""),"small"));
|
| 2075 |
who.title=s.email; row.append(who);
|
| 2076 |
+
for(const col of cols){ const t=col.of(s), c=mark("cell",""); c.append(ratio(t),bar(t.n?t.done/t.n:0)); c.title=`${col.title}: ${col.did} ${t.done} ืืชืื ${t.n}`+(t.avg!=null?`, ืฆืืื ${t.avg}`:""); row.append(c); }
|
| 2077 |
row.append(s.avg!=null?grade(s.avg):mark("none","โ"),mark("go","โน")); // the arrow says the row opens
|
| 2078 |
row.onclick=()=>showStudent(s.email);
|
| 2079 |
box.append(row);
|
|
|
|
| 2099 |
if(s.unmatched) head.append(mark("note",`${s.unmatched} ืืงืืืืช ืื ืืืื ืืืฉืคื ืฉืขื ืืืกื: ืื ื ืฉืืจื, ืืื ืื ื ืกืคืจืืช ืืืฉืคืืื ืฉืชืืจืืื ืืื ืืฆืืื. ืืื ืื ื ืืฉื ืืืคืืข ืืื ืืืื ืืื ืื.`,"p"));
|
| 2100 |
const hw=klass&&klass.homework&&ALL_CATS.find(c=>c.id===klass.homework&&CLASS_LESSONS.some(l=>l.id===c.lesson));
|
| 2101 |
if(hw){
|
| 2102 |
+
const t=topicTally(s,hw,listed), due=dueText(klass.due), over=t.done>=t.n;
|
| 2103 |
const sum=mark("hwsum"+(due.late&&!over?" late":""),""), line=mark("",`ืฉืืขืืจื ืืืช: ${hw.name}`,"b");
|
| 2104 |
line.append(mark("",` ยท ${lessonName(ALL_LESSONS.find(l=>l.id===hw.lesson))}`,"small"));
|
| 2105 |
if(due.text) line.append(mark(""," ยท "+due.text,"small"));
|
| 2106 |
+
sum.append(line,mark("",over?`โ ืกืืื/ื: ืื ${t.n} ืืืฉืคืืื ${didWord(hw)}`:`${didWord(hw)} ${t.done} ืืชืื ${t.n} ืืฉืคืืื`,"small")); head.append(sum);
|
| 2107 |
}
|
| 2108 |
box.append(head);
|
| 2109 |
const lessons=mark("card hard",""), lh=mark("","ืฉืืขืืจืื","h2"); lh.append(mark("","ืืืืฆื ืขื ืฉืืขืืจ ืคืืชืืช ืืช ืื ืืฉืืื ืฉืื","small")); lessons.append(lh);
|
|
|
|
| 2111 |
const t=stuTally(s,lessonPhrases(l,listed)), sec=part(lessons); sec.classList.add("lsum");
|
| 2112 |
sec.firstChild.append(mark("",lessonName(l)),mark("",t.done?`ืชืืจืืื ${t.done} ืืชืื ${t.n} ืืฉืคืืื`:t.missed?`ื ืืกื/ืชื, ืื ืืืื (${t.missed})`:"ืขืื ืื ืืชืืื/ื","small"),t.avg!=null?grade(t.avg):mark("none","โ"),bar(t.n?t.done/t.n:0));
|
| 2113 |
for(const c of ALL_CATS.filter(c=>c.lesson===l.id)){
|
| 2114 |
+
const t=topicTally(s,c,listed), row=mark("trow"+(t.done?"":" untouched"),"");
|
| 2115 |
row.append(mark("",c.name),mark("",triesText(t),"small"),ratio(t),t.avg!=null?grade(t.avg):mark("none","โ")); sec.append(row);
|
| 2116 |
+
if(c.write&&t.done){ // a writing topic: the sentences themselves
|
| 2117 |
+
const ol=mark("wrote","","ol"); for(const x of t.lines){ const li=mark("",x,"li"); li.dir="rtl"; ol.append(li); } sec.append(ol);
|
| 2118 |
+
}
|
| 2119 |
}
|
| 2120 |
}
|
| 2121 |
if(CLASS_SOON.length) lessons.append(mark("note","ืืงืจืื: "+byLevel(CLASS_SOON).map(g=>`${g.level.name}, ${lessonsWord(g.lessons)}`).join(" ยท "),"p"));
|
|
|
|
| 2158 |
for(const t of ALL_CATS.filter(t=>t.lesson===l.id)) g.append(new Option(t.name,t.id));
|
| 2159 |
}
|
| 2160 |
hw.value=c&&c.homework||""; $("editDue").value=c&&c.due||"";
|
| 2161 |
+
$("editDue").onchange=()=>{ // a day with no topic chosen: the homework is the written one of the class's last lesson that has it
|
| 2162 |
+
const on=[...$("editLessons").querySelectorAll(".chips :checked")].map(b=>b.value), own=writeHomework(ALL_LESSONS.filter(l=>on.includes(l.id)));
|
| 2163 |
+
if($("editDue").value&&!hw.value&&own) hw.value=own.id;
|
| 2164 |
+
};
|
| 2165 |
$("editEmails").value=c?c.emails.map(e=>[e,c.nicknames&&c.nicknames[e]].filter(Boolean).join(" ")).join("\n"):"";
|
| 2166 |
$("editSave").textContent=c?"ืฉืืืจื":"ืคืชืืืช ืืืืชื"; $("editDelete").hidden=!c; $("editMsg").textContent="";
|
| 2167 |
countStudents(); $("editDlg").showModal(); (c?$("editEmails"):$("editName")).focus();
|
|
|
|
| 2248 |
}
|
| 2249 |
$("newAdd").onclick=()=>{ wizAdd(); $("newEmail").focus(); };
|
| 2250 |
$("newEmail").onkeydown=e=>{ if(e.key==="Enter"){ e.preventDefault(); wizAdd(); } };
|
| 2251 |
+
const writeHomework=ls=>ALL_CATS.filter(c=>c.write&&ls.some(l=>l.id===c.lesson&&!l.soon)).pop(); // the lessons' last writing topic
|
| 2252 |
function wizHomework(){ // the topics of the level's ready lessons, under their lessons; the one chosen before stays
|
| 2253 |
const hw=$("newHw"), was=hw.value, ready=wizLessons().filter(l=>!l.soon);
|
| 2254 |
hw.innerHTML=""; hw.add(new Option(ready.length?"ืืื ืฉืืขืืจื ืืืช ืืื ืชืืื":"ืืจืื ืืื ืขืื ืืื ืฉืืขืืจืื ืืืื ืื",""));
|
|
|
|
| 2256 |
const g=document.createElement("optgroup"); g.label=l.name; hw.append(g);
|
| 2257 |
for(const t of ALL_CATS.filter(t=>t.lesson===l.id)) g.append(new Option(t.name,t.id));
|
| 2258 |
}
|
| 2259 |
+
const own=writeHomework(ready); // offered from the start: the teacher has only the day to set
|
| 2260 |
+
hw.value=[...hw.options].some(o=>o.value===was)&&(was||wiz.hwSeen)?was:own?own.id:""; wiz.hwSeen=true; hw.disabled=!ready.length;
|
| 2261 |
$("newDue").min=new Date().toLocaleDateString("sv"); hw.onchange();
|
| 2262 |
}
|
| 2263 |
$("newHw").onchange=()=>$("newDueBox").hidden=!$("newHw").value;
|
|
|
|
| 2349 |
login.onclick=()=>sb.auth.signInWithOAuth({provider:"google",
|
| 2350 |
options:{redirectTo:here,queryParams:{prompt:"select_account"}}});
|
| 2351 |
logout.onclick=$("switchBtn").onclick=async()=>{ // the best scores kept on the device belong to this student
|
| 2352 |
+
await sb.auth.signOut(); store.set("ihki.best2",{}); store.set("ihki.silent",{}); store.set("ihki.written",{}); store.set("ihki.unsent",{}); location.reload(); };
|
| 2353 |
sb.auth.onAuthStateChange((_e,session)=>{
|
| 2354 |
login.hidden=mail.hidden=!!session; logout.hidden=!session;
|
| 2355 |
logout.title=session?session.user.email||"":"";
|
|
|
|
| 2368 |
if(MY_CLASSES.length===1) MY_CLASS=mine[0];
|
| 2369 |
else{ const last=MY_CLASSES.find(c=>c.name===store.get("ihki.class","")); if(last) useClass(last); } // the class practised in last
|
| 2370 |
start.hidden=!ok||teacher; roles.hidden=$("toManage").hidden=!teacher; denied.hidden=ok;
|
| 2371 |
+
if(ok){ (teacher?$("practiceBtn"):start).focus({preventScroll:true}); loadProgress().then(()=>{ if(PHRASES.length&&$("wrap").inert) startCat(); }); loadContent(); loadWriting(); }
|
| 2372 |
},0);
|
| 2373 |
});
|
| 2374 |
}
|
static/privacy.html
CHANGED
|
@@ -24,7 +24,7 @@ h1{font-size:26px;margin:0 0 4px} h2{font-size:19px;margin:22px 0 4px}
|
|
| 24 |
<p>ืืฉืืชื ืืืืจืื ืืืืจ ืชืจืืื ืืขืืจืืช (ืืืืงืจืืคืื "ืืชืจืืืื ืืขืืจืืช"), ืืืืืืจ ืืืืื ืขื ืืื ืืืคืืคื ืฉืืื ืืืื ื ื ืฉืื ืืฉืจืช ืฉืื ื. ืืืง ืืืืคืืคื ืื, ืืืื Chrome, ืฉืืืืื ืืช ืืงืื ืืฉืืจืืช ืืืืื ืืืืืืจ ืฉื ืืฆืจื ืืืคืืคื (ืืืฉื Google). ืื ืื ื ืื ืฉืืืจืื ืืช ืื ืฉื ืืืจ.</p>
|
| 25 |
|
| 26 |
<h2>ืืชืงืืืืช ืืืืืื</h2>
|
| 27 |
-
<p>ืืืืจ ืื ืืงืืื ื ืฉืืจืื ื-Supabase, ืชืืช ืืืฉืืื ืฉืืื, ืืืฉืคื ืฉืชืจืืืชื, ืืฆืืื ืืืืืขื. ืืืืจื ืืืื ืืจืืืช ืืช ืื ืชืื ืื ืืืื ืืื ืืขืงืื ืืืจ ืืืชืงืืืืช ืฉืืื.</p>
|
| 28 |
|
| 29 |
<h2>ืื ื ืฉืืจ ืืืืฉืืจ ืฉืืื</h2>
|
| 30 |
<p>ืืฆืืื ืื ืืืืืื ืืืืชืจ ืืืืขืืคืืช ืฉืืื (ืฉืืขืืจ, ืงืื) ื ืฉืืจืื ืืืคืืคื ืฉืืื ืืืื, ืืื ืขื ืคืจืื ืืืชืืืจืืช.</p>
|
|
|
|
| 24 |
<p>ืืฉืืชื ืืืืจืื ืืืืจ ืชืจืืื ืืขืืจืืช (ืืืืงืจืืคืื "ืืชืจืืืื ืืขืืจืืช"), ืืืืืืจ ืืืืื ืขื ืืื ืืืคืืคื ืฉืืื ืืืื ื ื ืฉืื ืืฉืจืช ืฉืื ื. ืืืง ืืืืคืืคื ืื, ืืืื Chrome, ืฉืืืืื ืืช ืืงืื ืืฉืืจืืช ืืืืื ืืืืืืจ ืฉื ืืฆืจื ืืืคืืคื (ืืืฉื Google). ืื ืื ื ืื ืฉืืืจืื ืืช ืื ืฉื ืืืจ.</p>
|
| 25 |
|
| 26 |
<h2>ืืชืงืืืืช ืืืืืื</h2>
|
| 27 |
+
<p>ืืืืจ ืื ืืงืืื ื ืฉืืจืื ื-Supabase, ืชืืช ืืืฉืืื ืฉืืื, ืืืฉืคื ืฉืชืจืืืชื, ืืฆืืื ืืืืืขื. ืื ืืืฉืคืืื ืฉืืชื ืืืชืืื ืืฉืืขืืจื ืืืืช ื ืฉืืจืื ืฉื. ืืืืจื ืืืื ืืจืืืช ืืช ืื ืชืื ืื ืืืื ืืื ืืขืงืื ืืืจ ืืืชืงืืืืช ืฉืืื.</p>
|
| 28 |
|
| 29 |
<h2>ืื ื ืฉืืจ ืืืืฉืืจ ืฉืืื</h2>
|
| 30 |
<p>ืืฆืืื ืื ืืืืืื ืืืืชืจ ืืืืขืืคืืช ืฉืืื (ืฉืืขืืจ, ืงืื) ื ืฉืืจืื ืืืคืืคื ืฉืืื ืืืื, ืืื ืขื ืคืจืื ืืืชืืืจืืช.</p>
|
tests/test_scoring.py
CHANGED
|
@@ -356,7 +356,9 @@ def test_workbook_lesson_1():
|
|
| 356 |
from app.phrases import CATEGORIES, LESSONS, public_phrases
|
| 357 |
|
| 358 |
assert [l["id"] for l in LESSONS if not l.get("soon")] == ["1", "2"]
|
| 359 |
-
assert [c["id"] for c in CATEGORIES if c["lesson"] == "1"] == ["l1-pron", "l1-verbs", "l1-past", "l1-say", "l1-read"]
|
|
|
|
|
|
|
| 360 |
pub = public_phrases()
|
| 361 |
count = lambda cat: sum(p["cat"] == cat for p in pub)
|
| 362 |
assert [count(c) for c in ("l1-pron", "l1-verbs", "l1-past", "l1-say", "l1-read")] == [8, 4, 32, 10, 22]
|
|
@@ -395,7 +397,9 @@ def test_workbook_lesson_2():
|
|
| 395 |
from app.phrases import CATEGORIES, public_phrases
|
| 396 |
|
| 397 |
cats = ["l2-dual", "l2-family", "l2-poss", "l2-say", "l2-say2", "l2-read", "l2-talk", "l2-meet"]
|
| 398 |
-
assert [c["id"] for c in CATEGORIES if c["lesson"] == "2"] == cats
|
|
|
|
|
|
|
| 399 |
pub = public_phrases()
|
| 400 |
assert [sum(p["cat"] == c for p in pub) for c in cats] == [17, 24, 48, 23, 25, 13, 27, 24]
|
| 401 |
assert all(p["read"] == (p["cat"] == "l2-read") and "#" not in p["ar"] for p in pub if p["cat"].startswith("l2-"))
|
|
@@ -433,7 +437,16 @@ def test_sign_in_guards_the_practice_endpoints():
|
|
| 433 |
url, key, teachers = "https://proj.supabase.co", "sb_publishable_x", frozenset()
|
| 434 |
|
| 435 |
def __init__(self):
|
| 436 |
-
self.rows, self.cls, self.vids, self.txts = [], [], [], []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
def classes(self, fresh=False):
|
| 439 |
return self.cls
|
|
@@ -502,6 +515,13 @@ def test_sign_in_guards_the_practice_endpoints():
|
|
| 502 |
ALL = [l["id"] for l in LESSONS]
|
| 503 |
NO_HW = {"homework": "", "due": None}
|
| 504 |
T1, T2 = (next(k["id"] for k in CATEGORIES if k["lesson"] == l) for l in ALL[:2]) # a topic of each of the first two lessons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
# no class yet: any account is let in, to every lesson
|
| 506 |
assert c.get("/api/me", headers=good).json() == {"email": "A@b.c", "teacher": False, "classes": [], "lessons": ALL}
|
| 507 |
assert c.get("/api/class").status_code == 401 and c.get("/api/class", headers=good).status_code == 403
|
|
@@ -652,6 +672,8 @@ def test_sign_in_guards_the_practice_endpoints():
|
|
| 652 |
assert student["best"] == {str(PHRASES.index(VERB)): 88} and student["tries"] == {str(PHRASES.index(VERB)): 2}
|
| 653 |
assert (student["recordings"], student["days"], student["last"]) == (2, 1, "2026-10-09T10:00:00+00:00")
|
| 654 |
assert (new["email"], new["joined"], new["recordings"]) == ("new@b.c", False, 0) and student["joined"]
|
|
|
|
|
|
|
| 655 |
assert (student["classes"], new["classes"]) == ({"October 2026": ""}, {"October 2026": "ืื ื"})
|
| 656 |
assert x["classes"] == {"October 2026": "", "September 2026": ""} and y["classes"] == {"September 2026": ""}
|
| 657 |
# a class counts what was practised since it was opened: a new one starts clean (the student's own summary stays whole)
|
|
|
|
| 356 |
from app.phrases import CATEGORIES, LESSONS, public_phrases
|
| 357 |
|
| 358 |
assert [l["id"] for l in LESSONS if not l.get("soon")] == ["1", "2"]
|
| 359 |
+
assert [c["id"] for c in CATEGORIES if c["lesson"] == "1"] == ["l1-pron", "l1-verbs", "l1-past", "l1-say", "l1-read", "l1-hw"]
|
| 360 |
+
hw = CATEGORIES[5]["write"] # the workbook's homework: a task and five sentences to write, with nothing to say
|
| 361 |
+
assert hw["lines"] == 5 and hw["task"].startswith("ืืชืื ืืืืฉื ืืฉืคืืื") and "ืึดืื - ืื" in hw["task"]
|
| 362 |
pub = public_phrases()
|
| 363 |
count = lambda cat: sum(p["cat"] == cat for p in pub)
|
| 364 |
assert [count(c) for c in ("l1-pron", "l1-verbs", "l1-past", "l1-say", "l1-read")] == [8, 4, 32, 10, 22]
|
|
|
|
| 397 |
from app.phrases import CATEGORIES, public_phrases
|
| 398 |
|
| 399 |
cats = ["l2-dual", "l2-family", "l2-poss", "l2-say", "l2-say2", "l2-read", "l2-talk", "l2-meet"]
|
| 400 |
+
assert [c["id"] for c in CATEGORIES if c["lesson"] == "2"] == cats + ["l2-hw"] # the lesson ends with its written homework
|
| 401 |
+
hw = CATEGORIES[-1]["write"]
|
| 402 |
+
assert hw["lines"] == 5 and "ืคืชืจื ืืช ืื ืืฉืืขืืจ ืืฉื ื" in hw["task"] and "ืงึทืขึทื / ืึปืงึฐืขึนื โ ืืฉื" in hw["task"]
|
| 403 |
pub = public_phrases()
|
| 404 |
assert [sum(p["cat"] == c for p in pub) for c in cats] == [17, 24, 48, 23, 25, 13, 27, 24]
|
| 405 |
assert all(p["read"] == (p["cat"] == "l2-read") and "#" not in p["ar"] for p in pub if p["cat"].startswith("l2-"))
|
|
|
|
| 437 |
url, key, teachers = "https://proj.supabase.co", "sb_publishable_x", frozenset()
|
| 438 |
|
| 439 |
def __init__(self):
|
| 440 |
+
self.rows, self.cls, self.vids, self.txts, self.wrote = [], [], [], [], {}
|
| 441 |
+
|
| 442 |
+
def writings(self, token):
|
| 443 |
+
return {t: lines for (u, t), lines in self.wrote.items() if u == "u1"}
|
| 444 |
+
|
| 445 |
+
def save_writing(self, token, user_id, topic, lines):
|
| 446 |
+
self.wrote[user_id, topic] = lines
|
| 447 |
+
|
| 448 |
+
def all_writings(self):
|
| 449 |
+
return [{"user_id": u, "topic": t, "lines": lines} for (u, t), lines in self.wrote.items()]
|
| 450 |
|
| 451 |
def classes(self, fresh=False):
|
| 452 |
return self.cls
|
|
|
|
| 515 |
ALL = [l["id"] for l in LESSONS]
|
| 516 |
NO_HW = {"homework": "", "due": None}
|
| 517 |
T1, T2 = (next(k["id"] for k in CATEGORIES if k["lesson"] == l) for l in ALL[:2]) # a topic of each of the first two lessons
|
| 518 |
+
# written homework is kept for the student, a topic's lines in place of the ones before, and read back anywhere
|
| 519 |
+
assert c.get("/api/writing").status_code == 401 and c.get("/api/writing", headers=good).json() == {"writing": {}}
|
| 520 |
+
put = lambda topic, lines: c.put(f"/api/writing/{topic}", json={"lines": lines}, headers=good).status_code
|
| 521 |
+
assert put("l1-hw", ["ืึทื ึทื ืึทืึทึผืึตืช ", ""]) == 200 and put("l1-hw", ["ืึทื ึทื ืึทืึทึผืึตืช", "", "ืึดืึตู ืคึทืชึฐืึทืช"]) == 200
|
| 522 |
+
assert c.get("/api/writing", headers=good).json() == {"writing": {"l1-hw": ["ืึทื ึทื ืึทืึทึผืึตืช", "", "ืึดืึตู ืคึทืชึฐืึทืช"]}}
|
| 523 |
+
assert put(T1, ["x"]) == 404 and put("l1-hw", ["x"] * 6) == 400 and put("l1-hw", ["x" * 301]) == 400 and put("l1-hw", "x") == 400
|
| 524 |
+
assert c.put("/api/writing/l1-hw", json={"lines": ["x"]}).status_code == 401
|
| 525 |
# no class yet: any account is let in, to every lesson
|
| 526 |
assert c.get("/api/me", headers=good).json() == {"email": "A@b.c", "teacher": False, "classes": [], "lessons": ALL}
|
| 527 |
assert c.get("/api/class").status_code == 401 and c.get("/api/class", headers=good).status_code == 403
|
|
|
|
| 672 |
assert student["best"] == {str(PHRASES.index(VERB)): 88} and student["tries"] == {str(PHRASES.index(VERB)): 2}
|
| 673 |
assert (student["recordings"], student["days"], student["last"]) == (2, 1, "2026-10-09T10:00:00+00:00")
|
| 674 |
assert (new["email"], new["joined"], new["recordings"]) == ("new@b.c", False, 0) and student["joined"]
|
| 675 |
+
c.app.state.auth.wrote["u2", "l1-hw"] = ["ืึดืึตู ืคึทืชึฐืึทืช"] # the panel reads what each student wrote
|
| 676 |
+
assert [k["written"] for k in c.get("/api/class", headers=good).json()["students"][:2]] == [{"l1-hw": ["ืึดืึตู ืคึทืชึฐืึทืช"]}, {}]
|
| 677 |
assert (student["classes"], new["classes"]) == ({"October 2026": ""}, {"October 2026": "ืื ื"})
|
| 678 |
assert x["classes"] == {"October 2026": "", "September 2026": ""} and y["classes"] == {"September 2026": ""}
|
| 679 |
# a class counts what was practised since it was opened: a new one starts clean (the student's own summary stays whole)
|