Skip to content

Commit

Permalink
Some additional Games page improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gereon77 committed Jan 29, 2024
1 parent ce12d10 commit 0ea9672
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "./base.html" %}
{% load games_table %}
{% load custom_filters %}

{% block title %}
Games -
Expand Down Expand Up @@ -42,10 +43,10 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
</h4>
{% for user in request.online_now %}
{% if user.is_admin %}
<a style="margin-right: 10px; font-size: 1.125rem; color:brown" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
{{ user.username }}
<a style="margin-right: 10px; font-size: 1.125rem; color:brown; white-space: nowrap; display: inline-block;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
<span>{{ user.username }}</span>
{% if user.last_won_tournament %}
<span style="color: goldenrod"
<span style="color: goldenrod; display: inline-block;"
data-toggle="tooltip"
data-html="true"
title="Winner of </br><b>{{ user.last_won_tournament }}</b>"
Expand All @@ -55,10 +56,10 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
{% endif %}
</a>
{% elif user.is_high_member %}
<a style="margin-right: 10px; font-size: 1.125rem; color:darkgoldenrod" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
{{ user.username }}
<a style="margin-right: 10px; font-size: 1.125rem; color:darkgoldenrod; white-space: nowrap; display: inline-block;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
<span>{{ user.username }}</span>
{% if user.last_won_tournament %}
<span style="color: goldenrod"
<span style="color: goldenrod; display: inline-block;"
data-toggle="tooltip"
data-html="true"
title="Winner of </br><b>{{ user.last_won_tournament }}</b>"
Expand All @@ -68,10 +69,10 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
{% endif %}
</a>
{% else %}
<a style="margin-right: 10px; font-size: 1.125rem;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
{{ user.username }}
<a style="margin-right: 10px; font-size: 1.125rem; white-space: nowrap; display: inline-block;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
<span>{{ user.username }}</span>
{% if user.last_won_tournament %}
<span style="color: goldenrod"
<span style="color: goldenrod; display: inline-block;"
data-toggle="tooltip"
data-html="true"
title="Winner of </br><b>{{ user.last_won_tournament }}</b>"
Expand Down Expand Up @@ -119,8 +120,9 @@ <h4 class="card-title">Running Live Games</h4>
<h4 class="card-title">
<div class="row justify-content-between">
<div class="col">
<a href="/my_games">Your Games</a>
<a href="/my_games">Your Games <small>({{ my_games|get_length }})</small></a>
</div>
{% if perms.agotboardgame_main.add_game %}
<div class="col d-flex justify-content-end">
<button class="btn btn-primary"
type="button"
Expand All @@ -130,6 +132,7 @@ <h4 class="card-title">
<i class="fa fa-plus fa-lg" aria-hidden="true"></i>
</button>
</div>
{% endif %}
</div>
</h4>
<div class="row justify-content-center">
Expand Down Expand Up @@ -157,8 +160,9 @@ <h4 class="card-title">
<h4 class="card-title">
<div class="row justify-content-between">
<div class="col">
All Games
All Games <small>({{ all_games|get_length }})</small>
</div>
{% if perms.agotboardgame_main.add_game %}
<div class="col d-flex justify-content-end">
<button class="btn btn-primary"
type="button"
Expand All @@ -168,6 +172,7 @@ <h4 class="card-title">
<i class="fa fa-plus fa-lg" aria-hidden="true"></i>
</button>
</div>
{% endif %}
</div>
</h4>
<div class="row justify-content-center">
Expand All @@ -190,33 +195,11 @@ <h4 class="card-title">
</div>
</div>
</div>
{% if perms.agotboardgame_main.add_game %}
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<div class="row justify-content-center">
<div class="col-lg-8">
<form action="/games/" method="POST">
{% csrf_token %}
<div class="form-group">
<label for="game-name-input">Game name</label>
<input id="game-name-input" name="name" class="form-control" maxlength="200" required />
</div>
<button type="submit" class="btn btn-block btn-primary">
Create game
</button>
</form>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if perms.agotboardgame_main.can_play_as_another_player and inactive_games %}
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<h4 class="card-title">Games without a move for 5 days</h4>
<h4 class="card-title">Games without a move for 5 days <small>({{ inactive_games|get_length }})</small></h4>
<div style="max-height: 300px; overflow-y: auto">
{% games_table inactive_games user perms True %}
</div>
Expand All @@ -228,7 +211,7 @@ <h4 class="card-title">Games without a move for 5 days</h4>
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<h4 class="card-title">Tournament Games without a move for 2 days</h4>
<h4 class="card-title">Tournament Games without a move for 2 days <small>({{ inactive_tournament_games|get_length }})</small></h4>
<div style="max-height: 300px; overflow-y: auto">
{% games_table inactive_tournament_games user perms True %}
</div>
Expand All @@ -244,7 +227,7 @@ <h4 class="card-title">Tournament Games without a move for 2 days</h4>
data-toggle="tooltip"
title="These are games where the last move was more than 2 days ago and the player being waited on has not logged in for 8 days."
>
Games waiting for inactive players
Games waiting for inactive players <small>({{ replacement_needed_games|get_length }})</small>
</h4>
<div style="max-height: 300px; overflow-y: auto">
{% games_table replacement_needed_games user perms True %}
Expand All @@ -258,7 +241,7 @@ <h4 class="card-title">Tournament Games without a move for 2 days</h4>
<div class="card">
<div class="card-body">
<h4 class="card-title">
Inactive Private Games
Inactive Private Games <small>({{ inactive_private_games|get_length }})</small>
</h4>
<div style="max-height: 300px; overflow-y: auto">
{% games_table inactive_private_games user perms %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "./base.html" %}
{% load games_table %}
{% load custom_filters %}

