Skip to content

Commit

Permalink
Merge pull request #7 from RowanACM/attendance-2.0
Browse files Browse the repository at this point in the history
Attendance 2.0
  • Loading branch information
TylerCarberry authored Jul 21, 2017
2 parents 4163203 + e365025 commit dc4efa0
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 174 deletions.
223 changes: 67 additions & 156 deletions website/attendance/Scripts/attendance.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,65 +124,69 @@ function registeredForACM() {
}

function submitAttendance() {
var user = firebase.auth().currentUser;
if (user != null) {
console.log("SIGNING IN TO MEETING");
signingInToMeeting();

$.get({
url: "https://2dvdaw7sq1.execute-api.us-east-1.amazonaws.com/prod/attendance",
type: "get", //send it through get method
data: {
uid: user.uid,
name: user.displayName,
email: user.email
},
success: function(response) {
switch(response) {
case 100:
// Signed in successfully. New member
signedInToMeeting();
document.getElementById("attendance").innerHTML = "Signed in successfully ✓<br/>Welcome to your first ACM Meeting. You should have received an email with more information about the club.";
break;
case 110:
// Signed in successfully. Existing member
signedInToMeeting();
break;
case 120:
// Already signed in
signedInToMeeting();
break;
case 130:
// Already signed in
registeredForACM();
break;
case 200:
// Didn't sign in. Attendance disabled
document.getElementById("meeting_button").style.visibility = "hidden";
document.getElementById("attendance").innerHTML = "You already registered for ACM";
break;
case 210:
// Invalid input
document.getElementById("meeting_button").style.visibility = "visible";
document.getElementById("attendance").innerHTML = "Error signing in. Try again. ERROR MESSAGE: INVALID INPUT";
break;
case 220:
// Invalid input
document.getElementById("meeting_button").style.visibility = "visible";
document.getElementById("attendance").innerHTML = "Error signing in. Try again. ERROR MESSAGE: UNKNOWN ERROR";
break;
default:
// Invalid input
document.getElementById("meeting_button").style.visibility = "visible";
document.getElementById("attendance").innerHTML = "Error signing in. Try again. ERROR MESSAGE: UNKNOWN ERROR";
}
},
error: function(xhr) {
//Do Something to handle error
alert("Connection Error: " + xhr);
}
});
}
var user = firebase.auth().currentUser;
if (user != null) {
console.log("SIGNING IN TO MEETING");
signingInToMeeting();

firebase.auth().currentUser.getToken( /* forceRefresh */ true).then(function(idToken) {

$.get({
url: "https://api.rowanacm.org/prod/sign-in",
type: "get", //send it through get method
data: {
token: idToken
},
success: function(response) {
console.log(response);
switch (response["response_code"]) {
case 100:
// Signed in successfully. New member
signedInToMeeting();
document.getElementById("attendance").innerHTML = "Signed in successfully ✓<br/>Welcome to your first ACM Meeting. You should have received an email with more information about the club.";
break;
case 110:
// Signed in successfully. Existing member
signedInToMeeting();
break;
case 120:
// Already signed in
signedInToMeeting();
break;
case 130:
// Already signed in
registeredForACM();
break;
case 200:
// Didn't sign in. Attendance disabled
document.getElementById("meeting_button").style.visibility = "hidden";
document.getElementById("attendance").innerHTML = "You already registered for ACM";
break;
case 210:
// Invalid input
document.getElementById("meeting_button").style.visibility = "visible";
document.getElementById("attendance").innerHTML = "Error signing in. Try again. ERROR MESSAGE: INVALID INPUT";
break;
case 220:
// Invalid input
document.getElementById("meeting_button").style.visibility = "visible";
document.getElementById("attendance").innerHTML = "Error signing in. Try again. ERROR MESSAGE: UNKNOWN ERROR";
break;
default:
// Invalid input
document.getElementById("meeting_button").style.visibility = "visible";
document.getElementById("attendance").innerHTML = "Error signing in. Try again. ERROR MESSAGE: UNKNOWN ERROR";
}
},
error: function(xhr) {
//Do Something to handle error
alert("Connection Error: " + xhr);
}
});
}).catch(function(error) {
// Handle error
});
}
}


