forked from firka/firka
feat: omissions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:firka/ui/phone/pages/home/home_omissions.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firka/core/firka_bundle.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
@@ -177,6 +178,20 @@ GoRouter createAppRouter() {
|
||||
),
|
||||
],
|
||||
),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/omissions',
|
||||
pageBuilder: (context, state) => NoTransitionPage(
|
||||
key: state.pageKey,
|
||||
child: DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: HomeOmissionsScreen(initData),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -57,6 +57,11 @@ class ShellWithNavBar extends StatelessWidget {
|
||||
Majesticon.calendarSolid,
|
||||
Majesticon.calendarLine,
|
||||
),
|
||||
(
|
||||
initData.l10n.omissions,
|
||||
Majesticon.timerSolid,
|
||||
Majesticon.timerLine,
|
||||
),
|
||||
].indexed.map(
|
||||
(nav) => BottomNavIconWidget(
|
||||
() {
|
||||
|
||||
@@ -245,6 +245,119 @@ Future<void> showLessonBottomSheet(
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> showOmissionBottomSheet(
|
||||
BuildContext context,
|
||||
AppInitialization data,
|
||||
String description,
|
||||
List<Omission> omissions,
|
||||
) async {
|
||||
showFirkaBottomSheet(context, [
|
||||
Text(
|
||||
omissions.first.date.format(data.l10n, FormatMode.yyyymmdd),
|
||||
style: appStyle.fonts.H_18px.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
description,
|
||||
style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textSecondary),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
LimitedBox(
|
||||
maxHeight: 336,
|
||||
child: ListView.builder(
|
||||
itemCount: omissions.length,
|
||||
itemBuilder: (b, i) {
|
||||
final o = omissions[i];
|
||||
return FirkaCard.single(
|
||||
height: 64,
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
padding: EdgeInsets.only(left: 14, right: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/subtract.svg",
|
||||
color: appStyle.colors.a15p,
|
||||
width: 18,
|
||||
height: 18,
|
||||
),
|
||||
Text(
|
||||
o.lesson!.classNo?.toString() ?? "-",
|
||||
style: appStyle.fonts.B_14SB.apply(
|
||||
color: appStyle.colors.secondary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
FilledCircle(
|
||||
diameter: 36,
|
||||
color: appStyle.colors.a15p,
|
||||
child: ClassIconWidget(
|
||||
uid: o.subject.uid,
|
||||
className: o.subject.name,
|
||||
category: o.subject.name,
|
||||
color: appStyle.colors.accent,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
o.subject.name,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
o.teacher,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
o.lesson!.start.format(data.l10n, FormatMode.hmm),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
o.lesson!.end.format(data.l10n, FormatMode.hmm),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> showTestBottomSheet(
|
||||
BuildContext context,
|
||||
AppInitialization data,
|
||||
|
||||
@@ -45,6 +45,7 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
List<Test>? tests;
|
||||
List<Grade>? grades;
|
||||
List<Homework>? homework;
|
||||
List<Omission>? omissions;
|
||||
Student? student;
|
||||
Timer? timer;
|
||||
|
||||
@@ -66,6 +67,7 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
var testsFetched = 0;
|
||||
var gradesFetched = 0;
|
||||
var homeworkFetched = 0;
|
||||
var omissionFetched = 0;
|
||||
|
||||
widget.data.client
|
||||
.getTimeTableStream(
|
||||
@@ -139,6 +141,18 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
}
|
||||
});
|
||||
|
||||
widget.data.client.getOmissionsStream(cacheOnly: cacheOnly).forEach((
|
||||
omission,
|
||||
) {
|
||||
omissionFetched++;
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
this.omissions = omission.response;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
widget.data.client.getHomeworkStream(cacheOnly: cacheOnly).forEach((
|
||||
homework,
|
||||
) {
|
||||
@@ -161,7 +175,8 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
studentFetched < r ||
|
||||
testsFetched < r ||
|
||||
gradesFetched < r ||
|
||||
homeworkFetched < r) {
|
||||
homeworkFetched < r ||
|
||||
omissionFetched < r) {
|
||||
if (DateTime.now().difference(startTime) > maxWaitTime) {
|
||||
debugPrint('[HomeMain] Data fetch timed out after 30s');
|
||||
break;
|
||||
@@ -198,6 +213,7 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
final gradeItems = grades ?? [];
|
||||
final testItems = tests ?? [];
|
||||
final homeworkItems = homework ?? [];
|
||||
final omissionItems = omissions?.groupList((o) => o.date).values ?? [];
|
||||
final noticeBoardWidgets = <(Widget, DateTime)>[];
|
||||
|
||||
for (final item in infoItems) {
|
||||
@@ -216,6 +232,13 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
|
||||
noticeBoardWidgets.add((InfoCard.homework(entry), entry.creationDate));
|
||||
}
|
||||
|
||||
for (final omission in omissionItems) {
|
||||
noticeBoardWidgets.add((
|
||||
InfoCard.omission(omission),
|
||||
omission.first.date,
|
||||
));
|
||||
}
|
||||
|
||||
noticeBoardWidgets.sort(
|
||||
(item1, item2) => item2.$2.difference(item1.$2).inMilliseconds,
|
||||
);
|
||||
|
||||
324
firka/lib/ui/phone/pages/home/home_omissions.dart
Normal file
324
firka/lib/ui/phone/pages/home/home_omissions.dart
Normal file
@@ -0,0 +1,324 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/ui/phone/widgets/info_card.dart';
|
||||
import 'package:firka/ui/phone/widgets/omission_bar.dart';
|
||||
import 'package:firka_common/firka_common.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
import 'package:firka/ui/phone/widgets/grade_chart.dart';
|
||||
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
||||
import 'package:firka/ui/shared/grade_small_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:firka/api/consts.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/bloc/home_refresh_cubit.dart';
|
||||
import 'package:firka/core/settings.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka/ui/shared/delayed_spinner.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
class HomeOmissionsScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
|
||||
const HomeOmissionsScreen(this.data, {super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HomeOmissionsScreen();
|
||||
}
|
||||
|
||||
class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
|
||||
ApiResponse<List<Omission>>? omissions;
|
||||
|
||||
void _onRefreshRequested(BuildContext context) async {
|
||||
final cubit = context.read<HomeRefreshCubit>();
|
||||
omissions = await widget.data.client.getOmissions(forceCache: false);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
cubit.onRefreshComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
(() async {
|
||||
omissions = await widget.data.client.getOmissions(forceCache: false);
|
||||
if (mounted) setState(() {});
|
||||
})();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<HomeRefreshCubit, HomeRefreshState>(
|
||||
listenWhen: (previous, current) =>
|
||||
current.refreshTrigger != previous.refreshTrigger,
|
||||
listener: (context, state) {
|
||||
_onRefreshRequested(context);
|
||||
},
|
||||
child: _buildContent(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
if (omissions == null) {
|
||||
return Center(child: DelayedSpinnerWidget());
|
||||
}
|
||||
|
||||
final omissionItems = omissions!.response ?? [];
|
||||
|
||||
final overallExcused = omissionItems
|
||||
.where((o) => o.state == OmissionState.excused)
|
||||
.length;
|
||||
|
||||
final overallUnexcused = omissionItems
|
||||
.where((o) => o.state == OmissionState.unexcused)
|
||||
.length;
|
||||
|
||||
final overallPending = omissionItems
|
||||
.where((o) => o.state == OmissionState.pending)
|
||||
.length;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.data.l10n.subjects,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Expanded(
|
||||
child: FirkaCard.single(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.clipboardCheckSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
Text(
|
||||
overallExcused.toString(),
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
initData.l10n.omission_state_excused,
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: FirkaCard.single(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.timerSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.warningAccent,
|
||||
),
|
||||
Text(
|
||||
overallPending.toString(),
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.warningAccent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
initData.l10n.omission_state_pending,
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: FirkaCard.single(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.restrictedSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.errorAccent,
|
||||
),
|
||||
Text(
|
||||
overallUnexcused.toString(),
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.errorAccent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
initData.l10n.omission_state_unexcused,
|
||||
style: appStyle.fonts.B_16R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
OmissionBar(omissions: omissions!.response!),
|
||||
SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
Text(
|
||||
initData.l10n.subjects,
|
||||
style: appStyle.fonts.B_16SB.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
...omissionItems
|
||||
.fold(
|
||||
LinkedHashMap<Subject, List<Omission>>(
|
||||
equals: (a, b) => a.uid == b.uid,
|
||||
hashCode: (a) => a.uid.hashCode,
|
||||
),
|
||||
(map, o) =>
|
||||
map
|
||||
..putIfAbsent(o.subject, () => <Omission>[]).add(o),
|
||||
)
|
||||
.entries
|
||||
.map((entry) {
|
||||
final excused = entry.value
|
||||
.where((o) => o.state == OmissionState.excused)
|
||||
.length;
|
||||
|
||||
final unexcused = entry.value
|
||||
.where((o) => o.state == OmissionState.unexcused)
|
||||
.length;
|
||||
|
||||
final pending = entry.value
|
||||
.where((o) => o.state == OmissionState.pending)
|
||||
.length;
|
||||
|
||||
return FirkaCard.single(
|
||||
height: 64,
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
spacing: 12,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
InfoCard.buildSubject(
|
||||
appStyle.colors.accent,
|
||||
entry.key,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 2,
|
||||
children: [
|
||||
Text(
|
||||
entry.key.name,
|
||||
style: appStyle.fonts.B_16SB.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Row(
|
||||
spacing: 4,
|
||||
children: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.clipboardCheckSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
Text(
|
||||
excused.toString(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.timerSolid,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.warningAccent,
|
||||
),
|
||||
Text(
|
||||
pending.toString(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.restrictedLine,
|
||||
size: 12.0,
|
||||
color: appStyle.colors.errorAccent,
|
||||
),
|
||||
Text(
|
||||
unexcused.toString(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ class _HomeTimetableMonthlyScreen
|
||||
omission.subject.uid == omittedLesson.subject?.uid;
|
||||
});
|
||||
|
||||
if (omission?.state == "Igazolt") {
|
||||
if (omission?.state == OmissionState.excused) {
|
||||
body = Center(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
@@ -242,7 +242,7 @@ class _HomeTimetableMonthlyScreen
|
||||
break;
|
||||
}
|
||||
|
||||
if (omission?.lateForMin != null) {
|
||||
if (omission?.state == OmissionState.pending) {
|
||||
body = Center(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka_common/ui/components/filled_circle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
@@ -104,6 +105,31 @@ class InfoCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.omission(List<Omission> omissions) {
|
||||
String title = "-";
|
||||
for (final state in [
|
||||
OmissionState.pending,
|
||||
OmissionState.unexcused,
|
||||
OmissionState.excused,
|
||||
]) {
|
||||
final count = omissions.where((o) => o.state == state).length;
|
||||
title = initData.l10n.omissions_count(state.name, count);
|
||||
}
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
diameter: 36,
|
||||
color: appStyle.colors.a15p,
|
||||
child: SizedBox(),
|
||||
),
|
||||
texts: [
|
||||
title,
|
||||
DateFormat.MMMMd(initData.l10n.localeName).format(omissions.first.date),
|
||||
],
|
||||
onTap: (context) =>
|
||||
showOmissionBottomSheet(context, initData, title, omissions),
|
||||
);
|
||||
}
|
||||
|
||||
factory InfoCard.homework(Homework homework) {
|
||||
return InfoCard(
|
||||
icon: FilledCircle(
|
||||
|
||||
@@ -42,12 +42,10 @@ class LessonWidget extends StatelessWidget {
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("substitution");
|
||||
final showLessonNos =
|
||||
lesson.lessonNumber != null &&
|
||||
data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("lesson_no");
|
||||
final showLessonNos = data.settings
|
||||
.group("settings")
|
||||
.subGroup("timetable_toast")
|
||||
.boolean("lesson_no");
|
||||
final isDismissed = lesson.type.name == "UresOra";
|
||||
|
||||
var accent = appStyle.colors.accent;
|
||||
@@ -115,7 +113,7 @@ class LessonWidget extends StatelessWidget {
|
||||
height: 18,
|
||||
),
|
||||
Text(
|
||||
lesson.lessonNumber!.toString(),
|
||||
lesson.lessonNumber?.toString() ?? "-",
|
||||
style: appStyle.fonts.B_14SB.apply(
|
||||
color: secondary,
|
||||
),
|
||||
|
||||
87
firka/lib/ui/phone/widgets/omission_bar.dart
Normal file
87
firka/lib/ui/phone/widgets/omission_bar.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/ui/components/firka_card.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/ui/components/grade.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
|
||||
import 'package:firka/l10n/app_localizations.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class OmissionBar extends StatelessWidget {
|
||||
final List<Omission> omissions;
|
||||
|
||||
const OmissionBar({super.key, required this.omissions});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime start = now.copyWith(month: 9, day: 1);
|
||||
DateTime startOfTheYear = now.isBefore(start)
|
||||
? start.subtract(Duration(days: 365))
|
||||
: start;
|
||||
|
||||
Map<int, Color> dayToColor = omissions.fold(
|
||||
Map.identity(),
|
||||
(map, o) => map
|
||||
..putIfAbsent(
|
||||
o.date.difference(startOfTheYear).inDays,
|
||||
() => o.state == OmissionState.excused
|
||||
? appStyle.colors.accent
|
||||
: o.state == OmissionState.unexcused
|
||||
? appStyle.colors.errorAccent
|
||||
: appStyle.colors.warningAccent,
|
||||
),
|
||||
);
|
||||
|
||||
final bar = ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Row(
|
||||
children: List.generate(now.difference(startOfTheYear).inDays, (i) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
height: 12,
|
||||
color: dayToColor[i] ?? appStyle.colors.a15p,
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return FirkaCard.single(
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 8,
|
||||
children: [
|
||||
bar,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
DateFormat.MMMM(
|
||||
initData.l10n.localeName,
|
||||
).format(startOfTheYear).firstUpper(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
initData.l10n.now,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,21 @@ import 'subject.dart';
|
||||
|
||||
class Omission extends UidObj {
|
||||
final Subject subject;
|
||||
final Class? c;
|
||||
final OmittedLesson? lesson;
|
||||
final DateTime date;
|
||||
final String teacher;
|
||||
final NameUidDesc? type;
|
||||
final NameUidDesc? mode;
|
||||
final int? lateForMin;
|
||||
final DateTime createdAt;
|
||||
final String state;
|
||||
final OmissionState state;
|
||||
final NameUidDesc? proofType;
|
||||
final UidObj? classGroup;
|
||||
|
||||
const Omission({
|
||||
required super.uid,
|
||||
required this.subject,
|
||||
required this.c,
|
||||
required this.lesson,
|
||||
required this.date,
|
||||
required this.teacher,
|
||||
this.type,
|
||||
@@ -34,14 +34,14 @@ class Omission extends UidObj {
|
||||
return Omission(
|
||||
uid: json['Uid'],
|
||||
subject: Subject.fromJson(json['Tantargy']),
|
||||
c: json['Osztaly'] != null ? Class.fromJson(json['Osztaly']) : null,
|
||||
lesson: json['Ora'] != null ? OmittedLesson.fromJson(json['Ora']) : null,
|
||||
date: json.localDate('Datum')!,
|
||||
teacher: json['RogzitoTanarNeve'],
|
||||
type: json.nameUidDesc('Tipus'),
|
||||
mode: json.nameUidDesc('Mod'),
|
||||
lateForMin: json['KesesPercben'],
|
||||
createdAt: json.localDate('KeszitesDatuma')!,
|
||||
state: json['IgazolasAllapota'],
|
||||
state: OmissionState.fromString(json['IgazolasAllapota']),
|
||||
proofType: json.nameUidDesc('IgazolasTipusa'),
|
||||
classGroup: json.uid('OsztalyCsoport'),
|
||||
);
|
||||
@@ -52,7 +52,7 @@ class Omission extends UidObj {
|
||||
return 'Omission('
|
||||
'uid: "$uid", '
|
||||
'subject: $subject, '
|
||||
'c: $c, '
|
||||
'c: $lesson, '
|
||||
'date: $date, '
|
||||
'teacher: "$teacher", '
|
||||
'type: $type, '
|
||||
@@ -66,15 +66,39 @@ class Omission extends UidObj {
|
||||
}
|
||||
}
|
||||
|
||||
class Class {
|
||||
enum OmissionState {
|
||||
excused("Igazolt"),
|
||||
unexcused("Igazolatlan"),
|
||||
pending("Igazolando"),
|
||||
unknown("");
|
||||
|
||||
final String key;
|
||||
const OmissionState(this.key);
|
||||
|
||||
static fromString(String string) {
|
||||
for (final state in OmissionState.values) {
|
||||
if (state.key == string) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
print("Unknown omission state: ${string}");
|
||||
return OmissionState.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
class OmittedLesson {
|
||||
final DateTime start;
|
||||
final DateTime end;
|
||||
final int classNo;
|
||||
final int? classNo;
|
||||
|
||||
const Class({required this.start, required this.end, required this.classNo});
|
||||
const OmittedLesson({
|
||||
required this.start,
|
||||
required this.end,
|
||||
required this.classNo,
|
||||
});
|
||||
|
||||
factory Class.fromJson(Map<String, dynamic> json) {
|
||||
return Class(
|
||||
factory OmittedLesson.fromJson(Map<String, dynamic> json) {
|
||||
return OmittedLesson(
|
||||
start: json.localDate('KezdoDatum')!,
|
||||
end: json.localDate('VegDatum')!,
|
||||
classNo: json['Oraszam'],
|
||||
@@ -83,7 +107,7 @@ class Class {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Class('
|
||||
return 'OmittedLesson('
|
||||
'start: "$start", '
|
||||
'end: "$end", '
|
||||
'classNo: $classNo'
|
||||
|
||||
Reference in New Issue
Block a user