Skip to content

Commit

Permalink
places in AdminDatagrid
Browse files Browse the repository at this point in the history
  • Loading branch information
miakh committed Nov 10, 2023
1 parent 4f47971 commit 646289b
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/models/EventModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class EventModel extends IPlutoRowModel {
endDateColumn: PlutoCell(value: DateFormat('yyyy-MM-dd').format(endTime)),
endTimeColumn: PlutoCell(value: DateFormat('HH:mm').format(endTime)),
maxParticipantsColumn: PlutoCell(value: maxParticipants),
placeColumn: PlutoCell(value: place == null ? PlaceModel.WithouPlace : place!.toPlutoSelectString()),
placeColumn: PlutoCell(value: place == null ? PlaceModel.WithouValue : place!.toPlutoSelectString()),
splitForMenWomenColumn: PlutoCell(value: splitForMenWomen.toString()),
isGroupEventColumn: PlutoCell(value: isGroupEvent.toString()),
parentEventColumn: PlutoCell(value: parentEventIds?.map((e) => e.toString()).join(",")??"")
Expand Down
57 changes: 55 additions & 2 deletions lib/models/PlaceModel.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class PlaceModel {
import 'package:avapp/services/DataService.dart';
import 'package:pluto_grid/pluto_grid.dart';

import 'PlutoAbstract.dart';

class PlaceModel extends IPlutoRowModel {
dynamic latLng;
int? id;
String? title;
String? description;
String? type;
bool isHidden = false;

static const String WithouPlace = "---";
static const String WithouValue = "---";

static const String idColumn = "id";
static const String titleColumn = "title";
Expand All @@ -29,6 +34,27 @@ class PlaceModel {
);
}

static PlaceModel fromPlutoJson(Map<String, dynamic> json) {
return PlaceModel(
latLng: json[coordinatesColumn],
id: json[idColumn] == -1 ? null : json[idColumn],
title: json[titleColumn],
description: json[descriptionColumn].isEmpty ? null : json[descriptionColumn],
type: json[typeColumn] == WithouValue ? null : json[typeColumn],
isHidden: json[isHiddenColumn] == "true" ? true : false,
);
}

Map toJson() =>
{
idColumn: id,
titleColumn: title,
coordinatesColumn: {"latLng" : latLng },
descriptionColumn: description,
typeColumn: type,
isHiddenColumn: isHidden
};

PlaceModel({
this.latLng,
required this.id,
Expand All @@ -38,4 +64,31 @@ class PlaceModel {
this.isHidden = false});

String toPlutoSelectString() => "$id:$title";

@override
Future<void> deleteMethod() async {
await DataService.deletePlace(this);
}

@override
String toBasicString() {
return title.toString();
}

@override
PlutoRow toPlutoRow() {
return PlutoRow(cells: {
idColumn: PlutoCell(value: id),
titleColumn: PlutoCell(value: title),
descriptionColumn: PlutoCell(value: description ?? ""),
coordinatesColumn: PlutoCell(value: latLng),
typeColumn: PlutoCell(value: type ?? WithouValue),
isHiddenColumn: PlutoCell(value: isHidden),
});
}

@override
Future<void> updateMethod() async {
await DataService.updatePlace(this);
}
}
4 changes: 2 additions & 2 deletions lib/models/UserInfoModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class UserInfoModel extends IPlutoRowModel {
emailColumn: PlutoCell(value: email),
nameColumn: PlutoCell(value: name),
surnameColumn: PlutoCell(value: surname),
phoneColumn: PlutoCell(value: phone ?? PlaceModel.WithouPlace),
phoneColumn: PlutoCell(value: phone ?? PlaceModel.WithouValue),
roleColumn: PlutoCell(value: role),
accommodationColumn: PlutoCell(
value: accommodation ?? PlaceModel.WithouPlace),
value: accommodation ?? PlaceModel.WithouValue),
sexColumn: PlutoCell(value: sex),
isAdminColumn: PlutoCell(value: isAdmin.toString()),
isReceptionAdminColumn: PlutoCell(value: isReceptionAdmin.toString()),
Expand Down
131 changes: 129 additions & 2 deletions lib/pages/AdministrationPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:avapp/services/DataGridHelper.dart';
import 'package:avapp/services/DataService.dart';
import 'package:avapp/services/ImportHelper.dart';
import 'package:avapp/services/MailerSendHelper.dart';
import 'package:avapp/services/MapIconService.dart';
import 'package:avapp/services/ToastHelper.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
Expand All @@ -33,6 +34,7 @@ class AdministrationPage extends StatefulWidget {
class _AdministrationPageState extends State<AdministrationPage> {
List<String> places = [];
List<PlutoColumn> columns = [];
List<String> mapIcons = [];
late SingleTableDataGrid<UserInfoModel> usersDataGrid;

@override
Expand All @@ -50,8 +52,12 @@ class _AdministrationPageState extends State<AdministrationPage> {
Future<void> loadData() async {
var placesRaws = await DataService.getMapPlaces();
var placesStrings = placesRaws.map((p)=>p.toPlutoSelectString()).toList();
placesStrings.add(PlaceModel.WithouPlace);
placesStrings.add(PlaceModel.WithouValue);
places = placesStrings;

mapIcons = MapIconHelper.type2Icon.keys.toList();
mapIcons.add(PlaceModel.WithouValue);

setState(() {});
}

Expand Down Expand Up @@ -173,7 +179,7 @@ class _AdministrationPageState extends State<AdministrationPage> {
)
]);
return DefaultTabController(
length: 5,
length: 6,
child: Scaffold(
appBar: AppBar(
title: const Text("Admin"),
Expand All @@ -196,6 +202,12 @@ class _AdministrationPageState extends State<AdministrationPage> {
Padding(padding: EdgeInsets.all(12), child: Text("Události"))
]
),
Row(
children: [
Icon(Icons.pin_drop),
Padding(padding: EdgeInsets.all(12), child: Text("Místa"))
]
),
Row(
children: [
Icon(Icons.punch_clock_rounded),
Expand Down Expand Up @@ -495,6 +507,121 @@ class _AdministrationPageState extends State<AdministrationPage> {
width: 300
),
]).DataGrid(),
SingleTableDataGrid<PlaceModel>(
DataService.getPlaces,
PlaceModel.fromPlutoJson,
columns: [
PlutoColumn(
title: "",
field: "delete",
type: PlutoColumnType.text(),
readOnly: true,
enableFilterMenuItem: false,
enableSorting: false,
enableDropToResize: false,
enableColumnDrag: false,
enableContextMenu: false,
cellPadding: EdgeInsets.zero,
width: 100,
renderer: (rendererContext) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () async{
final id = rendererContext.row.cells[PlaceModel.idColumn]?.value as int?;
if (id == -1){
rendererContext.stateManager.removeRows([rendererContext.row]);
return;
}
setState(() {
rendererContext.row.setState(rendererContext.row.state == PlutoRowState.none ? PlutoRowState.added : PlutoRowState.none);
});
},
icon: const Icon(Icons.delete_forever)),
IconButton(
onPressed: () async{
var originRow = rendererContext.row;
var newRow = rendererContext.stateManager.getNewRows()[0];
newRow.cells[PlaceModel.idColumn]?.value = -1;
newRow.cells[PlaceModel.titleColumn]?.value = originRow.cells[PlaceModel.titleColumn]?.value;
newRow.cells[PlaceModel.descriptionColumn]?.value = originRow.cells[PlaceModel.descriptionColumn]?.value;
newRow.cells[PlaceModel.coordinatesColumn]?.value = originRow.cells[PlaceModel.coordinatesColumn]?.value;
newRow.cells[PlaceModel.typeColumn]?.value = originRow.cells[PlaceModel.typeColumn]?.value;
newRow.cells[PlaceModel.isHiddenColumn]?.value = originRow.cells[PlaceModel.isHiddenColumn]?.value;
var currentIndex = rendererContext.stateManager.rows.indexOf(originRow);
rendererContext.stateManager.insertRows(currentIndex+1, [newRow]);

setState(() {
newRow.setState(PlutoRowState.updated);
});
},
icon: const Icon(Icons.add)),]
);
}),
PlutoColumn(
title: "Id",
field: PlaceModel.idColumn,
type: PlutoColumnType.number(defaultValue: -1),
readOnly: true,
width: 50,
renderer: (rendererContext) => DataGridHelper.idRenderer(rendererContext),
),
PlutoColumn(
title: "Nadpis",
field: PlaceModel.titleColumn,
type: PlutoColumnType.text(),
width: 300
),
PlutoColumn(
title: "Popis",
field: PlaceModel.descriptionColumn,
type: PlutoColumnType.text(),
width: 300
),
PlutoColumn(
title: "Ikonka",
field: PlaceModel.typeColumn,
type: PlutoColumnType.select(mapIcons),
applyFormatterInEditing: false,
renderer: (rendererContext) => DataGridHelper.mapIconRenderer(rendererContext, setState),
//formatter: DataGridHelper.GetValueFromFormatted,
),
PlutoColumn(
title: "Skryté",
field: PlaceModel.isHiddenColumn,
type: PlutoColumnType.select(places),
applyFormatterInEditing: true,
enableEditingMode: false,
width: 100,
renderer: (rendererContext) => DataGridHelper.checkBoxRenderer(rendererContext, setState),
),
PlutoColumn(
width: 150,
title: "Pozice na mapě",
enableFilterMenuItem: false,
enableContextMenu: false,
enableSorting: false,
field: PlaceModel.coordinatesColumn,
type: PlutoColumnType.text(),
renderer: (rendererContext) {
return ElevatedButton(
onPressed: () async{
var placeModel = PlaceModel.fromPlutoJson(rendererContext.row.toJson());
Navigator.pushNamed(context, MapPage.ROUTE, arguments: placeModel).then((value) async {
if(value != null)
{
rendererContext.row.cells[PlaceModel.coordinatesColumn]?.value = value;
setState(() {
rendererContext.row.setState(PlutoRowState.updated);
});
}
});
},
child: const Row(children: [Icon(Icons.edit), Padding(padding: EdgeInsets.all(6), child: Text("Editovat")) ])
);
}),
]).DataGrid(),
SingleTableDataGrid<ExclusiveGroupModel>(
DataService.getExclusiveGroups,
ExclusiveGroupModel.fromPlutoJson,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/EventPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class _EventPageState extends State<EventPage> {
padding: const EdgeInsets.all(8.0),
alignment: Alignment.topRight,
child: TextButton(
onPressed: () => Navigator.pushNamed(context, MapPage.ROUTE, arguments: _event!.place!.id).then((value) => loadData(_event!.id!)),
onPressed: () => Navigator.pushNamed(context, MapPage.ROUTE, arguments: _event!.place).then((value) => loadData(_event!.id!)),
child: Text("Místo: ${_event?.place?.title??""}", style: normalTextStyle,))
)),
Visibility(
Expand Down
Loading

0 comments on commit 646289b

Please sign in to comment.