feat: select school terms and smooth refractive Dock motion
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import '../domain/course.dart';
|
||||
import '../domain/school_term.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
@@ -9,12 +10,14 @@ class ImportDraft {
|
||||
required this.source,
|
||||
required this.parserVersion,
|
||||
this.semesterLabel,
|
||||
this.schoolTerm,
|
||||
});
|
||||
final List<Course> courses;
|
||||
final bool explicitlyEmpty;
|
||||
final CourseSource source;
|
||||
final String parserVersion;
|
||||
final String? semesterLabel;
|
||||
final SchoolTerm? schoolTerm;
|
||||
}
|
||||
|
||||
class JsonScheduleImport {
|
||||
@@ -46,11 +49,28 @@ class JsonScheduleImport {
|
||||
if (courses.map((c) => c.id).toSet().length != courses.length) {
|
||||
throw const FormatException('课程标识重复');
|
||||
}
|
||||
final termIds = courses
|
||||
.map((c) => RegExp(r'^uestc-(\d+)-').firstMatch(c.id)?.group(1))
|
||||
.whereType<String>()
|
||||
.toSet();
|
||||
final term = json['schoolTerm'] != null
|
||||
? SchoolTerm.fromJson(
|
||||
Map<String, dynamic>.from(json['schoolTerm'] as Map),
|
||||
)
|
||||
: termIds.length == 1
|
||||
? SchoolTerm(int.parse(termIds.single))
|
||||
: null;
|
||||
if (termIds.length > 1 ||
|
||||
(term != null && termIds.any((id) => id != term.id.toString()))) {
|
||||
throw const FormatException('文件中包含不同学期的课程');
|
||||
}
|
||||
return ImportDraft(
|
||||
courses: List.unmodifiable(courses),
|
||||
explicitlyEmpty: json['explicitlyEmpty'] == true,
|
||||
source: source,
|
||||
parserVersion: 'json-v1',
|
||||
schoolTerm: source == CourseSource.demo ? null : term,
|
||||
semesterLabel: term?.label,
|
||||
);
|
||||
} on FormatException {
|
||||
rethrow;
|
||||
|
||||
Reference in New Issue
Block a user