mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-10 00:48:32 +01:00
implement find player
This commit is contained in:
@@ -13,6 +13,7 @@ PARAM_END = "end"
|
|||||||
|
|
||||||
BASE_URL = "http://{server}{path}?{paramStart}={start}&{paramEnd}={end}"
|
BASE_URL = "http://{server}{path}?{paramStart}={start}&{paramEnd}={end}"
|
||||||
MAX_ENTRY = "http://{server}/getmaxentries"
|
MAX_ENTRY = "http://{server}/getmaxentries"
|
||||||
|
FIND_PLAYER = "http://{server}/findplayer?string={pname}"
|
||||||
SEGMENT = 100
|
SEGMENT = 100
|
||||||
SEPERATOR = ','
|
SEPERATOR = ','
|
||||||
|
|
||||||
@@ -72,19 +73,34 @@ def leaderboard():
|
|||||||
'''Show main leaderboard page with range dependant on parameters'''
|
'''Show main leaderboard page with range dependant on parameters'''
|
||||||
|
|
||||||
# parse parameters #
|
# parse parameters #
|
||||||
start = flask.request.args.get(PARAM_START)
|
page = flask.request.args.get("page")
|
||||||
page = flask.request.args.get("page")
|
playerName = flask.request.args.get("string")
|
||||||
|
|
||||||
|
|
||||||
# intentional double if, page is supposed to overwrite start #
|
|
||||||
if start:
|
|
||||||
start = int(start)
|
|
||||||
if page:
|
if page:
|
||||||
start = SEGMENT * int(page)
|
start = SEGMENT * int(page)
|
||||||
else:
|
else:
|
||||||
start = 0
|
start = 0
|
||||||
|
|
||||||
|
# handle find player request #
|
||||||
|
cannotFindPlayer = ""
|
||||||
|
if playerName:
|
||||||
|
playersWithRankUrl = FIND_PLAYER.format(server=SERVER, pname=playerName)
|
||||||
|
playersWithRank = str(requests.get(playersWithRankUrl).content, "utf-8").split("\n")
|
||||||
|
|
||||||
|
if len(playersWithRank) == 1 and playersWithRank[0] == "":
|
||||||
|
cannotFindPlayer = flask.Markup("<div class=noPlayerFound>No player of that name</div>")
|
||||||
|
start = 0
|
||||||
|
elif len(playersWithRank) == 1:
|
||||||
|
rank = int(playersWithRank[0].split(SEPERATOR)[-1])
|
||||||
|
start = rank - (rank % SEGMENT)
|
||||||
|
else:
|
||||||
|
rank = int(playersWithRank[0].split(SEPERATOR)[-1])
|
||||||
|
start = rank - (rank % SEGMENT)
|
||||||
|
|
||||||
end = start + SEGMENT
|
end = start + SEGMENT
|
||||||
|
|
||||||
|
|
||||||
# request and check if we are within range #
|
# request and check if we are within range #
|
||||||
maxEntryUrl = MAX_ENTRY.format(server=SERVER)
|
maxEntryUrl = MAX_ENTRY.format(server=SERVER)
|
||||||
maxEntry = int(requests.get(maxEntryUrl).content)
|
maxEntry = int(requests.get(maxEntryUrl).content)
|
||||||
@@ -119,7 +135,8 @@ def leaderboard():
|
|||||||
finalResponse = flask.render_template("base.html", playerList=players, \
|
finalResponse = flask.render_template("base.html", playerList=players, \
|
||||||
columNames=columContent, \
|
columNames=columContent, \
|
||||||
start=start, \
|
start=start, \
|
||||||
endOfBoardIndicator=endOfBoardIndicator)
|
endOfBoardIndicator=endOfBoardIndicator, \
|
||||||
|
findPlayer=cannotFindPlayer)
|
||||||
return finalResponse
|
return finalResponse
|
||||||
|
|
||||||
@app.route('/static/<path:path>')
|
@app.route('/static/<path:path>')
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ var buttonForward = document.getElementById("button-forward")
|
|||||||
var buttonFirst = document.getElementById("button-first")
|
var buttonFirst = document.getElementById("button-first")
|
||||||
var isLastPage = document.getElementById("eof")
|
var isLastPage = document.getElementById("eof")
|
||||||
|
|
||||||
|
/* clean URL from unessesary parameters */
|
||||||
|
url.searchParams.delete("goto")
|
||||||
|
url.searchParams.delete("string")
|
||||||
|
|
||||||
/* disable buttons if nessesary */
|
/* disable buttons if nessesary */
|
||||||
if(!page || page == "0"){
|
if(!page || page == "0"){
|
||||||
buttonBackward.disabled = true
|
buttonBackward.disabled = true
|
||||||
@@ -22,9 +26,6 @@ if(isLastPage){
|
|||||||
|
|
||||||
function forward(){
|
function forward(){
|
||||||
|
|
||||||
/* clean URL from unessesary parameters */
|
|
||||||
url.searchParams.delete("goto")
|
|
||||||
|
|
||||||
if(page){
|
if(page){
|
||||||
page = parseInt(page) + 1
|
page = parseInt(page) + 1
|
||||||
}else{
|
}else{
|
||||||
@@ -37,9 +38,6 @@ function forward(){
|
|||||||
}
|
}
|
||||||
function backward(){
|
function backward(){
|
||||||
|
|
||||||
/* clean URL from unessesary parameters */
|
|
||||||
url.searchParams.delete("goto")
|
|
||||||
|
|
||||||
if(page){
|
if(page){
|
||||||
page = parseInt(page) - 1
|
page = parseInt(page) - 1
|
||||||
if(page < 0){
|
if(page < 0){
|
||||||
@@ -74,3 +72,14 @@ gotoRankInputField.addEventListener("keyup", function(event) {
|
|||||||
window.location.href = url.href
|
window.location.href = url.href
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var getPlayerInputField = document.getElementById("getPlayer");
|
||||||
|
getPlayerInputField.addEventListener("keyup", function(event) {
|
||||||
|
if (event.key == "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
var string = getPlayerInputField.value
|
||||||
|
url.searchParams.set("string", string)
|
||||||
|
url.searchParams.delete("page")
|
||||||
|
window.location.href = url.href
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ body{
|
|||||||
width: 100px;
|
width: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.noPlayerFound{
|
||||||
|
background: red;
|
||||||
|
float: left;
|
||||||
|
width: 180px;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
/* #################### LEADERBOARDS ##################### */
|
/* #################### LEADERBOARDS ##################### */
|
||||||
.leaderboard-container{
|
.leaderboard-container{
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
placeholder="search player...">
|
placeholder="search player...">
|
||||||
<input id="gotoRank" type="number" class=input-field-number
|
<input id="gotoRank" type="number" class=input-field-number
|
||||||
placeholder="goto rank...">
|
placeholder="goto rank...">
|
||||||
|
{{ findPlayer }}
|
||||||
</div>
|
</div>
|
||||||
<div class=leaderboard-container>
|
<div class=leaderboard-container>
|
||||||
<div class=colum-names>{{ columNames }}</div>
|
<div class=colum-names>{{ columNames }}</div>
|
||||||
@@ -32,7 +33,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class=footer>
|
<div class=footer>
|
||||||
<a class="footerLink" href="https://blog.atlantishq.de/about">Impressum/Legal</a>
|
<a class="footerLink" href="https://blog.atlantishq.de/about">Impressum/Legal</a>
|
||||||
<a class="footerLink mid" href="https://github.com/FAUSheppy/">Other Projects</a>
|
<a class="footerLink mid" href="https://blog.atlantishq.de/post/insurgency-rating-1/">
|
||||||
|
How does it work?</a>
|
||||||
<a class="footerLink" href="https://github.com/FAUSheppy/skillbird">Star on GitHub</a>
|
<a class="footerLink" href="https://github.com/FAUSheppy/skillbird">Star on GitHub</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user