Added api for custom timetable events
This commit is contained in:
@ -4,15 +4,24 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent-tab-view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:rrule/rrule.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
import '../../../api/mhsl/customTimetableEvent/customTimetableEvent.dart';
|
||||
import '../../../api/mhsl/customTimetableEvent/remove/removeCustomTimetableEvent.dart';
|
||||
import '../../../api/mhsl/customTimetableEvent/remove/removeCustomTimetableEventParams.dart';
|
||||
import '../../../api/webuntis/queries/getRooms/getRoomsResponse.dart';
|
||||
import '../../../api/webuntis/queries/getSubjects/getSubjectsResponse.dart';
|
||||
import '../../../api/webuntis/queries/getTimetable/getTimetableResponse.dart';
|
||||
import '../../../model/timetable/timetableProps.dart';
|
||||
import '../../../widget/centeredLeading.dart';
|
||||
import '../../../widget/confirmDialog.dart';
|
||||
import '../../../widget/debug/debugTile.dart';
|
||||
import '../../../widget/unimplementedDialog.dart';
|
||||
import '../more/roomplan/roomplan.dart';
|
||||
import 'arbitraryAppointment.dart';
|
||||
import 'customTimetableEventEditDialog.dart';
|
||||
|
||||
class AppointmentDetails {
|
||||
static String _getEventPrefix(String? code) {
|
||||
@ -22,8 +31,32 @@ class AppointmentDetails {
|
||||
}
|
||||
|
||||
static void show(BuildContext context, TimetableProps webuntisData, Appointment appointment) {
|
||||
GetTimetableResponseObject timetableData = appointment.id as GetTimetableResponseObject;
|
||||
(appointment.id as ArbitraryAppointment).handlers(
|
||||
(webuntis) => _webuntis(context, webuntisData, appointment, webuntis),
|
||||
(customData) => _custom(context, webuntisData, customData)
|
||||
);
|
||||
}
|
||||
|
||||
static void _bottomSheet(
|
||||
BuildContext context,
|
||||
Widget Function(BuildContext context) header,
|
||||
SliverChildListDelegate Function(BuildContext context) body
|
||||
) {
|
||||
showStickyFlexibleBottomSheet(
|
||||
minHeight: 0,
|
||||
initHeight: 0.4,
|
||||
maxHeight: 0.7,
|
||||
anchors: [0, 0.4, 0.7],
|
||||
isSafeArea: true,
|
||||
maxHeaderHeight: 100,
|
||||
|
||||
context: context,
|
||||
headerBuilder: (context, bottomSheetOffset) => header(context),
|
||||
bodyBuilder: (context, bottomSheetOffset) => body(context)
|
||||
);
|
||||
}
|
||||
|
||||
static void _webuntis(BuildContext context, TimetableProps webuntisData, Appointment appointment, GetTimetableResponseObject timetableData) {
|
||||
GetSubjectsResponseObject subject;
|
||||
GetRoomsResponseObject room;
|
||||
|
||||
@ -39,68 +72,155 @@ class AppointmentDetails {
|
||||
room = GetRoomsResponseObject(0, "?", "Unbekannt", true, "?");
|
||||
}
|
||||
|
||||
showStickyFlexibleBottomSheet(
|
||||
minHeight: 0,
|
||||
initHeight: 0.4,
|
||||
maxHeight: 0.7,
|
||||
anchors: [0, 0.4, 0.7],
|
||||
isSafeArea: true,
|
||||
|
||||
maxHeaderHeight: 150,
|
||||
|
||||
context: context,
|
||||
headerBuilder: (context, bottomSheetOffset) => Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("${_getEventPrefix(timetableData.code)}${subject.alternateName} - (${subject.longName})", style: const TextStyle(fontSize: 25), overflow: TextOverflow.ellipsis),
|
||||
Text("${Jiffy.parseFromDateTime(appointment.startTime).format(pattern: "HH:mm")} - ${Jiffy.parseFromDateTime(appointment.endTime).format(pattern: "HH:mm")}", style: const TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
),
|
||||
bodyBuilder: (context, bottomSheetOffset) => SliverChildListDelegate(
|
||||
[
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
title: Text("Status: ${timetableData.code != null ? "Geändert" : "Regulär"}"),
|
||||
_bottomSheet(
|
||||
context,
|
||||
(context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("${_getEventPrefix(timetableData.code)}${subject.alternateName}", textAlign: TextAlign.center, style: const TextStyle(fontSize: 25), overflow: TextOverflow.ellipsis),
|
||||
Text(subject.longName),
|
||||
Text("${Jiffy.parseFromDateTime(appointment.startTime).format(pattern: "HH:mm")} - ${Jiffy.parseFromDateTime(appointment.endTime).format(pattern: "HH:mm")}", style: const TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.room),
|
||||
title: Text("Raum: ${room.name} (${room.longName})"),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.house_outlined),
|
||||
onPressed: () {
|
||||
pushNewScreen(context, withNavBar: false, screen: const Roomplan());
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
(context) {
|
||||
return SliverChildListDelegate(
|
||||
[
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.notifications_active),
|
||||
title: Text("Status: ${timetableData.code != null ? "Geändert" : "Regulär"}"),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: timetableData.te.isNotEmpty
|
||||
? Text("Lehrkraft: ${timetableData.te[0].name} ${timetableData.te[0].longname.isNotEmpty ? "(${timetableData.te[0].longname})" : ""}")
|
||||
: const Text("?"),
|
||||
trailing: Visibility(
|
||||
visible: !kReleaseMode,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.textsms_outlined),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.room),
|
||||
title: Text("Raum: ${room.name} (${room.longName})"),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.house_outlined),
|
||||
onPressed: () {
|
||||
UnimplementedDialog.show(context);
|
||||
pushNewScreen(context, withNavBar: false, screen: const Roomplan());
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: timetableData.te.isNotEmpty
|
||||
? Text("Lehrkraft: ${timetableData.te[0].name} ${timetableData.te[0].longname.isNotEmpty ? "(${timetableData.te[0].longname})" : ""}")
|
||||
: const Text("?"),
|
||||
trailing: Visibility(
|
||||
visible: !kReleaseMode,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.textsms_outlined),
|
||||
onPressed: () {
|
||||
UnimplementedDialog.show(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.abc),
|
||||
title: Text("Typ: ${timetableData.activityType}"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.people),
|
||||
title: Text("Klasse(n): ${timetableData.kl.map((e) => e.name).join(", ")}"),
|
||||
),
|
||||
DebugTile(context).jsonData(timetableData.toJson()),
|
||||
],
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static void _custom(BuildContext context, TimetableProps webuntisData, CustomTimetableEvent appointment) {
|
||||
_bottomSheet(
|
||||
context,
|
||||
(context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(appointment.title, style: const TextStyle(fontSize: 25, overflow: TextOverflow.ellipsis)),
|
||||
Text("${Jiffy.parseFromDateTime(appointment.startDate).format(pattern: "HH:mm")} - ${Jiffy.parseFromDateTime(appointment.endDate).format(pattern: "HH:mm")}", style: const TextStyle(fontSize: 15)),
|
||||
],
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.abc),
|
||||
title: Text("Typ: ${timetableData.activityType}"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.people),
|
||||
title: Text("Klasse(n): ${timetableData.kl.map((e) => e.name).join(", ")}"),
|
||||
),
|
||||
DebugTile(context).jsonData(timetableData.toJson()),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
(context) {
|
||||
return SliverChildListDelegate(
|
||||
[
|
||||
const Divider(),
|
||||
Center(
|
||||
child: Wrap(
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => CustomTimetableEventEditDialog(existingEvent: appointment),
|
||||
);
|
||||
},
|
||||
label: const Text("Bearbeiten"),
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
ConfirmDialog(
|
||||
title: "Termin löschen",
|
||||
content: "Der ${appointment.rrule.isEmpty ? "Termin" : "Serientermin"} wird unwiederruflich gelöscht.",
|
||||
confirmButton: "Löschen",
|
||||
onConfirm: () {
|
||||
RemoveCustomTimetableEvent(
|
||||
RemoveCustomTimetableEventParams(
|
||||
appointment.id
|
||||
)
|
||||
).run().then((value) {
|
||||
Navigator.of(context).pop();
|
||||
Provider.of<TimetableProps>(context, listen: false).run(renew: true);
|
||||
});
|
||||
},
|
||||
).asDialog(context);
|
||||
},
|
||||
label: const Text("Löschen"),
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: Text(appointment.description.isEmpty ? "Keine Beschreibung" : appointment.description),
|
||||
),
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.repeat_outlined)),
|
||||
title: Text("Serie: ${appointment.rrule.isNotEmpty ? "Wiederholend" : "Einmailg"}"),
|
||||
subtitle: FutureBuilder(
|
||||
future: RruleL10nEn.create(),
|
||||
builder: (context, snapshot) {
|
||||
if(appointment.rrule.isEmpty) return const Text("Keine weiteren vorkomnisse");
|
||||
if(snapshot.data == null) return const Text("...");
|
||||
RecurrenceRule rrule = RecurrenceRule.fromString(appointment.rrule);
|
||||
if(!rrule.canFullyConvertToText) return const Text("Keine genauere Angabe möglich.");
|
||||
return Text(rrule.toText(l10n: snapshot.data!));
|
||||
},
|
||||
)
|
||||
),
|
||||
DebugTile(context).child(
|
||||
ListTile(
|
||||
leading: const CenteredLeading(Icon(Icons.rule)),
|
||||
title: const Text("RRule"),
|
||||
subtitle: Text(appointment.rrule),
|
||||
)
|
||||
),
|
||||
DebugTile(context).jsonData(appointment.toJson()),
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user