diff --git a/client/src/domainTranslations.js b/client/src/domainTranslations.js index f6aa44a0..1834bd00 100644 --- a/client/src/domainTranslations.js +++ b/client/src/domainTranslations.js @@ -15,6 +15,11 @@ export default { fields: { defaultPageSize: 'מספר שורות בטבלה', lateValue: 'שווי איחור', + lessonTimes: 'זמני שיעורים', + 'lessonTimes.days': 'ימים', + 'lessonTimes.periods': 'שיעורים', + 'lessonTimes.periods.start': 'שעת התחלה', + 'lessonTimes.periods.end': 'שעת סיום', phoneNumber: 'מספר טלפון', mailAddressTitle: 'שם השולח', mailAddressAlias: 'כתובת השולח', diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 6fb42c0d..43900c04 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -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; @@ -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 }) => ( + + + + {showDate && `${formatDate(gap.reportDate)} `}{gap.period.start} + + + שיעור {gap.period.number} ({gap.period.start}–{gap.period.end}) לא דווח + + + +); + 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. @@ -222,8 +239,9 @@ const TeacherReportCards = ({ isAdmin }) => { )} - {klass.lessons.map((row) => ( - + {(isAdmin ? klass.lessons : withLessonGaps(klass.lessons, lessonTimes)).map((row) => (row.isGap + ? + : ))} ); diff --git a/client/src/roadmapFeatures.js b/client/src/roadmapFeatures.js index 83d556c5..841f15c6 100644 --- a/client/src/roadmapFeatures.js +++ b/client/src/roadmapFeatures.js @@ -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' }, diff --git a/client/src/settings/GeneralSettingsInput.jsx b/client/src/settings/GeneralSettingsInput.jsx index 837f2f10..a036e662 100644 --- a/client/src/settings/GeneralSettingsInput.jsx +++ b/client/src/settings/GeneralSettingsInput.jsx @@ -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 ( + + + + + + + + + + + ); } diff --git a/client/src/settings/Settings.jsx b/client/src/settings/Settings.jsx index 5e7e06e0..4326a951 100644 --- a/client/src/settings/Settings.jsx +++ b/client/src/settings/Settings.jsx @@ -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'; @@ -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), diff --git a/client/src/settings/settingsUtil.js b/client/src/settings/settingsUtil.js index 0c386241..5e7bb7b7 100644 --- a/client/src/settings/settingsUtil.js +++ b/client/src/settings/settingsUtil.js @@ -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); diff --git a/client/src/utils/lessonGaps.js b/client/src/utils/lessonGaps.js new file mode 100644 index 00000000..6868ee51 --- /dev/null +++ b/client/src/utils/lessonGaps.js @@ -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; +} diff --git a/client/src/utils/lessonGaps.test.js b/client/src/utils/lessonGaps.test.js new file mode 100644 index 00000000..afb25282 --- /dev/null +++ b/client/src/utils/lessonGaps.test.js @@ -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); + }); +});