Skip to content

Commit 946b3b9

Browse files
mikebarkminCopilot
andcommitted
feat(lessons): add category-driven lesson planner
Replace the lesson planner category dropdown with FAB menus, show per-category calendar markers, and restore matching grade sessions when opening lesson entries from the calendar. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c79bd23 commit 946b3b9

7 files changed

Lines changed: 898 additions & 512 deletions

File tree

lib/features/grades/grade_repository.dart

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ class GradeRepository {
191191
Variable.withDateTime(normalizedDate),
192192
Variable.withString(categoryId),
193193
],
194-
readsFrom: {
195-
_database.gradeEntriesTable,
196-
_database.studentsTable,
197-
},
194+
readsFrom: {_database.gradeEntriesTable, _database.studentsTable},
198195
)
199196
.watch()
200197
.map(
@@ -205,6 +202,44 @@ class GradeRepository {
205202
);
206203
}
207204

205+
Future<String?> getPreferredSessionLabel({
206+
required int groupId,
207+
required DateTime date,
208+
required String categoryId,
209+
}) async {
210+
final normalizedDate = DateTime(date.year, date.month, date.day);
211+
final normalizedCategoryId = categoryId.trim();
212+
if (normalizedCategoryId.isEmpty) {
213+
return null;
214+
}
215+
216+
final rows = await _database
217+
.customSelect(
218+
'''
219+
SELECT g.session_label, COUNT(*) AS entry_count
220+
FROM grade_entries_table g
221+
JOIN students_table s ON s.id = g.student_id
222+
WHERE s.group_id = ? AND g.date = ? AND g.category_id = ?
223+
GROUP BY g.session_label
224+
ORDER BY entry_count DESC, g.session_label ASC
225+
LIMIT 1
226+
''',
227+
variables: [
228+
Variable.withInt(groupId),
229+
Variable.withDateTime(normalizedDate),
230+
Variable.withString(normalizedCategoryId),
231+
],
232+
)
233+
.getSingleOrNull();
234+
235+
if (rows == null) {
236+
return null;
237+
}
238+
239+
final sessionLabel = rows.read<String>('session_label').trim();
240+
return sessionLabel.isEmpty ? null : sessionLabel;
241+
}
242+
208243
Future<void> saveEntry({
209244
required int studentId,
210245
required DateTime date,

0 commit comments

Comments
 (0)