Skip to content

Commit

Permalink
Fix exams display of non enrolled ucs (#1418)
Browse files Browse the repository at this point in the history
  • Loading branch information
limwa authored Dec 26, 2024
2 parents 6c2279e + 56cbce2 commit 63ae08d
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 39 deletions.
3 changes: 2 additions & 1 deletion packages/uni_app/lib/controller/fetchers/exam_fetcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class ExamFetcher implements SessionDependantFetcher {
) &&
courseExam.examType != 'EE' &&
courseExam.examType != 'EAE' &&
courseExam.subject == uc.abbreviation &&
courseExam.subjectAcronym == uc.abbreviation &&
courseExam.subject == uc.name &&
uc.enrollmentIsValid() &&
!courseExam.hasEnded()) {
exams.add(courseExam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'package:uni/model/entities/exam.dart';
/// See the [Exam] class to see what data is stored in this database.
class AppExamsDatabase extends AppDatabase<List<Exam>> {
AppExamsDatabase()
: super('exams.db', [_createScript], onUpgrade: migrate, version: 7);
: super('exams.db', [_createScript], onUpgrade: migrate, version: 8);

static const _createScript = '''
CREATE TABLE exams(id TEXT, subject TEXT, start TEXT, finish TEXT,
CREATE TABLE exams(id TEXT, subjectAcronym TEXT, subject TEXT, start TEXT, finish TEXT,
rooms TEXT, examType TEXT, faculty TEXT, PRIMARY KEY (id,faculty)) ''';

/// Returns a list containing all of the exams stored in this database.
Expand All @@ -24,6 +24,7 @@ CREATE TABLE exams(id TEXT, subject TEXT, start TEXT, finish TEXT,
return List.generate(maps.length, (i) {
return Exam.secConstructor(
maps[i]['id'] as String,
maps[i]['subjectAcronym'] as String,
maps[i]['subject'] as String,
DateTime.parse(maps[i]['start'] as String),
DateTime.parse(maps[i]['finish'] as String),
Expand Down
5 changes: 4 additions & 1 deletion packages/uni_app/lib/controller/parsers/parser_exams.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ParserExams {
final dates = <String>[];
final examTypes = <String>[];
var rooms = <String>[];
String? subjectAcronym;
String? subject;
var id = '0';
var days = 0;
Expand All @@ -46,7 +47,8 @@ class ParserExams {
if (exams.querySelector('td.exame') != null) {
exams.querySelectorAll('td.exame').forEach((examsDay) {
if (examsDay.querySelector('a') != null) {
subject = examsDay.querySelector('a')!.text;
subjectAcronym = examsDay.querySelector('a')!.text;
subject = examsDay.querySelector('a')!.attributes['title'];
id = Uri.parse(examsDay.querySelector('a')!.attributes['href']!)
.queryParameters['p_exa_id']!;
}
Expand All @@ -73,6 +75,7 @@ class ParserExams {
id,
begin,
end,
subjectAcronym ?? '',
subject ?? '',
rooms,
examTypes[tableNum],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/uni_app/lib/generated/model/entities/exam.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uni_app/lib/generated/model/entities/trip.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/uni_app/lib/model/entities/exam.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Exam {
this.id,
this.start,
this.finish,
this.subjectAcronym,
this.subject,
this.rooms,
this.examType,
Expand All @@ -31,6 +32,7 @@ class Exam {

Exam.secConstructor(
this.id,
this.subjectAcronym,
this.subject,
this.start,
this.finish,
Expand All @@ -42,6 +44,7 @@ class Exam {
final DateTime start;
final DateTime finish;
final String id;
final String subjectAcronym;
final String subject;
final List<String> rooms;
final String examType;
Expand Down Expand Up @@ -81,7 +84,7 @@ class Exam {

@override
String toString() {
return '''$id - $subject - ${start.year} - $month - ${start.day} - $startTime-$finishTime - $examType - $rooms - $weekDay''';
return '''$id - $subjectAcronym - ${start.year} - $month - ${start.day} - $startTime-$finishTime - $examType - $rooms - $weekDay''';
}

/// Prints the data in this exam to the [Logger] with an INFO level.
Expand All @@ -92,7 +95,10 @@ class Exam {
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Exam && id == other.id && subject == other.subject;
other is Exam &&
id == other.id &&
subjectAcronym == other.subjectAcronym &&
subject == other.subject;

@override
int get hashCode => id.hashCode;
Expand Down
7 changes: 4 additions & 3 deletions packages/uni_app/lib/view/exams/widgets/exam_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _ExamRowState extends State<ExamRow> {
@override
Widget build(BuildContext context) {
final roomsKey =
'${widget.exam.subject}-${widget.exam.rooms}-${widget.exam.startTime}-'
'${widget.exam.subjectAcronym}-${widget.exam.rooms}-${widget.exam.startTime}-'
'${widget.exam.finishTime}';
return Center(
child: Container(
Expand All @@ -63,7 +63,8 @@ class _ExamRowState extends State<ExamRow> {
: [],
),
ExamTitle(
subject: widget.exam.subject,
subject: widget.exam.subjectAcronym,
subjectName: widget.exam.subject,
type: widget.exam.examType,
),
Row(
Expand Down Expand Up @@ -144,7 +145,7 @@ class _ExamRowState extends State<ExamRow> {

Event createExamEvent() {
return Event(
title: '${widget.exam.examType} ${widget.exam.subject}',
title: '${widget.exam.examType} ${widget.exam.subjectAcronym}',
location: widget.exam.rooms.toString(),
startDate: widget.exam.start,
endDate: widget.exam.finish,
Expand Down
17 changes: 11 additions & 6 deletions packages/uni_app/lib/view/exams/widgets/exam_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'package:flutter/material.dart';
class ExamTitle extends StatelessWidget {
const ExamTitle({
required this.subject,
required this.subjectName,
this.type,
this.reverseOrder = false,
super.key,
});
static const double borderRadius = 12;
static const double sideSizing = 12;
final String subject;
final String subjectName;
final String? type;
final bool reverseOrder;

Expand All @@ -25,12 +27,15 @@ class ExamTitle extends StatelessWidget {
type != null ? ' ($type) ' : '',
style: Theme.of(context).textTheme.bodyMedium,
);
final subjectWidget = Text(
subject,
style: Theme.of(context)
.textTheme
.headlineSmall
?.apply(color: Theme.of(context).colorScheme.tertiary),
final subjectWidget = Tooltip(
message: subjectName,
child: Text(
subject,
style: Theme.of(context)
.textTheme
.headlineSmall
?.apply(color: Theme.of(context).colorScheme.tertiary),
),
);

return Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class RemainingExamsWidget extends StatelessWidget {
style: Theme.of(context).textTheme.bodyLarge,
),
ExamTitle(
subject: exam.subject,
subject: exam.subjectAcronym,
subjectName: exam.subject,
type: exam.examType,
reverseOrder: true,
),
Expand Down
15 changes: 13 additions & 2 deletions packages/uni_app/test/unit/view/Pages/exams_page_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ void main() async {
await initTestEnvironment();

group('ExamsPage', () {
const firstExamSubject = 'SOPE';
const firstExamSubjectAcronym = 'SOPE';
const firstExamSubject = 'Sistemas Operativos';
const firstExamDate = '2019-09-11';
const secondExamSubject = 'SDIS';
const secondExamSubjectAcronym = 'SDIS';
const secondExamSubject = 'Sistemas Distribuídos';
const secondExamDate = '2019-09-12';

testWidgets('When given an empty list', (tester) async {
Expand All @@ -37,6 +39,7 @@ void main() async {
'1230',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand All @@ -63,6 +66,7 @@ void main() async {
'1231',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand All @@ -74,6 +78,7 @@ void main() async {
'1232',
secondExamBegin,
secondExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand Down Expand Up @@ -109,6 +114,7 @@ void main() async {
'1233',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand All @@ -120,6 +126,7 @@ void main() async {
'1234',
secondExamBegin,
secondExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
['B119', 'B107', 'B205'],
'ER',
Expand Down Expand Up @@ -154,6 +161,7 @@ void main() async {
'1235',
firstExamBegin,
firstExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
rooms,
'ER',
Expand All @@ -165,6 +173,7 @@ void main() async {
'1236',
secondExamBegin,
secondExamEnd,
firstExamSubjectAcronym,
firstExamSubject,
rooms,
'ER',
Expand All @@ -176,6 +185,7 @@ void main() async {
'1237',
thirdExamBegin,
thirdExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
rooms,
'ER',
Expand All @@ -187,6 +197,7 @@ void main() async {
'1238',
fourthExamBegin,
fourthExamEnd,
secondExamSubjectAcronym,
secondExamSubject,
rooms,
'ER',
Expand Down
Loading

0 comments on commit 63ae08d

Please sign in to comment.