From d44977d1b1da4cd320ff7ca6d673bdd5d50443d4 Mon Sep 17 00:00:00 2001 From: tylercarberry Date: Sun, 16 Jul 2017 16:10:15 -0400 Subject: [PATCH 1/3] Call new attendance endpoint api.rowanacm.org/prod/sign-in --- website/attendance/Scripts/attendance.js | 122 ++++++++++++----------- website/attendance/css/main.css | 25 ++++- website/attendance/index.html | 72 ++++++++++--- 3 files changed, 142 insertions(+), 77 deletions(-) diff --git a/website/attendance/Scripts/attendance.js b/website/attendance/Scripts/attendance.js index 907cfde..5052d54 100755 --- a/website/attendance/Scripts/attendance.js +++ b/website/attendance/Scripts/attendance.js @@ -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 ✓
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 ✓
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 + }); + } } diff --git a/website/attendance/css/main.css b/website/attendance/css/main.css index cacb0aa..26c7585 100644 --- a/website/attendance/css/main.css +++ b/website/attendance/css/main.css @@ -27,6 +27,7 @@ header { } .body { padding-left: 40px; + padding-bottom: 40px; } .body_first_half { width: 49%; @@ -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); diff --git a/website/attendance/index.html b/website/attendance/index.html index 897c605..9bdd2b7 100755 --- a/website/attendance/index.html +++ b/website/attendance/index.html @@ -6,6 +6,8 @@ + ACM Sign-In @@ -20,7 +22,7 @@ - + -
-
Rowan ACM
+
+ +
+

Admin

+ +
+ +
+
-

ADMIN

- - - - -

Current Meeting:

- + +

Current Meeting:

+ + + + From e429da508e0fca6618572c5d1290c52a05df1d90 Mon Sep 17 00:00:00 2001 From: tylercarberry Date: Fri, 21 Jul 2017 13:46:14 -0400 Subject: [PATCH 2/3] Make post announcement page Web dev already had a page that was using firebase to make an announcement. This page goes through the server directly. Feel free to delete this page and convert the old one to use the server. --- website/attendance/Scripts/attendance.js | 6 +++ website/attendance/css/main.css | 4 ++ website/attendance/index.html | 2 + website/create-announcement/index.html | 52 +++++++++++++++++++ .../create-announcement/postAnnouncement.js | 49 +++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 website/create-announcement/index.html create mode 100644 website/create-announcement/postAnnouncement.js diff --git a/website/attendance/Scripts/attendance.js b/website/attendance/Scripts/attendance.js index 5052d54..ae4a7a9 100755 --- a/website/attendance/Scripts/attendance.js +++ b/website/attendance/Scripts/attendance.js @@ -419,3 +419,9 @@ function exportAllAttendance(members) { }); } + +function updateGoogleToken() { + firebase.auth().currentUser.getToken( /* forceRefresh */ true).then(function(idToken) { + document.getElementById("google-token").innerHTML = "Google Token: " + idToken; + }) +} diff --git a/website/attendance/css/main.css b/website/attendance/css/main.css index 26c7585..5c800c6 100644 --- a/website/attendance/css/main.css +++ b/website/attendance/css/main.css @@ -127,4 +127,8 @@ a { .body { padding-left: 15px; } +} + +#google-token { + font-size: 7px; } \ No newline at end of file diff --git a/website/attendance/index.html b/website/attendance/index.html index 9bdd2b7..40ca2f8 100755 --- a/website/attendance/index.html +++ b/website/attendance/index.html @@ -103,6 +103,8 @@

Admin

mdc-button--primary mdc-ripple-surface" data-mdc-auto-init="MDCRipple">Change current meeting + +

Google Token:

diff --git a/website/create-announcement/index.html b/website/create-announcement/index.html new file mode 100644 index 0000000..f6deac7 --- /dev/null +++ b/website/create-announcement/index.html @@ -0,0 +1,52 @@ + + + + + ACM + + + + + + + + + + + + + + +
+ + + +
+

Create Announcement

+

Go to the attendance, sign in, scroll down and click on "Google Token" at the bottom of the page. Copy the google token. The token can be used more than once, but expires after 15 minutes

+

Committee must be either general, app, web, ai, robotics, or game

+ + +

Title:

+

Text:

+

Committee:

+ Also post on slack
+

Your google token:

+ + + + +
+ + + + diff --git a/website/create-announcement/postAnnouncement.js b/website/create-announcement/postAnnouncement.js new file mode 100644 index 0000000..304a995 --- /dev/null +++ b/website/create-announcement/postAnnouncement.js @@ -0,0 +1,49 @@ +var post = function() { + var title = document.getElementById("title").value; + var text = document.getElementById("text").value + var committee = document.getElementById("committee").value + var token = document.getElementById("token").value + var slack = document.getElementById("slack").checked + + if (title == "") { + showError("Title is empty."); + } else if (text == "") { + showError("Text is empty."); + } else if (token == "") { + showError("Token is empty."); + } else if (committee == "") { + showError("Committee is empty."); + } else { + + $.get({ + url: "https://api.rowanacm.org/prod/post-announcement", + type: "get", + data: { + title: title, + body: text, + committee: committee, + token: token, + also_post_on_slack: slack + }, + success: function(response) { + console.log(response); + alert(response.message); + }, + error: function(xhr) { + alert("Connection Error: " + xhr); + } + }); + + + } +}; + +var showError = function(message) { + alert(message); +}; + +var showSuccess= function(message) { + $("#succ-alert").html(message); + $("#succ-alert").show(); + $("#prob-alert").hide(); +}; From e365025ae83542ee36b394535d697dedb7cbcdbe Mon Sep 17 00:00:00 2001 From: tylercarberry Date: Fri, 21 Jul 2017 14:06:35 -0400 Subject: [PATCH 3/3] Remove export attendace buttons Since the attendance is being emailed automatically, the buttons are no longer needed. --- website/attendance/Scripts/attendance.js | 99 ------------------------ website/attendance/index.html | 31 +------- 2 files changed, 2 insertions(+), 128 deletions(-) diff --git a/website/attendance/Scripts/attendance.js b/website/attendance/Scripts/attendance.js index ae4a7a9..3269f6c 100755 --- a/website/attendance/Scripts/attendance.js +++ b/website/attendance/Scripts/attendance.js @@ -295,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() { @@ -327,99 +321,6 @@ 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; diff --git a/website/attendance/index.html b/website/attendance/index.html index 40ca2f8..7ae2dfc 100755 --- a/website/attendance/index.html +++ b/website/attendance/index.html @@ -72,37 +72,10 @@

Rowan ACM


-

Admin

- -
- -
- -
- +

Admin
Auto-attendance is enabled. You will be sent an email with the attendance every Saturday.

Current Meeting:

- +

Google Token: