Skip to content

Commit

Permalink
Merge pull request #306 from sinfo/feature/team-management
Browse files Browse the repository at this point in the history
Feature: Team Management
  • Loading branch information
PMax5 authored Nov 11, 2022
2 parents ab912df + 2f22660 commit 6dfeb31
Show file tree
Hide file tree
Showing 16 changed files with 1,116 additions and 289 deletions.
98 changes: 58 additions & 40 deletions backend/src/mongodb/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,48 +183,62 @@ func (m *MembersType) GetMembers(options GetMemberOptions) ([]*models.Member, er

var members []*models.Member = make([]*models.Member, 0)

query := mongo.Pipeline{

// filter by name first
{{
Key: "$match", Value: bson.M{
"name": bson.M{
"$regex": fmt.Sprintf(".*%s.*", nameFilter),
"$options": "i",
var query mongo.Pipeline
if len(nameFilter) > 0 {
query = mongo.Pipeline{
{{
"$match", bson.M{
"name": bson.M{
"$regex": fmt.Sprintf(".*%s.*", nameFilter),
"$options": "i",
},
},
},
}},

// get all the teams on which each member is participating,
// and add them to each member correspondingly
{{
Key: "$lookup", Value: bson.D{
{Key: "from", Value: Teams.Collection.Name()},
{Key: "localField", Value: "_id"},
{Key: "foreignField", Value: "members.member"},
{Key: "as", Value: "team"},
},
}},

// get an instance of each member for every team he/she belonged to
{{
Key: "$unwind", Value: "$team",
}},

// get the event associated with each team on each member
{{
Key: "$lookup", Value: bson.D{
{Key: "from", Value: Events.Collection.Name()},
{Key: "localField", Value: "team._id"},
{Key: "foreignField", Value: "teams"},
{Key: "as", Value: "event"},
},
}},
}},
}
} else {
query = mongo.Pipeline{

// filter by name first
{{
"$match", bson.M{
"name": bson.M{
"$regex": fmt.Sprintf(".*%s.*", nameFilter),
"$options": "i",
},
},
}},

// get all the teams on which each member is participating,
// and add them to each member correspondingly
{{
"$lookup", bson.D{
{"from", Teams.Collection.Name()},
{"localField", "_id"},
{"foreignField", "members.member"},
{"as", "team"},
},
}},

// get an instance of each member for every team he/she belonged to
{{
"$unwind", "$team",
}},

// get the event associated with each team on each member
{{
"$lookup", bson.D{
{"from", Events.Collection.Name()},
{"localField", "team._id"},
{"foreignField", "teams"},
{"as", "event"},
},
}},

// get an instance of each member for every event he/she belonged to
{{
Key: "$unwind", Value: "$event",
}},
// get an instance of each member for every event he/she belonged to
{{
"$unwind", "$event",
}},
}
}

if options.Event != nil {
Expand Down Expand Up @@ -330,6 +344,7 @@ func (m *MembersType) GetMembersParticipations(id primitive.ObjectID) ([]*models
options := GetEventsOptions{}
events, err := Events.GetEvents(options)
if err != nil {
print("ERROR #1", err)
return nil, err
}

Expand All @@ -339,6 +354,9 @@ func (m *MembersType) GetMembersParticipations(id primitive.ObjectID) ([]*models
for _, teamID := range event.Teams {
team, err := Teams.GetTeam(teamID)
if err != nil {
print("TEAM ID: ", teamID.Hex())
print("EVENT: ", event)
print("ERROR #2", err)
return nil, err
}
for _, teamMember := range team.Members {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/mongodb/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type UpdateTeamMemberData struct {

// CreateTeamMemberData contains data needed to create a team member
type CreateTeamMemberData struct {
Member primitive.ObjectID `json:"id"`
Member primitive.ObjectID `json:"member"`
Role models.TeamRole `json:"role"`
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/lib/components/appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:frontend/components/SearchResultWidget.dart';
import 'package:frontend/components/deckTheme.dart';
import 'package:frontend/components/eventNotifier.dart';
import 'package:frontend/components/SearchResultWidget.dart';
import 'package:frontend/main.dart';
import 'package:frontend/models/event.dart';
import 'package:frontend/routes/company/CompanyScreen.dart';
import 'package:frontend/routes/member/MemberScreen.dart';
Expand Down
50 changes: 28 additions & 22 deletions frontend/lib/components/filterBarTeam.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import 'package:flutter/material.dart';

class FilterBarTeam extends StatefulWidget {
String currentFilter;
final Function onSelected;
final List<String> teamFilters;

FilterBarTeam({Key? key, required this.onSelected}) : super(key: key);
FilterBarTeam(
{Key? key,
required this.currentFilter,
required this.teamFilters,
required this.onSelected})
: super(key: key);

@override
FilterBarTeamState createState() => FilterBarTeamState(onSelected: onSelected);
FilterBarTeamState createState() => FilterBarTeamState(
currentFilter: currentFilter,
teamFilters: teamFilters,
onSelected: onSelected);
}

class FilterBarTeamState extends State<FilterBarTeam> {
String currentFilter;
final List<String> teamFilters;
final Function onSelected;

FilterBarTeamState({Key? key, required this.onSelected});

int _currentIndex = 0;
List<String> _filters = [
"All",
"Coordination",
"DevTeam",
"Logistics",
"Multimedia",
"Partnerships",
"Social Network",
];
FilterBarTeamState(
{Key? key,
required this.currentFilter,
required this.teamFilters,
required this.onSelected});

@override
Widget build(BuildContext context) {
Expand All @@ -35,8 +40,8 @@ class FilterBarTeamState extends State<FilterBarTeam> {

rowChips() {
List<Widget> filters = [];
for (int i = 0; i < _filters.length; i++) {
filters.add(createChip(_filters[i], i));
for (int i = 0; i < teamFilters.length; i++) {
filters.add(createChip(teamFilters[i], i));
}
return Row(children: filters);
}
Expand All @@ -45,25 +50,26 @@ class FilterBarTeamState extends State<FilterBarTeam> {
return Container(
margin: EdgeInsets.all(7.0),
child: ChoiceChip(
selected: _currentIndex == index,
selected: label.toLowerCase() == currentFilter.toLowerCase(),
backgroundColor: Colors.indigo[100],
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.black12, width: 1),
borderRadius: BorderRadius.circular(15),
),
elevation: 2,
pressElevation: 1,
elevation: 1,
pressElevation: 3,
shadowColor: Colors.teal,
selectedColor: Colors.indigo[400],
onSelected: (bool selected) {
setState(() {
_currentIndex = selected ? index : _currentIndex;
onSelected(_filters[_currentIndex].toUpperCase());
onSelected(label.toUpperCase());
});
},
label: Text(label),
labelStyle: TextStyle(
color: _currentIndex != index ? Colors.indigo[400] : Colors.white,
color: label.toLowerCase() != currentFilter.toLowerCase()
? Colors.indigo[400]
: Colors.white,
),
padding: EdgeInsets.all(6.0),
),
Expand Down
10 changes: 0 additions & 10 deletions frontend/lib/components/filterbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ class FilterBarState extends State<FilterBar> {
FilterBarState({Key? key, required this.onSelected});

int _currentIndex = 0;
List<String> _filters = [
"All",
"Suggested",
"Contacted",
"Rejected",
"Give Up",
"Announced",
"In Conversations",
"In Negotiations"
];

@override
Widget build(BuildContext context) {
Expand Down
6 changes: 4 additions & 2 deletions frontend/lib/components/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'package:frontend/routes/member/AddMemberForm.dart';
import 'package:frontend/routes/member/MemberListWidget.dart';
import 'package:frontend/routes/speaker/SpeakerListWidget.dart';
import 'package:frontend/routes/speaker/AddSpeakerForm.dart';
import 'package:frontend/routes/teams/AddTeamMemberForm.dart';
import 'package:frontend/routes/session/AddSessionForm.dart';


class Routes {
static const String BaseRoute = '/';
static const String LoginRoute = '/login';
Expand All @@ -23,9 +23,9 @@ class Routes {
static const String AddSpeaker = '/add/speaker';
static const String ShowAllMembers = '/all/members';
static const String AddMember = '/add/member';
static const String AddTeamMember = '/add/teamMember';
static const String AddMeeting = '/add/meeting';
static const String AddSession = '/add/session';

}

Route<dynamic> generateRoute(RouteSettings settings) {
Expand All @@ -46,6 +46,8 @@ Route<dynamic> generateRoute(RouteSettings settings) {
return SlideRoute(page: AddSpeakerForm());
case Routes.ShowAllMembers:
return MaterialPageRoute(builder: (context) => MemberListWidget());
case Routes.AddTeamMember:
return MaterialPageRoute(builder: (context) => AddTeamMemberForm());
case Routes.AddMember:
return SlideRoute(page: AddMemberForm());
case Routes.AddMeeting:
Expand Down
4 changes: 4 additions & 0 deletions frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:frontend/routes/meeting/MeetingsNotifier.dart';
import 'package:frontend/routes/session/SessionsNotifier.dart';
import 'package:frontend/routes/speaker/speakerNotifier.dart';
import 'package:frontend/models/event.dart';
import 'package:frontend/routes/teams/TeamsNotifier.dart';
import 'package:frontend/services/authService.dart';
import 'package:frontend/services/eventService.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -49,6 +50,9 @@ Future main() async {
ChangeNotifierProvider<BottomNavigationBarProvider>(
create: (_) => BottomNavigationBarProvider(),
),
ChangeNotifierProvider<TeamsNotifier>(
create: (_) => TeamsNotifier(teams: []),
),
],
child: App(),
));
Expand Down
1 change: 1 addition & 0 deletions frontend/lib/models/member.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:frontend/models/contact.dart';
import 'package:frontend/models/team.dart';

class Member {
final String id;
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/models/team.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TeamPublic {

class Team {
final String? id;
final String? name;
String? name;
final List<TeamMember>? members;
final List<String>? meetings;

Expand All @@ -71,7 +71,7 @@ class Team {
id: json['id'],
name: json['name'],
members: members.map((e) => TeamMember.fromJson(e)).toList(),
meetings: meetings.length == 0? [] : meetings as List<String>,
meetings: meetings.length == 0 ? [] : meetings as List<String>,
);
}

Expand Down
Loading

0 comments on commit 6dfeb31

Please sign in to comment.