diff --git a/public/admin.js b/public/admin.js index fee477a..65f9f53 100644 --- a/public/admin.js +++ b/public/admin.js @@ -880,11 +880,31 @@ function toggleAddTaskForm(date) { }); } +function renderPrintTaskBlock(t) { + const title = t.itemTitle || t.offlineTitle; + const course = t.courseName ? `${esc(t.courseName)}` : `Offline`; + const status = t.done ? `✓ done` : ''; + const typeTag = t.type ? `${TYPE_LABEL[t.type] || t.type}` : ''; + let body = ''; + if (t.body) body = `
${t.body.split(/\n\n+/).map((p) => `

${esc(p.trim())}

`).join('')}
`; + return `
+
${course} ${typeTag} ${esc(title)} ${status}
+ ${body} +
`; +} + async function printWeekReport(studentId, start) { const r = await api(`/api/week-report/${studentId}?start=${start}`); - const taskRows = r.tasks - .map((t) => `${t.date}${esc(t.itemTitle || t.offlineTitle)}${esc(t.courseName || 'Offline')}${t.done ? '✓ done' : '—'}`) - .join(''); + // Group tasks by date + const byDate = {}; + for (const t of r.tasks) { (byDate[t.date] = byDate[t.date] || []).push(t); } + const dayBlocks = Object.entries(byDate).map(([date, tasks]) => + `
+

${date}

+ ${tasks.map(renderPrintTaskBlock).join('')} +
` + ).join('') || '

Nothing scheduled this week.

'; + const gradedRows = r.graded .map((g) => `${esc(g.itemTitle)}${esc(g.courseName)}${g.score}/${g.points_possible}`) .join(''); @@ -892,22 +912,34 @@ async function printWeekReport(studentId, start) { .map((t) => `${esc(t.list)}${t.score}/${t.total}`) .join(''); const win = window.open('', '_blank'); - win.document.write(`Weekly Report + win.document.write(`Weekly Plan — ${esc(r.student)} -

Weekly Report — ${esc(r.student)}

+

Weekly Plan — ${esc(r.student)}

Week of ${r.start}

Schedule

- ${taskRows || ''}
DateTaskCourseStatus
Nothing scheduled
+ ${dayBlocks}

Graded work

- ${gradedRows || ''}
ItemCourseScore
Nothing graded this week
+ ${gradedRows ? `${gradedRows}
ItemCourseScore
` : '

Nothing graded this week.

'}

Spelling tests

- ${spellingRows || ''}
ListScore
No spelling tests this week
+ ${spellingRows ? `${spellingRows}
ListScore
` : '

No spelling tests this week.

'}