/* Set the width of the side navigation to 250px and the left margin of the page content to 250px and add a black background color to body */
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}
/* Set the width of the side navigation to 0 and the left margin of the page content to 0, and the background color of body to white */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
document.body.style.backgroundColor = "white";
}
window.onload = function() {
document.getElementById('sideload').style.display = 'block';
var config = {
apiKey: "(insert the TitanScout Api Key Here)",
authDomain: "titanscoutandroid.firebaseapp.com",
databaseURL: "https://titanscoutandroid.firebaseio.com",
projectId: "titanscoutandroid",
storageBucket: "titanscoutandroid.appspot.com",
messagingSenderId: "1097635313476"
};
//eventually find a less-jank way to do this tho
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function(user) {
if (user != null) {
if (user.displayName != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.displayName;
} else if (user.email != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.email;
} else if (user.phoneNumber != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.phoneNumber;
} else {
document.getElementById('status').innerHTML = "You are signed in.";
}
} else {
window.location.replace('../../');
}
teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid);
teamAssoc.get().then(function(doc) {
if (doc.exists) {
list = doc.data()
teamNums = Object.keys(list)
document.getElementById('tns').innerHTML = ""
for (var i = 0; i < teamNums.length; i++) {
document.getElementById('tns').innerHTML += ""
}
} else {}
}).then(function() {
changeTeam(document.getElementById('tns').value)
})
});
}
function changeTeam(teamNum) {
document.getElementById('mselect').innerHTML = ""
var user = firebase.auth().currentUser;
ti = firebase.firestore().collection('teamData').doc("team-" + teamNum);
currentComp = null;
ti.get().then(function(doc) {
if (doc.exists) {
info = doc.data();
currentComp = info['currentCompetition'];
} else {
alert("Something's wrong with firebase.");
throw ("Something's wrong with firebase.");
}
}).then(function() {
if (currentComp != null) {
matches = firebase.firestore().collection('appBuilding').doc('team-' + teamNum).collection('competitions').doc(currentComp).collection('scoutsAndSchedule');
matches.get().then(function(qs) {
qs.forEach(function(dc) {
//regex search!
var pattern = /\d+/;
var name = dc.id;
document.getElementById('mselect').innerHTML += "";
});
cmatch(document.getElementById('mselect').value);
});
}
});
}
function cmatch(matchName) {
teamNum = document.getElementById('tns').value;
document.getElementById('tselect').innerHTML = ""
var user = firebase.auth().currentUser;
ti = firebase.firestore().collection('teamData').doc("team-" + teamNum);
currentComp = null;
ti.get().then(function(doc) {
if (doc.exists) {
info = doc.data();
currentComp = info['currentCompetition'];
} else {
alert("Something's wrong with firebase.");
throw ("Something's wrong with firebase.");
}
}).then(function() {
if (currentComp != null) {
match = firebase.firestore().collection('appBuilding').doc('team-' + teamNum).collection('competitions').doc(currentComp).collection('scoutsAndSchedule').doc('match-' + matchName)
match.get().then(function(doc) {
if (doc.exists) {
data = doc.data()
for (var i = 0; i < Object.keys(data['BLUE']).length; i++) {
var pattern = /\d+/;
document.getElementById('tselect').innerHTML += "";
}
for (var i = 0; i < Object.keys(data['RED']).length; i++) {
var pattern = /\d+/;
document.getElementById('tselect').innerHTML += "";
}
cseries(document.getElementById('sselect').value);
}
})
}
});
}
function cseries(seriesName) {
document.getElementById('FormData').innerHTML = ""
var user = firebase.auth().currentUser;
ti = firebase.firestore().collection('teamData').doc("team-" + teamNum);
currentComp = null;
ti.get().then(function(doc) {
if (doc.exists) {
info = doc.data();
currentComp = info['currentCompetition'];
} else {
alert("Something's wrong with firebase.");
throw ("Something's wrong with firebase.");
}
}).then(function() {
if (currentComp != null) {
if (seriesName == "quantitative") {
document.getElementById('FormData').innerHTML += "
"
for (var k = 0; k < questions[j][1]['elements'].length; k++) {
//// TODO: replace with real buttons for good styling
document.getElementById('FormData').innerHTML += questions[j][1]['elements'][k];
document.getElementById('FormData').innerHTML += ""
}
document.getElementById('FormData').innerHTML += "