diff --git a/filcnaplo_kreta_api/lib/models/absence.dart b/filcnaplo_kreta_api/lib/models/absence.dart index c0000e0..d694c86 100644 --- a/filcnaplo_kreta_api/lib/models/absence.dart +++ b/filcnaplo_kreta_api/lib/models/absence.dart @@ -1,5 +1,6 @@ import "category.dart"; import "subject.dart"; +import "teacher.dart"; class Absence { Map? json; @@ -7,7 +8,7 @@ class Absence { DateTime date; int delay; DateTime submitDate; - String teacher; + Teacher teacher; Justification state; Category? justification; Category? type; @@ -41,8 +42,12 @@ class Absence { DateTime lessonEnd; int? lessonIndex; if (json["Ora"] != null) { - lessonStart = json["Ora"]["KezdoDatum"] != null ? DateTime.parse(json["Ora"]["KezdoDatum"]).toLocal() : DateTime(0); - lessonEnd = json["Ora"]["VegDatum"] != null ? DateTime.parse(json["Ora"]["VegDatum"]).toLocal() : DateTime(0); + lessonStart = json["Ora"]["KezdoDatum"] != null + ? DateTime.parse(json["Ora"]["KezdoDatum"]).toLocal() + : DateTime(0); + lessonEnd = json["Ora"]["VegDatum"] != null + ? DateTime.parse(json["Ora"]["VegDatum"]).toLocal() + : DateTime(0); lessonIndex = json["Ora"]["Oraszam"]; } else { lessonStart = DateTime(0); @@ -51,26 +56,33 @@ class Absence { return Absence( id: json["Uid"], - date: json["Datum"] != null ? DateTime.parse(json["Datum"]).toLocal() : DateTime(0), + date: json["Datum"] != null + ? DateTime.parse(json["Datum"]).toLocal() + : DateTime(0), delay: json["KesesPercben"] ?? 0, - submitDate: json["KeszitesDatuma"] != null ? DateTime.parse(json["KeszitesDatuma"]).toLocal() : DateTime(0), - teacher: (json["RogzitoTanarNeve"] ?? "").trim(), + submitDate: json["KeszitesDatuma"] != null + ? DateTime.parse(json["KeszitesDatuma"]).toLocal() + : DateTime(0), + teacher: Teacher.fromString((json["RogzitoTanarNeve"] ?? "").trim()), state: json["IgazolasAllapota"] == "Igazolt" ? Justification.excused : json["IgazolasAllapota"] == "Igazolando" ? Justification.pending : Justification.unexcused, - justification: json["IgazolasTipusa"] != null ? Category.fromJson(json["IgazolasTipusa"]) : null, + justification: json["IgazolasTipusa"] != null + ? Category.fromJson(json["IgazolasTipusa"]) + : null, type: json["Tipus"] != null ? Category.fromJson(json["Tipus"]) : null, mode: json["Mod"] != null ? Category.fromJson(json["Mod"]) : null, subject: Subject.fromJson(json["Tantargy"] ?? {}), lessonStart: lessonStart, lessonEnd: lessonEnd, lessonIndex: lessonIndex, - group: json["OsztalyCsoport"] != null ? json["OsztalyCsoport"]["Uid"] : "", + group: + json["OsztalyCsoport"] != null ? json["OsztalyCsoport"]["Uid"] : "", json: json, ); } } -enum Justification { excused, unexcused, pending } \ No newline at end of file +enum Justification { excused, unexcused, pending } diff --git a/filcnaplo_kreta_api/lib/providers/absence_provider.dart b/filcnaplo_kreta_api/lib/providers/absence_provider.dart index c683447..6450953 100644 --- a/filcnaplo_kreta_api/lib/providers/absence_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/absence_provider.dart @@ -27,7 +27,10 @@ class AbsenceProvider with ChangeNotifier { // Load absences from the database if (userId != null) { - var dbAbsences = await Provider.of(_context, listen: false).userQuery.getAbsences(userId: userId); + var dbAbsences = + await Provider.of(_context, listen: false) + .userQuery + .getAbsences(userId: userId); _absences = dbAbsences; await convertBySettings(); } @@ -36,12 +39,26 @@ class AbsenceProvider with ChangeNotifier { // for renamed subjects Future convertBySettings() async { final _database = Provider.of(_context, listen: false); - Map renamedSubjects = (await _database.query.getSettings(_database)).renamedSubjectsEnabled - ? await _database.userQuery.renamedSubjects(userId: Provider.of(_context, listen: false).user!.id) - : {}; + Map renamedSubjects = + (await _database.query.getSettings(_database)).renamedSubjectsEnabled + ? await _database.userQuery.renamedSubjects( + userId: + Provider.of(_context, listen: false).user!.id) + : {}; + Map renamedTeachers = + (await _database.query.getSettings(_database)).renamedTeachersEnabled + ? await _database.userQuery.renamedTeachers( + userId: + Provider.of(_context, listen: false).user!.id) + : {}; for (Absence absence in _absences) { - absence.subject.renamedTo = renamedSubjects.isNotEmpty ? renamedSubjects[absence.subject.id] : null; + absence.subject.renamedTo = renamedSubjects.isNotEmpty + ? renamedSubjects[absence.subject.id] + : null; + absence.teacher.renamedTo = renamedTeachers.isNotEmpty + ? renamedTeachers[absence.teacher.id] + : null; } notifyListeners(); @@ -53,9 +70,11 @@ class AbsenceProvider with ChangeNotifier { if (user == null) throw "Cannot fetch Absences for User null"; String iss = user.instituteCode; - List? absencesJson = await Provider.of(_context, listen: false).getAPI(KretaAPI.absences(iss)); + List? absencesJson = await Provider.of(_context, listen: false) + .getAPI(KretaAPI.absences(iss)); if (absencesJson == null) throw "Cannot fetch Absences for User ${user.id}"; - List absences = absencesJson.map((e) => Absence.fromJson(e)).toList(); + List absences = + absencesJson.map((e) => Absence.fromJson(e)).toList(); if (absences.isNotEmpty || _absences.isNotEmpty) await store(absences); } @@ -66,7 +85,9 @@ class AbsenceProvider with ChangeNotifier { if (user == null) throw "Cannot store Absences for User null"; String userId = user.id; - await Provider.of(_context, listen: false).userStore.storeAbsences(absences, userId: userId); + await Provider.of(_context, listen: false) + .userStore + .storeAbsences(absences, userId: userId); _absences = absences; await convertBySettings(); } diff --git a/filcnaplo_kreta_api/lib/providers/grade_provider.dart b/filcnaplo_kreta_api/lib/providers/grade_provider.dart index b86c440..de33a64 100644 --- a/filcnaplo_kreta_api/lib/providers/grade_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/grade_provider.dart @@ -83,10 +83,15 @@ class GradeProvider with ChangeNotifier { Map renamedSubjects = _settings.renamedSubjectsEnabled ? await _database.userQuery.renamedSubjects(userId: _user.user!.id) : {}; + Map renamedTeachers = _settings.renamedTeachersEnabled + ? await _database.userQuery.renamedTeachers(userId: _user.user!.id) + : {}; for (Grade grade in _grades) { grade.subject.renamedTo = renamedSubjects.isNotEmpty ? renamedSubjects[grade.subject.id] : null; + grade.teacher.renamedTo = + renamedTeachers.isNotEmpty ? renamedTeachers[grade.teacher.id] : null; grade.value.value = _settings.goodStudent ? 5 : grade.json!["SzamErtek"] ?? 0; diff --git a/filcnaplo_kreta_api/lib/providers/homework_provider.dart b/filcnaplo_kreta_api/lib/providers/homework_provider.dart index 34cde5a..8f5fa4d 100644 --- a/filcnaplo_kreta_api/lib/providers/homework_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/homework_provider.dart @@ -48,11 +48,18 @@ class HomeworkProvider with ChangeNotifier { (await _database.query.getSettings(_database)).renamedSubjectsEnabled ? await _database.userQuery.renamedSubjects(userId: _user.id!) : {}; + Map renamedTeachers = + (await _database.query.getSettings(_database)).renamedTeachersEnabled + ? await _database.userQuery.renamedTeachers(userId: _user.id!) + : {}; for (Homework homework in _homework) { homework.subject.renamedTo = renamedSubjects.isNotEmpty ? renamedSubjects[homework.subject.id] : null; + homework.teacher.renamedTo = renamedTeachers.isNotEmpty + ? renamedTeachers[homework.teacher.id] + : null; } notifyListeners(); diff --git a/filcnaplo_kreta_api/lib/providers/timetable_provider.dart b/filcnaplo_kreta_api/lib/providers/timetable_provider.dart index fdd35d1..841a35f 100644 --- a/filcnaplo_kreta_api/lib/providers/timetable_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/timetable_provider.dart @@ -40,11 +40,18 @@ class TimetableProvider with ChangeNotifier { (await _database.query.getSettings(_database)).renamedSubjectsEnabled ? await _database.userQuery.renamedSubjects(userId: _user.id!) : {}; + Map renamedTeachers = + (await _database.query.getSettings(_database)).renamedTeachersEnabled + ? await _database.userQuery.renamedTeachers(userId: _user.id!) + : {}; for (Lesson lesson in _lessons.values.expand((e) => e)) { lesson.subject.renamedTo = renamedSubjects.isNotEmpty ? renamedSubjects[lesson.subject.id] : null; + lesson.teacher.renamedTo = renamedTeachers.isNotEmpty + ? renamedTeachers[lesson.teacher.id] + : null; } notifyListeners(); diff --git a/filcnaplo_mobile_ui/lib/common/widgets/absence/absence_view.dart b/filcnaplo_mobile_ui/lib/common/widgets/absence/absence_view.dart index ef9c006..23ec169 100755 --- a/filcnaplo_mobile_ui/lib/common/widgets/absence/absence_view.dart +++ b/filcnaplo_mobile_ui/lib/common/widgets/absence/absence_view.dart @@ -17,19 +17,23 @@ import 'package:provider/provider.dart'; import 'absence_view.i18n.dart'; class AbsenceView extends StatelessWidget { - const AbsenceView(this.absence, {Key? key, this.outsideContext, this.viewable = false}) : super(key: key); + const AbsenceView(this.absence, + {Key? key, this.outsideContext, this.viewable = false}) + : super(key: key); final Absence absence; final BuildContext? outsideContext; final bool viewable; static show(Absence absence, {required BuildContext context}) { - showBottomCard(context: context, child: AbsenceView(absence, outsideContext: context)); + showBottomCard( + context: context, child: AbsenceView(absence, outsideContext: context)); } @override Widget build(BuildContext context) { - Color color = AbsenceTile.justificationColor(absence.state, context: context); + Color color = + AbsenceTile.justificationColor(absence.state, context: context); SettingsProvider settingsProvider = Provider.of(context); return Padding( @@ -41,7 +45,8 @@ class AbsenceView extends StatelessWidget { ListTile( visualDensity: VisualDensity.compact, contentPadding: const EdgeInsets.only(left: 16.0, right: 12.0), - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0)), leading: Container( width: 44.0, height: 44.0, @@ -60,10 +65,18 @@ class AbsenceView extends StatelessWidget { absence.subject.renamedTo ?? absence.subject.name.capital(), maxLines: 2, overflow: TextOverflow.ellipsis, - style: TextStyle(fontWeight: FontWeight.w700, fontStyle: absence.subject.isRenamed && settingsProvider.renamedSubjectsItalics ? FontStyle.italic : null), + style: TextStyle( + fontWeight: FontWeight.w700, + fontStyle: absence.subject.isRenamed && + settingsProvider.renamedSubjectsItalics + ? FontStyle.italic + : null), ), subtitle: Text( - absence.teacher, + (absence.teacher.isRenamed + ? absence.teacher.renamedTo + : absence.teacher.name) ?? + '', // DateFormat("MM. dd. (EEEEE)", I18n.of(context).locale.toString()).format(absence.date), style: const TextStyle(fontWeight: FontWeight.w500), ), @@ -77,12 +90,15 @@ class AbsenceView extends StatelessWidget { if (absence.delay > 0) Detail( title: "delay".i18n, - description: absence.delay.toString() + " " + "minutes".i18n.plural(absence.delay), + description: absence.delay.toString() + + " " + + "minutes".i18n.plural(absence.delay), ), if (absence.lessonIndex != null) Detail( title: "Lesson".i18n, - description: "${absence.lessonIndex}. (${absence.lessonStart.format(context, timeOnly: true)}" + description: + "${absence.lessonIndex}. (${absence.lessonStart.format(context, timeOnly: true)}" " - " "${absence.lessonEnd.format(context, timeOnly: true)})", ), @@ -91,13 +107,19 @@ class AbsenceView extends StatelessWidget { title: "Excuse".i18n, description: absence.justification?.description ?? "", ), - if (absence.mode != null) Detail(title: "Mode".i18n, description: absence.mode?.description ?? ""), - Detail(title: "Submit date".i18n, description: absence.submitDate.format(context)), + if (absence.mode != null) + Detail( + title: "Mode".i18n, + description: absence.mode?.description ?? ""), + Detail( + title: "Submit date".i18n, + description: absence.submitDate.format(context)), // Show in timetable if (!viewable) Padding( - padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 6.0, top: 12.0), + padding: const EdgeInsets.only( + left: 16.0, right: 16.0, bottom: 6.0, top: 12.0), child: PanelActionButton( leading: const Icon(FeatherIcons.calendar), title: Text( @@ -109,12 +131,15 @@ class AbsenceView extends StatelessWidget { Navigator.of(context).pop(); if (outsideContext != null) { - ReverseSearch.getLessonByAbsence(absence, context).then((lesson) { + ReverseSearch.getLessonByAbsence(absence, context) + .then((lesson) { if (lesson != null) { TimetablePage.jump(outsideContext!, lesson: lesson); } else { - ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar( - content: Text("Cannot find lesson".i18n, style: const TextStyle(color: Colors.white)), + ScaffoldMessenger.of(context) + .showSnackBar(CustomSnackBar( + content: Text("Cannot find lesson".i18n, + style: const TextStyle(color: Colors.white)), backgroundColor: AppColors.of(context).red, context: context, ));