Skip to content

Commit

Permalink
merging PR Chaosthebot#514: Periodically refresh voters list
Browse files Browse the repository at this point in the history
Chaosthebot#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 Chaosthebot#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
  • Loading branch information
andrewda authored and chaosbot committed Jun 5, 2017
1 parent fb9b397 commit 287e86e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
69 changes: 37 additions & 32 deletions server/static/js/chaos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<table>";
for (let i = 0; i < list.length && i < 20; i += 1) {
tablehtml += `<tr><td><a href="https://github.com/${escape(list[i].names)}">${list[i].names}</a></td><td>${list[i].votes}</tr>`;
}
tablehtml += "</table>";
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 = "<table>";
for (let i = 0; i < list.length && i < 20; i += 1) {
tablehtml += `<tr><td><a href="https://github.com/${escape(list[i].names)}">${list[i].names}</a></td><td>${list[i].votes}</tr>`;
}
tablehtml += "</table>";
result.innerHTML = tablehtml;
}
}
};
};
}

getText();
setInterval(getText, 30000);

let termLoading = false;

Expand Down
3 changes: 2 additions & 1 deletion server/voters.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ <h1>Voters on Chaos</h1>

<script>
getText();
setInterval(getText, 30000);

function getText() {
var result = document.getElementById("result");
// read text from URL location
var request = new XMLHttpRequest();
request.open('GET', 'api/voters', true);
request.open('GET', 'voters.json', true);
request.send(null);
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status === 200) {
Expand Down

0 comments on commit 287e86e

Please sign in to comment.