Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Beta Phase
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceramcesoliveros committed Sep 26, 2018
1 parent 72d48ea commit 86538a7
Show file tree
Hide file tree
Showing 11 changed files with 521 additions and 143 deletions.
Binary file removed assets/lighthouse.gif
Binary file not shown.
92 changes: 92 additions & 0 deletions lib/admin/attendeesListAdmin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,40 @@ class AttendeesLists extends StatefulWidget {
}

class AttendeesListsState extends State<AttendeesLists> {
List<String> attendeesLists = new List();

Future<Null> queryEvents() async {
Firestore.instance
.collection('${widget.eventKey}_attendees')
.snapshots()
.listen((data) => data.documents
.forEach((doc) => attendeesLists.add(doc["username"])));
}

void initState() {
queryEvents();
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("List of Attendees"),
centerTitle: true,
backgroundColor: Colors.green[200],
actions: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(
context: context,
delegate: AttendeeSearchQuery(
attendeesLists: attendeesLists,
eventKey: widget.eventKey));
},
)
],
),
floatingActionButton: FloatingActionButton.extended(
label: Text("Add missing attendees"),
Expand Down Expand Up @@ -70,6 +97,7 @@ class AttendeesListsDocuments extends StatelessWidget {
color: Colors.white,
child: Column(children: [
ListTile(
leading: Icon(Icons.person),
trailing: IconButton(
icon: Icon(Icons.edit),
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
Expand Down Expand Up @@ -104,3 +132,67 @@ class AttendeesListsDocuments extends StatelessWidget {
);
}
}

class AttendeeSearchQuery extends SearchDelegate<String> {
final List<String> attendeesLists;
final String eventKey;
AttendeeSearchQuery({this.attendeesLists, this.eventKey});
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: Icon(Icons.clear),
onPressed: () {
query = "";
})
];
}

@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
onPressed: () {
close(context, null);
});
}

@override
Widget buildResults(BuildContext context) {
return Center(child: Text(query));
}

@override
Widget buildSuggestions(BuildContext context) {
final searchQuery = attendeesLists.isEmpty
? attendeesLists
: attendeesLists.where((p) => p.startsWith(query)).toSet().toList();
return attendeesLists == null
? ListTile(
title: Text("Search Attendee"),
)
: ListView.builder(
itemCount: searchQuery.length,
itemBuilder: (context, index) {
return ListTile(
onTap: () async {
query = searchQuery[0];
showResults(context);
},
title: RichText(
text: TextSpan(
text: searchQuery[index].substring(0, query.length),
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold),
children: [
TextSpan(
text: searchQuery[index].substring(query.length),
style: TextStyle(color: Colors.white70))
])),
leading: Icon(Icons.person),
);
},
);
}
}
8 changes: 8 additions & 0 deletions lib/admin/crudAttendees.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,26 @@ class EditAttendees extends StatefulWidget {
class _EditAttendeesState extends State<EditAttendees> {
GlobalKey<FormState> keyAttendee = GlobalKey<FormState>();
String name, attendOut, attendIn, eventKey, id;

Future<Null> setAttendees() async {
Map<String, String> setAttendee = {
"username": name,
"In": attendIn,
"Out": attendOut,
"eventKey": widget.eventKey
};

final eventAttendeesQuery = Firestore.instance
.collection('events_attended_${widget.id}')
.document(widget.eventKey);
final setQuery = Firestore.instance
.collection('${widget.eventKey}_attendees')
.document(widget.id);
setQuery.updateData(setAttendee).then((e) {
print("UPDATED");
eventAttendeesQuery.updateData(setAttendee).then((e) {
print("update attendee");
});
});
}

Expand Down
133 changes: 43 additions & 90 deletions lib/beacon/beacon_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ abstract class ListTab extends StatefulWidget {
}

class _ListTabState extends State<ListTab> {
Map<String, dynamic> status = {
"Connected": false,
"Distance": "Disconnected",
};
Map<String, dynamic> outAttendance = new Map();
Map<String, dynamic> setAttendees = {};
List<ListTabResult> _results = [];
StreamSubscription<ListTabResult> _subscription;
bool _running = false;
Expand All @@ -111,6 +105,20 @@ class _ListTabState extends State<ListTab> {
selectNotification: onSelectNotification);
}

Future<Null> signInAttendees(
{@required Duration duration,
@required DocumentReference attendees,
@required DocumentReference userRef}) async {
Fluttertoast.showToast(msg: "You are signed as attended");
}

Future<Null> signOutAttendees(
{@required Duration duration,
@required DocumentReference attendees,
@required DocumentReference userRef}) async {
Fluttertoast.showToast(msg: "Attendance Out!");
}

Future onSelectNotification(String payload) async {
if (payload != null) {
debugPrint("notification payload:" + payload);
Expand Down Expand Up @@ -144,7 +152,7 @@ class _ListTabState extends State<ListTab> {
'your channel name',
'your channel description',
importance: Importance.Min,
priority: Priority.Default,
priority: Priority.Low,
ongoing: true,
autoCancel: true,
playSound: false,
Expand Down Expand Up @@ -186,111 +194,56 @@ class _ListTabState extends State<ListTab> {
text: "Failed to Connect",
isSuccessful: false,
distance: null));
updateAttendees();
}

status = {
"Connected": result.isSuccessful,
"Distance": result.distance,
};
setAttendees = {
"eventID": widget.eventKey,
Map<String, dynamic> setAttendees = {
"eventName": widget.title,
"userid": prefs.getString('userid'),
"username": prefs.getString('username'),
"status": status,
"In": widget.eventTimeStart
.isAfter(widget.eventTimeStart.add(Duration(minutes: 15)))
? "Late"
: "Attended",
};
outAttendance = {
"eventID": widget.eventKey,
"Out": DateTime.now().isAfter(widget.eventTimeEnd) &&
widget.eventTimeEnd
.isBefore(widget.eventTimeEnd.add(Duration(minutes: 10)))
? "Completed"
: "Absent"
: "Present",
};

// outAttendance = {
// "eventID": widget.eventKey,
// "Out": DateTime.now().isAfter(widget.eventTimeEnd) &&
// widget.eventTimeEnd
// .isBefore(widget.eventTimeEnd.add(Duration(minutes: 10)))
// ? "Completed"
// : "Absent"
// };
result.distance < 7.0
? _showOngoingNotification(
successful:
result.distance < 7.0 ? 'Connected' : 'Disconnected',
status: result.text)
: _showStatusNotifcation();
DocumentReference attendeesRef = Firestore.instance.document(
"${widget.eventKey}_attendees/${prefs.getString('userid')}");

DocumentReference userRef = Firestore.instance.document(
"event_attended_${prefs.getString('userid')}/${widget.eventKey}");

attendeesRef.updateData(setAttendees).then((e) {
userRef.setData(setAttendees, merge: true).then((e) {
print("Added to Attended Events");
});
}).whenComplete(() {
Fluttertoast.showToast(msg: "Attendance Out!");
_onStop();
Navigator.pop(context);
});
});
});
_subscription.onDone(() async {
setState(() {
_running = false;
});
});
}

