mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2024-12-27 01:59:08 +00:00
continue with multi-form
This commit is contained in:
parent
f483cbbcfb
commit
926db38db9
@ -21,7 +21,7 @@
|
|||||||
<a href="../../team">Team</a>
|
<a href="../../team">Team</a>
|
||||||
<p>Scout Matches</p>
|
<p>Scout Matches</p>
|
||||||
<a href="../signUps" class="scoutMatchLinks">Sign Up For Matches</a>
|
<a href="../signUps" class="scoutMatchLinks">Sign Up For Matches</a>
|
||||||
<a href="../rpts" class="scoutMatchLinks">Submit Scouting Reports</a>
|
<a href="#" class="scoutMatchLinks">Submit Scouting Reports</a>
|
||||||
<a href="../../stats">Tournament Stats</a>
|
<a href="../../stats">Tournament Stats</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
@ -33,10 +33,10 @@
|
|||||||
<div>
|
<div>
|
||||||
Scouting For: <select id="tns" onchange="changeTeam(document.getElementById('tns').value)"></select>
|
Scouting For: <select id="tns" onchange="changeTeam(document.getElementById('tns').value)"></select>
|
||||||
</div>
|
</div>
|
||||||
<h2>Sign Up For Matches</h2>
|
|
||||||
<h2>Submit a Report:</h2>
|
<h2>Submit a Report:</h2>
|
||||||
|
<select id="mSelect"></select>
|
||||||
<div id=FormData>
|
<div id=FormData>
|
||||||
<select id="mSelect"></select>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,10 +48,127 @@ window.onload = function() {
|
|||||||
document.getElementById('tns').innerHTML += "<option value='" + teamNums[i] + "'>" + teamNums[i] + "</option>"
|
document.getElementById('tns').innerHTML += "<option value='" + teamNums[i] + "'>" + teamNums[i] + "</option>"
|
||||||
}
|
}
|
||||||
} else {}
|
} else {}
|
||||||
|
}).then(function() {
|
||||||
|
changeTeam(document.getElementById('tns').value)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeTeam(teamNum) {
|
||||||
|
//remove all event listeners for element by cloning it
|
||||||
|
var old_element = document.getElementById("mSelect");
|
||||||
|
var new_element = old_element.cloneNode(true);
|
||||||
|
old_element.parentNode.replaceChild(new_element, old_element);
|
||||||
|
//ok back to normal stuff
|
||||||
|
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) {
|
||||||
|
comps = firebase.firestore().collection('matchSignupsIndividual').doc(user.uid).collection("team-" + teamNum).doc(currentComp);
|
||||||
|
comps.get().then(function(doc) {
|
||||||
|
if (doc.exists) {
|
||||||
|
var matches = doc.data();
|
||||||
|
document.getElementById('mSelect').innerHTML = "";
|
||||||
|
for (var i = 0; i < Object.keys(matches).length; i++) {
|
||||||
|
name = Object.keys(matches)[i];
|
||||||
|
series = matches[Object.keys(matches)[i]]['series'];
|
||||||
|
completed = matches[Object.keys(matches)[i]]['completed'];
|
||||||
|
if (!completed) {
|
||||||
|
document.getElementById('mSelect').innerHTML += "<option value=" + name + series + ">" + name + "</option>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById('mSelect').addEventListener("change", function() {
|
||||||
|
updateForm(document.getElementById('mSelect').value, teamNum, currentComp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function lastWord(words) {
|
||||||
|
var n = words.split(" ");
|
||||||
|
return n[n.length - 1];
|
||||||
|
}
|
||||||
|
function firstWord(words) {
|
||||||
|
var n = words.split(" ");
|
||||||
|
return n[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateForm(locString, teamNum, competition) {
|
||||||
|
seriesList = [];
|
||||||
|
document.getElementById('FormData').innerHTML = ""
|
||||||
|
loc = firebase.firestore().collection('appBuliding').document("team-" + teamNum).collection('competitions').document(competition).collection(lastWord(locString));
|
||||||
|
loc.get().then(function(docs) {
|
||||||
|
docs.forEach(function(doc) {
|
||||||
|
seriesList.push(doc.data());
|
||||||
|
});
|
||||||
|
seriesList.sort(function(a, b) {
|
||||||
|
return a.order - b.order;
|
||||||
|
})
|
||||||
|
for (var i = 0; i < seriesList.length; i++) {
|
||||||
|
document.getElementById('FormData').innerHTML += "<h3>"
|
||||||
|
seriesList[i].id + "</h3>";
|
||||||
|
labels = Object.keys(seriesList[i].data());
|
||||||
|
var index = labels.indexOf('order');
|
||||||
|
if (index > -1) {
|
||||||
|
labels.splice(index, 1);
|
||||||
|
}
|
||||||
|
var questions = [];
|
||||||
|
for (var j = 0; j < labels.length; j++) {
|
||||||
|
questions.push([labels[j], seriesList[i].data()[labels[j]]])
|
||||||
|
}
|
||||||
|
questions.sort(function(a, b) {
|
||||||
|
return a[1].order - b[1].order;
|
||||||
|
})
|
||||||
|
for (var j = 0; j < questions.length; j++) {
|
||||||
|
document.getElementById('FormData').innerHTML += "<div>";
|
||||||
|
document.getElementById('FormData').innerHTML += questions[j][1]['title'];
|
||||||
|
if (questions[j][1]['type'] = 'shortText') {
|
||||||
|
document.getElementById('FormData').innerHTML += "<input id=''" + questions[j][0] + "' type='text'></input>";
|
||||||
|
} else if (questions[j][1]['type'] = 'longText') {
|
||||||
|
document.getElementById('FormData').innerHTML += "<textarea id=''" + questions[j][0] + "' rows='4' cols='50''></textarea>";
|
||||||
|
} else if (questions[j][1]['type'] = 'numerical') {
|
||||||
|
document.getElementById('FormData').innerHTML += "<input type='button' onclick='dec(" + questions[j][0] + ")' value='-'></input><span id='" +
|
||||||
|
questions[j][0] +
|
||||||
|
"'>" + (questions[j][1]['default']).toString() + "</span><input type='button' onclick='inc(" + questions[j][0] + ")' value='+'></input>";
|
||||||
|
} else if (questions[j][1]['type'] = 'range') {
|
||||||
|
document.getElementById('FormData').innerHTML += " " + questions[j][1]['min']['text'] + " ";
|
||||||
|
document.getElementById('FormData').innerHTML += "<input type='range' min='" + questions[j][1]['min']['val'] + "' max='" + questions[j][1]['max']['val'] + "'>";
|
||||||
|
document.getElementById('FormData').innerHTML += " " + questions[j][1]['max']['text'];
|
||||||
|
} else if (questions[j][1]['type'] = 'segment') {
|
||||||
|
document.getElementById('FormData').innerHTML += "<div id='" + questions[j][0] + "'>"
|
||||||
|
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 += "<input type='radio' name='" + questions[j][0] + "' value=" + questions[j][1]['elements'][k] + "></input>"
|
||||||
|
}
|
||||||
|
document.getElementById('FormData').innerHTML += "</div>"
|
||||||
|
}
|
||||||
|
document.getElementById('FormData').innerHTML += "</div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById('FormData').innerHTML += "<input type='button' onclick=subReport("+teamNum+","+competition+","+firstWord(locString)+") value='Submit'>"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function dec(id) {
|
||||||
|
document.getElementById(id).innerHTML = (parseInt(document.getElementById(id).innerHTML) - 1)).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
function inc(id) {
|
||||||
|
document.getElementById(id).innerHTML = (parseInt(document.getElementById(id).innerHTML) + 1)).toString()
|
||||||
|
}
|
||||||
|
|
||||||
function subRes() {
|
function subRes() {
|
||||||
firebase.firestore().collection('teamData').doc('team-' + document.getElementById('tns').value).get().then(function(doc) {
|
firebase.firestore().collection('teamData').doc('team-' + document.getElementById('tns').value).get().then(function(doc) {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
@ -66,7 +183,7 @@ function subRes() {
|
|||||||
push['teamDBRef'] = 'team-' + document.getElementById('tsn').value
|
push['teamDBRef'] = 'team-' + document.getElementById('tsn').value
|
||||||
push['speed'] = document.getElementById('speed').value
|
push['speed'] = document.getElementById('speed').value
|
||||||
push['sandstormCross'] = document.getElementById('SCross').value
|
push['sandstormCross'] = document.getElementById('SCross').value
|
||||||
push['strategy']= document.getElementById('strat').value
|
push['strategy'] = document.getElementById('strat').value
|
||||||
push['contrubution'] = document.getElementById('contrib').value
|
push['contrubution'] = document.getElementById('contrib').value
|
||||||
push['startingHatch'] = document.getElementById('habs').value
|
push['startingHatch'] = document.getElementById('habs').value
|
||||||
push['size'] = document.getElementById('egs').value
|
push['size'] = document.getElementById('egs').value
|
||||||
@ -95,7 +212,7 @@ function subRes() {
|
|||||||
push['teamDBRef'] = 'team-' + document.getElementById('tsn').value
|
push['teamDBRef'] = 'team-' + document.getElementById('tsn').value
|
||||||
push['speed'] = document.getElementById('speed').value
|
push['speed'] = document.getElementById('speed').value
|
||||||
push['sandstormCross'] = document.getElementById('SCross').value
|
push['sandstormCross'] = document.getElementById('SCross').value
|
||||||
push['strategy']= document.getElementById('strat').value
|
push['strategy'] = document.getElementById('strat').value
|
||||||
push['contrubution'] = document.getElementById('contrib').value
|
push['contrubution'] = document.getElementById('contrib').value
|
||||||
push['startingHatch'] = document.getElementById('habs').value
|
push['startingHatch'] = document.getElementById('habs').value
|
||||||
push['size'] = document.getElementById('egs').value
|
push['size'] = document.getElementById('egs').value
|
||||||
@ -120,7 +237,9 @@ function subRes() {
|
|||||||
|
|
||||||
).then(function() {
|
).then(function() {
|
||||||
alert('Submitted!')
|
alert('Submitted!')
|
||||||
setTimeout(function(){ window.location.href = '../scout'; }, 500);
|
setTimeout(function() {
|
||||||
|
window.location.href = '../scout';
|
||||||
|
}, 500);
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -150,15 +150,19 @@ function changeTeam(teamNum) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function addMatch(matchNum,seriesNum,position) {
|
|
||||||
|
function addMatch(matchNum, seriesNum, position) {
|
||||||
|
var success = false;
|
||||||
|
var teamNum = document.getElementById('tns').value
|
||||||
var user = firebase.auth().currentUser;
|
var user = firebase.auth().currentUser;
|
||||||
var name="anon"
|
var name = "anon"
|
||||||
if (user.displayName != null) {
|
if (user.displayName != null) {
|
||||||
name = user.displayName;
|
name = user.displayName;
|
||||||
} else if (user.email != null) {
|
} else if (user.email != null) {
|
||||||
name = user.email;
|
name = user.email;
|
||||||
} else if (user.phoneNumber != null) {
|
} else if (user.phoneNumber != null) {
|
||||||
name= user.phoneNumber;
|
name = user.phoneNumber;
|
||||||
|
}
|
||||||
ti = firebase.firestore().collection('teamData').doc("team-" + teamNum);
|
ti = firebase.firestore().collection('teamData').doc("team-" + teamNum);
|
||||||
currentComp = null;
|
currentComp = null;
|
||||||
ti.get().then(function(doc) {
|
ti.get().then(function(doc) {
|
||||||
@ -171,22 +175,41 @@ function addMatch(matchNum,seriesNum,position) {
|
|||||||
}
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
cci = firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp);
|
cci = firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp);
|
||||||
cci.get().then(function (doc) {
|
cci.get().then(function(doc) {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
info=doc.data();
|
info = doc.data();
|
||||||
match=info["match-"+matchNum.toString()];
|
match = info["match-" + matchNum.toString()];
|
||||||
pos=match[position];
|
pos = match[position];
|
||||||
occ=pos["series-"+seriesNum.toString()];
|
occ = pos["series-" + seriesNum.toString()];
|
||||||
if (occ == null) {
|
if (occ == null) {
|
||||||
info["match-"+matchNum.toString()][position]["series-"+seriesNum.toString()]=name;
|
info["match-" + matchNum.toString()][position]["series-" + seriesNum.toString()] = name;
|
||||||
firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp).set(info)
|
firebase.firestore().collection('matchSignupsTeam').doc("team-" + teamNum).collection('competitions').doc(currentComp).set(info)
|
||||||
alert('Added!')
|
success = true;
|
||||||
setTimeout(function(){ window.location.href = '../signUps'; }, 500);
|
} else {
|
||||||
}else{
|
alert(occ + "has added that match first.")
|
||||||
alert(occ+"has added that match first.")
|
setTimeout(function() {
|
||||||
setTimeout(function(){ window.location.href = '../signUps'; }, 500);
|
window.location.href = '../signUps';
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}).then(function() {
|
||||||
|
if (success) {
|
||||||
|
ti = firebase.firestore().collection('matchSignupsIndividual').doc(user.uid).collection("team-" + teamNum).doc(currentComp);
|
||||||
|
push = {
|
||||||
|
"match-" + matchNum.toString()+" "+position: {
|
||||||
|
'completed': false,
|
||||||
|
series: seriesNum.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cityRef.set(push, {
|
||||||
|
merge: true
|
||||||
|
}), then(function() {
|
||||||
|
alert('Added!')
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.href = '../signUps';
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user