Skip to content

Commit 1328f14

Browse files
client+server: delete goal method, refactoring and improving layout in learning support feature
1 parent da6759b commit 1328f14

15 files changed

Lines changed: 512 additions & 420 deletions

File tree

school_data_hub_client/lib/src/protocol/client.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,19 @@ class EndpointLearningSupportPlan extends _i1.EndpointRef {
12471247
},
12481248
);
12491249

1250+
_i2.Future<_i5.PupilData> deleteCategoryGoal(
1251+
int pupilId,
1252+
int supportGoalId,
1253+
) =>
1254+
caller.callServerEndpoint<_i5.PupilData>(
1255+
'learningSupportPlan',
1256+
'deleteCategoryGoal',
1257+
{
1258+
'pupilId': pupilId,
1259+
'supportGoalId': supportGoalId,
1260+
},
1261+
);
1262+
12501263
_i2.Future<_i30.SupportGoal> postSupportGoalCheck(
12511264
int supportGoalId,
12521265
int score,

school_data_hub_flutter/lib/features/learning_support/data/learning_support_api_service.dart

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -131,33 +131,19 @@ class LearningSupportApiService {
131131

132132
//- delete category goal
133133

134-
// String _deleteGoalUrl(String goalId) {
135-
// return '/support_goals/$goalId/delete';
136-
// }
137-
138-
// Future deleteGoal(String goalId) async {
139-
// _notificationService.apiRunning(true);
140-
141-
// final Response response = await _client.delete(
142-
// '${_baseUrl()}${_deleteGoalUrl(goalId)}',
143-
// options: _client.hubOptions,
144-
// );
145-
146-
// if (response.statusCode != 200) {
147-
// _notificationService.showSnackBar(
148-
// NotificationType.error, 'Fehler beim Löschen des Ziels');
149-
150-
// _notificationService.apiRunning(false);
151-
152-
// throw ApiException('Failed to delete category goal', response.statusCode);
153-
// }
154-
155-
// final PupilData pupil = PupilData.fromJson(response.data);
156-
157-
// _notificationService.apiRunning(false);
158-
159-
// return pupil;
160-
// }
134+
Future<PupilData?> deleteCategoryGoal({
135+
required int pupilId,
136+
required int supportGoalId,
137+
}) async {
138+
final updatedPupil = await ClientHelper.apiCall(
139+
call: () => _client.learningSupportPlan.deleteCategoryGoal(
140+
pupilId,
141+
supportGoalId,
142+
),
143+
errorMessage: 'Fehler beim Löschen des Ziels',
144+
);
145+
return updatedPupil;
146+
}
161147

162148
//- BULK IMPORT SUPPORT LEVELS ------------------------------------------
163149

school_data_hub_flutter/lib/features/learning_support/domain/learning_support_helper.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,20 @@ class LearningSupportHelper {
6969
}
7070
}
7171

72-
// static List<SupportGoal> getGoalsForCategory(
73-
// PupilProxy pupil, int categoryId) {
74-
// List<SupportGoal> goals = [];
75-
// if (pupil.supportGoals != null) {
76-
// for (SupportGoal goal in pupil.supportGoals!) {
77-
// if (goal.supportCategoryId == categoryId) {
78-
// goals.add(goal);
79-
// }
80-
// return goals;
81-
// }
82-
// }
83-
// return [];
84-
// }
72+
static List<SupportGoal> getGoalsForCategory(
73+
PupilProxy pupil,
74+
int categoryId,
75+
) {
76+
final goals = <SupportGoal>[];
77+
if (pupil.supportGoals != null) {
78+
for (final goal in pupil.supportGoals!) {
79+
if (goal.supportCategoryId == categoryId) {
80+
goals.add(goal);
81+
}
82+
}
83+
}
84+
return goals;
85+
}
8586

8687
// //- TODO: Is this necessary?
8788
// static SupportGoal? getGoalForCategory(PupilProxy pupil, int goalCategoryId) {

school_data_hub_flutter/lib/features/learning_support/domain/learning_support_manager.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,24 @@ class LearningSupportManager {
239239
// return;
240240
// }
241241

242-
// Future deleteGoal(String goalId) async {
243-
// final PupilData responsePupil =
244-
// await _learningSupportApiService.deleteGoal(goalId);
245-
246-
// locator<PupilManager>().updatePupilProxyWithPupilData(responsePupil);
247-
248-
// _notificationService.showSnackBar(
249-
// NotificationType.success, 'Ziel gelöscht');
242+
Future<void> deleteSupportGoal({
243+
required int pupilId,
244+
required int supportGoalId,
245+
}) async {
246+
final updatedPupil = await _learningSupportApiService.deleteCategoryGoal(
247+
pupilId: pupilId,
248+
supportGoalId: supportGoalId,
249+
);
250+
if (updatedPupil == null) {
251+
return;
252+
}
253+
_pupilManager.updatePupilProxyWithPupilData(updatedPupil);
250254

251-
// return;
252-
// }
255+
_notificationService.showSnackBar(
256+
NotificationType.success,
257+
'Ziel gelöscht',
258+
);
259+
}
253260

254261
//- GOAL CHECKS ----------------------------------------------------------
255262

school_data_hub_flutter/lib/features/learning_support/presentation/learning_support_list_page/widgets/learning_support_list_card.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/cus
55
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile_content.dart';
66
import 'package:school_data_hub_flutter/core/models/datetime_extensions.dart';
77
import 'package:school_data_hub_flutter/features/app_main_navigation/domain/main_menu_bottom_nav_manager.dart';
8-
import 'package:school_data_hub_flutter/features/learning_support/presentation/learning_support_list_page/widgets/support_category_status_batches.dart';
8+
import 'package:school_data_hub_flutter/features/learning_support/presentation/learning_support_list_page/widgets/support_goal_batches.dart';
99
import 'package:school_data_hub_flutter/features/learning_support/presentation/learning_support_list_page/widgets/support_goals_list.dart';
1010
import 'package:school_data_hub_flutter/features/pupil/domain/models/pupil_proxy.dart';
1111
import 'package:school_data_hub_flutter/features/pupil/presentation/pupil_profile_page/pupil_profile_page.dart';
@@ -132,7 +132,7 @@ class _LearningSupportCardState extends State<LearningSupportCard> {
132132
? _tileController.collapse()
133133
: _tileController.expand();
134134
},
135-
child: SupportCategoryStatusBatches(pupil: pupil),
135+
child: SupportGoalBatches(pupil: pupil),
136136
),
137137
],
138138
),

