feat: keep undergraduate exams independent of course terms

This commit is contained in:
Codex
2026-10-14 23:19:11 +08:00
parent 48367b8273
commit 141436f545
9 changed files with 419 additions and 99 deletions
+21 -1
View File
@@ -11,6 +11,7 @@ import '../domain/schedule_engine.dart';
import '../data/demo_schedule.dart';
import '../domain/exam_schedule.dart';
import '../domain/school_term.dart';
import '../domain/school_identity.dart';
class AppController extends ChangeNotifier {
AppController(this.store, this.notifications, this.calendar, this.clock);
@@ -89,6 +90,15 @@ class AppController extends ChangeNotifier {
Future<void> leaveDemo() => _run(() async {
isDemo = false;
});
Future<bool> selectSchool(SupportedSchool school) async {
var saved = false;
await _run(() async {
await _save(snapshot.copyWith(selectedSchool: school));
saved = true;
});
return saved;
}
Future<void> updateSettings(
AppSettings Function(AppSettings current) change,
) => _run(() async {
@@ -148,11 +158,17 @@ class AppController extends ChangeNotifier {
if (draft.courses.any((c) => c.source != draft.source)) {
throw const FormatException('课程来源不一致');
}
if (draft.schoolTerm?.school != SupportedSchool.uestcUndergraduate &&
draft.courses.any((c) => c.endPeriod > 11)) {
throw const FormatException('第12节需要本科课表来源');
}
await _save(
snapshot.copyWith(
courses: draft.courses,
schoolTerm: draft.schoolTerm,
clearExams: _differentTerm(draft.schoolTerm),
clearExams:
draft.schoolTerm?.school != SupportedSchool.uestcUndergraduate &&
_differentTerm(draft.schoolTerm),
settings: _differentTerm(draft.schoolTerm)
? snapshot.settings.copyWith(clearSemester: true)
: snapshot.settings,
@@ -188,6 +204,10 @@ class AppController extends ChangeNotifier {
});
Future<void> applyExams(ExamSchedule value) => _run(() async {
final validated = ExamSchedule.fromJson(value.toJson());
if (validated.school == SupportedSchool.uestcUndergraduate) {
await _save(snapshot.copyWith(examSchedule: validated));
return;
}
final term = SchoolTerm(int.parse(validated.termId));
final changed = _differentTerm(term);
await _save(