Merge pull request #102 from esSteres/indev
add `game` query param that bumps game to top
This commit is contained in:
commit
4f96c8114c
|
@ -9,12 +9,10 @@ socketio = SocketIO(app)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
if ('league' in request.args):
|
||||||
|
return render_template("index.html", league=request.args['league'])
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
@app.route('/league')
|
|
||||||
def league_page():
|
|
||||||
return render_template("index.html", league=request.args['name'])
|
|
||||||
|
|
||||||
@app.route('/game')
|
@app.route('/game')
|
||||||
def game_page():
|
def game_page():
|
||||||
return render_template("game.html")
|
return render_template("game.html")
|
||||||
|
|
|
@ -31,12 +31,18 @@ const updateGames = (json, filter) => {
|
||||||
$('#footer div').html("");
|
$('#footer div').html("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var searchparams = new URLSearchParams(window.location.search);
|
||||||
|
if (searchparams.has('game') && filterjson.some(x => x.timestamp == searchparams.get('game')) && grid.children[0].timestamp != searchparams.get('game')) {
|
||||||
|
var game = filterjson.find(x => x.timestamp == searchparams.get('game'))
|
||||||
|
var oldbox = Array.prototype.slice.call(grid.children).find(x => x.timestamp == game.timestamp)
|
||||||
|
if (oldbox) { clearBox(oldbox) }
|
||||||
|
insertGame(0, game)
|
||||||
|
}
|
||||||
|
|
||||||
//replace games that have ended with empty slots
|
//replace games that have ended with empty slots
|
||||||
for (var slotnum = 0; slotnum < grid.children.length; slotnum++) {
|
for (var slotnum = 0; slotnum < grid.children.length; slotnum++) {
|
||||||
if (grid.children[slotnum].className == "game" && !filterjson.some((x) => x.timestamp == grid.children[slotnum].timestamp)) {
|
if (grid.children[slotnum].className == "game" && !filterjson.some((x) => x.timestamp == grid.children[slotnum].timestamp)) {
|
||||||
grid.children[slotnum].className = "emptyslot";
|
clearBox(grid.children[slotnum])
|
||||||
grid.children[slotnum].timestamp = null;
|
|
||||||
grid.children[slotnum].innerHTML = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +55,7 @@ const updateGames = (json, filter) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
//adds game to list if not there already
|
//adds game to list if not there already
|
||||||
if (!Array.prototype.slice.call(grid.children).some((x) => x.timestamp == game.timestamp)) {
|
if (!Array.prototype.slice.call(grid.children).some(x => x.timestamp == game.timestamp)) {
|
||||||
for (var slotnum = 0; true; slotnum++) { //this is really a while loop but shh don't tell anyone
|
for (var slotnum = 0; true; slotnum++) { //this is really a while loop but shh don't tell anyone
|
||||||
if (slotnum >= grid.children.length) {
|
if (slotnum >= grid.children.length) {
|
||||||
for (var i = 0; i < 3; i ++) {
|
for (var i = 0; i < 3; i ++) {
|
||||||
|
@ -88,6 +94,20 @@ const insertGame = (gridboxnum, game) => {
|
||||||
thisBox.timestamp = game.timestamp;
|
thisBox.timestamp = game.timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const insertLeague = (league) => {
|
||||||
|
var btn = document.createElement("BUTTON");
|
||||||
|
btn.className = "filter";
|
||||||
|
btn.innerHTML = league;
|
||||||
|
$('#filters').append(btn);
|
||||||
|
return btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearBox = (box) => {
|
||||||
|
box.className = "emptyslot";
|
||||||
|
box.timestamp = null;
|
||||||
|
box.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
const updateLeagues = (games) => {
|
const updateLeagues = (games) => {
|
||||||
//get all leagues
|
//get all leagues
|
||||||
var leagues = []
|
var leagues = []
|
||||||
|
@ -110,10 +130,7 @@ const updateLeagues = (games) => {
|
||||||
|
|
||||||
// add leagues not already present
|
// add leagues not already present
|
||||||
for (var league of leagues) { // we removed the entries that are already there in the loop above
|
for (var league of leagues) { // we removed the entries that are already there in the loop above
|
||||||
var btn = document.createElement("BUTTON");
|
insertLeague(league)
|
||||||
btn.className = "filter"
|
|
||||||
btn.innerHTML = league
|
|
||||||
$('#filters').append(btn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//add click handlers to each filter
|
//add click handlers to each filter
|
||||||
|
@ -126,20 +143,23 @@ const updateLeagues = (games) => {
|
||||||
this.id = 'selected_filter';
|
this.id = 'selected_filter';
|
||||||
|
|
||||||
var search = new URLSearchParams();
|
var search = new URLSearchParams();
|
||||||
search.append("name", this.textContent);
|
search.append('league', this.textContent);
|
||||||
history.pushState({}, "", (this.textContent != 'All' ? "/league?" + search.toString() : "/"));
|
history.pushState({}, "", "/" + (this.textContent != 'All' ? "?" + search.toString() : ""));
|
||||||
updateGames(lastupdate, this.textContent);
|
updateGames(lastupdate, this.textContent);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onpopstate = function(e) {
|
window.onpopstate = function(e) {
|
||||||
var searchparams = new URLSearchParams(window.location.search)
|
var searchparams = new URLSearchParams(window.location.search);
|
||||||
updateLeagues(lastupdate);
|
updateLeagues(lastupdate);
|
||||||
$('#filters #selected_filter').attr('id', '');
|
$('#filters #selected_filter').attr('id', '');
|
||||||
if (searchparams.has('name')) {
|
if (searchparams.has('league')) {
|
||||||
$('#filters .filter').each(function(i) { if (this.textContent == searchparams.get('name')) { this.id = 'selected_filter' }})
|
var filter_found = false
|
||||||
updateGames(lastupdate, searchparams.get('name'));
|
$('#filters .filter').each(function(i) { if (this.textContent == searchparams.get('league')) { this.id = 'selected_filter'; filter_found = true }});
|
||||||
|
if (!filter_found) { insertLeague(searchparams.get('league')).id = 'selected_filter' }
|
||||||
|
|
||||||
|
updateGames(lastupdate, searchparams.get('league'));
|
||||||
} else {
|
} else {
|
||||||
$('#filters .filter').each(function(i) { if (this.textContent == 'All') { this.id = 'selected_filter' }})
|
$('#filters .filter').each(function(i) { if (this.textContent == 'All') { this.id = 'selected_filter' }})
|
||||||
updateGames(lastupdate, "All");
|
updateGames(lastupdate, "All");
|
||||||
|
|
|
@ -734,12 +734,13 @@ async def watch_game(channel, newgame, user = None, league = None):
|
||||||
discrim_string = "Unclaimed game."
|
discrim_string = "Unclaimed game."
|
||||||
state_init["is_league"] = False
|
state_init["is_league"] = False
|
||||||
|
|
||||||
if league is not None:
|
|
||||||
league_ext = "league?name=" + urllib.parse.quote_plus(league)
|
|
||||||
else:
|
|
||||||
league_ext = ""
|
|
||||||
await channel.send(f"{newgame.teams['away'].name} vs. {newgame.teams['home'].name}, starting at {config()['simmadome_url']+league_ext}")
|
|
||||||
timestamp = str(time.time() * 1000.0)
|
timestamp = str(time.time() * 1000.0)
|
||||||
|
ext = "?game="+timestamp
|
||||||
|
if league is not None:
|
||||||
|
ext += "&league=" + urllib.parse.quote_plus(league)
|
||||||
|
|
||||||
|
await channel.send(f"{newgame.teams['away'].name} vs. {newgame.teams['home'].name}, starting at {config()['simmadome_url']+ext}")
|
||||||
gamesarray.append((newgame, channel, user, timestamp))
|
gamesarray.append((newgame, channel, user, timestamp))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user