{% block title %}
Your Games -
Expand Down Expand Up @@ -41,10 +42,10 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
</h4>
{% for user in request.online_now %}
{% if user.is_admin %}
<a style="margin-right: 10px; font-size: 1.125rem; color:brown" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
{{ user.username }}
<a style="margin-right: 10px; font-size: 1.125rem; color:brown; white-space: nowrap; display: inline-block;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
<span>{{ user.username }}</span>
{% if user.last_won_tournament %}
<span style="color: goldenrod"
<span style="color: goldenrod; display: inline-block;"
data-toggle="tooltip"
data-html="true"
title="Winner of </br><b>{{ user.last_won_tournament }}</b>"
Expand All @@ -54,10 +55,10 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
{% endif %}
</a>
{% elif user.is_high_member %}
<a style="margin-right: 10px; font-size: 1.125rem; color:darkgoldenrod" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
{{ user.username }}
<a style="margin-right: 10px; font-size: 1.125rem; color:darkgoldenrod; white-space: nowrap; display: inline-block;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
<span>{{ user.username }}</span>
{% if user.last_won_tournament %}
<span style="color: goldenrod"
<span style="color: goldenrod; display: inline-block;"
data-toggle="tooltip"
data-html="true"
title="Winner of </br><b>{{ user.last_won_tournament }}</b>"
Expand All @@ -67,10 +68,10 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
{% endif %}
</a>
{% else %}
<a style="margin-right: 10px; font-size: 1.125rem;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
{{ user.username }}
<a style="margin-right: 10px; font-size: 1.125rem; white-space: nowrap; display: inline-block;" href="/user/{{ user.id }}" target="_blank" rel="noopener noreferrer">
<span>{{ user.username }}</span>
{% if user.last_won_tournament %}
<span style="color: goldenrod"
<span style="color: goldenrod; display: inline-block;"
data-toggle="tooltip"
data-html="true"
title="Winner of </br><b>{{ user.last_won_tournament }}</b>"
Expand All @@ -91,28 +92,29 @@ <h4 class="card-title">Online Users <small class="ml-2">({{ request.online_now |
</div>
</div>
</div>
{% if my_games %}
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<h4 class="card-title">
<div class="row justify-content-between">
<div class="col">
Your Games
Your Games <small>({{ my_games|get_length }})</small>
</div>
{% if perms.agotboardgame_main.add_game %}
<div class="col d-flex justify-content-end">
<button class="btn btn-primary"
type="button"
data-toggle="collapse"
data-target="#collapsed_create_your_game"
data-target="#collapsed_cg_for_your_games"
>
<i class="fa fa-plus fa-lg" aria-hidden="true"></i>
</button>
</div>
{% endif %}
</div>
</h4>
<div class="row justify-content-center">
<div class="col-lg-8 collapse" id="collapsed_create_your_game">
<div class="col-lg-8 collapse" id="collapsed_cg_for_your_games">
<form action="/games/" method="POST">
{% csrf_token %}
<div class="form-group">
Expand All @@ -128,15 +130,6 @@ <h4 class="card-title">
</div>
</div>
</div>
{% else %}
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<p class="mb-0">You currently have no running games!</p>
</div>
</div>
</div>
{% endif %}
{% if open_live_games %}
<div class="col-lg-11 mb-4">
<div class="card">
Expand All @@ -157,39 +150,57 @@ <h4 class="card-title">Running Live Games</h4>
</div>
</div>
{% endif %}
{% if my_created_games %}
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<h4 class="card-title mb-0">
<h4 class="card-title">
<div class="row justify-content-between">
<div class="col">
<a href="/games">All Games</a>
Your Created Games <small>({{ my_created_games|get_length }})</small>
</div>
{% if perms.agotboardgame_main.add_game %}
<div class="col d-flex justify-content-end">
<button class="btn btn-primary"
type="button"
data-toggle="collapse"
data-target="#collapsed_create_game"
data-target="#collapsed_cg_for_created_games"
>
<i class="fa fa-plus fa-lg" aria-hidden="true"></i>
</button>
</div>
{% endif %}
</div>
</h4>
<div class="row justify-content-center">
<div class="col-lg-8 collapse" id="collapsed_create_game">
<div class="col-lg-8 collapse" id="collapsed_cg_for_created_games">
<form action="/games/" method="POST">
{% csrf_token %}
<div class="form-group">
<label for="game-name-input">Game name</label>
<input id="game-name-input" name="name" class="form-control" maxlength="200" required {% if not perms.agotboardgame_main.add_game %}disabled{% endif %} />
<input id="game-name-input" name="name" class="form-control" maxlength="200" required {% if not perms.agotboardgame_main.add_game %}disabled{% endif %}/>
</div>
<button type="submit" class="btn btn-block btn-primary" {% if not perms.agotboardgame_main.add_game %}disabled{% endif %}>
Create game
</button>
</form>
</div>
</div>
{% games_table my_created_games user perms %}
</div>
</div>
</div>
{% endif %}
<div class="col-lg-11 mb-4">
<div class="card">
<div class="card-body">
<h4 class="card-title mb-0">
<div class="row justify-content-between">
<div class="col">
<a href="/games">All Games</a>
</div>
</div>
</h4>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# custom_filters.py
from django import template

register = template.Library()

@register.filter(name='get_length')
def get_length(value):
return len(value)
15 changes: 8 additions & 7 deletions agot-bg-website/agotboardgame_main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,15 @@ def my_games(request):
my_games = games_query.filter((Q(state=IN_LOBBY) | Q(state=ONGOING)) & Q(user_is_in_game=1)).order_by("state", "-last_active_at")
enrich_games(request, my_games, True, False, True)

my_created_games = games_query.filter((Q(state=IN_LOBBY) | Q(state=ONGOING)) & Q(owner=request.user)).order_by("state", "-last_active_at")
enrich_games(request, my_created_games, False, False, False)

last_finished_game = Game.objects.filter(state=FINISHED).annotate(players_count=Count('players')).latest()
public_room_id = Room.objects.get(name='public').id

return render(request, "agotboardgame_main/my_games.html", {
"my_games": my_games,
"my_created_games": my_created_games,
"open_live_games": open_live_games,
"running_live_games": running_live_games,
"last_finished_game": last_finished_game,
Expand Down Expand Up @@ -311,24 +315,21 @@ def games(request):
"last_finished_game": last_finished_game
})
elif request.method == "POST":
if not request.user.has_perm("agotboardgame_main.add_game"):
return HttpResponseRedirect("/")

name = request.POST.get("name", "")

if not request.user.has_perm("agotboardgame_main.add_game") or len(name) > 200:
return HttpResponseRedirect("/games")

game = Game()
game.name = name
game.owner = request.user
game.save()

if len(name) > 200:
return HttpResponseRedirect("/games")

return HttpResponseRedirect(f"/play/{game.id}")

def cancel_game(request, game_id):
if not request.user.has_perm("agotboardgame_main.cancel_game"):
return HttpResponseRedirect("/")
return HttpResponseRedirect("/games")

game = get_object_or_404(Game, id=game_id)

Expand Down

0 comments on commit 0ea9672

Please sign in to comment.