diff --git a/server.py b/server.py index 372a266c..ac6f740a 100644 --- a/server.py +++ b/server.py @@ -51,6 +51,8 @@ def increase_score(): if team["id"] == team_id: team["score"] += 1 + ## sort the scoreboard in descending order based on the score + scoreboard = sorted(scoreboard, key=lambda x: x["score"], reverse=True) return jsonify(scoreboard=scoreboard) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..3b8c7c57 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -23,6 +23,11 @@ function addTeamView(id, name, score){ $("#teams").append(team_template); } +// display the scoreboard on the page every time there was a change in the scoreboard +function update_scoreboard(){ + display_scoreboard(scoreboard); +} + function increase_score(id){ var team_id = {"id": id} $.ajax({ @@ -32,7 +37,8 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - + scoreboard = result.scoreboard; + update_scoreboard(); }, error: function(request, status, error){ console.log("Error");