Skip to content

Commit 8505c56

Browse files
App: Schoolday Events eventTime, refactor settings
1 parent df79baf commit 8505c56

6 files changed

Lines changed: 177 additions & 18 deletions

File tree

school_data_hub_flutter/lib/features/_schoolday_events/data/schoolday_event_api_service.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ class SchooldayEventApiService {
2424
int schooldayId,
2525
DateTime dateTime,
2626
SchooldayEventType type,
27-
String reason,
28-
) async {
27+
String reason, {
28+
String? eventTime,
29+
}) async {
2930
final userName = _hubSessionManager.userName!;
3031
_notificationService.apiRunning(true);
3132
final pupil = di<PupilProxyManager>().getPupilByPupilId(pupilId);
3233
final tutor = pupil?.groupTutor;
3334
try {
34-
final event = await _client.schooldayEvent.createSchooldayEvent(
35+
var event = await _client.schooldayEvent.createSchooldayEvent(
3536
pupilNameAndGroup: pupilName,
3637
dateTimeAsString: dateTime.formatDateForUser(),
3738
pupilId: pupilId,
@@ -42,6 +43,13 @@ class SchooldayEventApiService {
4243
tutor: tutor ?? '',
4344
);
4445

46+
if (eventTime != null) {
47+
event = await updateSchooldayEvent(
48+
schooldayEvent: event,
49+
eventTime: eventTime,
50+
);
51+
}
52+
4553
_notificationService.apiRunning(false);
4654

4755
return event;
@@ -77,11 +85,11 @@ class SchooldayEventApiService {
7785
SchooldayEventType? type,
7886
String? reason,
7987
bool? processed,
80-
//String? file,
8188
NullableStringRecord? processedBy,
8289
NullableDateTimeRecord? processedAt,
8390
int? schooldayId,
8491
NullableStringRecord? comment,
92+
String? eventTime,
8593
}) async {
8694
bool changedProcessedStatus = false;
8795
// if the schooldayEvent is patched as processed,
@@ -115,6 +123,7 @@ class SchooldayEventApiService {
115123
? processedAt.value
116124
: schooldayEvent.processedAt,
117125
comment: comment != null ? comment.value : schooldayEvent.comment,
126+
eventTime: eventTime ?? schooldayEvent.eventTime,
118127
);
119128
final pupil = di<PupilProxyManager>().getPupilByPupilId(
120129
schooldayEvent.pupilId,

school_data_hub_flutter/lib/features/_schoolday_events/domain/schoolday_event_manager.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ class SchooldayEventManager with ChangeNotifier {
118118
int schooldayId,
119119
DateTime dateTime,
120120
SchooldayEventType type,
121-
String reason,
122-
) async {
121+
String reason, {
122+
String? eventTime,
123+
}) async {
123124
final SchooldayEvent
124125
schooldayEvent = await _schooldayEventApiService.postSchooldayEvent(
125126
'${di<PupilProxyManager>().getPupilByPupilId(pupilId)!.firstName} (${di<PupilProxyManager>().getPupilByPupilId(pupilId)!.group})',
@@ -128,6 +129,7 @@ class SchooldayEventManager with ChangeNotifier {
128129
dateTime,
129130
type,
130131
reason,
132+
eventTime: eventTime,
131133
);
132134

133135
_updateSchooldayEventCollections(schooldayEvent);
@@ -167,6 +169,7 @@ class SchooldayEventManager with ChangeNotifier {
167169
NullableDateTimeRecord? processedAt,
168170
int? schooldayId,
169171
NullableStringRecord? comment,
172+
String? eventTime,
170173
}) async {
171174
String? cacheKey;
172175
if (processed == false && eventToUpdate.processedDocumentId != null) {
@@ -183,6 +186,7 @@ class SchooldayEventManager with ChangeNotifier {
183186
schooldayId: schooldayId,
184187
type: schoolEventType,
185188
comment: comment,
189+
eventTime: eventTime,
186190
);
187191

188192
_updateSchooldayEventCollections(schooldayEvent);

school_data_hub_flutter/lib/features/_schoolday_events/presentation/new_schoolday_event_page/new_schoolday_event_page.dart

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class NewSchooldayEventPage extends WatchingWidget {
5757
required bool admonitionInfo,
5858
required bool transitionAdvice,
5959
required bool other,
60+
required String eventTime,
6061
}) async {
6162
Set<String> schooldayEventReason = {};
6263
String schooldayEventReasons = '';
@@ -134,6 +135,7 @@ class NewSchooldayEventPage extends WatchingWidget {
134135
thisDate,
135136
schooldayEventType,
136137
schooldayEventReasons,
138+
eventTime: eventTime,
137139
);
138140
}
139141

@@ -145,6 +147,10 @@ class NewSchooldayEventPage extends WatchingWidget {
145147
final thisDate = createOnce(
146148
() => ValueNotifier<DateTime>(_schoolCalendarManager.thisDate.value),
147149
);
150+
final now = DateTime.now();
151+
final defaultTime =
152+
'${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}';
153+
final eventTime = createOnce(() => ValueNotifier<String>(defaultTime));
148154
final violenceAgainstPupils = createOnce(() => ValueNotifier<bool>(false));
149155
final violenceAgainstTeacher = createOnce(() => ValueNotifier<bool>(false));
150156
final violenceAgainstThings = createOnce(() => ValueNotifier<bool>(false));
@@ -269,6 +275,79 @@ class NewSchooldayEventPage extends WatchingWidget {
269275
],
270276
),
271277
const Gap(5),
278+
const Row(
279+
crossAxisAlignment: CrossAxisAlignment.center,
280+
children: [
281+
Text(
282+
'Uhrzeit',
283+
style: TextStyle(
284+
fontSize: 25,
285+
fontWeight: FontWeight.bold,
286+
),
287+
),
288+
],
289+
),
290+
Row(
291+
children: [
292+
IconButton(
293+
onPressed: () async {
294+
final TimeOfDay? picked = await showTimePicker(
295+
context: context,
296+
initialTime: TimeOfDay(
297+
hour: int.parse(eventTime.value.split(':')[0]),
298+
minute: int.parse(eventTime.value.split(':')[1]),
299+
),
300+
builder: (BuildContext context, Widget? child) {
301+
return MediaQuery(
302+
data: MediaQuery.of(
303+
context,
304+
).copyWith(alwaysUse24HourFormat: true),
305+
child: child!,
306+
);
307+
},
308+
);
309+
if (picked != null) {
310+
eventTime.value =
311+
'${picked.hour.toString().padLeft(2, '0')}:${picked.minute.toString().padLeft(2, '0')}';
312+
}
313+
},
314+
icon: Icon(
315+
Icons.access_time_rounded,
316+
color: AppColors.interactiveColor,
317+
),
318+
),
319+
InkWell(
320+
onTap: () async {
321+
final TimeOfDay? picked = await showTimePicker(
322+
context: context,
323+
initialTime: TimeOfDay(
324+
hour: int.parse(eventTime.value.split(':')[0]),
325+
minute: int.parse(eventTime.value.split(':')[1]),
326+
),
327+
builder: (BuildContext context, Widget? child) {
328+
return MediaQuery(
329+
data: MediaQuery.of(
330+
context,
331+
).copyWith(alwaysUse24HourFormat: true),
332+
child: child!,
333+
);
334+
},
335+
);
336+
if (picked != null) {
337+
eventTime.value =
338+
'${picked.hour.toString().padLeft(2, '0')}:${picked.minute.toString().padLeft(2, '0')}';
339+
}
340+
},
341+
child: Text(
342+
watch(eventTime).value,
343+
style: AppStyles.title.copyWith(
344+
color: AppColors.interactiveColor,
345+
),
346+
),
347+
),
348+
],
349+
),
350+
const Gap(5),
272351
const Text(
273352
'Grund',
274353
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
@@ -480,7 +559,7 @@ class NewSchooldayEventPage extends WatchingWidget {
480559
);
481560
return;
482561
}
483-
unawaited(
562+
unawaited(
484563
postSchooldayEvent(
485564
schooldayEventType: schooldayEventType,
486565
thisDate: thisDate.value,
@@ -499,6 +578,7 @@ class NewSchooldayEventPage extends WatchingWidget {
499578
admonitionInfo: admonitionInfo.value,
500579
transitionAdvice: transitionAdvice.value,
501580
other: other.value,
581+
eventTime: eventTime.value,
502582
),
503583
);
504584
Navigator.pop(context);

school_data_hub_flutter/lib/features/_schoolday_events/presentation/schoolday_event_list_page/widgets/pupil_schoolday_event_card.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,69 @@ class PupilSchooldayEventCard extends StatelessWidget {
114114
fontSize: 20,
115115
),
116116
),
117+
const Gap(10),
118+
isAuthorized
119+
? InkWell(
120+
onTap: () async {
121+
final eventTime =
122+
schooldayEvent.eventTime ?? '00:00';
123+
final TimeOfDay?
124+
picked = await showTimePicker(
125+
context: context,
126+
initialTime: TimeOfDay(
127+
hour: int.parse(
128+
eventTime.split(':')[0],
129+
),
130+
minute: int.parse(
131+
eventTime.split(':')[1],
132+
),
133+
),
134+
builder:
135+
(
136+
BuildContext context,
137+
Widget? child,
138+
) {
139+
return MediaQuery(
140+
data: MediaQuery.of(context)
141+
.copyWith(
142+
alwaysUse24HourFormat:
143+
true,
144+
),
145+
child: child!,
146+
);
147+
},
148+
);
149+
if (picked != null) {
150+
final newEventTime =
151+
'${picked.hour.toString().padLeft(2, '0')}:${picked.minute.toString().padLeft(2, '0')}';
152+
await _schooldayEventManager
153+
.updateSchooldayEvent(
154+
eventToUpdate: schooldayEvent,
155+
eventTime: newEventTime,
156+
);
157+
_notificationService.showSnackBar(
158+
NotificationType.success,
159+
'Uhrzeit erfolgreich geändert!',
160+
);
161+
}
162+
},
163+
child: Text(
164+
schooldayEvent.eventTime ?? '--:--',
165+
style: TextStyle(
166+
color: AppColors.interactiveColor,
167+
fontWeight: FontWeight.bold,
168+
fontSize: 20,
169+
),
170+
),
171+
)
172+
: Text(
173+
schooldayEvent.eventTime ?? '--:--',
174+
style: const TextStyle(
175+
color: Colors.black,
176+
fontWeight: FontWeight.bold,
177+
fontSize: 20,
178+
),
179+
),
117180
const Gap(5),
118181
InkWell(
119182
onLongPress: () {

school_data_hub_flutter/lib/features/app_settings/settings_page/widgets/settings_account_section.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SettingsAccountSection extends AbstractSettingsSection with WatchItMixin {
1919
)!.userInfo!.userName!;
2020
final isTester = di<HubSessionManager>().user!.userFlags.isTester;
2121
final isAdmin = di<HubSessionManager>().isAdmin;
22+
final int userCredit = di<HubSessionManager>().userCredit ?? 0;
2223
return SettingsSection(
2324
title: const Text(
2425
'Konto',
@@ -81,6 +82,14 @@ class SettingsAccountSection extends AbstractSettingsSection with WatchItMixin {
8182
value: const Text('App wird zurückgesetzt!'),
8283
//onPressed:
8384
),
85+
SettingsTile.navigation(
86+
leading: const Icon(Icons.attach_money_rounded),
87+
title: const Text('Guthaben'),
88+
value: Text(
89+
userCredit.toString(),
90+
style: const TextStyle(fontWeight: FontWeight.bold),
91+
),
92+
),
8493
],
8594
);
8695
}

school_data_hub_flutter/lib/features/app_settings/settings_page/widgets/settings_session_section.dart

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class SettingsSessionSection extends AbstractSettingsSection with WatchItMixin {
2525

2626
@override
2727
Widget build(BuildContext context) {
28-
di.allReady();
28+
callOnce((BuildContext context) async {
29+
await di.allReady();
30+
});
31+
2932
final serverName = watchPropertyValue((EnvManager x) => x.activeEnv);
3033
final _cacheManager = di<DefaultCacheManager>();
3134

@@ -38,7 +41,7 @@ class SettingsSessionSection extends AbstractSettingsSection with WatchItMixin {
3841

3942
final locale = AppLocalizations.of(context)!;
4043
final _hubSessionManager = di<HubSessionManager>();
41-
final int userCredit = _hubSessionManager.userCredit ?? 0;
44+
4245
final activeEnv = serverName;
4346
final activeSchemeKey = appColorSchemeKeyFromString(
4447
activeEnv?.colorSchemeKey,
@@ -150,15 +153,6 @@ class SettingsSessionSection extends AbstractSettingsSection with WatchItMixin {
150153
trailing: null,
151154
),
152155

153-
SettingsTile.navigation(
154-
leading: const Icon(Icons.attach_money_rounded),
155-
title: const Text('Guthaben'),
156-
value: Text(
157-
userCredit.toString(),
158-
style: const TextStyle(fontWeight: FontWeight.bold),
159-
),
160-
),
161-
162156
SettingsTile.navigation(
163157
onPressed: (context) async {
164158
final confirm = await confirmationDialog(

0 commit comments

Comments
 (0)