Skip to content

Commit

Permalink
Merge branch 'main' into prod/festapp
Browse files Browse the repository at this point in the history
  • Loading branch information
miakh committed Nov 6, 2024
2 parents ec2a505 + eb417eb commit 5662ee2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 46 deletions.
4 changes: 3 additions & 1 deletion lib/pages/AdministrationOccasion/ColumnHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ class ColumnHelper {
return columns;
},
ACCOMMODATION: (Map<String, dynamic> data) {
var select = data[DbOccasions.serviceTypeAccommodation]?.map((a)=>a.code).toList();
select.add("");
return [
PlutoColumn(
title: "Accommodation".tr(),
field: DbOccasions.serviceTypeAccommodation,
type: PlutoColumnType.select(data[DbOccasions.serviceTypeAccommodation]?.map((a)=>a.code).toList()),
type: PlutoColumnType.select(select),
applyFormatterInEditing: true,
enableEditingMode: true,
width: 100
Expand Down
62 changes: 41 additions & 21 deletions lib/pages/AdministrationOccasion/ServiceTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _ServiceTabState extends State<ServiceTab> {

List<ServiceItemModel>? allFood;
List<ServiceItemModel>? allAccommodation;
Key refreshKey = UniqueKey();

@override
void initState() {
Expand All @@ -49,32 +50,45 @@ class _ServiceTabState extends State<ServiceTab> {
setState(() {
allAccommodation = aa;
allFood = af;
refreshKey = UniqueKey();
});
}

@override
Widget build(BuildContext context) {
return allFood == null
? Center(child: CircularProgressIndicator()) // Show a loading indicator while food data is loading
: SingleTableDataGrid<OccasionUserModel>(
context,
DbUsers.getOccasionUsersServiceTab,
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.none,
Tb.occasion_users.user,
actionsExtended: DataGridActionsController(
areAllActionsEnabled: RightsService.canUpdateUsers,
isAddActionPossible: () => false),
headerChildren: [
DataGridAction(name: "Accommodation settings".tr(), action: (SingleTableDataGrid p0, [_]) => _accommodationDefinition(p0)),
DataGridAction(name: "Food settings".tr(), action: (SingleTableDataGrid p0, [_]) => _foodDefinition(p0)),
],
columns: ColumnHelper.generateColumns(columnIdentifiers, data: {ColumnHelper.FOOD: allFood, ColumnHelper.ACCOMMODATION: allAccommodation}),
).DataGrid();
return KeyedSubtree(
key: refreshKey,
child: allFood == null
? Center(child: CircularProgressIndicator())
: SingleTableDataGrid<OccasionUserModel>(
context,
DbUsers.getOccasionUsersServiceTab,
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.none,
Tb.occasion_users.user,
actionsExtended: DataGridActionsController(
areAllActionsEnabled: RightsService.canUpdateUsers,
isAddActionPossible: () => false),
headerChildren: [
DataGridAction(
name: "Accommodation settings".tr(),
action: (SingleTableDataGrid p0, [_]) =>
_accommodationDefinition(p0)),
DataGridAction(
name: "Food settings".tr(),
action: (SingleTableDataGrid p0, [_]) =>
_foodDefinition(p0)),
],
columns: ColumnHelper.generateColumns(columnIdentifiers, data: {
ColumnHelper.FOOD: allFood,
ColumnHelper.ACCOMMODATION: allAccommodation
}),
).DataGrid(),
);
}

_accommodationDefinition(SingleTableDataGrid<IPlutoRowModel> p0) {
showDialog(
_accommodationDefinition(SingleTableDataGrid<IPlutoRowModel> p0) async {
await showDialog(
context: context,
builder: (BuildContext context) {
return ServiceDialog(
Expand All @@ -85,10 +99,13 @@ class _ServiceTabState extends State<ServiceTab> {
);
},
);

// Reload data and trigger a full page rebuild
await loadData();
}

_foodDefinition(SingleTableDataGrid<IPlutoRowModel> p0) {
showDialog(
_foodDefinition(SingleTableDataGrid<IPlutoRowModel> p0) async {
await showDialog(
context: context,
builder: (BuildContext context) {
return ServiceDialog(
Expand All @@ -99,5 +116,8 @@ class _ServiceTabState extends State<ServiceTab> {
);
},
);

// Reload data and trigger a full page rebuild
await loadData();
}
}
52 changes: 28 additions & 24 deletions lib/pages/AdministrationOccasion/UsersTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _UsersTabState extends State<UsersTab> {
];

List<UserInfoModel> _allUsers = [];
Key refreshKey = UniqueKey(); // Initialize the refresh key

@override
void initState() {
Expand All @@ -49,34 +50,38 @@ class _UsersTabState extends State<UsersTab> {

Future<void> loadUsers() async {
_allUsers = await DbUsers.getAllUsersBasics();
setState(() {});
setState(() {
refreshKey = UniqueKey(); // Update the key to force a full rebuild
});
}

@override
Widget build(BuildContext context) {
return SingleTableDataGrid<OccasionUserModel>(
context,
DbUsers.getOccasionUsers,
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.deleteAndCheck,
Tb.occasion_users.user,
actionsExtended: DataGridActionsController(areAllActionsEnabled: RightsService.canUpdateUsers),
headerChildren: [
DataGridAction(name: "Import".tr(), action: (SingleTableDataGrid p0, [_]) => _import(p0)),
DataGridAction(name: "Add existing".tr(), action: (SingleTableDataGrid p0, [_]) => _addExisting(p0)),
DataGridAction(name: "Invite".tr(), action: (SingleTableDataGrid p0, [_]) => _invite(p0)),
DataGridAction(name: "Change password".tr(), action: (SingleTableDataGrid p0, [_]) => _setPassword(p0)),
DataGridAction(name: "Add to group".tr(), action: (SingleTableDataGrid p0, [_]) => _addToGroup(p0)),
],
columns: ColumnHelper.generateColumns(columnIdentifiers),
).DataGrid();
return KeyedSubtree(
key: refreshKey,
child: SingleTableDataGrid<OccasionUserModel>(
context,
DbUsers.getOccasionUsers,
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.deleteAndCheck,
Tb.occasion_users.user,
actionsExtended: DataGridActionsController(areAllActionsEnabled: RightsService.canUpdateUsers),
headerChildren: [
DataGridAction(name: "Import".tr(), action: (SingleTableDataGrid p0, [_]) => _import(p0)),
DataGridAction(name: "Add existing".tr(), action: (SingleTableDataGrid p0, [_]) => _addExisting(p0)),
DataGridAction(name: "Invite".tr(), action: (SingleTableDataGrid p0, [_]) => _invite(p0)),
DataGridAction(name: "Change password".tr(), action: (SingleTableDataGrid p0, [_]) => _setPassword(p0)),
DataGridAction(name: "Add to group".tr(), action: (SingleTableDataGrid p0, [_]) => _addToGroup(p0)),
],
columns: ColumnHelper.generateColumns(columnIdentifiers),
).DataGrid(),
);
}


// Actions (import, invite, change password, add to group, add existing)
Future<void> _import(SingleTableDataGrid dataGrid) async {
await UserManagementHelper.import(context);
await dataGrid.reloadData();
await loadUsers(); // Reload users and force rebuild
}

Future<void> _invite(SingleTableDataGrid dataGrid) async {
Expand Down Expand Up @@ -107,12 +112,11 @@ class _UsersTabState extends State<UsersTab> {
var nonAdded = _allUsers.where((u) => !_getCheckedUsers(dataGrid).any((cu) => cu.user == u.id)).toList();
DialogHelper.chooseUser(context, (chosenUser) async {
if (chosenUser != null) {
await DbUsers.addUserToOccasion(chosenUser.id, RightsService.currentOccasion!);
ToastHelper.Show(context, "Updated {item}.".tr(namedArgs: {"item": chosenUser.toString()}));
await DbUsers.addUserToOccasion(chosenUser.id, RightsService.currentOccasion!);
ToastHelper.Show(context, "Updated {item}.".tr(namedArgs: {"item": chosenUser.toString()}));
await loadUsers(); // Reload users and force rebuild
}
}, nonAdded, "Add".tr());

await dataGrid.reloadData();
}

List<OccasionUserModel> _getCheckedUsers(SingleTableDataGrid dataGrid) {
Expand All @@ -132,7 +136,7 @@ class _UsersTabState extends State<UsersTab> {
await DbUsers.updateOccasionUser(user);
ToastHelper.Show(context, "Invited: {user}.".tr(namedArgs: {"user": user.data![Tb.occasion_users.data_email]}));
}
await dataGrid.reloadData();
await loadUsers(); // Reload users and force rebuild
}
}
}

0 comments on commit 5662ee2

Please sign in to comment.