Expand Down Expand Up @@ -291,12 +295,6 @@ function determineIfAdmin() {

function showAdminViews() {
document.getElementById("admin_title").style.visibility = "visible";
document.getElementById("get_attendance_button").style.visibility = "visible";
document.getElementById("get_all_attendance_button").style.visibility = "visible";
document.getElementById("get_members_button").style.visibility = "visible";
document.getElementById("toggle_attendance_button").style.visibility = "visible";
document.getElementById("current_meeting_text").style.visibility = "visible";
document.getElementById("change_current_meeting_button").style.visibility = "visible";
}

function toggleAttendanceEnabled() {
Expand All @@ -323,95 +321,8 @@ function download(filename, text) {
}
}

function changeCurrentMeeting() {
var meetingVal = prompt("Set current meeting (Ex. jan_23): ", currentMeeting);
if(meetingVal != null && meetingVal.length > 3)
firebase.database().ref('attendance').child("status").child("current").set(meetingVal);

}

function exportAttendance() {
var exportRef = firebase.database().ref("members");
exportRef.once('value', function(snapshot) {
console.log("EXPORT RECEIVED");
var result = snapshot.val()
exportAttendance2(result);
});

}

function exportAllMembers() {
var exportRef = firebase.database().ref("members");
exportRef.once('value', function(snapshot) {
console.log("EXPORT RECEIVED");
var result = snapshot.val()
exportAllAttendance(result);
});

}

var temp;
function exportPeople() {
var exportRef = firebase.database().ref("members");
exportRef.once('value', function(snapshot) {
console.log("EXPORT RECEIVED");
temp = snapshot;
var result = snapshot.val()

var attendanceExport = "Name,Email,Meeting Count\n";
for(var member in result) {
var meeting_count = result[member]["meeting_count"];
if(meeting_count == "undefined")
meeting_count = 0;
attendanceExport += result[member]["name"] + "," + result[member]["email"] + "," + meeting_count + "\n";
}
var fileName = "acm_members.csv";
download(fileName, attendanceExport);
});

}


function exportAttendance2(members) {
var exportRef = firebase.database().ref("attendance").child(currentMeeting);
exportRef.once('value', function(snapshot) {
console.log("EXPORT RECEIVED");
result = snapshot.val()

var attendanceExport = "Name,Email\n";
for(var member in result) {
//var meeting_count = members[result[member]["uid"]]["meeting_count"];
attendanceExport += result[member]["name"] + "," + result[member]["email"] + "\n";

}
var fileName = "attendance_" + currentMeeting + ".csv";
download(fileName, attendanceExport);
});

}


function exportAllAttendance(members) {
var exportRef = firebase.database().ref("attendance");
exportRef.once('value', function(snapshot) {
console.log("EXPORT RECEIVED");
result = snapshot.val();

for(var week in result) {
if(week != "status") {
console.log(week);

var attendanceExport = "Name,Email\n";
for(var member in result[week]) {
if(members[member] != null) {
//var meeting_count = members[member]["meeting_count"];
attendanceExport += result[week][member]["name"] + "," + result[week][member]["email"] + "\n";
}
}
var fileName = "attendance_" + week + ".csv";
download(fileName, attendanceExport);
}
}
});

function updateGoogleToken() {
firebase.auth().currentUser.getToken( /* forceRefresh */ true).then(function(idToken) {
document.getElementById("google-token").innerHTML = "Google Token: " + idToken;
})
}
29 changes: 27 additions & 2 deletions website/attendance/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ header {
}
.body {
padding-left: 40px;
padding-bottom: 40px;
}
.body_first_half {
width: 49%;
Expand All @@ -48,31 +49,51 @@ header {
}
#sign_out {
visibility: hidden;
margin-bottom: 15px;
--mdc-theme-primary: #8e8e8e;
}
#admin_title {
visibility: hidden;
margin-bottom: 20px;
}
#signed_in {
margin: 10px;
}
#first_meeting {
margin: 10px;
}
#get_attendance_button {
visibility: hidden;
margin-bottom: 5px;
}
#toggle_attendance_button {
visibility: hidden;
margin-bottom: 5px;
}
#current_meeting_text {
visibility: hidden;
margin-top: 10px;
margin-bottom: 10px;
}
#change_current_meeting_button {
visibility: hidden;
margin-bottom: 5px;
}
#get_members_button {
visibility: hidden;
margin-bottom: 5px;
}
#get_all_attendance_button {
visibility: hidden;
margin-bottom: 5px;
}
#contribute {
--mdc-theme-primary: #8e8e8e;
margin-top: 15px;
margin-bottom: 25px;
}

