tra-analysis/website/public/scout/signUps/scripts.js

216 lines
8.8 KiB
JavaScript
Raw Normal View History

2019-03-16 20:47:56 +00:00
/* 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 += "<option value='" + teamNums[i] + "'>" + teamNums[i] + "</option>"
}
} else {}
}).then(function() {
changeTeam(document.getElementById('tns').value)
})
});
}
function changeTeam(teamNum) {
2019-03-18 23:06:11 +00:00
document.getElementById("matchTable").innerHTML = `<tr>
2019-03-16 20:47:56 +00:00
<td class="neu">Match Number</td>
<td class="neu">Series</td>
<td class="blue">Far Blue</td>
<td class="blue">Mid Blue</td>
<td class="blue">Near Blue</td>
<td class="red">Far Red</td>
<td class="red">Mid Red</td>
<td class="red">Near Red</td>
</tr>`;
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() {
cci = firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp);
cci.get().then(function(doc) {
if (doc.exists) {
2019-03-18 23:27:46 +00:00
compInfo = cci.data();
2019-03-16 20:47:56 +00:00
matches = Object.keys(compInfo);
matches.sort();
var nr = [],
mr = [],
fr = [],
nb = [],
mb = [],
fb = [];
for (var i = 0; i < matches.length; i++) {
mi = compInfo["match-" + (i + 1).toString()]
//sets up the table lists. i really hope it doesn't break.
for (var j = 0; j < 2; i++) {
if (mi['far-blue']['series-' + (j + 1).toString()] != null) {
fb.push(mi['far-blue']['series-' + (j + 1).toString()]);
} else {
fb.push("<span onclick='addMatch(" + (i + 1).toString() + "," + (j + 1).toString() + ",'far-blue')'>open</span>");
}
if (mi['mid-blue']['series-' + (j + 1).toString()] != null) {
mb.push(mi['mid-blue']['series-' + (j + 1).toString()]);
} else {
mb.push("<span onclick='addMatch(" + (i + 1).toString() + "+", (j + 1).toString() + ",'mid-blue')'>open</span>");
}
if (mi['near-blue']['series-' + (j + 1).toString()] != null) {
nb.push(mi['near-blue']['series-' + (j + 1).toString()]);
} else {
nb.push("<span onclick='addMatch(" + (i + 1).toString() + "," + (j + 1).toString() + ",'near-blue')'>open</span>");
}
if (mi['far-red']['series-' + (j + 1).toString()] != null) {
fr.push(mi['far-red']['series-' + (j + 1).toString()]);
} else {
fr.push("<span onclick='addMatch(" + (i + 1).toString() + "," + (j + 1).toString() + ",'far-red')'>open</span>");
}
if (mi['mid-red']['series-' + (j + 1).toString()] != null) {
mr.push(mi['mid-red']['series-' + (j + 1).toString()]);
} else {
mr.push("<span onclick='addMatch(" + (i + 1).toString() + "," + (j + 1).toString() + ",'mid-red')'>open</span>");
}
if (mi['near-red']['series-' + (j + 1).toString()] != null) {
nr.push(mi['near-red']['series-' + (j + 1).toString()]);
} else {
nr.push("<span onclick='addMatch(" + (i + 1).toString() + "," + (j + 1).toString() + ",'near-red')'>open</span>")
}
}
var outstr = "";
outstr += "<tr><td rowspan='2' class='neu'>Quals " + (i + 1).toString() + "</td>";
outstr += "<td class='neu'>Series 1</tr>";
outstr += "<td class='blue'>" + fb[0] + "</td>";
outstr += "<td class='blue'>" + mb[0] + "</td>";
outstr += "<td class='blue'>" + nb[0] + "</td>";
outstr += "<td class='blue'>" + fr[0] + "</td>";
outstr += "<td class='blue'>" + mr[0] + "</td>";
outstr += "<td class='blue'>" + nr[0] + "</td>";
outstr += "</tr>"
for (var k = 1; k < 2; i++) {
outstr += "<tr>";
outstr += "<td class='neu'>Series " + (k + 1).toString() + "</tr>";
outstr += "<td class='blue'>" + fb[k] + "</td>";
outstr += "<td class='blue'>" + mb[k] + "</td>";
outstr += "<td class='blue'>" + nb[k] + "</td>";
outstr += "<td class='blue'>" + fr[k] + "</td>";
outstr += "<td class='blue'>" + mr[k] + "</td>";
outstr += "<td class='blue'>" + nr[k] + "</td>";
outstr += "</tr>"
}
document.getElementById(matchTable).innerHTML += outstr;
}
}
});
});
}
2019-03-18 04:27:46 +00:00
function addMatch(matchNum, seriesNum, position) {
var success = false;
var teamNum = document.getElementById('tns').value
2019-03-16 20:47:56 +00:00
var user = firebase.auth().currentUser;
2019-03-18 04:27:46 +00:00
var name = "anon"
2019-03-16 20:47:56 +00:00
if (user.displayName != null) {
name = user.displayName;
} else if (user.email != null) {
name = user.email;
} else if (user.phoneNumber != null) {
2019-03-18 04:27:46 +00:00
name = user.phoneNumber;
}
2019-03-16 20:47:56 +00:00
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() {
cci = firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp);
2019-03-18 04:27:46 +00:00
cci.get().then(function(doc) {
2019-03-16 20:47:56 +00:00
if (doc.exists) {
2019-03-18 04:27:46 +00:00
info = doc.data();
match = info["match-" + matchNum.toString()];
pos = match[position];
occ = pos["series-" + seriesNum.toString()];
2019-03-16 20:47:56 +00:00
if (occ == null) {
2019-03-18 04:27:46 +00:00
info["match-" + matchNum.toString()][position]["series-" + seriesNum.toString()] = name;
2019-03-16 20:47:56 +00:00
firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp).set(info)
2019-03-18 04:27:46 +00:00
success = true;
} else {
alert(occ + "has added that match first.")
setTimeout(function() {
window.location.href = '../signUps';
}, 500);
}
}
}).then(function() {
if (success) {
ti = firebase.firestore().collection('matchSignupsIndividual').doc(user.uid).collection("team-" + teamNum).doc(currentComp);
2019-03-18 22:54:34 +00:00
label="match-" + matchNum.toString()+" "+position
push = {label: {
2019-03-18 04:27:46 +00:00
'completed': false,
2019-03-18 22:54:34 +00:00
'series': seriesNum.toString()
2019-03-18 04:27:46 +00:00
}
2019-03-16 20:47:56 +00:00
}
2019-03-18 04:27:46 +00:00
cityRef.set(push, {
merge: true
}), then(function() {
alert('Added!')
setTimeout(function() {
window.location.href = '../signUps';
}, 500);
});
2019-03-16 20:47:56 +00:00
}
});
});
}