Skip to content

Instantly share code, notes, and snippets.

@fcamblor
Last active January 23, 2018 07:43
Show Gist options
  • Select an option

  • Save fcamblor/e74d0b1927f333a952be001c123c4ae0 to your computer and use it in GitHub Desktop.

Select an option

Save fcamblor/e74d0b1927f333a952be001c123c4ae0 to your computer and use it in GitHub Desktop.
DevoxxFR CFP UI goodness to facilitate massive vote updates as a GoldenTicket
javascript:function createManualVoteFields(){$("#tableMyVotes tr").each((a,b)=>{$(b).find("td:eq(0)").append($("<input type='number' class='manualVote' size='1' style='width: 35px' />"))}),$("h3:eq(1)").append("&nbsp;&nbsp;<button class=\"btn btn-sm btn-primary\" onclick=\"submitManualVotes()\">Submit manual votes</button>")}function getVotes(){return $("#tableMyVotes tr").map((a,b)=>{return{id:$(b).find("td:eq(1) a").text(),score:+$(b).find("td:eq(0) button:eq(0)").text(),newScore:+$(b).find("td:eq(0) :input.manualVote").val(),title:$(b).find("td:eq(2)").text().trim(),track:$(b).find("td:eq(3)").text().trim()}}).filter((a,b)=>b.id)}function showCurrentVotesStats(){var a=getVotes(),b={votesPerScore:{},votesPerTrackThenScore:{},votesPerTrack:{}};$.each(a,function(d,e){b.votesPerScore[e.score]=b.votesPerScore[e.score]||[],b.votesPerTrack[e.track]=b.votesPerTrack[e.track]||[],b.votesPerTrackThenScore[e.track]=b.votesPerTrackThenScore[e.track]||{},b.votesPerTrackThenScore[e.track][e.score]=b.votesPerTrackThenScore[e.track][e.score]||[],b.votesPerScore[e.score].push(e),b.votesPerTrack[e.track].push(e),b.votesPerTrackThenScore[e.track][e.score].push(e)}),console.log("======= Stats ======="),console.log("== Votes per track =="),Object.keys(b.votesPerTrack).forEach(d=>console.log(" "+d+" => "+b.votesPerTrack[d].length)),console.log("== Votes per score =="),Object.keys(b.votesPerScore).forEach(d=>console.log(" "+d+" => "+b.votesPerScore[d].length)),console.log("== ["+getParameterByName("talkType")+"] Votes per track then score ==");var c={};Object.keys(b.votesPerTrackThenScore).forEach(d=>{c[d]={total:b.votesPerTrack[d].length},[0,1,2,3,4,5,6,7,8,9,10].forEach(e=>c[d][e]=""),Object.keys(b.votesPerTrackThenScore[d]).forEach(e=>c[d][e]=b.votesPerTrackThenScore[d][e].length)}),console.table(c)}function submitManualVotes(){$.when($("#tableMyVotes tr").filter((a,b)=>$(b).find(":input.manualVote").val()).map((a,b)=>{var c=$(b).find("td:eq(1) a").text(),d=+$(b).find(":input.manualVote").val();return console.log("id "+c+" => "+d),$.getJSON("/cfp/goldenticket/proposals/"+c+"/vote?vote="+d)})).then(()=>{console.log("Votes mis a jour :D !"),$(".manualVote").val("")})}function getParameterByName(a,b){b||(b=window.location.href),a=a.replace(/[\[\]]/g,"\\$&");var c=new RegExp("[?&]"+a+"(=([^&#]*)|&|#|$)"),d=c.exec(b);return d?d[2]?decodeURIComponent(d[2].replace(/\+/g," ")):"":null}createManualVoteFields();
function createManualVoteFields() {
$("#tableMyVotes tr").each((index, tr) => {
$(tr).find("td:eq(0)").append($("<input type='number' class='manualVote' size='1' style='width: 35px' />"));
});
$("h3:eq(1)").append('&nbsp;&nbsp;<button class="btn btn-sm btn-primary" onclick="submitManualVotes()">Submit manual votes</button>')
}
function getVotes() {
return $("#tableMyVotes tr").map((index, tr) => {
return {
id: $(tr).find("td:eq(1) a").text(),
score: Number($(tr).find("td:eq(0) button:eq(0)").text()),
newScore: Number($(tr).find("td:eq(0) :input.manualVote").val()),
title: $(tr).find("td:eq(2)").text().trim(),
track: $(tr).find("td:eq(3)").text().trim()
};
}).filter((index, vote) => vote.id);
}
function showCurrentVotesStats() {
var votes = getVotes();
var stats = {
votesPerScore: {},
votesPerTrackThenScore: {},
votesPerTrack: {}
};
$.each(votes, function(index, vote) {
stats.votesPerScore[vote.score] = stats.votesPerScore[vote.score] || [];
stats.votesPerTrack[vote.track] = stats.votesPerTrack[vote.track] || [];
stats.votesPerTrackThenScore[vote.track] = stats.votesPerTrackThenScore[vote.track] || {};
stats.votesPerTrackThenScore[vote.track][vote.score] = stats.votesPerTrackThenScore[vote.track][vote.score] || [];
stats.votesPerScore[vote.score].push(vote);
stats.votesPerTrack[vote.track].push(vote);
stats.votesPerTrackThenScore[vote.track][vote.score].push(vote);
});
console.log("======= Stats =======");
console.log("== Votes per track ==");
Object.keys(stats.votesPerTrack).forEach((track, index) => console.log(" "+track+" => "+stats.votesPerTrack[track].length));
console.log("== Votes per score ==");
Object.keys(stats.votesPerScore).forEach((score, index) => console.log(" "+score+" => "+stats.votesPerScore[score].length));
console.log("== ["+getParameterByName('talkType')+"] Votes per track then score ==");
var trackAndVotes = {};
Object.keys(stats.votesPerTrackThenScore).forEach((track) => {
trackAndVotes[track] = {total:stats.votesPerTrack[track].length};
[0,1,2,3,4,5,6,7,8,9,10].forEach((score) => trackAndVotes[track][score] = '');
Object.keys(stats.votesPerTrackThenScore[track]).forEach((score) => trackAndVotes[track][score] = stats.votesPerTrackThenScore[track][score].length);
});
console.table(trackAndVotes);
}
function submitManualVotes() {
$.when($("#tableMyVotes tr").filter((idx, tr) => $(tr).find(":input.manualVote").val()).map((idx, tr) => {
var id = $(tr).find("td:eq(1) a").text();
var vote = Number($(tr).find(":input.manualVote").val());
console.log("id "+id+" => "+vote);
return $.getJSON('/cfp/goldenticket/proposals/'+id+'/vote?vote='+vote);
})).then(() => { console.log("Votes mis a jour :D !"); $(".manualVote").val(''); });
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
createManualVoteFields();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment