Skip to content

Commit

Permalink
Merge pull request #1830 from gereon77/add-join-as-owner-button
Browse files Browse the repository at this point in the history
Add "Join as owner" button
  • Loading branch information
gereon77 authored Mar 25, 2024
2 parents 8a293e8 + 6f34b8a commit 9819475
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<th style="width: 1px">
Players
</th>
{% if show_join_as and perms.agotboardgame_main.can_play_as_another_player %}
{% if show_join_as_waited and perms.agotboardgame_main.can_play_as_another_player %}
<th style="width: 190px"></th>
{% elif show_join_as_owner and perms.agotboardgame_main.can_play_as_another_player %}
<th style="width: 190px"></th>
{% elif perms.agotboardgame_main.cancel_game %}
<th style="width: 120px"></th>
Expand Down Expand Up @@ -148,7 +150,7 @@
{% endif %}
</a>
{% endif %}
{% if show_join_as and game.inactive_user_id and perms.agotboardgame_main.can_play_as_another_player %}
{% if show_join_as_waited and game.inactive_user_id and perms.agotboardgame_main.can_play_as_another_player %}
<a class="btn btn-primary btn-sm"
href="/play/{{ game.id }}/{{ game.inactive_user_id }}"
target="_blank"
Expand All @@ -159,6 +161,17 @@
Join as ...
</a>
{% endif %}
{% if show_join_as_owner and perms.agotboardgame_main.can_play_as_another_player and game.state == "IN_LOBBY" %}
<a class="btn btn-primary btn-sm"
href="/play/{{ game.id }}/{{ game.owner.id }}"
target="_blank"
data-toggle="tooltip"
data-placement="right"
title="Join as game host"
>
Join as host
</a>
{% endif %}
{% if perms.agotboardgame_main.cancel_game %}
<form action="/game/{{ game.id }}/cancel" method="POST" class="d-inline" onsubmit="return confirm('Do you really want to cancel the game \'{{ game.name }}\'?');">
{% csrf_token %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h4 class="card-title">Online Users<small class="ml-2">({{ request.online_now |
<div class="card">
<div class="card-body">
<h4 class="card-title">Open Live Games</h4>
{% games_table open_live_games user perms %}
{% games_table open_live_games user perms False True %}
</div>
</div>
</div>
Expand Down Expand Up @@ -189,7 +189,7 @@ <h4 class="card-title">
</div>
</div>
<div style="max-height: 400px; overflow-y: auto">
{% games_table all_games user perms %}
{% games_table all_games user perms False True %}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h4 class="card-title">
<div class="card">
<div class="card-body">
<h4 class="card-title">Open Live Games</h4>
{% games_table open_live_games user perms %}
{% games_table open_live_games user perms False True %}
</div>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions agot-bg-website/agotboardgame_main/templatetags/games_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@


@register.inclusion_tag("agotboardgame_main/components/games_table.html")
def games_table(games, user, perms, showJoinAs = False):
return {"games": games, "user": user, "perms": perms, "on_probation": user.is_authenticated and user.is_in_group("On probation"), "show_join_as": showJoinAs}
def games_table(games, user, perms, showJoinAsWaited = False, showJoinAsOwner = False):
return {
"games": games,
"user": user,
"perms": perms,
"on_probation": user.is_authenticated and user.is_in_group("On probation"),
"show_join_as_waited": showJoinAsWaited,
"show_join_as_owner": showJoinAsOwner
}
6 changes: 3 additions & 3 deletions agot-bg-website/agotboardgame_main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +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)
#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,
#"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

0 comments on commit 9819475

Please sign in to comment.