mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +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}"
|
||||
MAX_ENTRY = "http://{server}/getmaxentries"
|
||||
FIND_PLAYER = "http://{server}/findplayer?string={pname}"
|
||||
SEGMENT = 100
|
||||
SEPERATOR = ','
|
||||
|
||||
@@ -72,19 +73,34 @@ def leaderboard():
|
||||
'''Show main leaderboard page with range dependant on 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:
|
||||
start = SEGMENT * int(page)
|
||||
else:
|
||||
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
|
||||
|
||||
|
||||
# request and check if we are within range #
|
||||
maxEntryUrl = MAX_ENTRY.format(server=SERVER)
|
||||
maxEntry = int(requests.get(maxEntryUrl).content)
|
||||
@@ -119,7 +135,8 @@ def leaderboard():
|
||||
finalResponse = flask.render_template("base.html", playerList=players, \
|
||||
columNames=columContent, \
|
||||
start=start, \
|
||||
endOfBoardIndicator=endOfBoardIndicator)
|
||||
endOfBoardIndicator=endOfBoardIndicator, \
|
||||
findPlayer=cannotFindPlayer)
|
||||
return finalResponse
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
|
||||
@@ -6,6 +6,10 @@ var buttonForward = document.getElementById("button-forward")
|
||||
var buttonFirst = document.getElementById("button-first")
|
||||
var isLastPage = document.getElementById("eof")
|
||||
|
||||
/* clean URL from unessesary parameters */
|
||||
url.searchParams.delete("goto")
|
||||
url.searchParams.delete("string")
|
||||
|
||||
/* disable buttons if nessesary */
|
||||
if(!page || page == "0"){
|
||||
buttonBackward.disabled = true
|
||||
@@ -22,9 +26,6 @@ if(isLastPage){
|
||||
|
||||
function forward(){
|
||||
|
||||
/* clean URL from unessesary parameters */
|
||||
url.searchParams.delete("goto")
|
||||
|
||||
if(page){
|
||||
page = parseInt(page) + 1
|
||||
}else{
|
||||
@@ -37,9 +38,6 @@ function forward(){
|
||||
}
|
||||
function backward(){
|
||||
|
||||
/* clean URL from unessesary parameters */
|
||||
url.searchParams.delete("goto")
|
||||
|
||||
if(page){
|
||||
page = parseInt(page) - 1
|
||||
if(page < 0){
|
||||
@@ -74,3 +72,14 @@ gotoRankInputField.addEventListener("keyup", function(event) {
|
||||
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;
|
||||
}
|
||||
|
||||
.noPlayerFound{
|
||||
background: red;
|
||||
float: left;
|
||||
width: 180px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* #################### LEADERBOARDS ##################### */
|
||||
.leaderboard-container{
|
||||
width: 80%;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
placeholder="search player...">
|
||||
<input id="gotoRank" type="number" class=input-field-number
|
||||
placeholder="goto rank...">
|
||||
{{ findPlayer }}
|
||||
</div>
|
||||
<div class=leaderboard-container>
|
||||
<div class=colum-names>{{ columNames }}</div>
|
||||
@@ -32,7 +33,8 @@
|
||||
</div>
|
||||
<div class=footer>
|
||||
<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>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user