1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-26 12:58:51 +00:00

Can update presence settings

This commit is contained in:
Pierre HUBERT 2021-04-22 15:54:30 +02:00
parent 96fb14e7de
commit da876f5978
3 changed files with 97 additions and 3 deletions

View File

@ -57,8 +57,9 @@ class ForezPresenceHelper {
/// Add a new day of presence
///
/// Throws in case of failure
static Future<void> addDay(DateTime dt) async =>
static Future<void> addDay(int groupID, DateTime dt) async =>
await ws("forez_presence/add_day", {
"group": groupID,
"year": dt.year,
"month": dt.month,
"day": dt.day,
@ -67,8 +68,9 @@ class ForezPresenceHelper {
/// Remove a new day of presence
///
/// Throws in case of failure
static Future<void> delDay(DateTime dt) async =>
static Future<void> delDay(int groupID, DateTime dt) async =>
await ws("forez_presence/del_day", {
"group": groupID,
"year": dt.year,
"month": dt.month,
"day": dt.day,

View File

@ -0,0 +1,91 @@
import 'package:comunic/helpers/forez_presence_helper.dart';
import 'package:comunic/lists/forez_presences_set.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/log_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Forez presence settings route
///
/// On this route, users can change there presence settings
///
/// @author Pierre Hubert
/// Show presence settings route
Future<void> showPresenceSettingsRoute(
BuildContext context, int groupID) async =>
await Navigator.push(context,
MaterialPageRoute(builder: (c) => PresenceSettings(groupID: groupID)));
class PresenceSettings extends StatefulWidget {
final int groupID;
const PresenceSettings({
Key key,
@required this.groupID,
}) : assert(groupID != null),
super(key: key);
@override
_PresenceSettingsState createState() => _PresenceSettingsState();
}
class _PresenceSettingsState extends State<PresenceSettings> {
PresenceSet _currPresences;
Future<void> _load() async {
await ForezPresenceHelper.refreshCache(widget.groupID);
_currPresences =
await ForezPresenceHelper.getForUser(widget.groupID, userID());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(tr("Presence settings")),
),
body: AsyncScreenWidget(
onReload: _load,
onBuild: _buildScreen,
errorMessage: tr("Failed to load data!"),
),
);
}
Widget _buildScreen() => ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
tr("Please click on the day you will be in the plain, so that everyone gets informed ! ;)"),
textAlign: TextAlign.center,
),
),
PresenceCalendarWidget(
presenceSet: _currPresences,
onDayClicked: _toggleDay,
),
],
);
void _toggleDay(DateTime dt) async {
try {
// Update current list
_currPresences.toggleDate(dt, userID());
// Update on server
if (_currPresences.containsDate(dt))
await ForezPresenceHelper.addDay(widget.groupID, dt);
else
await ForezPresenceHelper.delDay(widget.groupID, dt);
} catch (e, s) {
logError(e, s);
_currPresences.toggleDate(dt, userID());
snack(context, tr("Failed to update information!"));
}
}
}

View File

@ -2,6 +2,7 @@ import 'package:comunic/helpers/forez_presence_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/forez_presences_set.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/ui/routes/forez_presence_settings_route.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
@ -52,7 +53,7 @@ class _ForezPresenceSectionState extends State<ForezPresenceSection> {
bottom: 10,
child: FloatingActionButton(
backgroundColor: Colors.green,
onPressed: () {},
onPressed: () => showPresenceSettingsRoute(context, widget.groupID),
child: Icon(Icons.edit),
),
)