- - - -
+ + + + +
diff --git a/server.py b/server.py index 67a088a..9a44c73 100755 --- a/server.py +++ b/server.py @@ -8,6 +8,8 @@ import itertools import json import os import MapSummary +import random +import secrets from database import DatabaseConnection @@ -139,6 +141,50 @@ class Player: self.name = name self.prio = prio +# TODO +submission = dict() +@app.route("/role-submission", methods=['GET', 'POST']) +def roleSubmissionTool(): + positions=["Top", "Jungle", "Mid", "Support", "Bottom"] + + ident = flask.request.args.get("id") + if flask.request.method == 'POST': + + if not ident in submission: + submission.update({ ident : [] }) + + tmp = dict() + tmp.update({ "name" : flask.request.form["playername"] }) + for p in positions: + tmp.update({ p : flask.request.form["prio_{}".format(p)] }) + + existed = False + for pl in submission[ident]: + if pl["name"] == tmp["name"]: + for p in positions: + pl.update({ p : flask.request.form["prio_{}".format(p)] }) + existed = True + break; + + if not existed: + submission[ident] += [tmp] + + return flask.redirect("/balance-tool?id={}".format(ident)) + else: + return flask.render_template("role_submission.html", + positions=positions, + ident=ident) + +@app.route("/balance-tool-data") +def balanceToolData(): + ident = flask.request.args.get("id") + retDict = dict() + if not ident in submission: + return flask.Response(json.dumps({ "no-data" : False }), 200, mimetype='application/json') + retDict.update({ "submissions" : submission[ident] }) + return flask.Response(json.dumps(retDict), 200, mimetype='application/json') + + @app.route("/balance-tool", methods=['GET', 'POST']) def balanceTool(): positions=["Top", "Jungle", "Mid", "Support", "Bottom"] @@ -181,9 +227,15 @@ def balanceTool(): return flask.Response( json.dumps({ "content": renderContent }), 200, mimetype='application/json') else: + givenIdent = flask.request.args.get("id") + if givenIdent: + ident = givenIdent + else: + ident = secrets.token_urlsafe(16) return flask.render_template("json_builder.html", positions=positions, - sides=["left", "right"]) + sides=["left", "right"], + ident=ident) @app.route("/player") def player(): diff --git a/static/balance.js b/static/balance.js index e7d39d1..f0e6030 100644 --- a/static/balance.js +++ b/static/balance.js @@ -1,7 +1,8 @@ positions = [ "Top", "Jungle", "Mid", "Support" , "Bottom" ] acceptedParser = [ "top", "jungle", "mid", "sup" , "bot", "adc", "support", "bottom", "*" ] +sides = [ "left", "right"] -function checkPlayer() { +var checkPlayerFunc = function checkPlayer() { if(this.value == ""){ return } @@ -15,7 +16,7 @@ function checkPlayer() { }) } -function fastPosChanged() { +var fastPosChangedFunc = function fastPosChanged() { accepted = [ "top", "jungle", "mid", "sup" , "bot" ] uniqArr = [] @@ -63,7 +64,13 @@ function fastPosChanged() { arr = this.id.split("-") pNr = arr[arr.length-1] side = this.id.includes("left") ? "left" : "right" - string = "prio-" + side + "-" + accepted[i] + "-" + pNr + + roleSubmission = document.getElementById("fastpos-submission") + if(roleSubmission){ + string = "prio_" + accepted[i] + }else { + string = "prio-" + side + "-" + accepted[i] + "-" + pNr + } string = string.replace("top","Top") string = string.replace("jungle","Jungle") @@ -172,7 +179,6 @@ function parseMultiline(){ } }) - sides = [ "left", "right"] count = 0 sides.forEach(s => { for(i = 0; i<5; i++){ @@ -197,11 +203,63 @@ function parseMultiline(){ balance() } +function queryForPlayerData(){ + ident = document.getElementById("ident-field").innerHTML + fetch("/balance-tool-data?id=" + ident).then(r => r.json()).then(j => { + if("no-data" in j){ + return + } + j["submissions"].forEach(el => { + console.log(el) + breakToSubmissions = false + for(sid = 0; sid < 2; sid++){ + if(breakToSubmissions){ + break; + } + for(id = 0; id < 5; id++){ + stringPid = `playername-${sides[sid]}-${id}` + pnameObj = document.getElementById(stringPid) + if(pnameObj.value == "" || pnameObj.value == el["name"]){ + pnameObj.value = el["name"] + for(acc = 0; acc < 5; acc++){ + stringSelectorId = `prio-${sides[sid]}-${positions[acc]}-${id}` + selObj = document.getElementById(stringSelectorId) + selObj.value = el[positions[acc]] + } + breakToSubmissions = true + break; + } + } + } + }) + }) +} + +function copy() { + + ident = document.getElementById("ident-field").innerHTML + path = "/role-submission?id=" + copyText = window.location.protocol + window.location.hostname + path + ident + + navigator.clipboard.writeText(copyText) + document.getElementById("copyLink").innerHTML = "Copied!" + setTimeout(() => { + document.getElementById("copyLink").innerHTML = "Copy Submission Link" }, 500); + +} + fastPosFields = document.getElementsByClassName("fastpos") playerNameFields = document.getElementsByClassName("pname") -playerNameFields.forEach(el => el.addEventListener('input', checkPlayer)); -playerNameFields.forEach(el => el.addEventListener('focus', checkPlayer)); +playerNameFields.forEach(el => el.addEventListener('input', checkPlayerFunc)); +playerNameFields.forEach(el => el.addEventListener('focus', checkPlayerFunc)); -fastPosFields.forEach(el => el.addEventListener('input', fastPosChanged)); -fastPosFields.forEach(el => el.addEventListener('focus', fastPosChanged)); +fastPosFields.forEach(el => el.addEventListener('input', fastPosChangedFunc)); +//fastPosFields.forEach(el => el.addEventListener('focus', fastPosChangedFunc)); + +fastposSubmission = document.getElementById("fastpos-submission") +if(fastposSubmission){ + fastposSubmission.addEventListener("input", fastPosChangedFunc) + fastposSubmission.addEventListener("focus", fastPosChangedFunc) +} +setInterval(queryForPlayerData(), 3000) diff --git a/templates/json_builder.html b/templates/json_builder.html index c132e55..742f77c 100644 --- a/templates/json_builder.html +++ b/templates/json_builder.html @@ -8,6 +8,7 @@
{% include 'navbar.html' %} +