mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Can update presence settings
This commit is contained in:
		@@ -57,8 +57,9 @@ class ForezPresenceHelper {
 | 
				
			|||||||
  /// Add a new day of presence
 | 
					  /// Add a new day of presence
 | 
				
			||||||
  ///
 | 
					  ///
 | 
				
			||||||
  /// Throws in case of failure
 | 
					  /// 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", {
 | 
					      await ws("forez_presence/add_day", {
 | 
				
			||||||
 | 
					        "group": groupID,
 | 
				
			||||||
        "year": dt.year,
 | 
					        "year": dt.year,
 | 
				
			||||||
        "month": dt.month,
 | 
					        "month": dt.month,
 | 
				
			||||||
        "day": dt.day,
 | 
					        "day": dt.day,
 | 
				
			||||||
@@ -67,8 +68,9 @@ class ForezPresenceHelper {
 | 
				
			|||||||
  /// Remove a new day of presence
 | 
					  /// Remove a new day of presence
 | 
				
			||||||
  ///
 | 
					  ///
 | 
				
			||||||
  /// Throws in case of failure
 | 
					  /// 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", {
 | 
					      await ws("forez_presence/del_day", {
 | 
				
			||||||
 | 
					        "group": groupID,
 | 
				
			||||||
        "year": dt.year,
 | 
					        "year": dt.year,
 | 
				
			||||||
        "month": dt.month,
 | 
					        "month": dt.month,
 | 
				
			||||||
        "day": dt.day,
 | 
					        "day": dt.day,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										91
									
								
								lib/ui/routes/forez_presence_settings_route.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								lib/ui/routes/forez_presence_settings_route.dart
									
									
									
									
									
										Normal 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!"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -2,6 +2,7 @@ import 'package:comunic/helpers/forez_presence_helper.dart';
 | 
				
			|||||||
import 'package:comunic/helpers/users_helper.dart';
 | 
					import 'package:comunic/helpers/users_helper.dart';
 | 
				
			||||||
import 'package:comunic/lists/forez_presences_set.dart';
 | 
					import 'package:comunic/lists/forez_presences_set.dart';
 | 
				
			||||||
import 'package:comunic/lists/users_list.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/account_image_widget.dart';
 | 
				
			||||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
 | 
					import 'package:comunic/ui/widgets/async_screen_widget.dart';
 | 
				
			||||||
import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
 | 
					import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
 | 
				
			||||||
@@ -52,7 +53,7 @@ class _ForezPresenceSectionState extends State<ForezPresenceSection> {
 | 
				
			|||||||
          bottom: 10,
 | 
					          bottom: 10,
 | 
				
			||||||
          child: FloatingActionButton(
 | 
					          child: FloatingActionButton(
 | 
				
			||||||
            backgroundColor: Colors.green,
 | 
					            backgroundColor: Colors.green,
 | 
				
			||||||
            onPressed: () {},
 | 
					            onPressed: () => showPresenceSettingsRoute(context, widget.groupID),
 | 
				
			||||||
            child: Icon(Icons.edit),
 | 
					            child: Icon(Icons.edit),
 | 
				
			||||||
          ),
 | 
					          ),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user