From 287e86e109b7342ea4ee2594d306661183524727 Mon Sep 17 00:00:00 2001 From: Andrew Dassonville Date: Sun, 4 Jun 2017 18:59:59 -0700 Subject: [PATCH] merging PR #514: Periodically refresh voters list https://github.com/chaosbot/Chaos/pull/514: Periodically refresh voters list Description: This will refresh the voters list every 30 seconds to keep it up to date. In addition, I started using /voters.json again until we can figure out what's wrong with the /voters page. (revote of #510) :white_check_mark: PR passed with a vote of 10 for and 0 against, a weighted total of 9.5 and a threshold of 6.5, and a current meritocracy review. Vote record: @PlasmaPower: 1 @Smittyvb: 1 @andrewda: 1 @dyc3: 1 @e-beach: 1 @justync7: 1 @mark-i-m: 1 @md678685: 1 @rhengles: 1 @rohanrk: 1 --- server/static/js/chaos.js | 69 +++++++++++++++++++++------------------ server/voters.html | 3 +- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/server/static/js/chaos.js b/server/static/js/chaos.js index 73c61645..e053b17a 100644 --- a/server/static/js/chaos.js +++ b/server/static/js/chaos.js @@ -147,40 +147,45 @@ document.getElementById("main").onclick = () => { /** LOAD VOTERS LIST */ -const result = document.getElementById("result"); -// read text from URL location -const request = new XMLHttpRequest(); -request.open("GET", "voters?amount=20", true); -request.send(null); -request.onreadystatechange = () => { - if (request.readyState === 4 && request.status === 200) { - const type = request.getResponseHeader("Content-Type"); - if (type.indexOf("text") !== 1) { - const json = JSON.parse(request.responseText); - const keys = Object.keys(json); - const values = keys.map(key => json[key]); - - // combine arrays - const list = []; - for (let j = 0; j < keys.length; j += 1) { - list.push({ - names: keys[j], - votes: values[j], - }); +function getText() { + const result = document.getElementById("result"); + // read text from URL location + const request = new XMLHttpRequest(); + request.open("GET", "voters.json", true); + request.send(null); + request.onreadystatechange = () => { + if (request.readyState === 4 && request.status === 200) { + const type = request.getResponseHeader("Content-Type"); + if (type.indexOf("text") !== 1) { + const json = JSON.parse(request.responseText); + const keys = Object.keys(json); + const values = keys.map(key => json[key]); + + // combine arrays + const list = []; + for (let j = 0; j < keys.length; j += 1) { + list.push({ + names: keys[j], + votes: values[j], + }); + } + + // eslint-disable-next-line no-nested-ternary + list.sort((a, b) => b.votes - a.votes); + + let tablehtml = ""; + for (let i = 0; i < list.length && i < 20; i += 1) { + tablehtml += ``; + } + tablehtml += "
${list[i].names}${list[i].votes}
"; + result.innerHTML = tablehtml; } - - // eslint-disable-next-line no-nested-ternary - list.sort((a, b) => -((a.votes < b.votes) ? -1 : ((a.votes === b.votes) ? 0 : 1))); - - let tablehtml = ""; - for (let i = 0; i < list.length && i < 20; i += 1) { - tablehtml += ``; - } - tablehtml += "
${list[i].names}${list[i].votes}
"; - result.innerHTML = tablehtml; } - } -}; + }; +} + +getText(); +setInterval(getText, 30000); let termLoading = false; diff --git a/server/voters.html b/server/voters.html index 5c0a80e7..0910dd7b 100644 --- a/server/voters.html +++ b/server/voters.html @@ -12,12 +12,13 @@

Voters on Chaos