diff options
| author | Karan Jayachandra <karan.jayachandra@nxp.com> | 2025-07-25 15:30:07 +0200 |
|---|---|---|
| committer | Karan Jayachandra <karan.jayachandra@nxp.com> | 2025-07-25 15:30:07 +0200 |
| commit | 08e4a27c0db7fc2867cce3eb6f80799148c03ba6 (patch) | |
| tree | 9cf8636933099a550b02b281b6a885b7f3a7bf37 | |
| parent | 040a3a894e0816596532d7f7430baa4a5524f67b (diff) | |
Moved to a mobile friendly CSS framework
| -rw-r--r-- | app/__init__.py | 27 | ||||
| -rw-r--r-- | app/static/custom.css | 13 | ||||
| -rw-r--r-- | app/static/custom.js | 2 | ||||
| -rw-r--r-- | app/templates/controls.j2 | 83 | ||||
| -rw-r--r-- | app/templates/games.j2 | 6 | ||||
| -rw-r--r-- | app/templates/index.j2 | 11 | ||||
| -rw-r--r-- | app/templates/login.html | 8 | ||||
| -rw-r--r-- | app/templates/macros.j2 | 54 | ||||
| -rw-r--r-- | app/templates/players.j2 | 59 |
9 files changed, 121 insertions, 142 deletions
diff --git a/app/__init__.py b/app/__init__.py index 3d3b498..639f030 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -54,19 +54,29 @@ def get_list_of_courts(): return render_template("courts.j2", courts=g.courts.all()) +def login_required(f): + @wraps(f) + def decorated_function(*args, **kwargs): + if not is_logged_in(): + response = Response("User isn't logged in!") + response.headers["HX-Redirect"] = url_for("simplelogin.login") + return response + return f(*args, **kwargs) + + return decorated_function + + @app.route("/propose", methods=["POST"]) +@login_required def get_random_games(): - if not is_logged_in(): - return redirect(url_for("login")) g.levels = int(request.form["levels"].split()[0]) g.teams = request.form["team"] == "Teams" return render_template("games.j2", games=g.propose(), title="Proposal") @app.route("/confirm", methods=["POST"]) +@login_required def confirm_games(): - if not is_logged_in(): - return redirect(url_for("simplelogin.login")) return render_template("games.j2", games=g.confirm(), title=f"Round: {g.round()}") @@ -76,15 +86,6 @@ def clear_games(): "games.j2", games=g.current_round(), title=f"Round: {g.round()}" ) -def login_required(f): - @wraps(f) - def decorated_function(*args, **kwargs): - if not is_logged_in(): - response = Response("User isn't logged in!") - response.headers["HX-Redirect"] = url_for("simplelogin.login") - return response - return f(*args, **kwargs) - return decorated_function @app.route("/reset", methods=["POST"]) @login_required diff --git a/app/static/custom.css b/app/static/custom.css index 18462d3..9992ee5 100644 --- a/app/static/custom.css +++ b/app/static/custom.css @@ -1,21 +1,20 @@ -button, input, .select, .select select { +button, input, select { width: 100%; height: 100%; } -table { - font-size: 17.5px; -} td { width: 20%; } -.center { - margin: auto; - width: 50%; +.grid { + margin-top: 20px; + margin-bottom: 20px; } .parent { display: grid; grid-column-gap: 20px; grid-row-gap: 20px; + margin-top: 20px; + margin-bottom: 20px; } @media (min-width: 800px) { .parent { diff --git a/app/static/custom.js b/app/static/custom.js index 1d36493..2c47448 100644 --- a/app/static/custom.js +++ b/app/static/custom.js @@ -3,7 +3,7 @@ let timerRunningFlag = Number(sessionStorage.getItem("timerRunningFlag")) || 0; let deadline = Number(sessionStorage.getItem("deadline")) || new Date().getTime();
let clock = 0;
-function setTimer(m, s) {
+window.onload += function setTimer(m, s) {
let timer = document.getElementById("timer-display");
m = m < 10 ? ("0" + m) : m;
s = s < 10 ? ("0" + s) : s;
diff --git a/app/templates/controls.j2 b/app/templates/controls.j2 index f67f745..a8cba89 100644 --- a/app/templates/controls.j2 +++ b/app/templates/controls.j2 @@ -1,47 +1,46 @@ {% from "macros.j2" import court_button %} -<div class="fixed-grid has-6-cols"> - <div class="parent"> - {% for court in courts %} - {{ court_button(court) }} - {% endfor %} - </div> +<h3>Courts</h3> +<div class="parent"> +{% for court in courts %} + {{ court_button(court) }} +{% endfor %} </div> -<div class="columns"> - <div class="column"> - <div class="select is-responsive"> - <select name="levels"> - <option>10 Levels</option> - <option>8 Levels</option> - <option>6 Levels</option> - <option>4 Levels</option> - <option>2 Levels</option> - <option>0 Levels</option> - </select> - </div> - </div> - <div class="column"> - <div class="select is-responsive"> - <select name="team"> - <option>Random</option> - <option>Teams</option> - </select> - </div> - </div> - <div class="column"> - <button class="button is-dark is-responsive" - hx-post="/propose" - hx-target="#games" - hx-include="[name='levels'], [name='team']">Generate</button> +<h3>Generation</h3> +<div class="grid"> + <div class="select is-responsive"> + <select name="levels"> + <option>10 Levels</option> + <option>8 Levels</option> + <option>6 Levels</option> + <option>4 Levels</option> + <option>2 Levels</option> + <option>0 Levels</option> + </select> </div> - <div class="column"></div> - <div class="column"> - <button class="button is-dark is-responsive" - hx-post="/confirm" - hx-target="#games">Confirm</button> - </div> - <div class="column"> - <button class="button is-dark is-responsive" - hx-post="/reset" - hx-target="#games">RESET!</button> + <div class="select is-responsive"> + <select name="team"> + <option>Random</option> + <option>Teams</option> + </select> </div> +</div> +<div class="grid"> + <button class="button is-dark is-responsive" + hx-post="/propose" + hx-target="#games" + hx-include="[name='levels'], [name='team']">Generate</button> + <button class="button is-dark is-responsive" + hx-post="/confirm" + hx-target="#games">Confirm</button> + <button class="button is-dark is-responsive" + hx-post="/reset" + hx-target="#games">RESET!</button> +</div> +<h3>Timer</h3> +<div role="group"> + <button id="timer-dec"><i class="fas fa-light fa-minus"></i></button> + <input id="timer-display" type="text" style="text-align:center; " readonly></input> + <button id="timer-inc"><i class="fas fa-light fa-plus"></i></button> + <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>
\ No newline at end of file diff --git a/app/templates/games.j2 b/app/templates/games.j2 index dff1e0f..ce2a412 100644 --- a/app/templates/games.j2 +++ b/app/templates/games.j2 @@ -1,4 +1,5 @@ -<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth" id="games"> +<div class="overflow-auto"> +<table id="games"> <thead> <th colspan="5" align="center"> {{ title }} </th> </thead> @@ -18,4 +19,5 @@ </tr> {% endfor %} </tbody> -</table>
\ No newline at end of file +</table> +<div>
\ No newline at end of file diff --git a/app/templates/index.j2 b/app/templates/index.j2 index ce0d531..8a13fa0 100644 --- a/app/templates/index.j2 +++ b/app/templates/index.j2 @@ -3,11 +3,14 @@ <html lang="en"> {{ header(url_for) }} <body> - <section class="section"> - {{ navbar(url_for) }} + <header class="container">{{ navbar(url_for) }}</header> + <main class="container"> + <h2>Games</h2> <div hx-post="/clear" hx-swap="outerHTML" hx-trigger="load"></div> + <h2>Controls</h2> <div hx-get="/control" hx-swap="outerHTML" hx-trigger="load"></div> - {{ footer() }} - </section> + </main> + <footer class="container">{{ footer() }}</footer> + <script defer src="{{ url_for('static', filename='custom.js') }}"></script> </body> </html> diff --git a/app/templates/login.html b/app/templates/login.html index a42f2c5..e3109b6 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -3,8 +3,8 @@ <html lang="en"> {{ header(url_for) }} <body> - <section class="section"> - {{ navbar(url_for) }} + <header class="container">{{ navbar(url_for) }}</header> + <main class="container"> <form action="{{ url_for('simplelogin.login') }}" method="post"> <div class="form-group"> {{ form.csrf_token }} @@ -16,8 +16,8 @@ </form> <input class="button is-dark" type="submit" value="Login"> </form> - {{ footer() }} - </section> + </main> + <footer class="container">{{ footer() }}</footer> </body> </html>
\ No newline at end of file diff --git a/app/templates/macros.j2 b/app/templates/macros.j2 index 4fe35f0..17a2940 100644 --- a/app/templates/macros.j2 +++ b/app/templates/macros.j2 @@ -1,11 +1,11 @@ {% macro court_button(court) -%} -<button class= "button is-responsive {% if court.status %}is-success{% else %}is-danger{% endif %}" +<button class= "{% if court.status %}{% else %}contrast{% endif %}" hx-post="{{ "/court-toggle/" ~ court.id}}" hx-swap="outerHTML"> Court {{ court.id }}</button> {%- endmacro %} {% macro player_button(player) -%} -<button class="button is-responsive {% if player.status %}is-success{% else %}is-danger {% endif %}" +<button class="{% if player.status %}{% else %}contrast{% endif %}" hx-post="{{ "/player-toggle/" ~ player.id}}" hx-swap="outerHTML"> {{ player.first_name + " " + player.last_name}} </button> {%- endmacro %} @@ -16,56 +16,30 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Match Up!</title> <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}"> -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.4/css/bulma.min.css"> +<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"> <link rel="stylesheet" href="{{ url_for('static', filename='custom.css') }}"> <script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.6/dist/htmx.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/js/fontawesome.min.js"></script> -<script defer src="{{ url_for('static', filename='custom.js') }}"></script> </head> {%- endmacro %} {% macro footer() -%} -<div class="content has-text-centered">Made by <a href="https://karanjayachandra.com/">Karan</a> using <a href="https://flask.palletsprojects.com">Flask</a>, <a href="https://htmx.org/">HTMX</a>, <a href="https://carlosroso.com/notyf/">Notyf</a> and <a href="https://bulma.io">Bulma</a></div> +<div class="container">Made by <a href="https://karanjayachandra.com/">Karan</a> with <i class="fas fa-heart"></i></div> {%- endmacro %} + {% macro navbar(url_for) -%} -<nav class="level"> - <p class="level-item has-text-centered"> - <button class="button is-link" onclick="location.href = '/';">Games</button> - </p> - <p class="level-item has-text-centered"> - <button class="button is-link" onclick="location.href = '/players';">Players</button> - </p> - <div class="level-item has-text-centered"></div> - <div class="level-left"></div> - <div class="level-item has-text-centered"> - <p class="title">Match Up!</p> - </div> - <div class="level-item has-text-centered"></div> - <div class="level-right"> - <div class="field has-addons has-addons-centered"> - <div class="control"><button class="button is-dark" id="timer-dec"> - <span class="icon"><i class="fas fa-light fa-minus"></i></span> - </button></div> - <p class="control has-icons-left has-icons-right"> - <input class="input is-responsive" id="timer-display" type="text" style="text-align:center; " readonly> - <span class="icon is-small is-left"> - <i class="fas fa-light fa-clock"></i> - </span> - </p> - <div class="control"><button class="button is-dark" id="timer-inc"> - <span class="icon"><i class="fas fa-light fa-plus"></i></span> - </button></div> - <div class="control"><button class="button is-dark" id="timer-start"> - <span class="icon"><i class="fas fa-light fa-play"></i></span> - </button></div> - <div class="control"><button class="button is-dark" id="timer-stop"> - <span class="icon"><i class="fas fa-light fa-stop"></i></span> - </button></div> - </div> - </div> +<nav> + <ul> + <li><strong>Match Up!</strong></li> + </ul> + <ul> + <li><a href="/">Games</a></li> + <li><a href="/players">Players</a></li> + <li><a href="/login/">Admin</a></li> + </ul> </nav> {%- endmacro %}
\ No newline at end of file diff --git a/app/templates/players.j2 b/app/templates/players.j2 index 0499b73..f10b0a9 100644 --- a/app/templates/players.j2 +++ b/app/templates/players.j2 @@ -3,44 +3,45 @@ <html lang="en"> {{ header(url_for) }} <body> - <section class="section"> - {{ navbar(url_for) }} - <h4 class="title is-4">Members</h4> + <header class="container">{{ navbar(url_for) }}</header> + <main class="container"> + <h3 >Members</h3> <div class="parent"> {% for regular in regulars %} <div class="cell"> {{ player_button(regular) }} </div> {% endfor %} </div> - <h4 class="title is-4">Guests</h4> + <h3>Guests</h3> <div class="parent"> {% for guest in guests %} <div class="cell"> {{ player_button(guest) }} </div> {% endfor %} </div> - </section> - <section class="section"> - <div class="column"> - <button class="button is-dark is-responsive" - hx-post="/reset_players">RESET!</button> - </div> - <div class="column"> - <form method="POST" enctype="multipart/form-data" hx-post="/update_players"> - <div id="file-js" class="file has-name is-fullwidth"> - <label class="file-label"> - <input class="file-input" type="file" name="players" /> - <span class="file-cta"> - <span class="file-icon"> - <i class="fas fa-upload"></i> - </span> - <span class="file-label"> Choose a file… </span> - </span> - <span class="file-name"> No file uploaded </span> - </label> - <button class="button is-dark is-responsive">UPDATE!</button> - </div> - </form> - </div> - {{ footer() }} - </section> + <h3>Controls</h3> + <section class="section"> + <div class="column"> + <button class="button is-dark is-responsive" + hx-post="/reset_players">RESET!</button> + </div> + <div class="column"> + <form method="POST" enctype="multipart/form-data" hx-post="/update_players"> + <div id="file-js" class="file has-name is-fullwidth"> + <label class="file-label"> + <input class="file-input" type="file" name="players" /> + <span class="file-cta"> + <span class="file-icon"> + <i class="fas fa-upload"></i> + </span> + <span class="file-label"> Choose a file… </span> + </span> + <span class="file-name"> No file uploaded </span> + </label> + <button class="button is-dark is-responsive">UPDATE!</button> + </div> + </form> + </div> + <footer class="container">{{ footer() }}</footer> + </section> + </main> </body> </html>
\ No newline at end of file |
