diff --git a/client/src/domainTranslations.js b/client/src/domainTranslations.js
index 1834bd00..9e0ee56c 100644
--- a/client/src/domainTranslations.js
+++ b/client/src/domainTranslations.js
@@ -116,6 +116,7 @@ export default {
teacherReferenceId: 'מורה',
order: 'סדר הצגה',
phone: 'טלפון',
+ grade: 'שנתון',
},
},
klass_type: {
@@ -317,6 +318,7 @@ export default {
teacherReferenceId: 'מורה',
reportDate: 'תאריך דיווח',
lessonReferenceId: 'שיעור',
+ grade: 'שנתון',
reportHour: 'שעת דיווח',
},
},
diff --git a/client/src/entities/klass.jsx b/client/src/entities/klass.jsx
index 7c72d9c3..d4b9da05 100644
--- a/client/src/entities/klass.jsx
+++ b/client/src/entities/klass.jsx
@@ -80,6 +80,7 @@ const Datagrid = ({ isAdmin, children, ...props }) => {
+
{
+
{
const Representation = CommonRepresentation;
const importer = {
- fields: ['key', 'name', 'klassTypeId', 'teacherId', 'year', 'displayName', 'order', 'phone'],
+ fields: ['key', 'name', 'klassTypeId', 'teacherId', 'year', 'displayName', 'order', 'phone', 'grade'],
};
const entity = {
diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx
index 43900c04..c7640748 100644
--- a/client/src/entities/teacher-reported-today.jsx
+++ b/client/src/entities/teacher-reported-today.jsx
@@ -1,12 +1,13 @@
import { useState } from 'react';
import { DateInput, FunctionField, ReferenceField, RecordContextProvider, TextField, useGetList, useListContext, usePermissions } from 'react-admin';
-import { Box, ButtonBase, Card, CircularProgress, Popover, Typography } from '@mui/material';
+import { Alert, Box, ButtonBase, Card, CircularProgress, Popover, Tab, Tabs, 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 { defaultYearFilter } from '@shared/utils/yearFilter';
import { MAX_PAGE_SIZE } from '@shared/config/settings';
import { useLessonTimes } from 'src/settings/settingsUtil';
import { withLessonGaps } from 'src/utils/lessonGaps';
@@ -197,56 +198,121 @@ const GapRow = ({ gap, showDate }) => (
);
+const KlassCard = ({ klass, isAdmin, showDate, lessonTimes }) => {
+ const lessonCount = klass.lessons.length;
+ return (
+
+
+
+ {klass.klassReferenceId ? (
+
+
+
+
+
+ ) : 'ללא כיתה'}
+
+
+ {lessonCount === 1 ? 'שיעור אחד' : `${lessonCount} שיעורים`} · חסרו {sumMissing(klass.lessons)}
+
+
+ {isAdmin && (
+
+
+
+
+
+ )}
+ {(isAdmin ? klass.lessons : withLessonGaps(klass.lessons, lessonTimes)).map((row) => (row.isGap
+ ?
+ :
+ ))}
+
+ );
+};
+
+const KlassCards = ({ rows, isAdmin, showDate, lessonTimes }) => (
+
+ {groupByKlass(rows).map((klass) => (
+
+ ))}
+
+);
+
+const ALL_GRADES = 'all';
+
+// Tabs come from the grades of the current year's classes.
+const useCurrentYearGrades = () => {
+ const { data } = useGetList('klass', {
+ filter: { year: defaultYearFilter.year },
+ pagination: { page: 1, perPage: MAX_PAGE_SIZE },
+ sort: { field: 'grade', order: 'ASC' },
+ });
+ return [...new Set((data || []).map((klass) => klass.grade).filter(Boolean))];
+};
+
+const GradeSection = ({ title, children }) => (
+
+ {title}
+ {children}
+
+);
+
const TeacherReportCards = ({ isAdmin }) => {
const { data, total, filterValues } = useListContext();
const lessonTimes = useLessonTimes();
- const rows = data || [];
- const klasses = groupByKlass(rows);
+ const grades = useCurrentYearGrades();
+ const [selectedGrade, setSelectedGrade] = useState(ALL_GRADES);
+ const allRows = data || [];
+ const rows = selectedGrade === ALL_GRADES ? allRows : allRows.filter((row) => row.grade === selectedGrade);
// Show the date on each row unless the filter is a single day.
const showDate = !filterValues?.['reportDate:$gte'] || filterValues['reportDate:$gte'] !== filterValues['reportDate:$lte'];
+ const cardProps = { isAdmin, showDate, lessonTimes };
+
+ // A report range can include grades no longer used this year; still show them in the split view.
+ const sectionGrades = [...new Set([...grades, ...allRows.map((row) => row.grade).filter(Boolean)])];
+ const missingGradeRows = allRows.filter((row) => row.klassReferenceId && !row.grade);
+ const noKlassRows = allRows.filter((row) => !row.klassReferenceId);
return (
- {total > rows.length && (
+ {total > allRows.length && (
- מוצגים {rows.length} מתוך {total} שיעורים. צמצמו את טווח התאריכים כדי לראות את כולם.
+ מוצגים {allRows.length} מתוך {total} שיעורים. צמצמו את טווח התאריכים כדי לראות את כולם.
)}
-
-
- {klasses.map((klass) => {
- const lessonCount = klass.lessons.length;
- return (
-
-
-
- {klass.klassReferenceId ? (
-
-
-
-
-
- ) : 'ללא כיתה'}
-
-
- {lessonCount === 1 ? 'שיעור אחד' : `${lessonCount} שיעורים`} · חסרו {sumMissing(klass.lessons)}
-
-
- {isAdmin && (
-
-
-
-
-
- )}
- {(isAdmin ? klass.lessons : withLessonGaps(klass.lessons, lessonTimes)).map((row) => (row.isGap
- ?
- :
- ))}
-
- );
- })}
-
+ setSelectedGrade(grade)} variant="scrollable" scrollButtons="auto" sx={{ mb: 2 }}>
+
+ {grades.map((grade) => (
+
+ ))}
+
+
+ {selectedGrade === ALL_GRADES ? (
+ <>
+ {sectionGrades.map((grade) => {
+ const gradeRows = allRows.filter((row) => row.grade === grade);
+ return gradeRows.length > 0 && (
+
+
+
+ );
+ })}
+ {missingGradeRows.length > 0 && (
+
+ לא מוגדר שנתון לכיתה. יש להגדיר שנתון בטבלת הכיתות.
+
+
+ )}
+ {noKlassRows.length > 0 && (
+
+
+
+ )}
+ >
+ ) : (
+
+ )}
);
};
diff --git a/server/src/db/entities/Klass.entity.ts b/server/src/db/entities/Klass.entity.ts
index 2644668d..63107daa 100644
--- a/server/src/db/entities/Klass.entity.ts
+++ b/server/src/db/entities/Klass.entity.ts
@@ -122,6 +122,13 @@ export class Klass implements IHasUserId {
@Column('varchar', { name: 'phone', nullable: true, length: 20 })
phone: string | null;
+ @IsOptional({ groups: [CrudValidationGroups.UPDATE] })
+ @StringType
+ @MaxLength(50, { always: true })
+ @IsNotEmpty({ groups: [CrudValidationGroups.CREATE] })
+ @Column('varchar', { name: 'grade', nullable: true, length: 50 })
+ grade: string | null;
+
@IsOptional({ always: true })
@IsNumber({ maxDecimalPlaces: 0 }, { always: true })
@Column({ nullable: true })
diff --git a/server/src/db/view-entities/TeacherReportedToday.entity.ts b/server/src/db/view-entities/TeacherReportedToday.entity.ts
index 8c0617b2..c352f416 100644
--- a/server/src/db/view-entities/TeacherReportedToday.entity.ts
+++ b/server/src/db/view-entities/TeacherReportedToday.entity.ts
@@ -22,6 +22,7 @@ const PREVIOUS_REPORT_TIME = `LAG(att_reports.created_at) OVER (
lesson_reports.teacherReferenceId AS teacherReferenceId,
lesson_reports.lessonReferenceId AS lessonReferenceId,
lesson_reports.klassReferenceId AS klassReferenceId,
+ klasses.grade AS grade,
MIN(lesson_reports.createdAt) AS reportHour,
COUNT(DISTINCT CASE WHEN lesson_reports.absCount > 0 THEN lesson_reports.studentReferenceId END) AS missingGirlsCount
FROM (
@@ -45,7 +46,8 @@ const PREVIOUS_REPORT_TIME = `LAG(att_reports.created_at) OVER (
WHERE att_reports.teacherReferenceId IS NOT NULL
) reports
) lesson_reports
- GROUP BY lesson_reports.userId, lesson_reports.teacherReferenceId, lesson_reports.reportDate, lesson_reports.lessonReferenceId, lesson_reports.klassReferenceId, lesson_reports.lessonNumber
+ LEFT JOIN klasses ON klasses.id = lesson_reports.klassReferenceId
+ GROUP BY lesson_reports.userId, lesson_reports.teacherReferenceId, lesson_reports.reportDate, lesson_reports.lessonReferenceId, lesson_reports.klassReferenceId, lesson_reports.lessonNumber, klasses.grade
`,
})
export class TeacherReportedToday implements IHasUserId {
@@ -67,6 +69,9 @@ export class TeacherReportedToday implements IHasUserId {
@Column({ nullable: true })
klassReferenceId: number;
+ @Column({ nullable: true })
+ grade: string;
+
@Column()
reportHour: Date;
diff --git a/server/src/migrations/1792100000000-AddKlassGrade.ts b/server/src/migrations/1792100000000-AddKlassGrade.ts
new file mode 100644
index 00000000..cfb662e9
--- /dev/null
+++ b/server/src/migrations/1792100000000-AddKlassGrade.ts
@@ -0,0 +1,19 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class AddKlassGrade1792100000000 implements MigrationInterface {
+ name = 'AddKlassGrade1792100000000'
+
+ public async up(queryRunner: QueryRunner): Promise {
+ await queryRunner.query(`
+ ALTER TABLE \`klasses\`
+ ADD \`grade\` varchar(50) NULL
+ `);
+ }
+
+ public async down(queryRunner: QueryRunner): Promise {
+ await queryRunner.query(`
+ ALTER TABLE \`klasses\` DROP COLUMN \`grade\`
+ `);
+ }
+
+}
diff --git a/server/src/migrations/1792100000001-AddGradeToTeacherReportedTodayView.ts b/server/src/migrations/1792100000001-AddGradeToTeacherReportedTodayView.ts
new file mode 100644
index 00000000..8e06b2bf
--- /dev/null
+++ b/server/src/migrations/1792100000001-AddGradeToTeacherReportedTodayView.ts
@@ -0,0 +1,92 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class AddGradeToTeacherReportedTodayView1792100000001 implements MigrationInterface {
+ name = 'AddGradeToTeacherReportedTodayView1792100000001'
+
+ public async up(queryRunner: QueryRunner): Promise {
+ const dbName = queryRunner.connection.options.database;
+ await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]);
+ await queryRunner.query(`DROP VIEW \`teacher_reported_today\``);
+ await queryRunner.query(`CREATE VIEW \`teacher_reported_today\` AS
+ SELECT CONCAT(lesson_reports.userId, '_', lesson_reports.teacherReferenceId, '_', lesson_reports.reportDate, '_', COALESCE(lesson_reports.lessonReferenceId, 'null'), '_', COALESCE(lesson_reports.klassReferenceId, 'null'), '_', lesson_reports.lessonNumber) AS id,
+ lesson_reports.userId AS userId,
+ lesson_reports.reportDate AS reportDate,
+ lesson_reports.teacherReferenceId AS teacherReferenceId,
+ lesson_reports.lessonReferenceId AS lessonReferenceId,
+ lesson_reports.klassReferenceId AS klassReferenceId,
+ klasses.grade AS grade,
+ MIN(lesson_reports.createdAt) AS reportHour,
+ COUNT(DISTINCT CASE WHEN lesson_reports.absCount > 0 THEN lesson_reports.studentReferenceId END) AS missingGirlsCount
+ FROM (
+ SELECT reports.*,
+ SUM(reports.isNewLesson) OVER (
+ PARTITION BY reports.userId, reports.teacherReferenceId, reports.reportDate, reports.lessonReferenceId, reports.klassReferenceId
+ ORDER BY reports.createdAt, reports.id
+ ) AS lessonNumber
+ FROM (
+ SELECT att_reports.id AS id,
+ att_reports.user_id AS userId,
+ att_reports.report_date AS reportDate,
+ att_reports.teacherReferenceId AS teacherReferenceId,
+ att_reports.lessonReferenceId AS lessonReferenceId,
+ att_reports.klassReferenceId AS klassReferenceId,
+ att_reports.studentReferenceId AS studentReferenceId,
+ att_reports.abs_count AS absCount,
+ att_reports.created_at AS createdAt,
+ CASE WHEN att_reports.created_at <= LAG(att_reports.created_at) OVER (
+ PARTITION BY att_reports.user_id, att_reports.teacherReferenceId, att_reports.report_date, att_reports.lessonReferenceId, att_reports.klassReferenceId
+ ORDER BY att_reports.created_at, att_reports.id
+ ) + INTERVAL 15 MINUTE THEN 0 ELSE 1 END AS isNewLesson
+ FROM att_reports
+ WHERE att_reports.teacherReferenceId IS NOT NULL
+ ) reports
+ ) lesson_reports
+ LEFT JOIN klasses ON klasses.id = lesson_reports.klassReferenceId
+ GROUP BY lesson_reports.userId, lesson_reports.teacherReferenceId, lesson_reports.reportDate, lesson_reports.lessonReferenceId, lesson_reports.klassReferenceId, lesson_reports.lessonNumber, klasses.grade
+ `);
+ await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT CONCAT(lesson_reports.userId, '_', lesson_reports.teacherReferenceId, '_', lesson_reports.reportDate, '_', COALESCE(lesson_reports.lessonReferenceId, 'null'), '_', COALESCE(lesson_reports.klassReferenceId, 'null'), '_', lesson_reports.lessonNumber) AS id,\n lesson_reports.userId AS userId,\n lesson_reports.reportDate AS reportDate,\n lesson_reports.teacherReferenceId AS teacherReferenceId,\n lesson_reports.lessonReferenceId AS lessonReferenceId,\n lesson_reports.klassReferenceId AS klassReferenceId,\n klasses.grade AS grade,\n MIN(lesson_reports.createdAt) AS reportHour,\n COUNT(DISTINCT CASE WHEN lesson_reports.absCount > 0 THEN lesson_reports.studentReferenceId END) AS missingGirlsCount\n FROM (\n SELECT reports.*,\n SUM(reports.isNewLesson) OVER (\n PARTITION BY reports.userId, reports.teacherReferenceId, reports.reportDate, reports.lessonReferenceId, reports.klassReferenceId\n ORDER BY reports.createdAt, reports.id\n ) AS lessonNumber\n FROM (\n SELECT att_reports.id AS id,\n att_reports.user_id AS userId,\n att_reports.report_date AS reportDate,\n att_reports.teacherReferenceId AS teacherReferenceId,\n att_reports.lessonReferenceId AS lessonReferenceId,\n att_reports.klassReferenceId AS klassReferenceId,\n att_reports.studentReferenceId AS studentReferenceId,\n att_reports.abs_count AS absCount,\n att_reports.created_at AS createdAt,\n CASE WHEN att_reports.created_at <= LAG(att_reports.created_at) OVER (\n PARTITION BY att_reports.user_id, att_reports.teacherReferenceId, att_reports.report_date, att_reports.lessonReferenceId, att_reports.klassReferenceId\n ORDER BY att_reports.created_at, att_reports.id\n ) + INTERVAL 15 MINUTE THEN 0 ELSE 1 END AS isNewLesson\n FROM att_reports\n WHERE att_reports.teacherReferenceId IS NOT NULL\n ) reports\n ) lesson_reports\n LEFT JOIN klasses ON klasses.id = lesson_reports.klassReferenceId\n GROUP BY lesson_reports.userId, lesson_reports.teacherReferenceId, lesson_reports.reportDate, lesson_reports.lessonReferenceId, lesson_reports.klassReferenceId, lesson_reports.lessonNumber, klasses.grade"]);
+ }
+
+ public async down(queryRunner: QueryRunner): Promise {
+ const dbName = queryRunner.connection.options.database;
+ await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]);
+ await queryRunner.query(`DROP VIEW \`teacher_reported_today\``);
+ await queryRunner.query(`CREATE VIEW \`teacher_reported_today\` AS
+ SELECT CONCAT(lesson_reports.userId, '_', lesson_reports.teacherReferenceId, '_', lesson_reports.reportDate, '_', COALESCE(lesson_reports.lessonReferenceId, 'null'), '_', COALESCE(lesson_reports.klassReferenceId, 'null'), '_', lesson_reports.lessonNumber) AS id,
+ lesson_reports.userId AS userId,
+ lesson_reports.reportDate AS reportDate,
+ lesson_reports.teacherReferenceId AS teacherReferenceId,
+ lesson_reports.lessonReferenceId AS lessonReferenceId,
+ lesson_reports.klassReferenceId AS klassReferenceId,
+ MIN(lesson_reports.createdAt) AS reportHour,
+ COUNT(DISTINCT CASE WHEN lesson_reports.absCount > 0 THEN lesson_reports.studentReferenceId END) AS missingGirlsCount
+ FROM (
+ SELECT reports.*,
+ SUM(reports.isNewLesson) OVER (
+ PARTITION BY reports.userId, reports.teacherReferenceId, reports.reportDate, reports.lessonReferenceId, reports.klassReferenceId
+ ORDER BY reports.createdAt, reports.id
+ ) AS lessonNumber
+ FROM (
+ SELECT att_reports.id AS id,
+ att_reports.user_id AS userId,
+ att_reports.report_date AS reportDate,
+ att_reports.teacherReferenceId AS teacherReferenceId,
+ att_reports.lessonReferenceId AS lessonReferenceId,
+ att_reports.klassReferenceId AS klassReferenceId,
+ att_reports.studentReferenceId AS studentReferenceId,
+ att_reports.abs_count AS absCount,
+ att_reports.created_at AS createdAt,
+ CASE WHEN att_reports.created_at <= LAG(att_reports.created_at) OVER (
+ PARTITION BY att_reports.user_id, att_reports.teacherReferenceId, att_reports.report_date, att_reports.lessonReferenceId, att_reports.klassReferenceId
+ ORDER BY att_reports.created_at, att_reports.id
+ ) + INTERVAL 15 MINUTE THEN 0 ELSE 1 END AS isNewLesson
+ FROM att_reports
+ WHERE att_reports.teacherReferenceId IS NOT NULL
+ ) reports
+ ) lesson_reports
+ GROUP BY lesson_reports.userId, lesson_reports.teacherReferenceId, lesson_reports.reportDate, lesson_reports.lessonReferenceId, lesson_reports.klassReferenceId, lesson_reports.lessonNumber
+ `);
+ await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT CONCAT(lesson_reports.userId, '_', lesson_reports.teacherReferenceId, '_', lesson_reports.reportDate, '_', COALESCE(lesson_reports.lessonReferenceId, 'null'), '_', COALESCE(lesson_reports.klassReferenceId, 'null'), '_', lesson_reports.lessonNumber) AS id,\n lesson_reports.userId AS userId,\n lesson_reports.reportDate AS reportDate,\n lesson_reports.teacherReferenceId AS teacherReferenceId,\n lesson_reports.lessonReferenceId AS lessonReferenceId,\n lesson_reports.klassReferenceId AS klassReferenceId,\n MIN(lesson_reports.createdAt) AS reportHour,\n COUNT(DISTINCT CASE WHEN lesson_reports.absCount > 0 THEN lesson_reports.studentReferenceId END) AS missingGirlsCount\n FROM (\n SELECT reports.*,\n SUM(reports.isNewLesson) OVER (\n PARTITION BY reports.userId, reports.teacherReferenceId, reports.reportDate, reports.lessonReferenceId, reports.klassReferenceId\n ORDER BY reports.createdAt, reports.id\n ) AS lessonNumber\n FROM (\n SELECT att_reports.id AS id,\n att_reports.user_id AS userId,\n att_reports.report_date AS reportDate,\n att_reports.teacherReferenceId AS teacherReferenceId,\n att_reports.lessonReferenceId AS lessonReferenceId,\n att_reports.klassReferenceId AS klassReferenceId,\n att_reports.studentReferenceId AS studentReferenceId,\n att_reports.abs_count AS absCount,\n att_reports.created_at AS createdAt,\n CASE WHEN att_reports.created_at <= LAG(att_reports.created_at) OVER (\n PARTITION BY att_reports.user_id, att_reports.teacherReferenceId, att_reports.report_date, att_reports.lessonReferenceId, att_reports.klassReferenceId\n ORDER BY att_reports.created_at, att_reports.id\n ) + INTERVAL 15 MINUTE THEN 0 ELSE 1 END AS isNewLesson\n FROM att_reports\n WHERE att_reports.teacherReferenceId IS NOT NULL\n ) reports\n ) lesson_reports\n GROUP BY lesson_reports.userId, lesson_reports.teacherReferenceId, lesson_reports.reportDate, lesson_reports.lessonReferenceId, lesson_reports.klassReferenceId, lesson_reports.lessonNumber"]);
+ }
+
+}