#attendance {
font-size: 15px;

}
a {
color: rgb(30, 30, 30);
Expand Down Expand Up @@ -106,4 +127,8 @@ a {
.body {
padding-left: 15px;
}
}

#google-token {
font-size: 7px;
}
47 changes: 31 additions & 16 deletions website/attendance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<meta name="google-signin-cookiepolicy" content="single_host_origin">
<meta name="google-signin-scope" content="profile email">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="node_modules/material-components-web/dist/material-components-web.css">

<title>ACM Sign-In</title>
<link rel="shortcut icon" href="img/rowan_acm_logo.png">
Expand All @@ -20,7 +22,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https%3A%2F%2Fwww.google.com%2Fjsapi%3Fautoload%3D%7B%27modules%27%3A%5B%7B%27name%27%3A%27visualization%27%2C%27version%27%3A%271.1%27%2C%27packages%27%3A%5B%27corechart%27%5D%7D%5D%7D"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script src="Scripts/attendance.js"></script>
<script src="scripts/attendance.js"></script>
<script>
google.charts.load('current', {packages: ['corechart']});
google.charts.setOnLoadCallback(null);
Expand All @@ -44,30 +46,43 @@ <h1 class="main_header">Rowan ACM</h1>
</div>
</header>
<div class="body">
<p id="attendance">Sign in to your Google account <br /> (Rowan Email Address)</p>
<button type="button" class="animated infinite tada" id="meeting_button" onclick="submitAttendance()">MEETING SIGN IN</button>
<p id="attendance" class="mdc-typography--display1">Sign in to your Google account (Rowan Email Address)</p>
<button type="button" class="animated infinite tada mdc-button
mdc-button--raised
mdc-button--primary
mdc-ripple-surface" id="meeting_button" onclick="submitAttendance()">MEETING SIGN IN</button>
<div class="g-signin2" id="google_sign_in" data-onsuccess="onSignIn"></div>
<button type="button" id="sign_out" onclick="firebaseSignOut()">Google Sign Out</button>
<button type="button" id="sign_out" onclick="firebaseSignOut()" class="mdc-button
mdc-button--raised
mdc-button--primary
mdc-ripple-surface"
data-mdc-auto-init="MDCRipple">Google Sign Out</button>

<p id="signed_in">People signed in: Loading</p>
<p id="first_meeting">New members: Loading</p>
<p id="contribute"><a href="https://github.com/RowanACM/ACM_Site" target="_blank">Help code this website</a> </p>
<p id="signed_in" class="mdc-typography--display1">People signed in: Loading</p>
<p id="first_meeting" class="mdc-typography--display1">New members: Loading</p>
<p id="contribute"><a href="https://github.com/RowanACM/ACM_Site" target="_blank" class="mdc-button
mdc-button--raised
mdc-button--primary
mdc-ripple-surface
--mdl-theme-primary=f44336"
data-mdc-auto-init="MDCRipple">Help code this website</a> </p>

<a href="https://twitter.com/RowanACM" class="twitter-follow-button" data-show-count="false">Follow @RowanACM</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<br/>
<div class="fb-page" data-href="https://www.facebook.com/rowanacm" data-small-header="true" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="false"><blockquote cite="https://www.facebook.com/rowanacm" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/rowanacm">Rowan ACM</a></blockquote></div>

<div class="fb-like" data-href="https://www.facebook.com/rowanacm" data-layout="button_count" data-action="like" data-size="small" data-show-faces="false" data-share="false" style="vertical-align:top;zoom:1;*display:inline"></div>

<br/>
<p id="admin_title">ADMIN</p>
<button id="get_attendance_button" onclick="exportAttendance()">Export current attendance</button>
<button id="get_all_attendance_button" onclick="exportAllMembers()">Export every meeting attendance</button>
<button id="get_members_button" onclick="exportPeople()">Export current members</button>
<button id="toggle_attendance_button" onclick="toggleAttendanceEnabled()">Toggle attendance enabled</button>
<p id="current_meeting_text">Current Meeting: </p>
<button id="change_current_meeting_button" onclick="changeCurrentMeeting()">Change current meeting</button>
<h3 id="admin_title" class="mdc-typography--display0">Admin<br/>Auto-attendance is enabled. You will be sent an email with the attendance every Saturday.</h3>

<p id="current_meeting_text" class="mdc-typography--display1">Current Meeting: </p>


<p id="google-token" onclick="updateGoogleToken()">Google Token:</p>



</div>
</body>
<script src="node_modules/material-components-web/dist/material-components-web.js"></script>
<script>mdc.autoInit()</script>
</html>
Loading

0 comments on commit dc4efa0

Please sign in to comment.