+ },
+ },
+ 'my-timer': {
+ data: function() {
+ return {
+ time: 0, //remaining time, in seconds
+ running: false,
+ initialTime: 90, //1h30, in minutes
+ setter: false,
+ setterTime: 0, //to input new initial time
+ };
+ },
+ template: `
+ <div id="timer" :style="{lineHeight: divHeight + 'px', fontSize: 0.66*divHeight + 'px', width: divWidth + 'px', height: divHeight + 'px'}">
+ <div v-show="!setter" @click.left="pauseResume()" @click.right.prevent="reset()" :class="{timeout:time==0}">
+ {{ formattedTime }}
+ </div>
+ <input type="text" autofocus id="setter" @keyup.enter="setTime()" @keyup.esc="setter=false" v-show="setter" v-model="setterTime"></input>
+ <img class="close-cross" src="img/cross.svg" @click="$emit('clockover')"/>
+ </div>
+ `,
+ computed: {
+ formattedTime: function() {
+ let seconds = this.time % 60;
+ let minutes = Math.floor(this.time / 60);
+ return this.padToZero(minutes) + ":" + this.padToZero(seconds);
+ },
+ divHeight: function() {
+ return screen.height;
+ },
+ divWidth: function() {
+ return screen.width;
+ },
+ },
+ methods: {
+ setTime: function() {
+ this.initialTime = this.setterTime;
+ this.setter = false;
+ this.reset();
+ },
+ 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 = this.initialTime * 60;
+ },
+ start: function() {
+ if (!this.running)
+ return;
+ if (this.time == 0)
+ {
+ new Audio("sounds/gong.mp3").play();
+ this.running = false;
+ return;
+ }
+ if (this.time == this.initialTime * 60)
+ new Audio("sounds/gong.mp3").play(); //gong at the beginning
+ setTimeout(() => {
+ if (this.running)
+ this.time--;
+ this.start();
+ }, 1000);
+ },
+ },
+ created: function() {
+ this.setterTime = this.initialTime;
+ this.reset();
+ },
+ mounted: function() {
+ let timer = document.getElementById("timer");
+ let keyDict = {
+ 32: () => { this.setter = true; }, //Space
+ 27: () => { this.setter = false; }, //Esc
+ };
+ document.addEventListener("keyup", e => {
+ if (timer.style.display !== "none")
+ {
+ let func = keyDict[e.keyCode];
+ if (!!func)
+ {
+ e.preventDefault();
+ func();
+ }
+ }
+ });
+ },
+ },
+ 'my-ranking': {
+ props: ['players','sortByScore','commitScores'],
+ template: `
+ <div id="ranking">
+ <table class="ranking">
+ <tr class="title">
+ <th>Rang</th>
+ <th>Joueur</th>
+ <th>Points</th>
+ <th>Mini-pts</th>
+ </tr>
+ <tr v-for="p in sortedPlayers">
+ <td>{{ p.rank }}</td>
+ <td>{{ p.prenom }} {{ p.nom }}</td>
+ <td>{{ p.pdt }}</td>
+ <td>{{ p.session }}</td>
+ </tr>
+ </table>
+ <div class="button-container-vertical" style="width:200px">
+ <a id="download" href="#"></a>
+ <button class="btn" @click="download()" title="Télécharge le classement courant au format CSV">Télécharger</button>
+ <button class="btn cancel" @click="resetPlayers()" title="Réinitialise les scores à zéro. ATTENTION: action irréversible">
+ Réinitialiser
+ </button>
+ </div>
+ </div>
+ `,
+ computed: {
+ sortedPlayers: function() {
+ let res = this.rankPeople();
+ // Add rank information (taking care of ex-aequos)
+ let rank = 1;
+ for (let i=0; i<res.length; i++)
+ {
+ if (i==0 || this.sortByScore(res[i],res[i-1]) == 0)
+ res[i].rank = rank;
+ else //strictly lower scoring
+ res[i].rank = ++rank;
+ }
+ return res;
+ },
+ },
+ methods: {
+ rankPeople: function() {
+ return this.players
+ .slice(1) //discard Toto
+ .sort(this.sortByScore);
+ },
+ resetPlayers: function() {
+ if (confirm('Êtes-vous sûr ?'))
+ {
+ this.players
+ .slice(1) //discard Toto
+ .forEach( p => {
+ p.pdt = 0;
+ p.session = 0;
+ p.available = 1;
+ });
+ this.commitScores();
+ document.getElementById("doPairings").click();
+ }
+ },
+ download: function() {
+ // Prepare file content
+ let content = "prénom,nom,pdt,session\n";
+ this.players
+ .slice(1) //discard Toto
+ .sort(this.sortByScore)
+ .forEach( p => {
+ content += p.prenom + "," + p.nom + "," + p.pdt + "," + p.session + "\n";
+ });
+ // Prepare and trigger download link
+ let downloadAnchor = document.getElementById("download");
+ downloadAnchor.setAttribute("download", "classement.csv");
+ downloadAnchor.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content);
+ downloadAnchor.click();