Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesigning academic page #1151

Merged
merged 21 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:uni/controller/parsers/parser_course_unit_info.dart';
import 'package:uni/model/entities/course_units/course_unit_class.dart';
import 'package:uni/model/entities/course_units/course_unit_directory.dart';
import 'package:uni/model/entities/course_units/course_unit_sheet.dart';
import 'package:uni/model/entities/course_units/sheet.dart';
import 'package:uni/model/entities/session.dart';

class CourseUnitsInfoFetcher implements SessionDependantFetcher {
Expand All @@ -27,16 +28,27 @@ class CourseUnitsInfoFetcher implements SessionDependantFetcher {
return parseCourseUnitSheet(response);
}

Future<Sheet> fetchSheet(
Session session,
int occurId,
) async {
final url = '${getEndpoints(session)[0]}mob_ucurr_geral.perfil';
final response = await NetworkRouter.getWithCookies(
url,
{'pv_ocorrencia_id': occurId.toString()},
session,
);
return parseSheet(response);
}

Future<List<CourseUnitFileDirectory>> fetchCourseUnitFiles(
Session session,
int occurId,
) async {
final url = '${getEndpoints(session)[0]}mob_ucurr_geral.conteudos';
final response = await NetworkRouter.getWithCookies(
url,
{
'pv_ocorrencia_id': occurId.toString(),
},
{'pv_ocorrencia_id': occurId.toString()},
session,
);
return parseFiles(response, session);
Expand Down
47 changes: 47 additions & 0 deletions uni/lib/controller/parsers/parser_course_unit_info.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// ignore_for_file: unused_import
DGoiana marked this conversation as resolved.
Show resolved Hide resolved

import 'dart:collection';
import 'dart:convert';

import 'package:html/parser.dart';
Expand All @@ -7,6 +10,7 @@ import 'package:uni/model/entities/course_units/course_unit_class.dart';
import 'package:uni/model/entities/course_units/course_unit_directory.dart';
import 'package:uni/model/entities/course_units/course_unit_file.dart';
import 'package:uni/model/entities/course_units/course_unit_sheet.dart';
import 'package:uni/model/entities/course_units/sheet.dart';
import 'package:uni/model/entities/session.dart';

Future<List<CourseUnitFileDirectory>> parseFiles(
Expand Down Expand Up @@ -42,6 +46,44 @@ Future<List<CourseUnitFileDirectory>> parseFiles(
return dirs;
}

Future<Sheet> parseSheet(http.Response response) async {
final json = jsonDecode(response.body) as Map<String, dynamic>;
final professors = getCourseUnitProfessors(json['ds'] as List<dynamic>);
final regents = <Professor>[];

json['responsabilidades'].forEach((dynamic element) {
regents.add(Professor.fromJson(element as Map<String, dynamic>));
});

return Sheet(
professors: professors,
content: json['conteudo'].toString(),
evaluation: json['for_avaliacao'].toString(),
regents: regents,
);
}

List<Professor> getCourseUnitProfessors(List<dynamic> ds) {
final professors = <Professor>[];
for (final map in ds) {
for (final docente in map['docentes'] as Iterable) {
final professor = Professor(
code: docente['doc_codigo'].toString(),
name: shortName(docente['nome'].toString()),
classes: [map['tipo'].toString()],
);
if (professors.contains(professor)) {
professors[professors.indexWhere((element) => element == professor)]
.classes
.add(map['tipo'].toString());
} else {
professors.add(professor);
}
}
}
return professors;
}

Future<CourseUnitSheet> parseCourseUnitSheet(http.Response response) async {
final document = parse(response.body);
final titles = document.querySelectorAll('#conteudoinner h3');
Expand Down Expand Up @@ -119,3 +161,8 @@ String _htmlAfterElement(String body, String elementOuterHtml) {
final index = body.indexOf(elementOuterHtml) + elementOuterHtml.length;
return body.substring(index, body.indexOf('<h3>', index));
}

String shortName(String name) {
final splitName = name.split(' ');
return '${splitName.first} ${splitName.last}';
}
49 changes: 49 additions & 0 deletions uni/lib/model/entities/course_units/sheet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:io';

import 'package:uni/controller/parsers/parser_course_unit_info.dart';

class Sheet {
Sheet({
required this.professors,
required this.content,
required this.evaluation,
required this.regents,
});
List<Professor> professors;
List<Professor> regents;
String content;
String evaluation;
}

class Professor {
Professor({
required this.code,
required this.name,
required this.classes,
this.picture,
});

factory Professor.fromJson(Map<String, dynamic> json) {
return Professor(
code: json['codigo'].toString(),
name: shortName(json['nome'].toString()),
classes: [],
);
}

File? picture;
String code;
String name;
List<String> classes;

@override
bool operator ==(Object other) {
if (other is Professor) {
return other.code == code;
}
return false;
}

@override
int get hashCode => code.hashCode;
}
12 changes: 7 additions & 5 deletions uni/lib/model/providers/lazy/course_units_info_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: unused_import
DGoiana marked this conversation as resolved.
Show resolved Hide resolved

import 'dart:collection';

import 'package:tuple/tuple.dart';
Expand All @@ -6,11 +8,12 @@ import 'package:uni/model/entities/course_units/course_unit.dart';
import 'package:uni/model/entities/course_units/course_unit_class.dart';
import 'package:uni/model/entities/course_units/course_unit_directory.dart';
import 'package:uni/model/entities/course_units/course_unit_sheet.dart';
import 'package:uni/model/entities/course_units/sheet.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/model/providers/state_provider_notifier.dart';
import 'package:uni/model/providers/state_providers.dart';

typedef SheetsMap = Map<CourseUnit, CourseUnitSheet>;
typedef SheetsMap = Map<CourseUnit, Sheet>;
typedef ClassesMap = Map<CourseUnit, List<CourseUnitClass>>;
typedef FilesMap = Map<CourseUnit, List<CourseUnitFileDirectory>>;

Expand All @@ -25,7 +28,7 @@ class CourseUnitsInfoProvider
initialState: Tuple3({}, {}, {}),
);

UnmodifiableMapView<CourseUnit, CourseUnitSheet> get courseUnitsSheets =>
UnmodifiableMapView<CourseUnit, Sheet> get courseUnitsSheets =>
UnmodifiableMapView(state!.item1);

UnmodifiableMapView<CourseUnit, List<CourseUnitClass>>
Expand All @@ -38,9 +41,8 @@ class CourseUnitsInfoProvider
CourseUnit courseUnit,
Session session,
) async {
state!.item1[courseUnit] = await CourseUnitsInfoFetcher()
.fetchCourseUnitSheet(session, courseUnit.occurrId);
notifyListeners();
state!.item1[courseUnit] =
await CourseUnitsInfoFetcher().fetchSheet(session, courseUnit.occurrId);
}

Future<void> fetchCourseUnitClasses(
Expand Down
37 changes: 37 additions & 0 deletions uni/lib/view/common_widgets/generic_expandable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:expandable/expandable.dart';
import 'package:flutter/material.dart';

class GenericExpandable extends StatelessWidget {
const GenericExpandable(
{super.key, required this.title, required this.content});

final String title;
final Widget content;

@override
Widget build(BuildContext context) {
return ExpandablePanel(
header: Align(
alignment: Alignment.centerLeft,
child: Text(title, style: const TextStyle(fontSize: 20)),
),
collapsed: ShaderMask(
shaderCallback: (bounds) => const LinearGradient(
colors: [Colors.black, Colors.transparent],
stops: [0.7, 1.0],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
).createShader(bounds),
blendMode: BlendMode.dstIn,
child: ClipRect(
child: Align(
alignment: Alignment.topCenter,
heightFactor: 0.25,
child: content,
),
),
),
expanded: content,
);
}
}
3 changes: 1 addition & 2 deletions uni/lib/view/course_unit_info/course_unit_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ class CourseUnitDetailPageViewState
final sheet = context
.read<CourseUnitsInfoProvider>()
.courseUnitsSheets[widget.courseUnit];

if (sheet == null || sheet.sections.isEmpty) {
if (sheet == null) {
return Center(
child: Text(
S.of(context).no_info,
Expand Down
Loading
Loading