mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +01:00
implement role submissioN
This commit is contained in:
54
server.py
54
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():
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
</head>
|
||||
<body class="bg-special">
|
||||
{% include 'navbar.html' %}
|
||||
<div id="ident-field" style="display: none;">{{ ident }}</div>
|
||||
<div class="container mt-3 mb-3" role="main">
|
||||
|
||||
<div class="row">
|
||||
@@ -17,23 +18,21 @@
|
||||
</div>
|
||||
|
||||
<button type="button" class="mb-3 btn btn-secondary" onclick="balance()">Go</button>
|
||||
|
||||
<div class="spinner-border" id="loading" style="display: none;" role="status">
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
<button type="button" class="mb-3 btn btn-secondary" onclick="queryForPlayerData()">
|
||||
Check Submissions
|
||||
</button></br>
|
||||
<button id="copyLink" type="button" class="mb-3 btn btn-secondary" onclick="copy()">
|
||||
Copy Submission Link
|
||||
</button>
|
||||
|
||||
<div class="spinner-border" id="loading" style="display: none;" role="status">
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
<div id="response-container" class="mt-3 mb-3">
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<textarea type="text" id="multi-line-copy" rows="10"
|
||||
placeholder="Have everybody write their roles in the form of 'top > mid = sup = jungle >adc' in the chat and then copy it in here and hit 'Use Multiline Input' :)"
|
||||
class="form-control md-textarea"></textarea>
|
||||
<button type="button" class="mb-3 btn btn-secondary" onclick="parseMultiline()">
|
||||
Use Multiline Input..
|
||||
</button>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="row">
|
||||
{% for side in sides %}
|
||||
@@ -74,6 +73,15 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<textarea type="text" id="multi-line-copy" rows="10"
|
||||
placeholder="Have everybody write their roles in the form of 'top > mid = sup = jungle >adc' in the chat and then copy it in here and hit 'Use Multiline Input' :)"
|
||||
class="form-control md-textarea"></textarea>
|
||||
<button type="button" class="mb-3 btn btn-secondary" onclick="parseMultiline()">
|
||||
Use Multiline Input..
|
||||
</button>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
|
||||
52
templates/role_submission.html
Normal file
52
templates/role_submission.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Balance and Submission Tool</title>
|
||||
<meta name="Description" content="Sheppy is awesome?">
|
||||
<script defer src="/static/balance.js"></script>
|
||||
{% include 'default_head_content.html' %}
|
||||
</head>
|
||||
<body class="bg-special">
|
||||
{% include 'navbar.html' %}
|
||||
<div class="container mt-3 mb-3" role="main">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<h1>Role Preference Submission Tool</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- player name field -->
|
||||
<form action="/role-submission?id={{ ident }}" method="POST">
|
||||
<input class="form-control pname m-3" type="text" placeholder="Player"
|
||||
name="playername" id="playername">
|
||||
|
||||
<!-- fast postition slection field -->
|
||||
<input class="form-control fastpos m-3" type="text"
|
||||
placeholder="top > mid = bot"
|
||||
id="fastpos-submission">
|
||||
|
||||
<div class="col-sm m-3" style="min-width: 300px;">
|
||||
<!-- checkboxes for pos -->
|
||||
{% for pos in positions %}
|
||||
<div>
|
||||
<label style="min-width: 100px;"
|
||||
for="prio_{{ pos }}">{{ pos }}</label>
|
||||
<select name="prio_{{ pos }}" id="prio_{{ pos }}"
|
||||
class="form-select ml-3 mr-3">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
<option value="5">5</option>
|
||||
</select>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
{% include 'footer.html' %}
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user