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

215 lines
8.7 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:28:47 +00:00
compInfo = doc.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.
2019-03-18 23:35:59 +00:00
for (var j = 0; j < 2; j++) {
2019-03-16 20:47:56 +00:00
if (mi['far-blue']['series-' + (j + 1).toString()] != null) {
fb.push(mi['far-blue']['series-' + (j + 1).toString()]);
} else {
2019-03-19 00:15:17 +00:00
fb.push(`<span onclick="addMatch(${(i + 1).toString()},${(j + 1).toString()},'far-blue')">open</span>`);
2019-03-16 20:47:56 +00:00
}
if (mi['mid-blue']['series-' + (j + 1).toString()] != null) {
mb.push(mi['mid-blue']['series-' + (j + 1).toString()]);
} else {
2019-03-19 00:15:17 +00:00
mb.push(`<span onclick="addMatch(${(i + 1).toString()},${(j + 1).toString()},'mid-blue')">open</span>`);
2019-03-16 20:47:56 +00:00
}
if (mi['near-blue']['series-' + (j + 1).toString()] != null) {
nb.push(mi['near-blue']['series-' + (j + 1).toString()]);
} else {
2019-03-19 00:15:17 +00:00
nb.push(`<span onclick="addMatch(${(i + 1).toString()},${(j + 1).toString()},'near-blue')">open</span>`);
2019-03-16 20:47:56 +00:00
}
if (mi['far-red']['series-' + (j + 1).toString()] != null) {
fr.push(mi['far-red']['series-' + (j + 1).toString()]);
} else {
2019-03-19 00:15:17 +00:00
fr.push(`<span onclick="addMatch(${(i + 1).toString()},${(j + 1).toString()},'far-red')">open</span>`);
2019-03-16 20:47:56 +00:00
}
if (mi['mid-red']['series-' + (j + 1).toString()] != null) {
mr.push(mi['mid-red']['series-' + (j + 1).toString()]);
} else {
2019-03-19 00:15:17 +00:00
mr.push(`<span onclick="addMatch(${(i + 1).toString()},${(j + 1).toString()},'mid-red')">open</span>`);
2019-03-16 20:47:56 +00:00
}
if (mi['near-red']['series-' + (j + 1).toString()] != null) {
nr.push(mi['near-red']['series-' + (j + 1).toString()]);
} else {
2019-03-19 00:15:17 +00:00
nr.push(`<span onclick="addMatch(${(i + 1).toString()},${(j + 1).toString()},'near-red')">open</span>`)
2019-03-16 20:47:56 +00:00
}
}
var outstr = "";
outstr += "<tr><td rowspan='2' class='neu'>Quals " + (i + 1).toString() + "</td>";
2019-03-18 23:53:41 +00:00
outstr += "<td class='neu'>Series 1</td>";
2019-03-16 20:47:56 +00:00
outstr += "<td class='blue'>" + fb[0] + "</td>";
outstr += "<td class='blue'>" + mb[0] + "</td>";
outstr += "<td class='blue'>" + nb[0] + "</td>";
2019-03-18 23:53:41 +00:00
outstr += "<td class='red'>" + fr[0] + "</td>";
outstr += "<td class='red'>" + mr[0] + "</td>";
outstr += "<td class='red'>" + nr[0] + "</td>";
2019-03-16 20:47:56 +00:00
outstr += "</tr>"
2019-03-18 23:38:45 +00:00
for (var k = 1; k < 2; k++) {
2019-03-16 20:47:56 +00:00
outstr += "<tr>";
2019-03-18 23:53:41 +00:00
outstr += "<td class='neu'>Series " + (k + 1).toString() + "</td>";
2019-03-16 20:47:56 +00:00
outstr += "<td class='blue'>" + fb[k] + "</td>";
outstr += "<td class='blue'>" + mb[k] + "</td>";
outstr += "<td class='blue'>" + nb[k] + "</td>";
2019-03-18 23:53:41 +00:00
outstr += "<td class='red'>" + fr[k] + "</td>";
outstr += "<td class='red'>" + mr[k] + "</td>";
outstr += "<td class='red'>" + nr[k] + "</td>";
2019-03-16 20:47:56 +00:00
outstr += "</tr>"
}
2019-03-18 23:41:20 +00:00
document.getElementById('matchTable').innerHTML += outstr;
2019-03-16 20:47:56 +00:00
}
}
});
});
}
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-19 01:47:16 +00:00
var push = {}
push["match-" + matchNum.toString() + " " + position] = {
'completed': false,
'series': seriesNum.toString()
2019-03-16 20:47:56 +00:00
}
2019-03-19 00:16:17 +00:00
ti.set(push, {
2019-03-18 04:27:46 +00:00
merge: true
2019-03-19 00:16:17 +00:00
}).then(function() {
2019-03-18 04:27:46 +00:00
alert('Added!')
setTimeout(function() {
window.location.href = '../signUps';
}, 500);
});
2019-03-16 20:47:56 +00:00
}
});
});
}