Skip to content

Commit

Permalink
Integrated create recurrence event API. (#2412)
Browse files Browse the repository at this point in the history
* feat: Integrated create recurrence event API

* minor bug fix
  • Loading branch information
Azad99-9 authored Mar 9, 2024
1 parent 8fb384f commit 4a669a4
Show file tree
Hide file tree
Showing 19 changed files with 1,412 additions and 718 deletions.
53 changes: 53 additions & 0 deletions lib/constants/recurrence_values.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// Class containing constants for recurrence options.
class Recurrance {
/// Constant representing an event that does not repeat.
static const once = 'Does not repeat';

/// Constant representing daily recurrence.
static const daily = 'day';

/// Constant representing weekly recurrence.
static const weekly = 'week';

/// Constant representing monthly recurrence.
static const monthly = 'month';

/// Constant representing yearly recurrence.
static const yearly = 'year';

/// Constant representing a custom recurrence.
static const custom = 'custom...';

/// Constant representing Monday in weekdays.
static const weekdayMonday = 'MO';

/// Constant representing Tuesday in weekdays.
static const weekdayTuesday = 'TU';

/// Constant representing Wednesday in weekdays.
static const weekdayWednesday = 'WE';

/// Constant representing Thursday in weekdays.
static const weekdayThursday = 'TH';

/// Constant representing Friday in weekdays.
static const weekdayFriday = 'FR';

/// Constant representing Saturday in weekdays.
static const weekdaySaturday = 'SA';

/// Constant representing Sunday in weekdays.
static const weekdaySunday = 'SU';
}

/// Class containing constants for event end types.
class EventEndTypes {
/// Constant representing an event that never ends.
static const never = 'Never';

/// Constant representing an event that ends on a specific date.
static const on = 'On';

/// Constant representing an event that ends after a specified number of occurrences.
static const after = 'After';
}
8 changes: 6 additions & 2 deletions lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/post/post_model.dart';
import 'package:talawa/splash_screen.dart';
import 'package:talawa/view_model/after_auth_view_models/chat_view_models/direct_chat_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart';
import 'package:talawa/views/after_auth_screens/add_post_page.dart';
import 'package:talawa/views/after_auth_screens/app_settings/app_settings_page.dart';
import 'package:talawa/views/after_auth_screens/chat/chat_message_screen.dart';
Expand Down Expand Up @@ -199,9 +200,12 @@ Route<dynamic> generateRoute(RouteSettings settings) {

// Returns the CreateEventPage Widget
case Routes.customRecurrencePage:
final model = settings.arguments! as CreateEventViewModel;
return MaterialPageRoute(
builder: (context) =>
CustomRecurrencePage(key: const Key('CreateEvent')),
builder: (context) => CustomRecurrencePage(
key: const Key('CreateEvent'),
model: model,
),
);

// Returns the ProfilePage Widget
Expand Down
31 changes: 2 additions & 29 deletions lib/utils/event_queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,8 @@ class EventQueries {
/// This function generates a GraphQL mutation string for creating an event.
String addEvent() {
return """
mutation createEvent( \$organizationId: ID!,
\$title:String!,
\$description: String!,
\$startTime: Time,
\$endTime: Time,
\$allDay: Boolean!,
\$recurring: Boolean!,
\$isPublic: Boolean!,
\$isRegisterable: Boolean!,
\$location: String,
\$startDate : Date!,
\$endDate : Date!,
) {
createEvent(
data:{
organizationId: \$organizationId,
title: \$title,
description: \$description,
isPublic: \$isPublic,
isRegisterable: \$isRegisterable,
recurring: \$recurring,
allDay: \$allDay,
startTime: \$startTime,
endTime: \$endTime,
startDate: \$startDate,
endDate: \$endDate,
location: \$location,
}
){
mutation Mutation(\$data: EventInput!, \$recurrenceRuleData: RecurrenceRuleInput) {
createEvent(data: \$data, recurrenceRuleData: \$recurrenceRuleData) {
_id
title
description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:talawa/constants/recurrence_values.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';
Expand Down Expand Up @@ -35,6 +36,13 @@ class CreateEventViewModel extends BaseModel {
TextEditingController eventDescriptionTextController =
TextEditingController();

/// Repeats Every count controller.
TextEditingController repeatsEveryCountController =
TextEditingController(text: '1');

/// Event ends After n occurences controller.
TextEditingController endOccurenceController = TextEditingController();

/// Event Start Time.
TimeOfDay eventStartTime = TimeOfDay.now();

Expand All @@ -48,7 +56,7 @@ class CreateEventViewModel extends BaseModel {
DateTime eventStartDate = DateTime.now();

/// Event End Date.
DateTime eventEndDate = DateTime.now();
DateTime? eventEndDate = DateTime.now();

/// Public Event or Not.
bool isPublicSwitch = true;
Expand All @@ -71,6 +79,33 @@ class CreateEventViewModel extends BaseModel {
/// Longitude store.
double? longitude;

/// is an allday event.
bool isAllDay = true;

/// Is a recurring event.
bool isRecurring = false;

/// recurrence count.
int recurranceCount = 1;

/// recurrence.
String? recurrance;

/// RecurranceRuleData frequency.
String recurranceFrequency = Recurrance.weekly;

/// Monthly recurrence.
String monthlyRecurrence = 'Monthly on day 3';

/// weekdays.
Set<String> weekdays = {Recurrance.weekdayTuesday};

/// Event end type.
String eventEndType = EventEndTypes.never;

/// Custom recurrance event end date.
DateTime? eventEndOnEndDate = DateTime.now();

//late OrganizationService _organizationService;
late final Map<String, bool> _memberCheckedMap = {};
late final List<User> _selectedMembers = [];
Expand Down Expand Up @@ -150,39 +185,50 @@ class CreateEventViewModel extends BaseModel {
validate = AutovalidateMode.disabled;

// variables initialisation
final DateTime startDate = eventStartDate;
final DateTime endDate = eventEndDate;
final DateTime startTime = DateTime(
startDate.year,
startDate.month,
startDate.day,
eventStartDate.year,
eventStartDate.month,
eventStartDate.day,
eventStartTime.hour,
eventStartTime.minute,
);
final DateTime endTime = DateTime(
endDate.year,
endDate.month,
endDate.day,
eventEndDate?.year ?? DateTime.now().year,
eventEndDate?.month ?? DateTime.now().month,
eventEndDate?.day ?? DateTime.now().day,
eventEndTime.hour,
eventEndTime.minute,
);

final String? frequency = getRecurrance(recurranceFrequency);

// all required data for creating an event
final Map<String, dynamic> variables = {
'startDate': DateFormat('yyyy-MM-dd').format(startDate),
'endDate': DateFormat('yyyy-MM-dd').format(endDate),
'organizationId': _currentOrg.id,
'title': eventTitleTextController.text,
'description': eventDescriptionTextController.text,
'location': eventLocationTextController.text,
'isPublic': isPublicSwitch,
'isRegisterable': isRegisterableSwitch,
'recurring': false,
'allDay': false,
'startTime': '${DateFormat('HH:mm:ss').format(startTime)}Z',
'endTime': '${DateFormat('HH:mm:ss').format(endTime)}Z',
if (latitude != null) 'latitude': latitude,
if (longitude != null) 'longitude': longitude,
"data": {
'startDate': DateFormat('yyyy-MM-dd').format(eventStartDate),
if (eventEndDate != null)
'endDate': DateFormat('yyyy-MM-dd').format(eventEndDate!),
'organizationId': _currentOrg.id,
'title': eventTitleTextController.text,
'description': eventDescriptionTextController.text,
'location': eventLocationTextController.text,
'isPublic': isPublicSwitch,
'isRegisterable': isRegisterableSwitch,
'recurring': isRecurring,
'recurrance': recurrance ?? frequency,
'allDay': isAllDay,
'startTime': '${DateFormat('HH:mm:ss').format(startTime)}Z',
if (eventEndDate != null)
'endTime': '${DateFormat('HH:mm:ss').format(endTime)}Z',
if (latitude != null) 'latitude': latitude,
if (longitude != null) 'longitude': longitude,
},
if (recurrance == null)
'recurrenceRuleData': {
if (eventEndType != EventEndTypes.never) 'count': recurranceCount,
'frequency': frequency,
if (frequency == 'WEEKLY') 'weekDays': List.from(weekdays),
},
};

navigationService.pushDialog(
Expand All @@ -194,6 +240,7 @@ class CreateEventViewModel extends BaseModel {
EventQueries().addEvent(),
variables: variables,
);
print(result);
navigationService.pop();
if (result != null) {
navigationService.pop();
Expand Down Expand Up @@ -288,4 +335,41 @@ class CreateEventViewModel extends BaseModel {

notifyListeners();
}

/// Updates the event end date to selected event end date.
///
/// **params**:
/// * `selectedEndDate`: new event end date selected by user.
///
/// **returns**:
/// None
void setEventEndDate(DateTime? selectedEndDate) {
eventEndDate = selectedEndDate;
notifyListeners();
}

/// Returns corresponding recurrence value based on frequency.
///
/// **params**:
/// * `frequency`: Recurrence frequency selected by user.
///
/// **returns**:
/// * `String?`: Recurrence value.
String? getRecurrance(String frequency) {
isRecurring = true;
if (frequency == Recurrance.daily || frequency == 'Every day') {
return 'DAILY';
} else if (frequency == Recurrance.weekly || frequency == 'Every week') {
return 'WEEKLY';
} else if (frequency == Recurrance.monthly || frequency == 'Every month') {
return 'MONTHLY';
} else if (frequency == Recurrance.yearly || frequency == 'Every year') {
return 'YEARLY';
} else if (frequency == Recurrance.once) {
isRecurring = false;
return null;
} else {
return null;
}
}
}
Loading

0 comments on commit 4a669a4

Please sign in to comment.