school_data_hub_flutter/lib/features/learning_support/presentation/learning_support_list_page/widgets/support_category_status_batches.dart renamed to school_data_hub_flutter/lib/features/learning_support/presentation/learning_support_list_page/widgets/support_goal_batches.dart

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_it/flutter_it.dart';
33
import 'package:gap/gap.dart';
4-
import 'package:school_data_hub_client/school_data_hub_client.dart';
54
import 'package:school_data_hub_flutter/features/learning_support/domain/learning_support_helper.dart';
65
import 'package:school_data_hub_flutter/features/learning_support/domain/support_category_manager.dart';
76
import 'package:school_data_hub_flutter/features/pupil/domain/models/pupil_proxy.dart';
87

9-
class SupportCategoryStatusBatches extends StatelessWidget {
8+
class SupportGoalBatches extends StatelessWidget {
109
final PupilProxy pupil;
11-
const SupportCategoryStatusBatches({super.key, required this.pupil});
10+
const SupportGoalBatches({super.key, required this.pupil});
1211

1312
@override
1413
Widget build(BuildContext context) {
1514
final learningSupportManager = di<SupportCategoryManager>();
16-
List<SupportCategoryStatus> supportCategoryStatuses =
17-
pupil.supportCategoryStatuses!;
15+
final supportGoals = pupil.supportGoals ?? [];
1816
List<Widget> widgetList = [];
1917
Map<int, int> categoryCounts = {};
20-
Set<int> countedCategoryIds = {};
2118

22-
// Calculate counts
23-
for (SupportCategoryStatus supportCategoryStatus
24-
in supportCategoryStatuses) {
25-
if (countedCategoryIds.contains(
26-
supportCategoryStatus.supportCategoryId,
27-
)) {
28-
continue;
29-
}
30-
countedCategoryIds.add(supportCategoryStatus.supportCategoryId);
19+
// Calculate counts of support goals per root category
20+
for (final supportGoal in supportGoals) {
3121
int rootCategoryId = learningSupportManager
32-
.getRootSupportCategory(supportCategoryStatus.supportCategoryId)
22+
.getRootSupportCategory(supportGoal.supportCategoryId)
3323
.categoryId;
34-
if (categoryCounts.containsKey(rootCategoryId)) {
35-
categoryCounts[rootCategoryId] = categoryCounts[rootCategoryId]! + 1;
36-
} else {
37-
categoryCounts[rootCategoryId] = 1;
38-
}
24+
categoryCounts[rootCategoryId] =
25+
(categoryCounts[rootCategoryId] ?? 0) + 1;
3926
}
4027

4128
categoryCounts.forEach((categoryId, count) {
@@ -47,8 +34,8 @@ class SupportCategoryStatusBatches extends StatelessWidget {
4734
mainAxisSize: MainAxisSize.min,
4835
children: [
4936
Container(
50-
width: 35.0,
51-
height: 35.0,
37+
width: 30.0,
38+
height: 30.0,
5239
decoration: BoxDecoration(
5340
color: LearningSupportHelper.getRootSupportCategoryColor(
5441
rootCategory,
@@ -60,15 +47,15 @@ class SupportCategoryStatusBatches extends StatelessWidget {
6047
LearningSupportHelper.getRootSupportCategoryIcon(
6148
rootCategory,
6249
),
63-
width: 40.0,
64-
height: 40.0,
50+
width: 35.0,
51+
height: 35.0,
6552
),
6653
),
6754
),
6855
const Gap(2),
6956
Text(
7057
count.toString(),
71-
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
58+
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.bold),
7259
),
7360
],
7461
),

school_data_hub_flutter/lib/features/learning_support/presentation/new_support_category_status_page/new_support_category_status_page.dart

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_it/flutter_it.dart';
23
import 'package:gap/gap.dart';
34
import 'package:school_data_hub_flutter/common/theme/app_colors.dart';
45
import 'package:school_data_hub_flutter/common/theme/styles.dart';
@@ -10,7 +11,6 @@ import 'package:school_data_hub_flutter/features/learning_support/presentation/w
1011
import 'package:school_data_hub_flutter/features/learning_support/presentation/widgets/support_category_parents_names.dart';
1112
import 'package:school_data_hub_flutter/features/learning_support/presentation/widgets/support_category_widgets/support_category_status_dropdown.dart';
1213
import 'package:school_data_hub_flutter/features/pupil/domain/pupil_proxy_manager.dart';
13-
import 'package:flutter_it/flutter_it.dart';
1414

1515
class NewSupportCategoryStatusPage extends StatelessWidget {
1616
final NewSupportCategoryStatusController controller;
@@ -73,18 +73,21 @@ class NewSupportCategoryStatusPage extends StatelessWidget {
7373
minimumSize: const Size.fromHeight(60),
7474
),
7575
onPressed: () async {
76-
final int?
77-
categoryId = await Navigator.of(context).push(
78-
MaterialPageRoute(
79-
builder: (ctx) => SelectSupportCategoryPage(
80-
pupil: pupilManager.getPupilByPupilId(
81-
controller.widget.pupilId,
82-
)!,
83-
elementType:
84-
controller.widget.elementType,
85-
),
86-
),
87-
);
76+
final int? categoryId =
77+
await Navigator.of(context).push(
78+
MaterialPageRoute(
79+
builder: (ctx) =>
80+
SelectSupportCategoryPage(
81+
pupil: pupilManager
82+
.getPupilByPupilId(
83+
controller.widget.pupilId,
84+
)!,
85+
elementType: controller
86+
.widget
87+
.elementType,
88+
),
89+
),
90+
);
8891
if (categoryId == null) {
8992
return;
9093
}
@@ -95,61 +98,11 @@ class NewSupportCategoryStatusPage extends StatelessWidget {
9598
style: AppStyles.buttonTextStyle,
9699
),
97100
)
98-
: InkWell(
99-
child: Container(
100-
decoration: BoxDecoration(
101-
borderRadius: BorderRadius.circular(5.0),
102-
color: supportCategoryManager
103-
.getCategoryColor(
104-
controller.goalCategoryId!,
105-
),
106-
),
107-
child: Padding(
108-
padding: const EdgeInsets.only(
109-
top: 5.0,
110-
bottom: 8,
111-
),
112-
child: Wrap(
113-
crossAxisAlignment:
114-
WrapCrossAlignment.center,
115-
children: [
116-
...categoryTreeAncestorsNames(
117-
categoryId:
118-
controller.goalCategoryId!,
119-
categoryColor: Colors
120-
.white, //locator<LearningSupportManager>().getCategoryColor(controller.goalCategoryId!),
121-
),
122-
],
123-
),
124-
),
125-
),
101+
: CategoryTreeAncestors(
102+
categoryId: controller.goalCategoryId!,
126103
),
127104
const Gap(5),
128-
controller.goalCategoryId == null
129-
? const SizedBox.shrink()
130-
: controller.goalCategoryId == 0
131-
? const SizedBox.shrink()
132-
: Row(
133-
children: [
134-
Flexible(
135-
child: Text(
136-
supportCategoryManager
137-
.getSupportCategory(
138-
controller.goalCategoryId!,
139-
)
140-
.name,
141-
style: TextStyle(
142-
fontSize: 20,
143-
color: supportCategoryManager
144-
.getCategoryColor(
145-
controller.goalCategoryId!,
146-
),
147-
fontWeight: FontWeight.bold,
148-
),
149-
),
150-
),
151-
],
152-
),
105+
153106
const Gap(5),
154107
Row(
155108
crossAxisAlignment: CrossAxisAlignment.start,

school_data_hub_flutter/lib/features/learning_support/presentation/new_support_goal_page/new_support_goal_page.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,8 @@ class NewSupportGoalPage extends StatelessWidget {
9595
top: 5.0,
9696
bottom: 8,
9797
),
98-
child: Wrap(
99-
crossAxisAlignment: WrapCrossAlignment.center,
100-
alignment: WrapAlignment.center,
101-
children: [
102-
...categoryTreeAncestorsNames(
103-
categoryId: controller.goalCategoryId!,
104-
categoryColor: learningSupportManager
105-
.getCategoryColor(
106-
controller.goalCategoryId!,
107-
),
108-
),
109-
],
98+
child: CategoryTreeAncestors(
99+
categoryId: controller.goalCategoryId!,
110100
),
111101
),
112102
),

0 commit comments

Comments
 (0)