Skip to content

Commit

Permalink
Venue Management for Event Plugin (GSoC) (PalisadoesFoundation#2527)
Browse files Browse the repository at this point in the history
* Venue Management for Event Plugin (GSoC)

* adding tests

* adding tests

* fixing tests

* fixing tests

* fixing tests

* fixing tests

* making required changes
  • Loading branch information
Dante291 authored Jul 26, 2024
1 parent d2c9bdd commit 36912b0
Show file tree
Hide file tree
Showing 13 changed files with 1,012 additions and 117 deletions.
Binary file added assets/images/defaultImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions lib/models/events/event_venue.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/// The `Venue` class represents a venue for events.
class Venue {
/// Constructs a `Venue` instance.
///
/// [id] is the unique identifier of the venue.
/// [capacity] is the maximum number of people the venue can accommodate.
/// [description] provides additional details about the venue.
/// [imageUrl] is the URL of the venue's image.
/// [name] is the name of the venue.
/// [organizationId] is the identifier of the organization to which the venue belongs.
Venue({
this.id,
this.capacity,
this.description,
this.imageUrl,
this.name,
this.organizationId,
});

/// Creates a `Venue` instance from a JSON object.
///
/// The [json] parameter is a map containing the venue data.
///
/// Returns an instance of `Venue`.
factory Venue.fromJson(Map<String, dynamic> json) {
return Venue(
id: json['_id'] as String?,
capacity: json['capacity'] as int?,
description: json['description'] as String?,
imageUrl: json['imageUrl'] as String? ?? '',
name: json['name'] as String?,
organizationId:
(json['organization'] as Map<String, dynamic>?)?['_id'] as String?,
);
}

/// The unique identifier of the venue.
final String? id;

/// The maximum number of people the venue can accommodate.
final int? capacity;

/// Provides additional details about the venue.
final String? description;

/// The URL of the venue's image.
final String? imageUrl;

/// The name of the venue.
final String? name;

/// The identifier of the organization to which the venue belongs.
final String? organizationId;
}
24 changes: 24 additions & 0 deletions lib/utils/queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,28 @@ query {
}
''';
}

/// Query to get the list of Venues in an organisation.
///
/// **params**:
/// None
///
/// **returns**:
/// * `String`: Query in string form, to be passed to graphql client.
String venueListQuery() {
return """
query GetVenueByOrgId(\$orgId: ID!, \$first: Int, \$orderBy: VenueOrderByInput, \$where: VenueWhereInput) {
getVenueByOrgId(orgId: \$orgId, first: \$first, orderBy: \$orderBy, where: \$where) {
_id
capacity
name
description
imageUrl
organization {
_id
}
}
}
""";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:intl/intl.dart';
import 'package:talawa/constants/recurrence_values.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/events/event_venue.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/services/event_service.dart';
Expand Down Expand Up @@ -357,4 +359,33 @@ class CreateEventViewModel extends BaseModel {
eventEndDate = selectedEndDate;
notifyListeners();
}

/// Fetches the list of venues registered to an organisation.
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<List<Venue>>`: Returns the list of venues in an organisation.
Future<List<Venue>> fetchVenues() async {
final String query = queries.venueListQuery();
final QueryResult result = await databaseFunctions.gqlAuthQuery(
query,
variables: {
"orgId": _currentOrg.id,
},
) as QueryResult<Object?>;

if (result.data == null) {
return [];
}
final data = result.data!;
final List<dynamic> venuesList = data['getVenueByOrgId'] as List<dynamic>;

final List<Venue> venues = venuesList.map((venue) {
return Venue.fromJson(venue as Map<String, dynamic>);
}).toList();

return venues;
}
}
104 changes: 104 additions & 0 deletions lib/views/after_auth_screens/events/create_event_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import 'package:flutter/material.dart';
import 'package:talawa/constants/recurrence_values.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/events/event_venue.dart';
import 'package:talawa/services/graphql_config.dart';
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/utils/app_localization.dart';
import 'package:talawa/utils/validators.dart';
import 'package:talawa/view_model/after_auth_view_models/event_view_models/create_event_view_model.dart';
import 'package:talawa/view_model/main_screen_view_model.dart';
import 'package:talawa/views/after_auth_screens/events/create_event_form.dart';
import 'package:talawa/views/after_auth_screens/events/venue_bottom_sheet.dart';
import 'package:talawa/views/base_view.dart';
import 'package:talawa/widgets/add_members_bottom_sheet.dart';
import 'package:talawa/widgets/date_time_picker.dart';
Expand All @@ -26,6 +29,9 @@ class CreateEventPage extends StatefulWidget {

/// _CreateEventPageState returns a widget for a Page to Creatxe the Event in the Organization.
class _CreateEventPageState extends State<CreateEventPage> {
/// venue selected by the user.
Venue? selectedVenue;

@override
Widget build(BuildContext context) {
final TextStyle subtitleTextStyle =
Expand Down Expand Up @@ -133,6 +139,104 @@ class _CreateEventPageState extends State<CreateEventPage> {
),
SizedBox(height: SizeConfig.screenHeight! * 0.013),
const Divider(),
GestureDetector(
onTap: () async {
final List<Venue> venues = await model.fetchVenues();
if (!context.mounted) return;
final Venue? selected =
await showModalBottomSheet<Venue>(
context: context,
isScrollControlled: true,
builder: (context) {
return VenueBottomSheet(venues: venues);
},
);
if (selected != null) {
setState(() {
selectedVenue = selected;
});
}
},
child: selectedVenue == null
? Container(
height: 50.0,
padding:
const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
const Icon(Icons.add_location),
const SizedBox(width: 10.0),
Text(
AppLocalizations.of(context)!
.strictTranslate('Add Venue'),
style:
Theme.of(context).textTheme.titleMedium,
),
],
),
)
: Container(
height: 100.0,
padding:
const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
if (selectedVenue!.imageUrl!.isNotEmpty)
Image.network(
selectedVenue!.imageUrl!.replaceAll(
'http://localhost:4000',
GraphqlConfig.orgURI!
.replaceFirst('/graphql', ''),
),
)
else
Image.asset(
'assets/images/defaultImg.png',
width: 50,
height: 50,
fit: BoxFit.cover,
),
const SizedBox(width: 10.0),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
selectedVenue!.name!,
style: Theme.of(context)
.textTheme
.titleMedium,
),
Text(
'Capacity: ${selectedVenue!.capacity}',
style: Theme.of(context)
.textTheme
.bodySmall,
),
],
),
),
Column(
children: [
IconButton(
onPressed: () {
setState(() {
selectedVenue = null;
});
},
icon: const Icon(Icons.cancel),
),
const Icon(Icons.edit),
],
),
],
),
),
),
const Divider(),
SizedBox(
width: SizeConfig.screenWidth,
child: Wrap(
Expand Down
Loading

0 comments on commit 36912b0

Please sign in to comment.