mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +01:00
more features
This commit is contained in:
@@ -133,9 +133,14 @@ def rounds():
|
||||
# display outcome
|
||||
# display map
|
||||
|
||||
@app.route("/balance-tool")
|
||||
@app.route("/balance-tool", methods=['GET', 'POST'])
|
||||
def balanceTool():
|
||||
return flask.render_template("json_builder.html",
|
||||
if flask.request.method == 'POST':
|
||||
print(flask.request.json)
|
||||
return flask.Response(json.dumps({"content":"<div>test</div>"}),
|
||||
200, mimetype='application/json')
|
||||
else:
|
||||
return flask.render_template("json_builder.html",
|
||||
positions=["Top", "Jungle", "Mid", "Support", "Bottom"],
|
||||
sides=["left", "right"])
|
||||
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
positions = [ "Top", "Jungle", "Mid", "Support" , "Bottom" ]
|
||||
|
||||
function checkPlayer() {
|
||||
if(this.value == ""){
|
||||
return
|
||||
}
|
||||
url = "/player?id=" + this.value
|
||||
fetch(url).then(r => {
|
||||
if(r.status == 200){
|
||||
this.style.background = "#74bb74"
|
||||
}else{
|
||||
//this.style.background = "#d25252"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function fastPosChanged() {
|
||||
|
||||
accepted = [ "top", "jungle", "mid", "sup" , "bot" ]
|
||||
@@ -61,19 +75,44 @@ function fastPosChanged() {
|
||||
selector.style.background = "lightblue"
|
||||
}
|
||||
|
||||
/* allow some basic shit */
|
||||
console.log(clean)
|
||||
if(clean == "*" || clean == ""){
|
||||
console.log("lol")
|
||||
retVal = true
|
||||
}
|
||||
|
||||
if(retVal){
|
||||
this.style.background = "green"
|
||||
this.style.background = "#74bb74"
|
||||
}else{
|
||||
this.style.background = "red"
|
||||
this.style.background = "#d25252"
|
||||
}
|
||||
}
|
||||
|
||||
function balance(){
|
||||
|
||||
sides = ["left", "right"]
|
||||
var prioList = [5, 5, 5, 5, 5]
|
||||
var pname = "undef"
|
||||
|
||||
blue = [ "", "", "", "", ""]
|
||||
red = [ "", "", "", "", ""]
|
||||
|
||||
dictToBeSorted = {
|
||||
0 : [],
|
||||
1 : [],
|
||||
2 : [],
|
||||
3 : [],
|
||||
4 : []
|
||||
}
|
||||
filler = []
|
||||
impossible = []
|
||||
|
||||
dictAll = {}
|
||||
for(sid = 0; sid < 2; sid++){
|
||||
for(id = 0; id < 5; id++){
|
||||
|
||||
var pname = "undef"
|
||||
var prioList = [5, 5, 5, 5, 5]
|
||||
|
||||
stringPid = `playername-${sides[sid]}-${id}`
|
||||
pnameObj = document.getElementById(stringPid)
|
||||
pname = pnameObj.value
|
||||
@@ -82,11 +121,74 @@ function balance(){
|
||||
selObj = document.getElementById(stringSelectorId)
|
||||
prioList[acc] = selObj.value
|
||||
}
|
||||
|
||||
dictAll[pname] = prioList
|
||||
|
||||
/* deal with one pos andys */
|
||||
countPos = prioList.filter(a => a < 5).length
|
||||
if(countPos == 1){
|
||||
pos = null
|
||||
count = 0
|
||||
prioList.forEach(a => {
|
||||
if(a < 5){
|
||||
pos = positions[count]
|
||||
}
|
||||
count++;
|
||||
})
|
||||
indexPos = positions.indexOf(pos)
|
||||
if(blue[indexPos] == ""){
|
||||
blue[indexPos] = pname
|
||||
}else if(red[indexPos] == ""){
|
||||
red[indexPos] = pname
|
||||
}else{
|
||||
impossible += [pname]
|
||||
}
|
||||
}else if(prioList.reduce((a, b) => a + b, 0) == 25){
|
||||
/* those are fillers */
|
||||
fillers += [pname]
|
||||
}else{
|
||||
for(i = 0; i<5; i++){
|
||||
dictToBeSorted[i] += [{ "name" : pname, "val" : prioList[i]}]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
console.log(pname, prioList)
|
||||
|
||||
/* fill rest */
|
||||
for(i = 0; i < 5; i++){
|
||||
if(red[i] == ""){
|
||||
candidates = dictToBeSorted[i]
|
||||
}
|
||||
if(blue[i] == ""){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
jsonData = JSON.stringify(dictAll, null, 4);
|
||||
console.log(jsonData)
|
||||
|
||||
/* transmitt */
|
||||
fetch(window.location.href, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'Content-Type': 'application/json' },
|
||||
body: jsonData
|
||||
}).then(r => r.json()).then(j => {
|
||||
console.log(j)
|
||||
console.log(j["content"])
|
||||
cont = document.getElementById("response-container")
|
||||
cont.innerHTML = j["content"]
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fastPosFields = document.getElementsByClassName("fastpos")
|
||||
playerNameFields = document.getElementsByClassName("pname")
|
||||
|
||||
playerNameFields.forEach(el => el.addEventListener('input', checkPlayer));
|
||||
playerNameFields.forEach(el => el.addEventListener('focus', checkPlayer));
|
||||
|
||||
fastPosFields.forEach(el => el.addEventListener('input', fastPosChanged));
|
||||
fastPosFields.forEach(el => el.addEventListener('focus', fastPosChanged));
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
<h1>Balance Tool</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="button" class="mb-3 btn btn-secondary" onclick="balance()">Go</button>
|
||||
|
||||
<div id="response-container" class="row mt-3 mb-3">
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<div class="row">
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
{% for side in sides %}
|
||||
@@ -28,7 +31,7 @@
|
||||
<div class="col-sm">
|
||||
|
||||
<!-- player name field -->
|
||||
<input class="form-control" type="text" placeholder="Player"
|
||||
<input class="form-control pname" type="text" placeholder="Player"
|
||||
id="playername-{{ side }}-{{ field }}">
|
||||
|
||||
<!-- fast postition slection field -->
|
||||
|
||||
Reference in New Issue
Block a user