X-Git-Url: https://git.auder.net/?p=westcastle.git;a=blobdiff_plain;f=js%2Findex.js;h=870be76d8b0429c2f1e8f6835d904c82a0b7fd10;hp=944a51b2a548b796465e981ffbc168f96a4863b9;hb=fd4a69e4ea369afb39c01f1207d79b0ab2d4cc8e;hpb=7a00c4090c05f7c5f9d9b1b49bcf749b90f95c06 diff --git a/js/index.js b/js/index.js index 944a51b..870be76 100644 --- a/js/index.js +++ b/js/index.js @@ -21,7 +21,7 @@ new Vue({

Absents

- + @@ -61,8 +61,8 @@ new Vue({ - - + + @@ -70,14 +70,24 @@ new Vue({
{{ p.prenom }} {{ p.nom }}
Score PdT
{{ i+1 }}
{{ p.rank }} {{ p.prenom }} {{ p.nom }} {{ p.score }} {{ p.pdt }}
`, - computed: { + computed: { //TODO: first sort on score, then on Pdt (and reciprocally) --> function add fraction relative Pdt / score (compute min max first, take care of 0 case) sortedPlayers: function() { let sortFunc = this.sortMethod == "score" ? this.sortByScore : this.sortByPdt; - return this.players - .map( p => { return p; }) //to not alter original array + let res = this.players + .map( p => { return Object.assign({}, p); }) //to not alter original array .sort(sortFunc); + // Add rank information (taking care of ex-aequos) + let rank = 1; + for (let i=0; iTable {{ index+1 }}

- + - - - -
{{ players[i].prenom }} {{ players[i].nom }}{{ players[i].prenom }} {{ players[i].nom }} {{ pdts[index][j] }}
  
@@ -128,7 +134,9 @@ new Vue({
- +
{{ players[tables[currentIndex][i]].prenom }} {{ players[tables[currentIndex][i]].nom }} + {{ players[tables[currentIndex][i]].prenom }} {{ players[tables[currentIndex][i]].nom }} +
@@ -177,6 +185,11 @@ new Vue({ else this.unpaired = currentTable; } + // Ensure that all tables have 4 players + tables.forEach( t => { + if (t.length < 4) + t.push(0); //index of "Toto", ghost player + }); this.tables = tables; this.scores = tables.map( t => { return []; }); //empty scores this.pdts = tables.map( t => { return []; }); //empty pdts @@ -195,7 +208,7 @@ new Vue({ let sortedPdts = this.pdts[this.currentIndex] .map( (s,i) => { return {value:s, index:i}; }) .sort( (a,b) => { return parseInt(b.value) - parseInt(a.value); }); - let scores = [4, 2, 1, 0]; //TODO: biased for 3-players tables. TODO: ex-aequos ?! + let scores = [4, 2, 1, 0]; //TODO: ex-aequos ?! for (let i=0; i { return Object.assign({}, p); }) //deep (enough) copy .sort( (a,b) => { return b.score - a.score; }); xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers))); @@ -234,6 +248,13 @@ new Vue({ p.pdt = !!p.pdt ? parseInt(p.pdt) : 0; p.available = !!p.available ? p.available : 1; //use integer for fputcsv PHP func }); + players.unshift({ //add ghost 4th player for 3-players tables + prenom: "Toto", + nom: "", + score: 0, + pdt: 0, + available: 0, + }); self.players = players; } };