void updateAttendees() async {
Duration duration = Duration(seconds: 30);
SharedPreferences prefs = await SharedPreferences.getInstance();
DocumentReference attendeesRef = Firestore.instance
.document("${widget.eventKey}_attendees/${prefs.getString('userid')}");

DocumentReference userRef = Firestore.instance.document(
"event_attended_${prefs.getString('userid')}/${widget.eventKey}");

if (widget.eventTimeStart
.isBefore(widget.eventTimeStart.add(Duration(seconds: 10)))) {
signInAttendees(
duration: duration, attendees: attendeesRef, userRef: userRef);
} else if (widget.eventTimeEnd
.isAfter(widget.eventTimeEnd.add(Duration(minutes: 5)))) {
signOutAttendees(
duration: duration, attendees: attendeesRef, userRef: userRef);
}
}

void signInAttendees(
{@required Duration duration,
@required DocumentReference attendees,
@required DocumentReference userRef}) async {
Future.delayed(duration, () async {
Firestore.instance.runTransaction((transAttendees) async {
DocumentSnapshot snapshot = await transAttendees.get(attendees);
if (!snapshot.exists) {
await transAttendees.set(attendees, setAttendees);
Fluttertoast.showToast(
msg: "You have been signed as ATTENDED",
gravity: ToastGravity.BOTTOM);
}
});
});
Firestore.instance.runTransaction((tx) async {
DocumentSnapshot snapshot = await tx.get(userRef);
if (snapshot.exists) {
await tx.update(userRef, setAttendees);
}
});
}

void signOutAttendees(
{@required Duration duration,
@required DocumentReference attendees,
@required DocumentReference userRef}) async {
Future.delayed(duration, () async {
Firestore.instance.runTransaction((transAttendees) async {
DocumentSnapshot snapshot = await transAttendees.get(attendees);
if (snapshot.exists) {
await transAttendees.update(attendees, outAttendance);
Navigator.of(context).pop();
Future.delayed(Duration(seconds: 30), () {
_onStop();
}
});
});
});

Firestore.instance.runTransaction((tx) async {
DocumentSnapshot snapshot = await tx.get(userRef);
if (snapshot.exists) {
await tx.update(userRef, outAttendance);
}
});
}

@override
Expand Down
Loading

0 comments on commit 86538a7

Please sign in to comment.