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 5, 2024
2 parents dd51635 + 581adcb commit 5302cbc
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 39 deletions.
21 changes: 11 additions & 10 deletions lib/components/dataGrid/AdministrationHeader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class AdministrationHeader<T extends IPlutoRowModel> extends StatefulWidget {
final PlutoGridStateManager stateManager;
final SingleTableDataGrid dataGrid;
final List<DataGridAction>? headerChildren;
final DataGridExtendedActions? saveExtended;
final DataGridActionsController? saveExtended;

const AdministrationHeader({required this.stateManager, Key? key, required this.fromPlutoJson, required this.loadData, this.headerChildren, this.saveExtended, required this.dataGrid}) : super(key: key);

final T Function(Map<String, dynamic>) fromPlutoJson;
final Future<void> Function() loadData;
@override
_AdministrationHeaderState createState() => _AdministrationHeaderState(fromPlutoJson, loadData, dataGrid, headerChildren: headerChildren, actionsExtended: saveExtended);
_AdministrationHeaderState createState() => _AdministrationHeaderState(fromPlutoJson, loadData, dataGrid, headerChildren: headerChildren, actionsController: saveExtended);

static PlutoGridConfiguration defaultPlutoGridConfiguration(BuildContext context, String langCode) {
return PlutoGridConfiguration(
Expand All @@ -48,10 +48,10 @@ class _AdministrationHeaderState<T extends IPlutoRowModel> extends State<Adminis
final Future<void> Function() loadData;
final SingleTableDataGrid dataGrid;
List<DataGridAction>? headerChildren = [];
final DataGridExtendedActions? actionsExtended;
final DataGridActionsController? actionsController;
List<Widget> allChildren = [];

_AdministrationHeaderState(this.fromPlutoJson, this.loadData, this.dataGrid, {this.headerChildren, this.actionsExtended});
_AdministrationHeaderState(this.fromPlutoJson, this.loadData, this.dataGrid, {this.headerChildren, this.actionsController});

@override
Widget build(BuildContext context) {
Expand All @@ -70,26 +70,27 @@ class _AdministrationHeaderState<T extends IPlutoRowModel> extends State<Adminis
allChildren.insertAll(0, [const VerticalDivider()]);
}
allChildren.insertAll(0, [
if(actionsController?.isAddActionPossible?.call()??true)
ElevatedButton(
onPressed: actionsExtended != null && actionsExtended!.areAllActionsEnabled != null && !actionsExtended!.areAllActionsEnabled!()
onPressed: actionsController != null && actionsController!.areAllActionsEnabled != null && !actionsController!.areAllActionsEnabled!()
? null :
_addRow,
child: const Text("Add").tr(),
),
ElevatedButton(
onPressed: actionsExtended != null && actionsExtended!.areAllActionsEnabled != null && !actionsExtended!.areAllActionsEnabled!()
onPressed: actionsController != null && actionsController!.areAllActionsEnabled != null && !actionsController!.areAllActionsEnabled!()
? null :
_cancelChanges,
child: const Text("Discard changes").tr(),
),
ElevatedButton(
onPressed: actionsExtended != null && actionsExtended!.areAllActionsEnabled != null && !actionsExtended!.areAllActionsEnabled!() ?
onPressed: actionsController != null && actionsController!.areAllActionsEnabled != null && !actionsController!.areAllActionsEnabled!() ?
null :
() {
actionsExtended?.saveAction?.action == null ? _saveChanges() :
actionsExtended!.saveAction!.action!(dataGrid, _saveChanges);
actionsController?.saveAction?.action == null ? _saveChanges() :
actionsController!.saveAction!.action!(dataGrid, _saveChanges);
},
child: Text(actionsExtended?.saveAction?.name??"Save changes".tr()),
child: Text(actionsController?.saveAction?.name??"Save changes".tr()),
)
,]);

Expand Down
5 changes: 3 additions & 2 deletions lib/components/dataGrid/DataGridAction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class DataGridAction{
DataGridAction({this.action, this.name, this.isEnabled});
}

class DataGridExtendedActions{
class DataGridActionsController{
bool Function()? isAddActionPossible;
bool Function()? areAllActionsEnabled;
DataGridAction? saveAction;
DataGridExtendedActions({this.saveAction, this.areAllActionsEnabled});
DataGridActionsController({this.saveAction, this.areAllActionsEnabled, this.isAddActionPossible});
}
2 changes: 1 addition & 1 deletion lib/components/dataGrid/SingleTableDataGrid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SingleTableDataGrid<T extends IPlutoRowModel> {
final T Function(Map<String, dynamic>) fromPlutoJson;
final BuildContext context;

final DataGridExtendedActions? actionsExtended;
final DataGridActionsController? actionsExtended;
final List<DataGridAction>? headerChildren;

SingleTableDataGrid(this.context, this.loadData, this.fromPlutoJson, this.firstColumnType, this.idColumn, {required this.columns, this.headerChildren, this.actionsExtended});
Expand Down
2 changes: 2 additions & 0 deletions lib/dataModels/Tb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class OccasionUsersTb{
String get data_phone => "phone";
String get data_accommodation => "accommodation";
String get data_isInvited => "is_invited";
String get data_note => "note";
String get data_diet => "diet";
String get data_text1 => "text1";
String get data_text2 => "text2";
String get data_text3 => "text3";
Expand Down
12 changes: 0 additions & 12 deletions lib/dataModels/UserInfoModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ class UserInfoModel {

static const sexes = ["male", "female"];

static const migrateColumns =
{
idColumn:"Id",
emailReadonlyColumn:"E-mail",
nameColumn:"Jméno",
surnameColumn:"Příjmení",
sexColumn:"Pohlaví",
accommodationColumn:"Varianta ubytování",
phoneColumn:"Telefon",
roleColumn:"Role",
};

UserInfoModel({
this.id,
this.email,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/AdminDashboard/UsersScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _UsersScreenState extends State<UsersScreen> {
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.deleteAndCheck,
Tb.occasion_users.user,
actionsExtended: DataGridExtendedActions(
actionsExtended: DataGridActionsController(
saveAction: DataGridAction(
action: (datagrid, [action]) async {
await action!();
Expand Down
10 changes: 5 additions & 5 deletions lib/pages/AdministrationOccasion/AdminPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ class _AdminPageState extends State<AdminPage> with SingleTickerProviderStateMix
),
Row(
children: [
const Icon(Icons.people),
Padding(padding: const EdgeInsets.all(12), child: const Text("Users").tr())
const Icon(Icons.food_bank),
Padding(padding: const EdgeInsets.all(12), child: const Text("Service").tr())
]
),
Row(
children: [
const Icon(Icons.food_bank),
Padding(padding: const EdgeInsets.all(12), child: const Text("Service").tr())
const Icon(Icons.people),
Padding(padding: const EdgeInsets.all(12), child: const Text("Users").tr())
]
),
],
Expand All @@ -137,8 +137,8 @@ class _AdminPageState extends State<AdminPage> with SingleTickerProviderStateMix
PlacesTab(svgIcons: svgIcons, mapIcons: mapIcons, loadPlaces: loadPlaces,),
ExclusivityTab(),
UserGroupsTab(),
UsersTab(),
ServiceTab(),
UsersTab(),
],
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/AdministrationOccasion/ColumnHelper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ColumnHelper {
PlutoColumn(
title: "Note".tr(),
enableEditingMode: RightsService.canUpdateUsers(),
field: Tb.occasion_users.data_text3,
field: Tb.occasion_users.data_note,
type: PlutoColumnType.text(),
width: 200,
),
Expand All @@ -147,7 +147,7 @@ class ColumnHelper {
PlutoColumn(
title: "Diet".tr(),
enableEditingMode: RightsService.canUpdateUsers(),
field: Tb.occasion_users.data_text4,
field: Tb.occasion_users.data_diet,
type: PlutoColumnType.text(),
width: 200,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/AdministrationOccasion/PlacesTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PlacesTab extends StatelessWidget {
PlaceModel.fromPlutoJson,
DataGridFirstColumn.deleteAndDuplicate,
Tb.places.id,
actionsExtended: DataGridExtendedActions(saveAction:
actionsExtended: DataGridActionsController(saveAction:
DataGridAction(
action: (datagrid, [action]) async {
await action!();
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/AdministrationOccasion/ServiceTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class _ServiceTabState extends State<ServiceTab> {
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.none,
Tb.occasion_users.user,
actionsExtended: DataGridExtendedActions(areAllActionsEnabled: RightsService.canUpdateUsers),
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)),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/AdministrationOccasion/UsersTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _UsersTabState extends State<UsersTab> {
OccasionUserModel.fromPlutoJson,
DataGridFirstColumn.deleteAndCheck,
Tb.occasion_users.user,
actionsExtended: DataGridExtendedActions(areAllActionsEnabled: RightsService.canUpdateUsers),
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)),
Expand Down
18 changes: 15 additions & 3 deletions lib/services/ImportHelper.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import 'package:fstapp/dataModels/Tb.dart';
import 'package:csv/csv.dart';
import 'package:cross_file/cross_file.dart';
import 'package:fstapp/dataModels/UserInfoModel.dart';
import 'package:intl/intl.dart';

class ImportHelper {

static Map<String, String> get migrateColumns =>
{
Tb.user_info.id:"Id",
Tb.user_info.email_readonly:"E-mail",
Tb.user_info.name:"Jméno",
Tb.user_info.surname:"Příjmení",
Tb.user_info.sex:"Pohlaví",
Tb.occasion_users.data_accommodation:"Varianta ubytování",
Tb.occasion_users.data_phone:"Telefon",
Tb.occasion_users.role:"Role",
};

static int getIndex(String s, List<String> row)
{
return row.indexOf(UserInfoModel.migrateColumns[s]!);
return row.indexOf(migrateColumns[s]!);
}

static Future<List<Map<String, dynamic>>> getUsersFromFile(XFile file) async {
Expand All @@ -18,7 +30,7 @@ static Future<List<Map<String, dynamic>>> getUsersFromFile(XFile file) async {

var firstRow = fields[0].map((e) => e.toString()).toList();
Map<String, int> userColumnIndex = {};
for(var keyValue in UserInfoModel.migrateColumns.entries) {
for(var keyValue in migrateColumns.entries) {
var index = firstRow.indexOf(keyValue.value);
if(index == -1) {
continue;
Expand Down

0 comments on commit 5302cbc

Please sign in to comment.