diff options
| -rw-r--r-- | app/__init__.py | 3 | ||||
| -rw-r--r-- | app/static/file.js | 11 | ||||
| -rw-r--r-- | app/static/timer.js (renamed from app/static/custom.js) | 180 | ||||
| -rw-r--r-- | app/templates/controls.j2 | 12 | ||||
| -rw-r--r-- | app/templates/games.j2 | 2 | ||||
| -rw-r--r-- | app/templates/index.j2 | 4 | ||||
| -rw-r--r-- | app/templates/macros.j2 | 4 | ||||
| -rw-r--r-- | app/templates/players.j2 | 14 |
8 files changed, 116 insertions, 114 deletions
diff --git a/app/__init__.py b/app/__init__.py index 639f030..0e0ea09 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -31,7 +31,7 @@ g = Session() @app.route("/", methods=["GET"]) def home(): - return render_template("index.j2", url_for=url_for) + return render_template("index.j2", url_for=url_for, login_status=is_logged_in()) @app.route("/control", methods=["GET"]) @@ -46,6 +46,7 @@ def get_list_of_players(): regulars=g.players.regulars(), guests=g.players.guests(), url_for=url_for, + login_status=is_logged_in(), ) diff --git a/app/static/file.js b/app/static/file.js new file mode 100644 index 0000000..403ddf6 --- /dev/null +++ b/app/static/file.js @@ -0,0 +1,11 @@ +window.onload = function() { + const fileInput = document.querySelector("#file-js input[type=file]"); + if (fileInput !== null) { + fileInput.onchange = () => { + if (fileInput.files.length > 0) { + const fileName = document.querySelector("#file-js .file-name"); + fileName.textContent = fileInput.files[0].name; + } + } + }; +}
\ No newline at end of file diff --git a/app/static/custom.js b/app/static/timer.js index 3daeb17..e8e7854 100644 --- a/app/static/custom.js +++ b/app/static/timer.js @@ -1,91 +1,91 @@ -let minsPerRound = Number(sessionStorage.getItem("minsPerRound")) || 12;
-let timerRunningFlag = Number(sessionStorage.getItem("timerRunningFlag")) || 0;
-let deadline = Number(sessionStorage.getItem("deadline")) || new Date().getTime();
-let clock = 0;
-
-function setTimer(m, s) {
- let timer = document.getElementById("timer-display");
- m = m < 10 ? ("0" + m) : m;
- s = s < 10 ? ("0" + s) : s;
- timer.value = `${m}:${s}`;
-}
-
-function setSessionData() {
- sessionStorage.setItem("deadline", deadline);
- sessionStorage.setItem("minsPerRound", minsPerRound);
- sessionStorage.setItem("timerRunningFlag", timerRunningFlag);
-}
-
-function resetTimer() {
- clearInterval(clock);
- setTimer(minsPerRound, 0);
- timerRunningFlag = 0;
- setSessionData();
-}
-
-function updateTimer(milliseconds) {
- const m = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60));
- const s = Math.floor((milliseconds % (1000 * 60)) / 1000);
- setTimer(m, s);
-}
-
-function refreshTimer() {
- const now = new Date().getTime();
- const millisecondsToDeadline = deadline - now;
- if (millisecondsToDeadline > 0) {
- updateTimer(millisecondsToDeadline);
- return;
- }
- resetTimer();
- const notification = new Notyf({
- duration: 30 * 1000,
- position: {x: 'center', y: 'top'},
- types: [{
- type: 'success',
- background: 'indianred',
- duration: 1000 * 1000,
- dismissible: true
- }]
- });
- notification.success("Round completed");
-}
-
-function startTimer(fresh) {
- if (fresh) {
- now = new Date().getTime();
- const millisecondsToDeadline = minsPerRound * 60 * 1000;
- deadline = now + millisecondsToDeadline;
- }
- timerRunningFlag = 1;
- setSessionData();
- clock = setInterval(refreshTimer, 1000);
-}
-
-window.onload = function () {
- if (timerRunningFlag)
- startTimer(0);
- else resetTimer();
-
- document.getElementById("timer-start").addEventListener('click', ()=> {
- if (timerRunningFlag != 0) return;
- startTimer(1);
- });
-
- document.getElementById("timer-stop").addEventListener('click', ()=>{
- resetTimer();
- });
-
- document.getElementById("timer-inc").addEventListener('click', ()=> {
- if (timerRunningFlag == 0) {
- minsPerRound += 1;
- resetTimer();
- }
- });
-
- document.getElementById("timer-dec").addEventListener('click', ()=> {
- if (timerRunningFlag == 0 && minsPerRound != 0) {
- minsPerRound -= 1;
- resetTimer();
- }
- });
+let minsPerRound = Number(sessionStorage.getItem("minsPerRound")) || 12; +let timerRunningFlag = Number(sessionStorage.getItem("timerRunningFlag")) || 0; +let deadline = Number(sessionStorage.getItem("deadline")) || new Date().getTime(); +let clock = 0; + +function setTimer(m, s) { + let timer = document.getElementById("timer-display"); + m = m < 10 ? ("0" + m) : m; + s = s < 10 ? ("0" + s) : s; + timer.value = `${m}:${s}`; +} + +function setSessionData() { + sessionStorage.setItem("deadline", deadline); + sessionStorage.setItem("minsPerRound", minsPerRound); + sessionStorage.setItem("timerRunningFlag", timerRunningFlag); +} + +function resetTimer() { + clearInterval(clock); + setTimer(minsPerRound, 0); + timerRunningFlag = 0; + setSessionData(); +} + +function updateTimer(milliseconds) { + const m = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60)); + const s = Math.floor((milliseconds % (1000 * 60)) / 1000); + setTimer(m, s); +} + +function refreshTimer() { + const now = new Date().getTime(); + const millisecondsToDeadline = deadline - now; + if (millisecondsToDeadline > 0) { + updateTimer(millisecondsToDeadline); + return; + } + resetTimer(); + const notification = new Notyf({ + duration: 30 * 1000, + position: {x: 'center', y: 'top'}, + types: [{ + type: 'success', + background: 'indianred', + duration: 1000 * 1000, + dismissible: true + }] + }); + notification.success("Round completed"); +} + +function startTimer(fresh) { + if (fresh) { + now = new Date().getTime(); + const millisecondsToDeadline = minsPerRound * 60 * 1000; + deadline = now + millisecondsToDeadline; + } + timerRunningFlag = 1; + setSessionData(); + clock = setInterval(refreshTimer, 1000); +} + +window.onload = function () { + if (timerRunningFlag) + startTimer(0); + else resetTimer(); + + document.getElementById("timer-start").addEventListener('click', ()=> { + if (timerRunningFlag != 0) return; + startTimer(1); + }); + + document.getElementById("timer-stop").addEventListener('click', ()=>{ + resetTimer(); + }); + + document.getElementById("timer-inc").addEventListener('click', ()=> { + if (timerRunningFlag == 0) { + minsPerRound += 1; + resetTimer(); + } + }); + + document.getElementById("timer-dec").addEventListener('click', ()=> { + if (timerRunningFlag == 0 && minsPerRound != 0) { + minsPerRound -= 1; + resetTimer(); + } + }); }
\ No newline at end of file diff --git a/app/templates/controls.j2 b/app/templates/controls.j2 index 14e7520..8e7440e 100644 --- a/app/templates/controls.j2 +++ b/app/templates/controls.j2 @@ -1,10 +1,4 @@ {% from "macros.j2" import court_button %} -<h3>Courts</h3> -<div class="parent"> -{% for court in courts %} - {{ court_button(court) }} -{% endfor %} -</div> <h3>Generation</h3> <div class="grid"> <div class="select is-responsive"> @@ -47,4 +41,10 @@ <div class="grid"> <button id="timer-start"><i class="fas fa-light fa-play"></i></button> <button id="timer-stop"><i class="fas fa-light fa-stop"></i></button> +</div> +<h3>Courts</h3> +<div class="parent"> +{% for court in courts %} + {{ court_button(court) }} +{% endfor %} </div>
\ No newline at end of file diff --git a/app/templates/games.j2 b/app/templates/games.j2 index ce2a412..5041ce1 100644 --- a/app/templates/games.j2 +++ b/app/templates/games.j2 @@ -10,7 +10,7 @@ </thead> <tbody> {% for game in games %} - <tr {% if game.team_1[0].first_name == 'RESERVED' %} class="is-danger" {% endif %}> + <tr {% if game.team_1[0].first_name == 'RESERVED' %} data-theme="dark" {% endif %}> <th align="center" style="width: 8%;">{{ game.court.id }}</th> <td style="width: 23%;"><strong>{{ game.team_1[0].first_name }}</strong>{{ " " + game.team_1[0].last_name }}</th> <td style="width: 23%;"><strong>{{ game.team_1[1].first_name }}</strong>{{ " " + game.team_1[1].last_name }}</th> diff --git a/app/templates/index.j2 b/app/templates/index.j2 index 8a13fa0..af6ca4c 100644 --- a/app/templates/index.j2 +++ b/app/templates/index.j2 @@ -3,7 +3,7 @@ <html lang="en"> {{ header(url_for) }} <body> - <header class="container">{{ navbar(url_for) }}</header> + <header class="container">{{ navbar(url_for, login_status) }}</header> <main class="container"> <h2>Games</h2> <div hx-post="/clear" hx-swap="outerHTML" hx-trigger="load"></div> @@ -11,6 +11,6 @@ <div hx-get="/control" hx-swap="outerHTML" hx-trigger="load"></div> </main> <footer class="container">{{ footer() }}</footer> - <script defer src="{{ url_for('static', filename='custom.js') }}"></script> + <script src="{{ url_for('static', filename='timer.js') }}"></script> </body> </html> diff --git a/app/templates/macros.j2 b/app/templates/macros.j2 index 17a2940..e82b910 100644 --- a/app/templates/macros.j2 +++ b/app/templates/macros.j2 @@ -31,7 +31,7 @@ {%- endmacro %} -{% macro navbar(url_for) -%} +{% macro navbar(url_for, login_status) -%} <nav> <ul> <li><strong>Match Up!</strong></li> @@ -39,7 +39,7 @@ <ul> <li><a href="/">Games</a></li> <li><a href="/players">Players</a></li> - <li><a href="/login/">Admin</a></li> + {% if login_status %}<li><a href="/logout/">Logout</a></li>{% else %}<li><a href="/login/">Login</a></li>{% endif %} </ul> </nav> {%- endmacro %}
\ No newline at end of file diff --git a/app/templates/players.j2 b/app/templates/players.j2 index 4b9660e..bacb215 100644 --- a/app/templates/players.j2 +++ b/app/templates/players.j2 @@ -3,7 +3,7 @@ <html lang="en"> {{ header(url_for) }} <body> - <header class="container">{{ navbar(url_for) }}</header> + <header class="container">{{ navbar(url_for, login_status) }}</header> <main class="container"> <h3 >Members</h3> <div class="parent"> @@ -34,17 +34,7 @@ </form> </div> <footer class="container">{{ footer() }}</footer> - <script> - const fileInput = document.querySelector("#file-js input[type=file]"); - if (fileInput !== null) { - fileInput.onchange = () => { - if (fileInput.files.length > 0) { - const fileName = document.querySelector("#file-js .file-name"); - fileName.textContent = fileInput.files[0].name; - } - } - }; - </script> + <script src="{{ url_for('static', filename='file.js') }}"></script> </main> </body> </html>
\ No newline at end of file |
