View the student screens as a class (תצוגה ככיתה) (#16)
Browse filesA developer or a teacher who is in no class picks a class on top of the student screens and sees its tests, assignments and subjects.
- docs/tasks/prd-mathly.md +1 -0
- mathly2/access.py +23 -0
- mathly2/ai_help.py +2 -1
- mathly2/assignments.py +4 -4
- mathly2/main.py +4 -2
- mathly2/realtests.py +3 -3
- mathly2/skills.py +4 -2
- mathly2/static/api.js +9 -0
- mathly2/static/app.css +6 -0
- mathly2/static/student.js +19 -2
- mathly2/tests/test_view_as_class.py +96 -0
- openspec/changes/view-as-class/proposal.md +23 -0
- openspec/changes/view-as-class/specs/accounts-and-classes/spec.md +12 -0
- openspec/changes/view-as-class/tasks.md +5 -0
docs/tasks/prd-mathly.md
CHANGED
|
@@ -455,6 +455,7 @@ A tab bar at the bottom of the screen leads between them: home, path (named "ה
|
|
| 455 |
*Reference: `app/prompter.py`, `static/prompter.js`, and the management sheet in `static/math.js`.*
|
| 456 |
|
| 457 |
- **DEV-1 Every permission.** A developer can open any class's progress, tests, assignments, inbox and AI queue, as the class's teacher can, and everything managers and admins can do.
|
|
|
|
| 458 |
- **DEV-2 Prompter (פרומפטר).** A developer writes or pastes a text and shows it full screen as a scrolling teleprompter. Saved texts (a title up to 120 characters; up to 200 texts) belong to the account and are on every device; what is being edited is also kept in the browser, so nothing is lost before it is saved.
|
| 459 |
Keys: space starts and stops, ↑/↓ change speed, +/− change size, M mirrors, F is full screen, Esc leaves; the mouse and a presentation remote work too.
|
| 460 |
A saved text can have an **outline (ראשי פרקים)**: on request the AI rewrites the text as the same slides with two to four very short topic reminders each, once; it is kept with the text and can be edited. Changing the text without sending an outline drops the outline, so a stale one is never shown.
|
|
|
|
| 455 |
*Reference: `app/prompter.py`, `static/prompter.js`, and the management sheet in `static/math.js`.*
|
| 456 |
|
| 457 |
- **DEV-1 Every permission.** A developer can open any class's progress, tests, assignments, inbox and AI queue, as the class's teacher can, and everything managers and admins can do.
|
| 458 |
+
**תצוגה ככיתה.** A developer or a teacher who is in no class sees a picker on top of the student screens and can view them as a class (a developer any class, a teacher the classes they teach): its tests, assignments, subjects and photo help, as its students see them. Progress, stars and readiness stay their own. A student cannot pick another class.
|
| 459 |
- **DEV-2 Prompter (פרומפטר).** A developer writes or pastes a text and shows it full screen as a scrolling teleprompter. Saved texts (a title up to 120 characters; up to 200 texts) belong to the account and are on every device; what is being edited is also kept in the browser, so nothing is lost before it is saved.
|
| 460 |
Keys: space starts and stops, ↑/↓ change speed, +/− change size, M mirrors, F is full screen, Esc leaves; the mouse and a presentation remote work too.
|
| 461 |
A saved text can have an **outline (ראשי פרקים)**: on request the AI rewrites the text as the same slides with two to four very short topic reminders each, once; it is kept with the text and can be edited. Changing the text without sending an outline drops the outline, so a stale one is never shown.
|
mathly2/access.py
CHANGED
|
@@ -43,6 +43,29 @@ def need(permission: str) -> Callable[..., dict]:
|
|
| 43 |
return dependency
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def learner(request: Request, user: dict = Depends(need("path.use"))) -> dict:
|
| 47 |
"""Someone who may use the path: a teacher or developer, or a student who is in a class. A person whose
|
| 48 |
only role is student and who is in no class is asked to talk to their teacher (403)."""
|
|
|
|
| 43 |
return dependency
|
| 44 |
|
| 45 |
|
| 46 |
+
VIEW_CLASS = "x-view-class" # a developer or a teacher who is in no class previews the student screens as this class
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def preview_classes(request: Request, user: dict) -> list[dict]:
|
| 50 |
+
"""The classes this person may preview the student screens as: a developer every class, a teacher the classes they teach."""
|
| 51 |
+
if allowed(user["roles"], "*"):
|
| 52 |
+
return request.app.state.store.classes()
|
| 53 |
+
if "teacher" in user["roles"]:
|
| 54 |
+
return reads.of(request).classes_taught(user["email"])
|
| 55 |
+
return []
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def my_classes(request: Request, user: dict) -> list[dict]:
|
| 59 |
+
"""The classes the student screens are about: the person's own classes as a student; for a developer or a teacher who is in no
|
| 60 |
+
class, the class picked in "תצוגה ככיתה" (the X-View-Class header), if they may preview it."""
|
| 61 |
+
here = reads.of(request)
|
| 62 |
+
own = here.classes_of_student(user["email"])
|
| 63 |
+
picked = request.headers.get(VIEW_CLASS, "")
|
| 64 |
+
if own or not picked.isdigit() or set(user["roles"]) == {"student"}:
|
| 65 |
+
return own
|
| 66 |
+
return [c for c in preview_classes(request, user) if c["id"] == int(picked)][:1]
|
| 67 |
+
|
| 68 |
+
|
| 69 |
def learner(request: Request, user: dict = Depends(need("path.use"))) -> dict:
|
| 70 |
"""Someone who may use the path: a teacher or developer, or a student who is in a class. A person whose
|
| 71 |
only role is student and who is in no class is asked to talk to their teacher (403)."""
|
mathly2/ai_help.py
CHANGED
|
@@ -213,7 +213,8 @@ def requeue_after_restart(store) -> int:
|
|
| 213 |
# ---- the student ----
|
| 214 |
|
| 215 |
def _student_classes(request: Request, user: dict) -> list[dict]:
|
| 216 |
-
|
|
|
|
| 217 |
|
| 218 |
|
| 219 |
def _choose_class(request: Request, user: dict, wanted: int | None) -> dict:
|
|
|
|
| 213 |
# ---- the student ----
|
| 214 |
|
| 215 |
def _student_classes(request: Request, user: dict) -> list[dict]:
|
| 216 |
+
from .access import my_classes
|
| 217 |
+
return my_classes(request, user)
|
| 218 |
|
| 219 |
|
| 220 |
def _choose_class(request: Request, user: dict, wanted: int | None) -> dict:
|
mathly2/assignments.py
CHANGED
|
@@ -11,7 +11,7 @@ from pydantic import BaseModel, Field
|
|
| 11 |
from starlette.concurrency import run_in_threadpool
|
| 12 |
|
| 13 |
from . import attempts, cleanup, clock, pictures, reads
|
| 14 |
-
from .access import allowed, learner, need
|
| 15 |
from .pictures import PictureError
|
| 16 |
from .realtests import _my_class, lesson_names
|
| 17 |
from .written import picture_error
|
|
@@ -161,7 +161,7 @@ def _my_assignment(request: Request, user: dict, assignment_id: int) -> dict:
|
|
| 161 |
"""An assignment of one of the student's classes (404 for anything else, and for a removed one)."""
|
| 162 |
here = reads.of(request)
|
| 163 |
row = here.get_assignment(assignment_id)
|
| 164 |
-
mine = {c["id"] for c in
|
| 165 |
if row is None or row["removed_at"] or row["class_id"] not in mine:
|
| 166 |
raise HTTPException(404, "המשימה לא נמצאה")
|
| 167 |
return row
|
|
@@ -210,7 +210,7 @@ def student_assignment(request: Request, user: dict, row: dict, sub: dict | None
|
|
| 210 |
def my_assignments(request: Request, user: dict = Depends(learner)) -> list[dict]:
|
| 211 |
"""The student's assignments: the open ones first by due date, then the done ones."""
|
| 212 |
here, today = reads.of(request), clock.school_day()
|
| 213 |
-
class_ids = [c["id"] for c in
|
| 214 |
here.prefetch(("assignments_of_classes", class_ids), ("submissions_of_user", user["id"]), ("attempts_of", user["id"], "exercise_test"))
|
| 215 |
subs = {s["assignment_id"]: s for s in here.submissions_of_user(user["id"])}
|
| 216 |
shown = [student_assignment(request, user, r, subs.get(r["id"]), today) for r in here.assignments_of_classes(class_ids)]
|
|
@@ -375,7 +375,7 @@ def return_submission(submission_id: int, body: SendBack, request: Request, user
|
|
| 375 |
def grade_rows(request: Request, user: dict) -> list[dict]:
|
| 376 |
"""Graded assignments and done exercise-test assignments, with the teacher's note. A removed assignment keeps its grade."""
|
| 377 |
store, here = request.app.state.store, reads.of(request)
|
| 378 |
-
class_ids = [c["id"] for c in
|
| 379 |
rows = {r["id"]: r for r in store.assignments_of_classes(class_ids, include_removed=True)}
|
| 380 |
out = []
|
| 381 |
subs = {s["assignment_id"]: s for s in store.submissions_of_user(user["id"])}
|
|
|
|
| 11 |
from starlette.concurrency import run_in_threadpool
|
| 12 |
|
| 13 |
from . import attempts, cleanup, clock, pictures, reads
|
| 14 |
+
from .access import allowed, learner, need, my_classes
|
| 15 |
from .pictures import PictureError
|
| 16 |
from .realtests import _my_class, lesson_names
|
| 17 |
from .written import picture_error
|
|
|
|
| 161 |
"""An assignment of one of the student's classes (404 for anything else, and for a removed one)."""
|
| 162 |
here = reads.of(request)
|
| 163 |
row = here.get_assignment(assignment_id)
|
| 164 |
+
mine = {c["id"] for c in my_classes(request, user)}
|
| 165 |
if row is None or row["removed_at"] or row["class_id"] not in mine:
|
| 166 |
raise HTTPException(404, "המשימה לא נמצאה")
|
| 167 |
return row
|
|
|
|
| 210 |
def my_assignments(request: Request, user: dict = Depends(learner)) -> list[dict]:
|
| 211 |
"""The student's assignments: the open ones first by due date, then the done ones."""
|
| 212 |
here, today = reads.of(request), clock.school_day()
|
| 213 |
+
class_ids = [c["id"] for c in my_classes(request, user)]
|
| 214 |
here.prefetch(("assignments_of_classes", class_ids), ("submissions_of_user", user["id"]), ("attempts_of", user["id"], "exercise_test"))
|
| 215 |
subs = {s["assignment_id"]: s for s in here.submissions_of_user(user["id"])}
|
| 216 |
shown = [student_assignment(request, user, r, subs.get(r["id"]), today) for r in here.assignments_of_classes(class_ids)]
|
|
|
|
| 375 |
def grade_rows(request: Request, user: dict) -> list[dict]:
|
| 376 |
"""Graded assignments and done exercise-test assignments, with the teacher's note. A removed assignment keeps its grade."""
|
| 377 |
store, here = request.app.state.store, reads.of(request)
|
| 378 |
+
class_ids = [c["id"] for c in my_classes(request, user)]
|
| 379 |
rows = {r["id"]: r for r in store.assignments_of_classes(class_ids, include_removed=True)}
|
| 380 |
out = []
|
| 381 |
subs = {s["assignment_id"]: s for s in store.submissions_of_user(user["id"])}
|
mathly2/main.py
CHANGED
|
@@ -11,7 +11,7 @@ from fastapi import Request
|
|
| 11 |
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
| 12 |
from fastapi.staticfiles import StaticFiles
|
| 13 |
|
| 14 |
-
from .access import RoleResolver, learner, permissions_of
|
| 15 |
from .auth import DevAuthenticator, SupabaseAuthenticator, current_user
|
| 16 |
from .bank import Bank, load_bank
|
| 17 |
|
|
@@ -114,7 +114,9 @@ def create_app(settings: Settings | None = None, bank: Bank | None = None, store
|
|
| 114 |
store.link_user(user["email"], user["id"])
|
| 115 |
return {"email": user["email"], "roles": user["roles"], "permissions": sorted(permissions_of(user["roles"])),
|
| 116 |
"classes": [{"id": c["id"], "name": c["name"]} for c in classes_as_student],
|
| 117 |
-
"teaching": [{"id": c["id"], "name": c["name"]} for c in here.classes_taught(user["email"])]
|
|
|
|
|
|
|
| 118 |
|
| 119 |
@app.get("/api/lessons")
|
| 120 |
def lessons(request: Request, user: dict = Depends(learner)) -> list[dict]:
|
|
|
|
| 11 |
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
| 12 |
from fastapi.staticfiles import StaticFiles
|
| 13 |
|
| 14 |
+
from .access import RoleResolver, learner, permissions_of, preview_classes
|
| 15 |
from .auth import DevAuthenticator, SupabaseAuthenticator, current_user
|
| 16 |
from .bank import Bank, load_bank
|
| 17 |
|
|
|
|
| 114 |
store.link_user(user["email"], user["id"])
|
| 115 |
return {"email": user["email"], "roles": user["roles"], "permissions": sorted(permissions_of(user["roles"])),
|
| 116 |
"classes": [{"id": c["id"], "name": c["name"]} for c in classes_as_student],
|
| 117 |
+
"teaching": [{"id": c["id"], "name": c["name"]} for c in here.classes_taught(user["email"])],
|
| 118 |
+
"preview": [] if classes_as_student or set(user["roles"]) == {"student"} # "תצוגה ככיתה" in the student view
|
| 119 |
+
else [{"id": c["id"], "name": c["name"]} for c in preview_classes(request, user)]}
|
| 120 |
|
| 121 |
@app.get("/api/lessons")
|
| 122 |
def lessons(request: Request, user: dict = Depends(learner)) -> list[dict]:
|
mathly2/realtests.py
CHANGED
|
@@ -10,7 +10,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
|
| 10 |
from pydantic import BaseModel, Field
|
| 11 |
|
| 12 |
from . import writtentest, attempts, clock, exam, readiness, reads
|
| 13 |
-
from .access import allowed, learner, need
|
| 14 |
from .learning import MASTERED, next_skill, skill_state
|
| 15 |
|
| 16 |
router = APIRouter(prefix="/api")
|
|
@@ -289,7 +289,7 @@ def _next_path_skill(request: Request, user: dict, subject: str = "math") -> str
|
|
| 289 |
def home(request: Request, user: dict = Depends(learner), subject: str = Query("math", max_length=40)) -> dict:
|
| 290 |
"""The student's home: the upcoming tests (nearest first) with their readiness, the lesson map, and the next skill of the path."""
|
| 291 |
here, today, uid = reads.of(request), clock.school_day(), user["id"]
|
| 292 |
-
class_ids = [c["id"] for c in
|
| 293 |
from . import rounds
|
| 294 |
from .skills import RECENT, behind_lessons, lesson_map, subject_param
|
| 295 |
subject = subject_param(request, user, subject)
|
|
@@ -306,7 +306,7 @@ def home(request: Request, user: dict = Depends(learner), subject: str = Query("
|
|
| 306 |
def _student_test(request: Request, user: dict, test_id: int) -> dict:
|
| 307 |
here = reads.of(request)
|
| 308 |
test = here.get_test(test_id)
|
| 309 |
-
mine = {c["id"] for c in
|
| 310 |
if test is None or test["removed_at"] or not (test["class_id"] in mine or allowed(user["roles"], "*")):
|
| 311 |
raise HTTPException(404, "המבחן לא נמצא")
|
| 312 |
return test
|
|
|
|
| 10 |
from pydantic import BaseModel, Field
|
| 11 |
|
| 12 |
from . import writtentest, attempts, clock, exam, readiness, reads
|
| 13 |
+
from .access import allowed, learner, my_classes, need
|
| 14 |
from .learning import MASTERED, next_skill, skill_state
|
| 15 |
|
| 16 |
router = APIRouter(prefix="/api")
|
|
|
|
| 289 |
def home(request: Request, user: dict = Depends(learner), subject: str = Query("math", max_length=40)) -> dict:
|
| 290 |
"""The student's home: the upcoming tests (nearest first) with their readiness, the lesson map, and the next skill of the path."""
|
| 291 |
here, today, uid = reads.of(request), clock.school_day(), user["id"]
|
| 292 |
+
class_ids = [c["id"] for c in my_classes(request, user)]
|
| 293 |
from . import rounds
|
| 294 |
from .skills import RECENT, behind_lessons, lesson_map, subject_param
|
| 295 |
subject = subject_param(request, user, subject)
|
|
|
|
| 306 |
def _student_test(request: Request, user: dict, test_id: int) -> dict:
|
| 307 |
here = reads.of(request)
|
| 308 |
test = here.get_test(test_id)
|
| 309 |
+
mine = {c["id"] for c in my_classes(request, user)}
|
| 310 |
if test is None or test["removed_at"] or not (test["class_id"] in mine or allowed(user["roles"], "*")):
|
| 311 |
raise HTTPException(404, "המבחן לא נמצא")
|
| 312 |
return test
|
mathly2/skills.py
CHANGED
|
@@ -88,9 +88,11 @@ def _round_view(request: Request, skill_id: str, rows: list[dict], round_start:
|
|
| 88 |
|
| 89 |
def studied_subjects(request: Request, user: dict) -> list[str] | None:
|
| 90 |
"""The subjects of the student's classes, in the bank's subject order; None means all (a teacher or a developer)."""
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
return None
|
| 93 |
-
mine = {s for c in
|
| 94 |
return [s["id"] for s in request.app.state.bank.subjects if s["id"] in mine]
|
| 95 |
|
| 96 |
|
|
|
|
| 88 |
|
| 89 |
def studied_subjects(request: Request, user: dict) -> list[str] | None:
|
| 90 |
"""The subjects of the student's classes, in the bank's subject order; None means all (a teacher or a developer)."""
|
| 91 |
+
from .access import my_classes
|
| 92 |
+
classes = my_classes(request, user)
|
| 93 |
+
if set(user["roles"]) - {"student"} and not classes: # a teacher or a developer who previews no class: everything
|
| 94 |
return None
|
| 95 |
+
mine = {s for c in classes for s in (c.get("subjects") or ["math"])}
|
| 96 |
return [s["id"] for s in request.app.state.bank.subjects if s["id"] in mine]
|
| 97 |
|
| 98 |
|
mathly2/static/api.js
CHANGED
|
@@ -8,6 +8,14 @@ export class ApiError extends Error {
|
|
| 8 |
const MESSAGES = { 503: "שירות ההתחברות לא זמין כרגע, נסו שוב בעוד רגע", 403: "אין הרשאה לפעולה הזו" };
|
| 9 |
|
| 10 |
const remembered = new Map(); // GET path -> the last answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
let changes = 0; // counts changes, so an answer to a read that began before one is not kept
|
| 12 |
onSignOut(() => { remembered.clear(); changes++; });
|
| 13 |
|
|
@@ -15,6 +23,7 @@ async function request(path, { method = "GET", body } = {}) {
|
|
| 15 |
const started = changes;
|
| 16 |
if (method !== "GET") { remembered.clear(); changes++; } // after a change of theirs, no old answer is ever shown
|
| 17 |
const headers = { Authorization: "Bearer " + await token() };
|
|
|
|
| 18 |
if (body !== undefined) headers["Content-Type"] = "application/json";
|
| 19 |
const response = await fetch(path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
|
| 20 |
if (response.ok) {
|
|
|
|
| 8 |
const MESSAGES = { 503: "שירות ההתחברות לא זמין כרגע, נסו שוב בעוד רגע", 403: "אין הרשאה לפעולה הזו" };
|
| 9 |
|
| 10 |
const remembered = new Map(); // GET path -> the last answer
|
| 11 |
+
const VIEW_KEY = "mathly2.view-class";
|
| 12 |
+
|
| 13 |
+
/** "תצוגה ככיתה": the class a developer or a teacher who is in no class sees the student screens as (kept on this device). */
|
| 14 |
+
export const viewClass = () => { try { return localStorage.getItem(VIEW_KEY) || ""; } catch { return ""; } };
|
| 15 |
+
export function setViewClass(id) {
|
| 16 |
+
try { if (id) localStorage.setItem(VIEW_KEY, String(id)); else localStorage.removeItem(VIEW_KEY); } catch { /* private window */ }
|
| 17 |
+
remembered.clear(); changes++; // every screen is now about another class
|
| 18 |
+
}
|
| 19 |
let changes = 0; // counts changes, so an answer to a read that began before one is not kept
|
| 20 |
onSignOut(() => { remembered.clear(); changes++; });
|
| 21 |
|
|
|
|
| 23 |
const started = changes;
|
| 24 |
if (method !== "GET") { remembered.clear(); changes++; } // after a change of theirs, no old answer is ever shown
|
| 25 |
const headers = { Authorization: "Bearer " + await token() };
|
| 26 |
+
if (viewClass()) headers["X-View-Class"] = viewClass();
|
| 27 |
if (body !== undefined) headers["Content-Type"] = "application/json";
|
| 28 |
const response = await fetch(path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
|
| 29 |
if (response.ok) {
|
mathly2/static/app.css
CHANGED
|
@@ -775,3 +775,9 @@ body:has(#lesson-map) p:has(> #to-subjects) { margin-block: 0 4px; }
|
|
| 775 |
.qz-final-row { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
|
| 776 |
.qz-final input { width: 9em; font-size: 18px; padding: 8px 10px; min-height: 44px; text-align: center; }
|
| 777 |
.qz-checking .qz-grade b { font-size: 40px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
.qz-final-row { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
|
| 776 |
.qz-final input { width: 9em; font-size: 18px; padding: 8px 10px; min-height: 44px; text-align: center; }
|
| 777 |
.qz-checking .qz-grade b { font-size: 40px; }
|
| 778 |
+
|
| 779 |
+
/* "תצוגה ככיתה" on top of the student screens, for a developer or a teacher who is in no class (student.js). */
|
| 780 |
+
.view-as { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 8px; padding: 8px 12px; border-radius: 12px;
|
| 781 |
+
border: 1px dashed color-mix(in srgb, var(--sky-gold) 60%, transparent); background: color-mix(in srgb, var(--sky-gold) 8%, transparent); }
|
| 782 |
+
.view-as select { min-height: 40px; }
|
| 783 |
+
.view-as .muted { font-size: 13px; }
|
mathly2/static/student.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// The student's screens, switched by the address after "#": "/" the subjects, "/subject/<id>" a subject's home, "/subject/<id>/path"
|
| 2 |
// its path, "/skill/<id>" a skill's sheet over its subject's path, "/collection". The subject of a skill, a quiz or a test opened by a
|
| 3 |
// link is asked from the server, so a reload lands on the right subject's path.
|
| 4 |
-
import { api } from "./api.js";
|
| 5 |
import { esc } from "./math.js";
|
| 6 |
import { setSubject } from "./ui.js";
|
| 7 |
import * as exercise from "./exercise.js";
|
|
@@ -12,7 +12,24 @@ import * as quiz from "./quiz.js";
|
|
| 12 |
import * as lessonRound from "./round.js";
|
| 13 |
import { route as onRoute } from "./router.js";
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
if (!me.classes.length && me.roles.every(r => r === "student")) {
|
| 17 |
view(`<section class="card" id="no-class"><h2>עוד לא בכיתה</h2>
|
| 18 |
<p>עוד לא הוסיפו אותך לכיתה. בקשו מהמורה או ממנהל הכיתות להוסיף את כתובת המייל שבה נכנסתם:</p>
|
|
|
|
| 1 |
// The student's screens, switched by the address after "#": "/" the subjects, "/subject/<id>" a subject's home, "/subject/<id>/path"
|
| 2 |
// its path, "/skill/<id>" a skill's sheet over its subject's path, "/collection". The subject of a skill, a quiz or a test opened by a
|
| 3 |
// link is asked from the server, so a reload lands on the right subject's path.
|
| 4 |
+
import { api, setViewClass, viewClass } from "./api.js";
|
| 5 |
import { esc } from "./math.js";
|
| 6 |
import { setSubject } from "./ui.js";
|
| 7 |
import * as exercise from "./exercise.js";
|
|
|
|
| 12 |
import * as lessonRound from "./round.js";
|
| 13 |
import { route as onRoute } from "./router.js";
|
| 14 |
|
| 15 |
+
/** "תצוגה ככיתה": a developer or a teacher who is in no class picks the class the student screens show (its tests, assignments, subjects).
|
| 16 |
+
* Their own progress stays theirs. The bar sits on top of every student screen. */
|
| 17 |
+
function withPreview(me, view) {
|
| 18 |
+
const classes = me.preview || [];
|
| 19 |
+
if (!classes.length) { if (viewClass()) setViewClass(""); return view; }
|
| 20 |
+
if (viewClass() && !classes.some(c => String(c.id) === viewClass())) setViewClass(""); // a class that is gone, or not theirs any more
|
| 21 |
+
const bar = () => `<div class="view-as" id="view-as"><label for="view-class">תצוגה ככיתה:</label>
|
| 22 |
+
<select id="view-class"><option value="">בלי כיתה (כל השיעורים, בלי מבחנים)</option>${classes.map(c =>
|
| 23 |
+
`<option value="${c.id}"${String(c.id) === viewClass() ? " selected" : ""}>${esc(c.name)}</option>`).join("")}</select>
|
| 24 |
+
<span class="muted">ההתקדמות והכוכבים הם שלך.</span></div>`;
|
| 25 |
+
return html => {
|
| 26 |
+
view(bar() + html);
|
| 27 |
+
document.getElementById("view-class").addEventListener("change", event => { setViewClass(event.target.value); location.reload(); });
|
| 28 |
+
};
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export async function show(me, rawView) {
|
| 32 |
+
const view = withPreview(me, rawView);
|
| 33 |
if (!me.classes.length && me.roles.every(r => r === "student")) {
|
| 34 |
view(`<section class="card" id="no-class"><h2>עוד לא בכיתה</h2>
|
| 35 |
<p>עוד לא הוסיפו אותך לכיתה. בקשו מהמורה או ממנהל הכיתות להוסיף את כתובת המייל שבה נכנסתם:</p>
|
mathly2/tests/test_view_as_class.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""""תצוגה ככיתה": a developer or a teacher who is in no class previews the student screens as a class (its tests, assignments, subjects)."""
|
| 2 |
+
from datetime import timedelta
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
from fastapi.testclient import TestClient
|
| 6 |
+
|
| 7 |
+
from mathly2 import clock
|
| 8 |
+
from mathly2.bank import load_bank
|
| 9 |
+
from mathly2.config import Settings
|
| 10 |
+
from mathly2.main import create_app
|
| 11 |
+
from mathly2.store import InMemoryStore
|
| 12 |
+
from mathly2.tests.serve import offline_formulas, running
|
| 13 |
+
from mathly2.tests.test_boardwork_api import auth
|
| 14 |
+
|
| 15 |
+
KID, TEACHER, OTHER, DEV = "kid@school.test", "t@school.test", "t2@school.test", "dev@school.test"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def world():
|
| 19 |
+
bank, store = load_bank(), InMemoryStore()
|
| 20 |
+
mine = store.create_class("setup", "ט מצוינות", lessons=[l["id"] for l in bank.lessons], teacher_email=TEACHER)
|
| 21 |
+
other = store.create_class("setup", "ט 2", lessons=[l["id"] for l in bank.lessons], teacher_email=OTHER)
|
| 22 |
+
store.add_member(mine["id"], KID)
|
| 23 |
+
soon = store.create_test(mine["id"], clock.school_day() + timedelta(days=1), ["t", "t2"], TEACHER, created_at=clock.now() - timedelta(days=20))
|
| 24 |
+
later = store.create_test(mine["id"], clock.school_day() + timedelta(days=43), ["q", "q2"], TEACHER, created_at=clock.now())
|
| 25 |
+
store.create_test(other["id"], clock.school_day() + timedelta(days=5), ["k"], OTHER, created_at=clock.now())
|
| 26 |
+
store.create_assignment(mine["id"], "דף עבודה", clock.school_day() + timedelta(days=3), TEACHER, "pages", pages=["1"])
|
| 27 |
+
app = create_app(Settings(teachers=frozenset({TEACHER, OTHER}), developers=frozenset({DEV})), bank=bank, store=store)
|
| 28 |
+
client = TestClient(app)
|
| 29 |
+
for who in (KID, TEACHER, OTHER, DEV):
|
| 30 |
+
client.get("/api/me", headers=auth(who))
|
| 31 |
+
return client, mine, other, soon, later
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def as_class(who, class_id):
|
| 35 |
+
return {**auth(who), "X-View-Class": str(class_id)}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def test_a_developer_previews_any_class_and_sees_what_its_student_sees():
|
| 39 |
+
client, mine, other, soon, later = world()
|
| 40 |
+
assert [c["name"] for c in client.get("/api/me", headers=auth(DEV)).json()["preview"]] == ["ט מצוינות", "ט 2"]
|
| 41 |
+
assert client.get("/api/home", headers=auth(DEV)).json()["tests"] == [] # no class picked: no tests
|
| 42 |
+
student = client.get("/api/home", headers=auth(KID)).json()
|
| 43 |
+
dev = client.get("/api/home", headers=as_class(DEV, mine["id"])).json()
|
| 44 |
+
assert [t["id"] for t in dev["tests"]] == [t["id"] for t in student["tests"]] == [soon["id"], later["id"]]
|
| 45 |
+
assert [a["title"] for a in client.get("/api/assignments", headers=as_class(DEV, mine["id"])).json()] == ["דף עבודה"]
|
| 46 |
+
assert [t["date"] for t in client.get("/api/home", headers=as_class(DEV, other["id"])).json()["tests"]] != [t["date"] for t in dev["tests"]]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def test_a_teacher_previews_only_the_classes_they_teach():
|
| 50 |
+
client, mine, other, soon, later = world()
|
| 51 |
+
assert [c["id"] for c in client.get("/api/me", headers=auth(TEACHER)).json()["preview"]] == [mine["id"]]
|
| 52 |
+
assert len(client.get("/api/home", headers=as_class(TEACHER, mine["id"])).json()["tests"]) == 2
|
| 53 |
+
assert client.get("/api/home", headers=as_class(TEACHER, other["id"])).json()["tests"] == [] # not theirs: nothing
|
| 54 |
+
assert client.get("/api/assignments", headers=as_class(TEACHER, other["id"])).json() == []
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_a_student_cannot_preview_another_class_and_keeps_their_own():
|
| 58 |
+
client, mine, other, soon, later = world()
|
| 59 |
+
assert client.get("/api/me", headers=auth(KID)).json()["preview"] == []
|
| 60 |
+
tests = client.get("/api/home", headers=as_class(KID, other["id"])).json()["tests"]
|
| 61 |
+
assert [t["id"] for t in tests] == [soon["id"], later["id"]] # the header changes nothing
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@pytest.fixture
|
| 65 |
+
def browser():
|
| 66 |
+
playwright = pytest.importorskip("playwright.sync_api")
|
| 67 |
+
with playwright.sync_playwright() as p:
|
| 68 |
+
b = p.chromium.launch()
|
| 69 |
+
yield b
|
| 70 |
+
b.close()
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_in_the_browser_a_developer_picks_a_class_and_its_nearest_test_is_on_home(browser):
|
| 74 |
+
client, mine, other, soon, later = world()
|
| 75 |
+
with running(client.app) as url:
|
| 76 |
+
page = offline_formulas(browser.new_page(viewport={"width": 390, "height": 844}))
|
| 77 |
+
errors = []
|
| 78 |
+
page.on("pageerror", lambda e: errors.append(str(e)))
|
| 79 |
+
page.goto(url)
|
| 80 |
+
page.fill("#email", DEV)
|
| 81 |
+
page.click("#dev button")
|
| 82 |
+
page.wait_for_selector("#nav .roles")
|
| 83 |
+
page.click("#nav [data-role='student']")
|
| 84 |
+
page.wait_for_selector("#view-as")
|
| 85 |
+
page.click(".subject-card")
|
| 86 |
+
page.wait_for_selector(".tabs")
|
| 87 |
+
assert page.locator("#nearest-test").count() == 0 # no class: no test
|
| 88 |
+
page.select_option("#view-class", str(mine["id"]))
|
| 89 |
+
page.wait_for_selector("#nearest-test")
|
| 90 |
+
assert "מחר" in page.inner_text("#nearest-test") and page.input_value("#view-class") == str(mine["id"]) # kept after the reload
|
| 91 |
+
page.click("#nearest-test .strip-main")
|
| 92 |
+
page.wait_for_selector("#other-tests")
|
| 93 |
+
assert len(page.locator("#other-tests li").all()) == 1 # 28.12 under "מבחנים נוספים"
|
| 94 |
+
page.select_option("#view-class", "")
|
| 95 |
+
page.wait_for_selector("#view-as")
|
| 96 |
+
assert errors == []
|
openspec/changes/view-as-class/proposal.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Proposal
|
| 2 |
+
|
| 3 |
+
## Why
|
| 4 |
+
|
| 5 |
+
A developer or a teacher who opens the student view is in no class, so the student screens show no tests, assignments or readiness: they
|
| 6 |
+
cannot check what the students of a class see (a new test on home, its lessons).
|
| 7 |
+
|
| 8 |
+
## What Changes
|
| 9 |
+
|
| 10 |
+
- "תצוגה ככיתה": a picker on top of the student screens for a developer or a teacher who is in no class. A developer can pick any class, a teacher the classes they teach.
|
| 11 |
+
- With a class picked, the student screens show that class's tests, assignments, subjects and photo help; progress, stars and readiness stay the viewer's own.
|
| 12 |
+
- The choice is kept on the device and sent with every request (`X-View-Class`); the server checks it. A student's own classes are never replaced.
|
| 13 |
+
|
| 14 |
+
## Capabilities
|
| 15 |
+
|
| 16 |
+
### New Capabilities
|
| 17 |
+
|
| 18 |
+
### Modified Capabilities
|
| 19 |
+
- `accounts-and-classes`: previewing the student screens as a class.
|
| 20 |
+
|
| 21 |
+
## Impact
|
| 22 |
+
|
| 23 |
+
- `access.py` (`my_classes`, `preview_classes`), its use in `realtests.py`, `assignments.py`, `ai_help.py`, `skills.py`; `/api/me` returns `preview`. `static/api.js`, `static/student.js`.
|
openspec/changes/view-as-class/specs/accounts-and-classes/spec.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## ADDED Requirements
|
| 2 |
+
|
| 3 |
+
### Requirement: View the student screens as a class
|
| 4 |
+
A developer or a teacher who is in no class as a student SHALL be able to pick a class in "תצוגה ככיתה" on top of the student screens: a developer any class, a teacher only a class they teach. With a class picked, the student screens SHALL show that class's tests, assignments, subjects and photo help; progress, stars and readiness SHALL stay the viewer's own. A pick the person may not make SHALL show nothing of that class, and a student's own classes SHALL never be replaced.
|
| 5 |
+
|
| 6 |
+
#### Scenario: A developer checks a new test
|
| 7 |
+
- **WHEN** a developer opens the student view, picks "ט מצוינות" and opens math
|
| 8 |
+
- **THEN** home shows the class's nearest test, and its test page lists the class's other tests
|
| 9 |
+
|
| 10 |
+
#### Scenario: Another teacher's class
|
| 11 |
+
- **WHEN** a teacher sends another teacher's class as the class to view
|
| 12 |
+
- **THEN** no test or assignment of that class is shown
|
openspec/changes/view-as-class/tasks.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Tasks
|
| 2 |
+
|
| 3 |
+
- [x] 1.1 Add `my_classes` and `preview_classes` (`access.py`) and use them wherever the student screens read the student's classes; `/api/me` returns `preview`. Verify with `test_view_as_class.py` (a developer, a teacher, a student).
|
| 4 |
+
- [x] 1.2 Add the picker on top of the student screens and send the pick with every request (`student.js`, `api.js`). Verify with the browser test.
|
| 5 |
+
- [x] 1.3 Update the PRD (DEV-1). Verify that `openspec validate view-as-class --strict` passes.
|