forked from firka/student-legacy
actually finished teacher rename
This commit is contained in:
parent
ded029e4cb
commit
6003f6fd2a
@ -1,5 +1,6 @@
|
|||||||
import "category.dart";
|
import "category.dart";
|
||||||
import "subject.dart";
|
import "subject.dart";
|
||||||
|
import "teacher.dart";
|
||||||
|
|
||||||
class Absence {
|
class Absence {
|
||||||
Map? json;
|
Map? json;
|
||||||
@ -7,7 +8,7 @@ class Absence {
|
|||||||
DateTime date;
|
DateTime date;
|
||||||
int delay;
|
int delay;
|
||||||
DateTime submitDate;
|
DateTime submitDate;
|
||||||
String teacher;
|
Teacher teacher;
|
||||||
Justification state;
|
Justification state;
|
||||||
Category? justification;
|
Category? justification;
|
||||||
Category? type;
|
Category? type;
|
||||||
@ -41,8 +42,12 @@ class Absence {
|
|||||||
DateTime lessonEnd;
|
DateTime lessonEnd;
|
||||||
int? lessonIndex;
|
int? lessonIndex;
|
||||||
if (json["Ora"] != null) {
|
if (json["Ora"] != null) {
|
||||||
lessonStart = json["Ora"]["KezdoDatum"] != null ? DateTime.parse(json["Ora"]["KezdoDatum"]).toLocal() : DateTime(0);
|
lessonStart = json["Ora"]["KezdoDatum"] != null
|
||||||
lessonEnd = json["Ora"]["VegDatum"] != null ? DateTime.parse(json["Ora"]["VegDatum"]).toLocal() : DateTime(0);
|
? 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"];
|
lessonIndex = json["Ora"]["Oraszam"];
|
||||||
} else {
|
} else {
|
||||||
lessonStart = DateTime(0);
|
lessonStart = DateTime(0);
|
||||||
@ -51,23 +56,30 @@ class Absence {
|
|||||||
|
|
||||||
return Absence(
|
return Absence(
|
||||||
id: json["Uid"],
|
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,
|
delay: json["KesesPercben"] ?? 0,
|
||||||
submitDate: json["KeszitesDatuma"] != null ? DateTime.parse(json["KeszitesDatuma"]).toLocal() : DateTime(0),
|
submitDate: json["KeszitesDatuma"] != null
|
||||||
teacher: (json["RogzitoTanarNeve"] ?? "").trim(),
|
? DateTime.parse(json["KeszitesDatuma"]).toLocal()
|
||||||
|
: DateTime(0),
|
||||||
|
teacher: Teacher.fromString((json["RogzitoTanarNeve"] ?? "").trim()),
|
||||||
state: json["IgazolasAllapota"] == "Igazolt"
|
state: json["IgazolasAllapota"] == "Igazolt"
|
||||||
? Justification.excused
|
? Justification.excused
|
||||||
: json["IgazolasAllapota"] == "Igazolando"
|
: json["IgazolasAllapota"] == "Igazolando"
|
||||||
? Justification.pending
|
? Justification.pending
|
||||||
: Justification.unexcused,
|
: 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,
|
type: json["Tipus"] != null ? Category.fromJson(json["Tipus"]) : null,
|
||||||
mode: json["Mod"] != null ? Category.fromJson(json["Mod"]) : null,
|
mode: json["Mod"] != null ? Category.fromJson(json["Mod"]) : null,
|
||||||
subject: Subject.fromJson(json["Tantargy"] ?? {}),
|
subject: Subject.fromJson(json["Tantargy"] ?? {}),
|
||||||
lessonStart: lessonStart,
|
lessonStart: lessonStart,
|
||||||
lessonEnd: lessonEnd,
|
lessonEnd: lessonEnd,
|
||||||
lessonIndex: lessonIndex,
|
lessonIndex: lessonIndex,
|
||||||
group: json["OsztalyCsoport"] != null ? json["OsztalyCsoport"]["Uid"] : "",
|
group:
|
||||||
|
json["OsztalyCsoport"] != null ? json["OsztalyCsoport"]["Uid"] : "",
|
||||||
json: json,
|
json: json,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,10 @@ class AbsenceProvider with ChangeNotifier {
|
|||||||
|
|
||||||
// Load absences from the database
|
// Load absences from the database
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
var dbAbsences = await Provider.of<DatabaseProvider>(_context, listen: false).userQuery.getAbsences(userId: userId);
|
var dbAbsences =
|
||||||
|
await Provider.of<DatabaseProvider>(_context, listen: false)
|
||||||
|
.userQuery
|
||||||
|
.getAbsences(userId: userId);
|
||||||
_absences = dbAbsences;
|
_absences = dbAbsences;
|
||||||
await convertBySettings();
|
await convertBySettings();
|
||||||
}
|
}
|
||||||
@ -36,12 +39,26 @@ class AbsenceProvider with ChangeNotifier {
|
|||||||
// for renamed subjects
|
// for renamed subjects
|
||||||
Future<void> convertBySettings() async {
|
Future<void> convertBySettings() async {
|
||||||
final _database = Provider.of<DatabaseProvider>(_context, listen: false);
|
final _database = Provider.of<DatabaseProvider>(_context, listen: false);
|
||||||
Map<String, String> renamedSubjects = (await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
Map<String, String> renamedSubjects =
|
||||||
? await _database.userQuery.renamedSubjects(userId: Provider.of<UserProvider>(_context, listen: false).user!.id)
|
(await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
||||||
: {};
|
? await _database.userQuery.renamedSubjects(
|
||||||
|
userId:
|
||||||
|
Provider.of<UserProvider>(_context, listen: false).user!.id)
|
||||||
|
: {};
|
||||||
|
Map<String, String> renamedTeachers =
|
||||||
|
(await _database.query.getSettings(_database)).renamedTeachersEnabled
|
||||||
|
? await _database.userQuery.renamedTeachers(
|
||||||
|
userId:
|
||||||
|
Provider.of<UserProvider>(_context, listen: false).user!.id)
|
||||||
|
: {};
|
||||||
|
|
||||||
for (Absence absence in _absences) {
|
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();
|
notifyListeners();
|
||||||
@ -53,9 +70,11 @@ class AbsenceProvider with ChangeNotifier {
|
|||||||
if (user == null) throw "Cannot fetch Absences for User null";
|
if (user == null) throw "Cannot fetch Absences for User null";
|
||||||
String iss = user.instituteCode;
|
String iss = user.instituteCode;
|
||||||
|
|
||||||
List? absencesJson = await Provider.of<KretaClient>(_context, listen: false).getAPI(KretaAPI.absences(iss));
|
List? absencesJson = await Provider.of<KretaClient>(_context, listen: false)
|
||||||
|
.getAPI(KretaAPI.absences(iss));
|
||||||
if (absencesJson == null) throw "Cannot fetch Absences for User ${user.id}";
|
if (absencesJson == null) throw "Cannot fetch Absences for User ${user.id}";
|
||||||
List<Absence> absences = absencesJson.map((e) => Absence.fromJson(e)).toList();
|
List<Absence> absences =
|
||||||
|
absencesJson.map((e) => Absence.fromJson(e)).toList();
|
||||||
|
|
||||||
if (absences.isNotEmpty || _absences.isNotEmpty) await store(absences);
|
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";
|
if (user == null) throw "Cannot store Absences for User null";
|
||||||
String userId = user.id;
|
String userId = user.id;
|
||||||
|
|
||||||
await Provider.of<DatabaseProvider>(_context, listen: false).userStore.storeAbsences(absences, userId: userId);
|
await Provider.of<DatabaseProvider>(_context, listen: false)
|
||||||
|
.userStore
|
||||||
|
.storeAbsences(absences, userId: userId);
|
||||||
_absences = absences;
|
_absences = absences;
|
||||||
await convertBySettings();
|
await convertBySettings();
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,15 @@ class GradeProvider with ChangeNotifier {
|
|||||||
Map<String, String> renamedSubjects = _settings.renamedSubjectsEnabled
|
Map<String, String> renamedSubjects = _settings.renamedSubjectsEnabled
|
||||||
? await _database.userQuery.renamedSubjects(userId: _user.user!.id)
|
? await _database.userQuery.renamedSubjects(userId: _user.user!.id)
|
||||||
: {};
|
: {};
|
||||||
|
Map<String, String> renamedTeachers = _settings.renamedTeachersEnabled
|
||||||
|
? await _database.userQuery.renamedTeachers(userId: _user.user!.id)
|
||||||
|
: {};
|
||||||
|
|
||||||
for (Grade grade in _grades) {
|
for (Grade grade in _grades) {
|
||||||
grade.subject.renamedTo =
|
grade.subject.renamedTo =
|
||||||
renamedSubjects.isNotEmpty ? renamedSubjects[grade.subject.id] : null;
|
renamedSubjects.isNotEmpty ? renamedSubjects[grade.subject.id] : null;
|
||||||
|
grade.teacher.renamedTo =
|
||||||
|
renamedTeachers.isNotEmpty ? renamedTeachers[grade.teacher.id] : null;
|
||||||
|
|
||||||
grade.value.value =
|
grade.value.value =
|
||||||
_settings.goodStudent ? 5 : grade.json!["SzamErtek"] ?? 0;
|
_settings.goodStudent ? 5 : grade.json!["SzamErtek"] ?? 0;
|
||||||
|
@ -48,11 +48,18 @@ class HomeworkProvider with ChangeNotifier {
|
|||||||
(await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
(await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
||||||
? await _database.userQuery.renamedSubjects(userId: _user.id!)
|
? await _database.userQuery.renamedSubjects(userId: _user.id!)
|
||||||
: {};
|
: {};
|
||||||
|
Map<String, String> renamedTeachers =
|
||||||
|
(await _database.query.getSettings(_database)).renamedTeachersEnabled
|
||||||
|
? await _database.userQuery.renamedTeachers(userId: _user.id!)
|
||||||
|
: {};
|
||||||
|
|
||||||
for (Homework homework in _homework) {
|
for (Homework homework in _homework) {
|
||||||
homework.subject.renamedTo = renamedSubjects.isNotEmpty
|
homework.subject.renamedTo = renamedSubjects.isNotEmpty
|
||||||
? renamedSubjects[homework.subject.id]
|
? renamedSubjects[homework.subject.id]
|
||||||
: null;
|
: null;
|
||||||
|
homework.teacher.renamedTo = renamedTeachers.isNotEmpty
|
||||||
|
? renamedTeachers[homework.teacher.id]
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -40,11 +40,18 @@ class TimetableProvider with ChangeNotifier {
|
|||||||
(await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
(await _database.query.getSettings(_database)).renamedSubjectsEnabled
|
||||||
? await _database.userQuery.renamedSubjects(userId: _user.id!)
|
? await _database.userQuery.renamedSubjects(userId: _user.id!)
|
||||||
: {};
|
: {};
|
||||||
|
Map<String, String> renamedTeachers =
|
||||||
|
(await _database.query.getSettings(_database)).renamedTeachersEnabled
|
||||||
|
? await _database.userQuery.renamedTeachers(userId: _user.id!)
|
||||||
|
: {};
|
||||||
|
|
||||||
for (Lesson lesson in _lessons.values.expand((e) => e)) {
|
for (Lesson lesson in _lessons.values.expand((e) => e)) {
|
||||||
lesson.subject.renamedTo = renamedSubjects.isNotEmpty
|
lesson.subject.renamedTo = renamedSubjects.isNotEmpty
|
||||||
? renamedSubjects[lesson.subject.id]
|
? renamedSubjects[lesson.subject.id]
|
||||||
: null;
|
: null;
|
||||||
|
lesson.teacher.renamedTo = renamedTeachers.isNotEmpty
|
||||||
|
? renamedTeachers[lesson.teacher.id]
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -17,19 +17,23 @@ import 'package:provider/provider.dart';
|
|||||||
import 'absence_view.i18n.dart';
|
import 'absence_view.i18n.dart';
|
||||||
|
|
||||||
class AbsenceView extends StatelessWidget {
|
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 Absence absence;
|
||||||
final BuildContext? outsideContext;
|
final BuildContext? outsideContext;
|
||||||
final bool viewable;
|
final bool viewable;
|
||||||
|
|
||||||
static show(Absence absence, {required BuildContext context}) {
|
static show(Absence absence, {required BuildContext context}) {
|
||||||
showBottomCard(context: context, child: AbsenceView(absence, outsideContext: context));
|
showBottomCard(
|
||||||
|
context: context, child: AbsenceView(absence, outsideContext: context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Color color = AbsenceTile.justificationColor(absence.state, context: context);
|
Color color =
|
||||||
|
AbsenceTile.justificationColor(absence.state, context: context);
|
||||||
SettingsProvider settingsProvider = Provider.of<SettingsProvider>(context);
|
SettingsProvider settingsProvider = Provider.of<SettingsProvider>(context);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
@ -41,7 +45,8 @@ class AbsenceView extends StatelessWidget {
|
|||||||
ListTile(
|
ListTile(
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
contentPadding: const EdgeInsets.only(left: 16.0, right: 12.0),
|
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(
|
leading: Container(
|
||||||
width: 44.0,
|
width: 44.0,
|
||||||
height: 44.0,
|
height: 44.0,
|
||||||
@ -60,10 +65,18 @@ class AbsenceView extends StatelessWidget {
|
|||||||
absence.subject.renamedTo ?? absence.subject.name.capital(),
|
absence.subject.renamedTo ?? absence.subject.name.capital(),
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
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(
|
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),
|
// DateFormat("MM. dd. (EEEEE)", I18n.of(context).locale.toString()).format(absence.date),
|
||||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
@ -77,12 +90,15 @@ class AbsenceView extends StatelessWidget {
|
|||||||
if (absence.delay > 0)
|
if (absence.delay > 0)
|
||||||
Detail(
|
Detail(
|
||||||
title: "delay".i18n,
|
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)
|
if (absence.lessonIndex != null)
|
||||||
Detail(
|
Detail(
|
||||||
title: "Lesson".i18n,
|
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)})",
|
"${absence.lessonEnd.format(context, timeOnly: true)})",
|
||||||
),
|
),
|
||||||
@ -91,13 +107,19 @@ class AbsenceView extends StatelessWidget {
|
|||||||
title: "Excuse".i18n,
|
title: "Excuse".i18n,
|
||||||
description: absence.justification?.description ?? "",
|
description: absence.justification?.description ?? "",
|
||||||
),
|
),
|
||||||
if (absence.mode != null) Detail(title: "Mode".i18n, description: absence.mode?.description ?? ""),
|
if (absence.mode != null)
|
||||||
Detail(title: "Submit date".i18n, description: absence.submitDate.format(context)),
|
Detail(
|
||||||
|
title: "Mode".i18n,
|
||||||
|
description: absence.mode?.description ?? ""),
|
||||||
|
Detail(
|
||||||
|
title: "Submit date".i18n,
|
||||||
|
description: absence.submitDate.format(context)),
|
||||||
|
|
||||||
// Show in timetable
|
// Show in timetable
|
||||||
if (!viewable)
|
if (!viewable)
|
||||||
Padding(
|
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(
|
child: PanelActionButton(
|
||||||
leading: const Icon(FeatherIcons.calendar),
|
leading: const Icon(FeatherIcons.calendar),
|
||||||
title: Text(
|
title: Text(
|
||||||
@ -109,12 +131,15 @@ class AbsenceView extends StatelessWidget {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
if (outsideContext != null) {
|
if (outsideContext != null) {
|
||||||
ReverseSearch.getLessonByAbsence(absence, context).then((lesson) {
|
ReverseSearch.getLessonByAbsence(absence, context)
|
||||||
|
.then((lesson) {
|
||||||
if (lesson != null) {
|
if (lesson != null) {
|
||||||
TimetablePage.jump(outsideContext!, lesson: lesson);
|
TimetablePage.jump(outsideContext!, lesson: lesson);
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
|
ScaffoldMessenger.of(context)
|
||||||
content: Text("Cannot find lesson".i18n, style: const TextStyle(color: Colors.white)),
|
.showSnackBar(CustomSnackBar(
|
||||||
|
content: Text("Cannot find lesson".i18n,
|
||||||
|
style: const TextStyle(color: Colors.white)),
|
||||||
backgroundColor: AppColors.of(context).red,
|
backgroundColor: AppColors.of(context).red,
|
||||||
context: context,
|
context: context,
|
||||||
));
|
));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user