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
79 changes: 71 additions & 8 deletions client/src/entities/teacher-reported-today.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { DateInput, ReferenceField, RecordContextProvider, TextField, useListContext, usePermissions } from 'react-admin';
import { Box, Card, Typography } from '@mui/material';
import { useState } from 'react';
import { DateInput, ReferenceField, RecordContextProvider, TextField, useGetList, useListContext, usePermissions } from 'react-admin';
import { Box, ButtonBase, Card, CircularProgress, Popover, Typography } from '@mui/material';
import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity';
import { CommonList } from '@shared/components/crudContainers/CommonList';
import { EmptyPage } from '@shared/components/crudContainers/EmptyPage';
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';

// 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 @@ -67,6 +69,70 @@ function groupByKlass(rows) {
});
}

// The same subject taught twice in a day shows as two rows; a row's reports end where the next one's begin.
const nextLessonStart = (row, lessons) => lessons.find((other) =>
other.teacherReferenceId === row.teacherReferenceId
&& other.lessonReferenceId === row.lessonReferenceId
&& other.reportDate === row.reportDate
&& other.reportHour > row.reportHour
)?.reportHour;

const MissingGirlsList = ({ row, until }) => {
const filter = {
teacherReferenceId: row.teacherReferenceId,
klassReferenceId: row.klassReferenceId,
lessonReferenceId: row.lessonReferenceId,
'reportDate:$eq': row.reportDate,
'absCount:$gt': 0,
'createdAt:$gte': row.reportHour,
...(until && { 'createdAt:$lt': until }),
};
const { data, isPending } = useGetList('att_report', { filter, pagination: { page: 1, perPage: MAX_PAGE_SIZE }, sort: { field: 'id', order: 'ASC' } });
if (isPending) {
return <CircularProgress size={20} sx={{ m: 2 }} />;
}
const studentIds = [...new Set((data || []).map((report) => report.studentReferenceId))];
return (
<Box component="ol" sx={{ m: 0, py: 1, px: 4, minWidth: 180 }}>
{studentIds.map((studentReferenceId) => (
<Typography component="li" variant="body2" key={studentReferenceId} sx={{ py: 0.25 }}>
<RecordContextProvider value={{ studentReferenceId }}>
<ReferenceField source="studentReferenceId" reference="student" link={false}>
<TextField source="name" />
</ReferenceField>
</RecordContextProvider>
</Typography>
))}
</Box>
);
};

// Names are fetched only when the count is clicked, so opening the report stays one query.
const MissingGirls = ({ row, until }) => {
const [anchorEl, setAnchorEl] = useState(null);
const count = missingCount(row);
if (count === 0) {
return <Box component="span" sx={missingPillSx(count)} title="מספר בנות שחסרו">–</Box>;
}
return (
<>
<ButtonBase onClick={(event) => setAnchorEl(event.currentTarget)} sx={{ ...missingPillSx(count), cursor: 'pointer' }} title="הצגת שמות הבנות שחסרו">
{count}
</ButtonBase>
<Popover
open={Boolean(anchorEl)}
anchorEl={anchorEl}
onClose={() => setAnchorEl(null)}
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
transformOrigin={{ vertical: 'top', horizontal: 'left' }}
>
<Typography variant="subtitle2" sx={{ px: 2, pt: 1.5 }}>בנות שחסרו</Typography>
<MissingGirlsList row={row} until={until} />
</Popover>
</>
);
};

const sumMissing = (rows) => rows.reduce((sum, row) => sum + missingCount(row), 0);

const SummaryTiles = ({ rows, klassCount }) => {
Expand All @@ -88,8 +154,7 @@ const SummaryTiles = ({ rows, klassCount }) => {
);
};

const LessonRow = ({ row, showDate }) => {
const count = missingCount(row);
const LessonRow = ({ row, showDate, until }) => {
return (
<RecordContextProvider value={row}>
<Box sx={{ display: 'grid', gridTemplateColumns: showDate ? '96px minmax(0, 1fr) minmax(0, 1fr) 44px' : '48px minmax(0, 1fr) minmax(0, 1fr) 44px', gap: 1.5, alignItems: 'center', px: 2, py: 1.25, borderTop: 1, borderColor: 'divider' }}>
Expand All @@ -108,9 +173,7 @@ const LessonRow = ({ row, showDate }) => {
<TextField source="name" />
</ReferenceField>
</Typography>
<Box component="span" sx={missingPillSx(count)} title="מספר בנות שחסרו">
{count === 0 ? '–' : count}
</Box>
<MissingGirls row={row} until={until} />
</Box>
</RecordContextProvider>
);
Expand Down Expand Up @@ -158,7 +221,7 @@ const TeacherReportCards = ({ isAdmin }) => {
</RecordContextProvider>
)}
{klass.lessons.map((row) => (
<LessonRow key={row.id} row={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 @@ -31,6 +31,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
Loading