Added api for custom timetable events
This commit is contained in:
@ -1,151 +0,0 @@
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:rrule_generator/rrule_generator.dart';
|
||||
|
||||
class AddCustomTimetableEventDialog extends StatefulWidget {
|
||||
const AddCustomTimetableEventDialog({super.key});
|
||||
|
||||
@override
|
||||
State<AddCustomTimetableEventDialog> createState() => _AddCustomTimetableEventDialogState();
|
||||
}
|
||||
|
||||
class _AddCustomTimetableEventDialogState extends State<AddCustomTimetableEventDialog> {
|
||||
DateTime _date = DateTime.now();
|
||||
TimeOfDay _starTime = TimeOfDay.now().replacing(minute: 00);
|
||||
TimeOfDay _endTime = TimeOfDay.now().replacing(minute: 30);
|
||||
final TextEditingController _eventName = TextEditingController();
|
||||
final TextEditingController _eventDescription = TextEditingController();
|
||||
String _recurringRule = "";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
insetPadding: const EdgeInsets.all(20),
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
title: const Text('Termin hinzufügen'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: TextField(
|
||||
controller: _eventName,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Terminname",
|
||||
border: OutlineInputBorder()
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: TextField(
|
||||
controller: _eventDescription,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Beschreibung",
|
||||
border: OutlineInputBorder()
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: Text(Jiffy.parseFromDateTime(_date).yMMMd),
|
||||
subtitle: const Text("Datum"),
|
||||
onTap: () async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _date,
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
if (pickedDate != null && pickedDate != _date) {
|
||||
setState(() {
|
||||
_date = pickedDate;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(_starTime.format(context).toString()),
|
||||
subtitle: const Text("Beginnend"),
|
||||
onTap: () async {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: _starTime,
|
||||
);
|
||||
if(pickedTime == null) return;
|
||||
setState(() {
|
||||
_starTime = pickedTime;
|
||||
});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text(_endTime.format(context).toString()),
|
||||
subtitle: const Text("Endend"),
|
||||
onTap: () async {
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: _endTime,
|
||||
);
|
||||
if (pickedTime != null && pickedTime != _endTime) {
|
||||
setState(() {
|
||||
_endTime = pickedTime;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
RRuleGenerator(
|
||||
config: RRuleGeneratorConfig(
|
||||
headerEnabled: true,
|
||||
weekdayBackgroundColor: Theme.of(context).colorScheme.secondary,
|
||||
weekdaySelectedBackgroundColor: Theme.of(context).primaryColor,
|
||||
weekdayColor: Colors.black,
|
||||
),
|
||||
initialRRule: _recurringRule,
|
||||
textDelegate: const GermanRRuleTextDelegate(),
|
||||
onChange: (String newValue) {
|
||||
log("Rule: $newValue");
|
||||
setState(() {
|
||||
_recurringRule = newValue;
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Abbrechen'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// Hier kannst du die Eingaben verwenden
|
||||
String startDate = '${_date.day}/${_date.month}/${_date.year}';
|
||||
String startTime = '${_starTime.hour}:${_starTime.minute}';
|
||||
String endTime = '${_endTime.hour}:${_endTime.minute}';
|
||||
String eventName = _eventName.text;
|
||||
String recurringFrequency = _recurringRule;
|
||||
|
||||
// Hier kannst du die Daten speichern oder weiterverarbeiten
|
||||
print('Startdatum: $startDate');
|
||||
print('Startzeit: $startTime');
|
||||
print('Endzeit: $endTime');
|
||||
print('Terminname: $eventName');
|
||||
|
||||
// Hier könntest du die Termindaten weiterverarbeiten, z.B. speichern und den Dialog schließen
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Hinzufügen'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ class _AppointmentComponentState extends State<AppointmentComponent> {
|
||||
FittedBox(
|
||||
fit: BoxFit.fitWidth,
|
||||
child: Text(
|
||||
meeting.location ?? "-",
|
||||
(meeting.location == null || meeting.location!.isEmpty ? " " : meeting.location!),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
softWrap: true,
|
||||
|
@ -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()),
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
23
lib/view/pages/timetable/arbitraryAppointment.dart
Normal file
23
lib/view/pages/timetable/arbitraryAppointment.dart
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
import '../../../api/mhsl/customTimetableEvent/customTimetableEvent.dart';
|
||||
import '../../../api/webuntis/queries/getTimetable/getTimetableResponse.dart';
|
||||
|
||||
class ArbitraryAppointment {
|
||||
GetTimetableResponseObject? webuntis;
|
||||
CustomTimetableEvent? custom;
|
||||
|
||||
ArbitraryAppointment({this.webuntis, this.custom}) {}
|
||||
|
||||
bool hasWebuntis() {
|
||||
return webuntis != null;
|
||||
}
|
||||
|
||||
bool hasCustom() {
|
||||
return custom != null;
|
||||
}
|
||||
|
||||
void handlers(void Function(GetTimetableResponseObject webuntisData) webuntis, void Function(CustomTimetableEvent customData) custom) {
|
||||
if(hasWebuntis()) webuntis(this.webuntis!);
|
||||
if(hasCustom()) custom(this.custom!);
|
||||
}
|
||||
}
|
199
lib/view/pages/timetable/customTimetableEventEditDialog.dart
Normal file
199
lib/view/pages/timetable/customTimetableEventEditDialog.dart
Normal file
@ -0,0 +1,199 @@
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/extensions/dateTime.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:rrule_generator/rrule_generator.dart';
|
||||
import 'package:time_range_picker/time_range_picker.dart';
|
||||
|
||||
import '../../../api/mhsl/customTimetableEvent/add/addCustomTimetableEvent.dart';
|
||||
import '../../../api/mhsl/customTimetableEvent/add/addCustomTimetableEventParams.dart';
|
||||
import '../../../api/mhsl/customTimetableEvent/customTimetableEvent.dart';
|
||||
import '../../../api/mhsl/customTimetableEvent/update/updateCustomTimetableEvent.dart';
|
||||
import '../../../api/mhsl/customTimetableEvent/update/updateCustomTimetableEventParams.dart';
|
||||
import '../../../model/accountData.dart';
|
||||
import '../../../model/timetable/timetableProps.dart';
|
||||
import '../../../widget/infoDialog.dart';
|
||||
|
||||
class CustomTimetableEventEditDialog extends StatefulWidget {
|
||||
final CustomTimetableEvent? existingEvent;
|
||||
const CustomTimetableEventEditDialog({this.existingEvent, super.key});
|
||||
|
||||
@override
|
||||
State<CustomTimetableEventEditDialog> createState() => _AddCustomTimetableEventDialogState();
|
||||
}
|
||||
|
||||
class _AddCustomTimetableEventDialogState extends State<CustomTimetableEventEditDialog> {
|
||||
late DateTime _date = widget.existingEvent?.startDate ?? DateTime.now();
|
||||
late TimeOfDay _startTime = widget.existingEvent?.startDate.toTimeOfDay() ?? const TimeOfDay(hour: 08, minute: 00);
|
||||
late TimeOfDay _endTime = widget.existingEvent?.endDate.toTimeOfDay() ?? const TimeOfDay(hour: 09, minute: 30);
|
||||
late final TextEditingController _eventName = TextEditingController(text: widget.existingEvent?.title);
|
||||
late final TextEditingController _eventDescription = TextEditingController(text: widget.existingEvent?.description);
|
||||
late String _recurringRule = widget.existingEvent?.rrule ?? "";
|
||||
|
||||
late bool isEditingExisting = widget.existingEvent != null;
|
||||
|
||||
bool validate() {
|
||||
if(_eventName.text.isEmpty) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void fetchTimetable() {
|
||||
Provider.of<TimetableProps>(context, listen: false).run(renew: true);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
insetPadding: const EdgeInsets.all(20),
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
title: const Text('Termin hinzufügen'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: TextField(
|
||||
controller: _eventName,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Terminname",
|
||||
border: OutlineInputBorder()
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: TextField(
|
||||
controller: _eventDescription,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Beschreibung",
|
||||
border: OutlineInputBorder()
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: Text(Jiffy.parseFromDateTime(_date).yMMMd),
|
||||
subtitle: const Text("Datum"),
|
||||
onTap: () async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _date,
|
||||
firstDate: DateTime.now().subtract(const Duration(days: 30)),
|
||||
lastDate: DateTime.now().add(const Duration(days: 30)),
|
||||
);
|
||||
if (pickedDate != null && pickedDate != _date) {
|
||||
setState(() {
|
||||
_date = pickedDate;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text("${_startTime.format(context).toString()} - ${_endTime.format(context).toString()}"),
|
||||
subtitle: const Text("Zeitraum"),
|
||||
onTap: () async {
|
||||
TimeRange timeRange = await showTimeRangePicker(
|
||||
context: context,
|
||||
start: _startTime,
|
||||
end: _endTime,
|
||||
disabledTime: TimeRange(startTime: const TimeOfDay(hour: 16, minute: 30), endTime: const TimeOfDay(hour: 08, minute: 00)),
|
||||
disabledColor: Colors.grey,
|
||||
paintingStyle: PaintingStyle.fill,
|
||||
interval: const Duration(minutes: 5),
|
||||
fromText: "Beginnend",
|
||||
toText: "Endend",
|
||||
strokeColor: Theme.of(context).colorScheme.secondary,
|
||||
minDuration: const Duration(minutes: 45),
|
||||
selectedColor: Theme.of(context).primaryColor,
|
||||
ticks: 24,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_startTime = timeRange.startTime;
|
||||
_endTime = timeRange.endTime;
|
||||
});
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
RRuleGenerator(
|
||||
config: RRuleGeneratorConfig(
|
||||
headerEnabled: true,
|
||||
weekdayBackgroundColor: Theme.of(context).colorScheme.secondary,
|
||||
weekdaySelectedBackgroundColor: Theme.of(context).primaryColor,
|
||||
weekdayColor: Colors.black,
|
||||
),
|
||||
initialRRule: _recurringRule,
|
||||
textDelegate: const GermanRRuleTextDelegate(),
|
||||
onChange: (String newValue) {
|
||||
log("Rule: $newValue");
|
||||
setState(() {
|
||||
_recurringRule = newValue;
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Abbrechen'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if(!validate()) return;
|
||||
|
||||
CustomTimetableEvent editedEvent = CustomTimetableEvent(
|
||||
id: "",
|
||||
title: _eventName.text,
|
||||
description: _eventDescription.text,
|
||||
startDate: _date.withTime(_startTime),
|
||||
endDate: _date.withTime(_endTime),
|
||||
rrule: _recurringRule,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
if(!isEditingExisting) {
|
||||
AddCustomTimetableEvent(
|
||||
AddCustomTimetableEventParams(
|
||||
AccountData().getUserSecret(),
|
||||
editedEvent
|
||||
)
|
||||
).run().then((value) {
|
||||
Navigator.of(context).pop();
|
||||
fetchTimetable();
|
||||
})
|
||||
.catchError((error, stack) {
|
||||
InfoDialog.show(context, error.toString());
|
||||
});
|
||||
} else {
|
||||
UpdateCustomTimetableEvent(
|
||||
UpdateCustomTimetableEventParams(
|
||||
widget.existingEvent?.id ?? "",
|
||||
editedEvent
|
||||
)
|
||||
).run().then((value) {
|
||||
Navigator.of(context).pop();
|
||||
fetchTimetable();
|
||||
})
|
||||
.catchError((error, stack) {
|
||||
InfoDialog.show(context, error.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
child: Text(isEditingExisting ? "Speichern" : "Erstellen"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/extensions/dateTime.dart';
|
||||
import 'package:marianum_mobile/view/pages/timetable/addCustomTimetableEventDialog.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
@ -17,6 +16,8 @@ import '../../../widget/loadingSpinner.dart';
|
||||
import '../../../widget/placeholderView.dart';
|
||||
import 'appointmenetComponent.dart';
|
||||
import 'appointmentDetails.dart';
|
||||
import 'arbitraryAppointment.dart';
|
||||
import 'customTimetableEventEditDialog.dart';
|
||||
import 'timeRegionComponent.dart';
|
||||
import 'timetableEvents.dart';
|
||||
|
||||
@ -70,7 +71,7 @@ class _TimetableState extends State<Timetable> {
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => const AddCustomTimetableEventDialog(),
|
||||
builder: (context) => const CustomTimetableEventEditDialog(),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
},
|
||||
@ -232,7 +233,7 @@ class _TimetableState extends State<Timetable> {
|
||||
DateTime startTime = _parseWebuntisTimestamp(element.date, element.startTime);
|
||||
DateTime endTime = _parseWebuntisTimestamp(element.date, element.endTime);
|
||||
return Appointment(
|
||||
id: element,
|
||||
id: ArbitraryAppointment(webuntis: element),
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
subject: subjects.result.firstWhere((subject) => subject.id == element.su[0].id).name,
|
||||
@ -246,7 +247,7 @@ class _TimetableState extends State<Timetable> {
|
||||
} catch(e) {
|
||||
DateTime endTime = _parseWebuntisTimestamp(element.date, element.endTime);
|
||||
return Appointment(
|
||||
id: element,
|
||||
id: ArbitraryAppointment(webuntis: element),
|
||||
startTime: _parseWebuntisTimestamp(element.date, element.startTime),
|
||||
endTime: endTime,
|
||||
subject: "Änderung",
|
||||
@ -259,6 +260,20 @@ class _TimetableState extends State<Timetable> {
|
||||
}
|
||||
}).toList();
|
||||
|
||||
appointments.addAll(data.getCustomTimetableEventResponse.events.map((customEvent) {
|
||||
return Appointment(
|
||||
id: ArbitraryAppointment(custom: customEvent),
|
||||
startTime: customEvent.startDate,
|
||||
endTime: customEvent.endDate,
|
||||
location: customEvent.description,
|
||||
subject: customEvent.title,
|
||||
recurrenceRule: customEvent.rrule,
|
||||
color: Colors.deepOrange,
|
||||
startTimeZone: '',
|
||||
endTimeZone: '',
|
||||
);
|
||||
}));
|
||||
|
||||
return TimetableEvents(appointments);
|
||||
}
|
||||
|
||||
@ -288,8 +303,10 @@ class _TimetableState extends State<Timetable> {
|
||||
}
|
||||
|
||||
bool _isCrossedOut(CalendarAppointmentDetails calendarEntry) {
|
||||
GetTimetableResponseObject webuntisElement = (calendarEntry.appointments.first.id as GetTimetableResponseObject);
|
||||
|
||||
return webuntisElement.code == "cancelled";
|
||||
ArbitraryAppointment appointment = calendarEntry.appointments.first.id as ArbitraryAppointment;
|
||||
if(appointment.hasWebuntis()) {
|
||||
return appointment.webuntis!.code == "cancelled";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user