diff --git a/app/routers/games.py b/app/routers/games.py index 240efce..57595e6 100644 --- a/app/routers/games.py +++ b/app/routers/games.py @@ -68,7 +68,7 @@ def list_games( skip: int = 0, limit: int = 100, sort_by="id", sort_order="asc", db=Depends(get_db) ): match sort_by: - case "id": + case "id" | "date": return crud.get_games( db, skip=skip, limit=limit, sort_by=sort_by, sort_order=sort_order ) diff --git a/app/static/css/base.css b/app/static/css/base.css index bddcacb..550c147 100644 --- a/app/static/css/base.css +++ b/app/static/css/base.css @@ -62,9 +62,32 @@ a#create_game_link { margin-top: 5px; padding: 2px 10px; border-radius: 10px; - } +/* + * Tables + */ +th { + background-color: #0080ff; +} + +th.active { + background-color: #0007ee; + color: grey; +} + +th.asc::after { + content: "^" +} + +th.desc::after { + content: "V" +} + +/* + * Footer + */ + footer { position: fixed; left: 0; diff --git a/app/static/js/game_list.js b/app/static/js/game_list.js new file mode 100644 index 0000000..9a3c779 --- /dev/null +++ b/app/static/js/game_list.js @@ -0,0 +1,37 @@ +$(document).ready(function() { + // Set header-active indication depending on variables + const search_params = new Proxy(new URLSearchParams(window.location.search), { + get: (searchParams, prop) => searchParams.get(prop), + }); + sort_by = search_params['sort_by'] + if (sort_by != undefined) { + header_object = $('th#' + sort_by + '_header') + header_object.addClass('active') + if (search_params['sort_order'] == 'desc') { + header_object.addClass('desc') + } else { + header_object.addClass('asc') + } + } + + $('th').click(function() { + sort_order = 'asc' + sort_by = $(this).attr('id').replace('_header', '') + if (sort_by == 'decks') { + alert('Sorting by the set-of-decks is not currently supported (how would that even work?)'); + return; + } + if ($(this).hasClass('active')) { + // Header has already been clicked at some point - so reverse the sorting + if ($(this).hasClass('asc')) { + sort_order = 'desc' + } + } + const url = new URL(window.location.href) + url.searchParams.set('skip', 0) + url.searchParams.set('sort_by', sort_by) + url.searchParams.set('sort_order', sort_order) + window.location.href = url.href + }) + +}) \ No newline at end of file diff --git a/app/templates/games/list.html b/app/templates/games/list.html index ea02a7d..daa3a95 100644 --- a/app/templates/games/list.html +++ b/app/templates/games/list.html @@ -4,15 +4,16 @@ {% block head %} {{ super() }} + {% endblock %} {% block content %}

Games

- - - + + + {% for game in games %}
DateDecksWinning DeckDateDecksWinning Deck