X-Git-Url: https://git.auder.net/game/current/git-logo.png?a=blobdiff_plain;f=js%2Findex.js;h=0d2adad0026adcdd1c931675ff836ca2f7d9a7d9;hb=ce0473b4fac73ad9ac63cf8fa480548817349804;hp=a4a0dc777aa6aa278ae68d1159d320be0d2ee0a8;hpb=1369a09d4b3a4d3c3d19b68197a311fbb7ec97f4;p=westcastle.git
diff --git a/js/index.js b/js/index.js
index a4a0dc7..0d2adad 100644
--- a/js/index.js
+++ b/js/index.js
@@ -45,88 +45,6 @@ new Vue({
},
},
},
- 'my-ranking': {
- props: ['players','sortByScore','writeScoreToDb'],
- template: `
-
-
-
- Rang |
- Joueur |
- Points |
- Mini-pts |
-
-
- {{ p.rank }} |
- {{ p.prenom }} {{ p.nom }} |
- {{ p.pdt }} |
- {{ p.session }} |
-
-
-
-
-
-
-
- `,
- computed: {
- sortedPlayers: function() {
- let res = this.rankPeople();
- // Add rank information (taking care of ex-aequos)
- let rank = 1;
- for (let i=0; i { return Object.assign({}, p); }) //to not alter original array
- .sort(this.sortByScore);
- },
- resetPlayers: function() {
- this.players
- .slice(1) //discard Toto
- .forEach( p => {
- p.pdt = 0;
- p.session = 0;
- p.available = 1;
- });
- this.writeScoreToDb();
- document.getElementById("runPairing").click(); //TODO: hack...
- },
- restoreLast: function() {
- let xhr = new XMLHttpRequest();
- let self = this;
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200)
- {
- let players = JSON.parse(xhr.responseText);
- if (players.length > 0)
- {
- players.unshift({ //add ghost 4th player for 3-players tables
- prenom: "Toto",
- nom: "",
- pdt: 0,
- session: 0,
- available: 0,
- });
- self.players = players;
- }
- }
- };
- xhr.open("GET", "scripts/rw_players.php?restore=1", true);
- xhr.send(null);
- },
- },
- },
'my-pairings': {
props: ['players','writeScoreToDb'],
data: function() {
@@ -165,7 +83,7 @@ new Vue({
{{ players[tables[currentIndex][i]].prenom }} {{ players[tables[currentIndex][i]].nom }}
|
- |
+ |
@@ -236,8 +154,8 @@ new Vue({
},
setScore: function() {
let sortedSessions = this.sessions[this.currentIndex]
- .map( (s,i) => { return {value:s, index:i}; })
- .sort( (a,b) => { return parseInt(b.value) - parseInt(a.value); });
+ .map( (s,i) => { return {value:parseInt(s), index:i}; })
+ .sort( (a,b) => { return b.value - a.value; });
let pdts = [4, 2, 1, 0];
// NOTE: take care of ex-aequos (spread points subtotal)
let curSum = 0, curCount = 0, start = 0;
@@ -262,6 +180,156 @@ new Vue({
this.currentIndex = -1;
this.writeScoreToDb();
},
+ clickRestore: function() {
+ document.getElementById('restoreBtn').click();
+ },
+ },
+ },
+ 'my-timer': {
+ data: function() {
+ return {
+ time: 0, //remaining time, in seconds
+ running: false,
+ };
+ },
+ template: `
+
+
+ {{ formattedTime }}
+
+
+
+ `,
+ computed: {
+ formattedTime: function() {
+ let seconds = this.time % 60;
+ let minutes = Math.floor(this.time / 60);
+ return this.padToZero(minutes) + ":" + this.padToZero(seconds);
+ },
+ textHeight: function() {
+ return screen.height;
+ },
+ },
+ methods: {
+ padToZero: function(a) {
+ if (a < 10)
+ return "0" + a;
+ return a;
+ },
+ pauseResume: function() {
+ this.running = !this.running;
+ if (this.running)
+ this.start();
+ },
+ reset: function(e) {
+ this.running = false;
+ this.time = 5400; //1:30
+ },
+ start: function() {
+ if (!this.running)
+ return;
+ if (this.time == 0)
+ {
+ new Audio("sounds/gong.mp3").play();
+ this.running = false;
+ return;
+ }
+ setTimeout(() => {
+ if (this.running)
+ this.time--;
+ this.start();
+ }, 1000);
+ },
+ },
+ created: function() {
+ this.reset();
+ },
+ },
+ 'my-ranking': {
+ props: ['players','sortByScore','writeScoreToDb'],
+ template: `
+
+
+
+ Rang |
+ Joueur |
+ Points |
+ Mini-pts |
+
+
+ {{ p.rank }} |
+ {{ p.prenom }} {{ p.nom }} |
+ {{ p.pdt }} |
+ {{ p.session }} |
+
+
+
+
+
+
+
+ `,
+ computed: {
+ sortedPlayers: function() {
+ let res = this.rankPeople();
+ // Add rank information (taking care of ex-aequos)
+ let rank = 1;
+ for (let i=0; i {
+ p.pdt = 0;
+ p.session = 0;
+ p.available = 1;
+ });
+ this.writeScoreToDb();
+ document.getElementById("runPairing").click();
+ },
+ restoreLast: function() {
+ let xhr = new XMLHttpRequest();
+ let self = this;
+ xhr.onreadystatechange = function() {
+ if (this.readyState == 4 && this.status == 200)
+ {
+ let players = JSON.parse(xhr.responseText);
+ if (players.length > 0)
+ {
+ players.unshift({ //add ghost 4th player for 3-players tables
+ prenom: "Toto",
+ nom: "",
+ pdt: 0,
+ session: 0,
+ available: 0,
+ });
+ // NOTE: Vue warning "do not mutate property" if direct self.players = players
+ for (let i=1; i { return Object.assign({}, p); }) //deep (enough) copy
.sort(this.sortByScore);
xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers)));
},