mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +01:00
implement buttons
This commit is contained in:
@@ -53,6 +53,18 @@ class Player:
|
||||
# mark returned string as preformated html #
|
||||
return flask.Markup(string)
|
||||
|
||||
def requestRange(start, end):
|
||||
'''Request a range from the rating server'''
|
||||
|
||||
# request information from rating server #
|
||||
requestURL = BASE_URL.format(server=SERVER, \
|
||||
path=LOCATION, \
|
||||
paramStart=PARAM_START, \
|
||||
paramEnd=PARAM_END, \
|
||||
start=start, \
|
||||
end=end)
|
||||
|
||||
return str(requests.get(requestURL).content, "utf-8")
|
||||
|
||||
@app.route('/leaderboard')
|
||||
def leaderboard():
|
||||
@@ -71,15 +83,14 @@ def leaderboard():
|
||||
|
||||
end = start + SEGMENT
|
||||
|
||||
# request information from rating server #
|
||||
requestURL = BASE_URL.format(server=SERVER, \
|
||||
path=LOCATION, \
|
||||
paramStart=PARAM_START, \
|
||||
paramEnd=PARAM_END, \
|
||||
start=start, \
|
||||
end=end)
|
||||
|
||||
responseString = str(requests.get(requestURL).content, "utf-8")
|
||||
# request and check if we are within range #
|
||||
responseString = requestRange(start, end)
|
||||
if "MAXENTRY:" in responseString:
|
||||
maxentry = int(responseString.split(":")[1])
|
||||
start = maxentry - SEGMENT - 1
|
||||
end = maxentry - 1
|
||||
responseString = requestRange(start, end)
|
||||
|
||||
# create relevant html-lines from player
|
||||
players = [Player(line) for line in responseString.split("\n")]
|
||||
|
||||
46
static/buttons.js
Normal file
46
static/buttons.js
Normal file
@@ -0,0 +1,46 @@
|
||||
function forward(){
|
||||
|
||||
var url = new URL(window.location.href)
|
||||
var start = url.searchParams.get("start")
|
||||
var page = url.searchParams.get("page")
|
||||
|
||||
if(page){
|
||||
page = parseInt(page) + 1
|
||||
}else if(start){
|
||||
page = Math.trunc(parseInt(start)/100) + 1
|
||||
}else{
|
||||
page = 1
|
||||
}
|
||||
|
||||
url.searchParams.set("page", page)
|
||||
window.location.href = url.href
|
||||
|
||||
}
|
||||
function backward(){
|
||||
|
||||
var url = new URL(window.location.href)
|
||||
var start = url.searchParams.get("start")
|
||||
var page = url.searchParams.get("page")
|
||||
|
||||
if(page){
|
||||
page = parseInt(page) - 1
|
||||
if(page < 0){
|
||||
page = 0
|
||||
}
|
||||
}else if(start){
|
||||
page = Math.trunc(parseInt(start)/100) - 1
|
||||
}else{
|
||||
page = 0
|
||||
}
|
||||
|
||||
url.searchParams.set("page", page)
|
||||
window.location.href = url.href
|
||||
}
|
||||
|
||||
function firstPage(){
|
||||
var href = window.location.href
|
||||
var parameterSeperator = "?"
|
||||
if(href.includes(parameterSeperator)){
|
||||
window.location.href = href.split(parameterSeperator)[0]
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,9 @@ body{
|
||||
.top-bar{
|
||||
position: fixed;
|
||||
background-color: orange;
|
||||
height: 20px;
|
||||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
padding-left: 10px;
|
||||
|
||||
left: 0;
|
||||
top: 0;
|
||||
@@ -23,6 +23,7 @@ body{
|
||||
.top-button{
|
||||
height: 80%;
|
||||
float: left;
|
||||
|
||||
margin-right: 10px;
|
||||
|
||||
background-color: red;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="static/site.css">
|
||||
<script src="static/buttons.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class=top-bar>
|
||||
<div class=top-button>Forward</div>
|
||||
<div class=top-button>Backward</div>
|
||||
<div class=top-button>Top 100</div>
|
||||
<button type="button" onclick=forward() class=top-button>Forward </button>
|
||||
<button type="button" onclick=backward() class=top-button>Backward</button>
|
||||
<button type="button" onclick=firstPage() class=top-button>Top 100 </button>
|
||||
|
||||
<input class=input-field>
|
||||
<input class=input-field>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user