Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/src/domainTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default {
fields: {
defaultPageSize: 'מספר שורות בטבלה',
lateValue: 'שווי איחור',
lessonTimes: 'זמני שיעורים',
'lessonTimes.days': 'ימים',
'lessonTimes.periods': 'שיעורים',
'lessonTimes.periods.start': 'שעת התחלה',
'lessonTimes.periods.end': 'שעת סיום',
phoneNumber: 'מספר טלפון',
mailAddressTitle: 'שם השולח',
mailAddressAlias: 'כתובת השולח',
Expand Down
22 changes: 20 additions & 2 deletions client/src/entities/teacher-reported-today.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { adminUserFilter } from '@shared/components/fields/PermissionFilter';
import { filterArrayByParams } from '@shared/utils/filtersUtil';
import { useIsAdmin } from '@shared/utils/permissionsUtil';
import { MAX_PAGE_SIZE } from '@shared/config/settings';
import { useLessonTimes } from 'src/settings/settingsUtil';
import { withLessonGaps } from 'src/utils/lessonGaps';

// This is a card view, not a table, so cap high rather than paginate at 10 rows.
const LIST_PAGE_SIZE = 1000;
Expand Down Expand Up @@ -181,8 +183,23 @@ const LessonRow = ({ row, showDate, until }) => {
);
};

// A lesson from the lessonTimes setting that had no report while later lessons that day did.
const GapRow = ({ gap, showDate }) => (
<Box sx={{ px: 2, py: 0.75, borderTop: 1, borderColor: 'divider' }}>
<Box sx={{ display: 'grid', gridTemplateColumns: showDate ? '96px minmax(0, 1fr)' : '48px minmax(0, 1fr)', gap: 1.5, alignItems: 'center', px: 1, py: 0.5, border: '1px dashed', borderColor: 'text.disabled', borderRadius: 1, color: 'text.secondary' }}>
<Typography variant="body2" sx={{ fontVariantNumeric: 'tabular-nums' }}>
{showDate && `${formatDate(gap.reportDate)} `}{gap.period.start}
</Typography>
<Typography variant="body2">
שיעור {gap.period.number} ({gap.period.start}–{gap.period.end}) לא דווח
</Typography>
</Box>
</Box>
);

const TeacherReportCards = ({ isAdmin }) => {
const { data, total, filterValues } = useListContext();
const lessonTimes = useLessonTimes();
const rows = data || [];
const klasses = groupByKlass(rows);
// Show the date on each row unless the filter is a single day.
Expand Down Expand Up @@ -222,8 +239,9 @@ const TeacherReportCards = ({ isAdmin }) => {
</Box>
</RecordContextProvider>
)}
{klass.lessons.map((row) => (
<LessonRow key={row.id} row={row} showDate={showDate} until={nextLessonStart(row, klass.lessons)} />
{(isAdmin ? klass.lessons : withLessonGaps(klass.lessons, lessonTimes)).map((row) => (row.isGap
? <GapRow key={row.id} gap={row} showDate={showDate} />
: <LessonRow key={row.id} row={row} showDate={showDate} until={nextLessonStart(row, klass.lessons)} />
))}
</Card>
);
Expand Down
1 change: 1 addition & 0 deletions client/src/roadmapFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default [
{ html: 'מסך ההגדרות: הגדרת שם וכתובת השולח במיילים שנשלחים מהמערכת', status: 'בוצע', statusColor: 'success' },
{ html: 'רשימת דיווחי נוכחות: פעולה "עריכה מרוכזת" לשינוי תאריך, כיתה, מורה, שיעור ועוד במספר רשומות יחד (שדה ריק לא משתנה)', status: 'בוצע', statusColor: 'success' },
{ html: 'דוחות "מורות שדיווחו נוכחות" ו"מעקב חיסורים": הצגת שם לתצוגה של כיתה, שיעור ומורה כשהוגדר', status: 'בוצע', statusColor: 'success' },
{ html: 'הגדרת זמני שיעורים לכל יום במסך ההגדרות, ובדוח המורות שדיווחו: ריבוע ריק לשיעור שלא דווח באמצע היום', status: 'בוצע', statusColor: 'success' },

// { html: 'הגדרת תקופת זמן לפי תאריכים', status: 'בקרוב', statusColor: 'warning' },
// { html: 'הגדרת תקופת זמן לפי יום בשבוע', status: 'בוצע', statusColor: 'success' },
Expand Down
30 changes: 28 additions & 2 deletions client/src/settings/GeneralSettingsInput.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { NumberInput, required } from 'react-admin';
import { ArrayInput, CheckboxGroupInput, NumberInput, SimpleFormIterator, TimeInput, required } from 'react-admin';
import { CommonSettingsAccordion } from '@shared/components/settings/CommonSettingsAccordion';
import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput';
import { PAGE_SIZE_OPTIONS } from '@shared/config/settings';

const pageSizeOptions = PAGE_SIZE_OPTIONS.map((option) => ({ id: option, name: option }));

// Keep the "HH:mm" string; TimeInput's default parse turns it into a Date.
const parseTime = (value) => value || null;

const weekdayChoices = [
{ id: 0, name: 'ראשון' },
{ id: 1, name: 'שני' },
{ id: 2, name: 'שלישי' },
{ id: 3, name: 'רביעי' },
{ id: 4, name: 'חמישי' },
{ id: 5, name: 'שישי' },
];

export function GeneralSettingsInput() {
return (
<CommonSettingsAccordion
id="general-settings"
title="הגדרות כלליות"
subtitle="מספר שורות בטבלה ושווי איחור"
subtitle="מספר שורות בטבלה, שווי איחור וזמני שיעורים"
>
<CommonAutocompleteInput
source="defaultPageSize"
Expand All @@ -25,6 +37,20 @@ export function GeneralSettingsInput() {
validate={required()}
helperText="המשקל של איחור אחד בחישוב החיסורים. לדוגמה, 0.3 אומר שכל איחור נספר כ-0.3 מחיסור (כלומר, כ-3-4 איחורים שווים לחיסור אחד)"
/>
<ArrayInput
source="lessonTimes"
helperText="שעות ההתחלה והסיום של כל שיעור, לכל קבוצת ימים. בדוח המורות שדיווחו נוכחות יוצג ריבוע ריק לשיעור שלא דווח באמצע היום"
>
<SimpleFormIterator disableReordering>
<CheckboxGroupInput source="days" choices={weekdayChoices} validate={required()} />
<ArrayInput source="periods">
<SimpleFormIterator inline disableReordering>
<TimeInput source="start" parse={parseTime} validate={required()} />
<TimeInput source="end" parse={parseTime} validate={required()} />
</SimpleFormIterator>
</ArrayInput>
</SimpleFormIterator>
</ArrayInput>
</CommonSettingsAccordion>
);
}
3 changes: 2 additions & 1 deletion client/src/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useNavigate } from 'react-router-dom';
import { getDefaultPageSize } from '@shared/utils/settingsUtil';
import { CommonSettingsAccordion } from '@shared/components/settings/CommonSettingsAccordion';
import { DashboardItemsInput } from '@shared/components/settings/DashboardItemsInput';
import { getLateValue, getDashboardItems, getReportStyles, getReportCardSettings, normalizeReportStyles } from './settingsUtil';
import { getLateValue, getLessonTimes, getDashboardItems, getReportStyles, getReportCardSettings, normalizeReportStyles } from './settingsUtil';
import { ReportStylesInput } from './ReportStylesInput';
import { GeneralSettingsInput } from './GeneralSettingsInput';
import { MailSettingsInput } from './MailSettingsInput';
Expand All @@ -39,6 +39,7 @@ export default function Settings() {
const defaultValues = {
defaultPageSize: getDefaultPageSize(identity),
lateValue: getLateValue(identity),
lessonTimes: getLessonTimes(identity),
dashboardItems: getDashboardItems(identity),
reportStyles: normalizeReportStyles(getReportStyles(identity)),
reportCardSettings: getReportCardSettings(identity),
Expand Down
9 changes: 9 additions & 0 deletions client/src/settings/settingsUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export function getLateValue(identity) {
return identity?.additionalData?.lateValue || 0.3;
}

export function useLessonTimes() {
const { identity } = useGetIdentity();
return getLessonTimes(identity);
}

export function getLessonTimes(identity) {
return identity?.additionalData?.lessonTimes || [];
}

export const useDashboardItems = () => {
const { identity } = useGetIdentity();
return getDashboardItems(identity);
Expand Down
71 changes: 71 additions & 0 deletions client/src/utils/lessonGaps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const ISRAEL_TIMEZONE = 'Asia/Jerusalem';

const timeToMinutes = (time) => {
const [hours, minutes] = String(time).split(':').map(Number);
return hours * 60 + minutes;
};

// Date (YYYY-MM-DD) and minutes since midnight of a timestamp, in Israel time.
const getIsraelDateAndMinutes = (value) => {
const parts = Object.fromEntries(
new Intl.DateTimeFormat('en-CA', {
timeZone: ISRAEL_TIMEZONE,
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
}).formatToParts(new Date(value)).map(({ type, value }) => [type, value])
);
return { date: `${parts.year}-${parts.month}-${parts.day}`, minutes: Number(parts.hour) * 60 + Number(parts.minute) };
};

const toDateOnly = (value) => String(value).slice(0, 10);

const getWeekday = (dateOnly) => new Date(`${dateOnly}T00:00:00Z`).getUTCDay();

// The day's lessons from the lessonTimes setting, sorted by start time.
export function getDayPeriods(lessonTimes, dateOnly) {
const weekday = getWeekday(dateOnly);
const group = lessonTimes.find((item) => Array.isArray(item?.days) && item.days.map(Number).includes(weekday));
return (Array.isArray(group?.periods) ? group.periods : [])
.filter((period) => period?.start && period?.end)
.map((period) => ({ start: period.start, end: period.end, startMinutes: timeToMinutes(period.start) }))
.sort((a, b) => a.startMinutes - b.startMinutes)
.map((period, index) => ({ ...period, number: index + 1 }));
}

// A report belongs to the last lesson that started at or before it (a report in the break counts for the lesson before).
// Reports entered on another day than their report date, or before the first lesson, belong to no lesson.
const getPeriodIndex = (row, periods) => {
const { date, minutes } = getIsraelDateAndMinutes(row.reportHour);
if (date !== toDateOnly(row.reportDate)) {
return -1;
}
return periods.findLastIndex((period) => period.startMinutes <= minutes);
};

// The class's lessons with an empty slot ({ isGap: true, period, reportDate }) before each reported lesson
// that comes after one or more unreported lessons of the same day. Nothing is added after the last report of the day.
// A lesson is placed by the time it was reported, so a report entered late counts for the lesson it was entered in.
export function withLessonGaps(lessons, lessonTimes) {
if (!Array.isArray(lessonTimes) || !lessonTimes.length) {
return lessons;
}
const result = [];
// Rows are sorted by report time, so a late entry for another date can come in between; track each date separately.
const lastIndexByDate = new Map();
lessons.forEach((row) => {
const reportDate = toDateOnly(row.reportDate);
const periods = getDayPeriods(lessonTimes, reportDate);
const index = getPeriodIndex(row, periods);
const lastIndex = lastIndexByDate.get(reportDate) ?? -1;
if (index > lastIndex) {
if (lastIndex >= 0) {
periods.slice(lastIndex + 1, index).forEach((period) => {
result.push({ isGap: true, id: `gap_${reportDate}_${period.number}`, reportDate: row.reportDate, period });
});
}
lastIndexByDate.set(reportDate, index);
}
result.push(row);
});
return result;
}
95 changes: 95 additions & 0 deletions client/src/utils/lessonGaps.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { getDayPeriods, withLessonGaps } from './lessonGaps';

// 2026-10-14 is a Wednesday (weekday 3); Israel is UTC+3 on that date.
const lessonTimes = [
{
days: [0, 1, 2, 3, 4],
periods: [
{ start: '08:00', end: '08:45' },
{ start: '08:45', end: '09:30' },
{ start: '09:45', end: '10:30' },
{ start: '10:30', end: '11:15' },
{ start: '11:15', end: '12:00' },
],
},
{ days: [5], periods: [{ start: '08:00', end: '08:45' }] },
];

const lesson = (id, reportHour, reportDate = '2026-10-14') => ({ id, reportDate, reportHour });

describe('getDayPeriods', () => {
it('picks the group of the weekday and numbers lessons by start time', () => {
const periods = getDayPeriods([{ days: ['3'], periods: [{ start: '09:00', end: '09:45' }, { start: '08:00', end: '08:45' }] }], '2026-10-14');
expect(periods.map((period) => [period.number, period.start])).toEqual([[1, '08:00'], [2, '09:00']]);
});

it('returns no lessons for a day without a group', () => {
expect(getDayPeriods(lessonTimes, '2026-10-17')).toEqual([]);
});
});

describe('withLessonGaps', () => {
it('returns the lessons unchanged when no lesson times are set', () => {
const lessons = [lesson(1, '2026-10-14T05:10:00Z'), lesson(2, '2026-10-14T08:00:00Z')];
expect(withLessonGaps(lessons, [])).toBe(lessons);
expect(withLessonGaps(lessons, undefined)).toBe(lessons);
});

it('adds an empty slot for each unreported lesson between reported ones', () => {
// 08:10 is lesson 1, 11:20 is lesson 5: lessons 2-4 were skipped.
const result = withLessonGaps([lesson(1, '2026-10-14T05:10:00Z'), lesson(2, '2026-10-14T08:20:00Z')], lessonTimes);
expect(result.map((row) => (row.isGap ? `gap${row.period.number}` : row.id))).toEqual([1, 'gap2', 'gap3', 'gap4', 2]);
});

it('counts a report in the break for the lesson before it', () => {
// 09:35 is the break after lesson 2, 09:50 is lesson 3: nothing skipped.
const result = withLessonGaps([lesson(1, '2026-10-14T05:50:00Z'), lesson(2, '2026-10-14T06:35:00Z'), lesson(3, '2026-10-14T06:50:00Z')], lessonTimes);
expect(result.some((row) => row.isGap)).toBe(false);
});

it('adds nothing before the first or after the last report of the day', () => {
const result = withLessonGaps([lesson(1, '2026-10-14T06:50:00Z')], lessonTimes);
expect(result).toEqual([lesson(1, '2026-10-14T06:50:00Z')]);
});

it('does not add a slot between two reports of the same lesson', () => {
const result = withLessonGaps([lesson(1, '2026-10-14T05:10:00Z'), lesson(2, '2026-10-14T05:30:00Z')], lessonTimes);
expect(result.some((row) => row.isGap)).toBe(false);
});

it('ignores reports entered on another day than their report date', () => {
// Report for the 13th entered on the 14th at 11:20 must not open a gap on either day.
const result = withLessonGaps([
lesson(1, '2026-10-13T05:10:00Z', '2026-10-13'),
lesson(2, '2026-10-14T05:10:00Z'),
lesson(3, '2026-10-14T08:20:00Z', '2026-10-13'),
], lessonTimes);
expect(result.some((row) => row.isGap)).toBe(false);
});

it('tracks each date separately', () => {
const result = withLessonGaps([
lesson(1, '2026-10-13T05:10:00Z', '2026-10-13'),
lesson(2, '2026-10-14T05:10:00Z'),
lesson(3, '2026-10-14T06:50:00Z'),
], lessonTimes);
expect(result.map((row) => (row.isGap ? `gap${row.period.number}` : row.id))).toEqual([1, 2, 'gap2', 3]);
});

it('accepts report dates serialized as full timestamps', () => {
const result = withLessonGaps([lesson(1, '2026-10-14T05:10:00Z', '2026-10-14T00:00:00.000Z'), lesson(2, '2026-10-14T06:50:00Z', '2026-10-14T00:00:00.000Z')], lessonTimes);
expect(result.filter((row) => row.isGap).map((row) => row.period.number)).toEqual([2]);
});

it('places a report entered late by the time it was entered', () => {
// Lesson 1 at 08:10, lesson 3 at 09:55, then lesson 2 reported late at 10:20 counts as lesson 3.
const result = withLessonGaps([lesson(1, '2026-10-14T05:10:00Z'), lesson(2, '2026-10-14T06:55:00Z'), lesson(3, '2026-10-14T07:20:00Z')], lessonTimes);
expect(result.map((row) => (row.isGap ? `gap${row.period.number}` : row.id))).toEqual([1, 'gap2', 2, 3]);
});

it('ignores malformed lesson times', () => {
const lessons = [lesson(1, '2026-10-14T05:10:00Z'), lesson(2, '2026-10-14T08:20:00Z')];
expect(withLessonGaps(lessons, 'bad')).toBe(lessons);
expect(withLessonGaps(lessons, [{ days: '3', periods: 'x' }, null])).toEqual(lessons);
});
});
Loading