ui tweaks, admin form
This commit is contained in:
+8
-1
@@ -1,5 +1,5 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import SubmitField, IntegerField, RadioField
|
||||
from wtforms import SubmitField, IntegerField, RadioField, StringField
|
||||
from wtforms.validators import DataRequired, NumberRange
|
||||
|
||||
class GuessForm(FlaskForm):
|
||||
@@ -13,3 +13,10 @@ class GuessForm(FlaskForm):
|
||||
class PlayForm(FlaskForm):
|
||||
card = RadioField('Vyber kartu', validators=[DataRequired(message='Musíš vybrať kartu')])
|
||||
submit = SubmitField('Zahraj')
|
||||
|
||||
class AdminForm(FlaskForm):
|
||||
player0 = StringField('0', validators=[DataRequired()])
|
||||
player1 = StringField('1', validators=[DataRequired()])
|
||||
player2 = StringField('2', validators=[DataRequired()])
|
||||
player3 = StringField('3', validators=[DataRequired()])
|
||||
submit = SubmitField()
|
||||
|
||||
+33
-10
@@ -2,14 +2,16 @@ from api import app
|
||||
from bridzik import Bridzik, Card, Card_colors, Card_values, BridzikException
|
||||
import json
|
||||
from flask import render_template, url_for, flash, redirect
|
||||
from api.forms import GuessForm, PlayForm
|
||||
from api.forms import GuessForm, PlayForm, AdminForm
|
||||
|
||||
b = Bridzik()
|
||||
b.add_player_guess(0, 1)
|
||||
b.add_player_guess(1, 1)
|
||||
b.add_player_guess(2, 1)
|
||||
b.add_player_guess(3, 2)
|
||||
# b.play_card(3, b.get_status(3)['player_cards'][0])
|
||||
|
||||
players = [
|
||||
'Jakub',
|
||||
'Timo',
|
||||
'Katka',
|
||||
'Ondrej'
|
||||
]
|
||||
|
||||
@app.route('/bridzik_api/get_status/<id>')
|
||||
def get_status(id: int):
|
||||
@@ -19,16 +21,20 @@ def get_status(id: int):
|
||||
def status(player):
|
||||
player = int(player)
|
||||
game_status = b.get_status(player)
|
||||
action = None
|
||||
form = None
|
||||
player_cards = Card.sort_card_list(b.series[-1].get_last_round().player_cards[player])
|
||||
game_status['player_cards'] = [str(c) for c in player_cards]
|
||||
if b.is_completed() or b.series[-1].get_last_round().get_active_player() != player:
|
||||
return render_template('status.html', status=game_status)
|
||||
pass
|
||||
elif not b.series[-1].get_last_round().is_guessing_completed():
|
||||
form = GuessForm(max_guess= 8 - b.series[-1].get_last_round().round_number)
|
||||
return render_template('status.html', status=game_status, player=player, action='guess', form=form)
|
||||
action = 'guess'
|
||||
else:
|
||||
player_cards = b.series[-1].get_last_round().player_cards[player]
|
||||
form = PlayForm()
|
||||
form.card.choices = [(str(c), str(c)) for c in player_cards]
|
||||
return render_template('status.html', status=game_status, player=player, action='play', form=form)
|
||||
action = 'play'
|
||||
return render_template('status.html', status=game_status, player=player, action=action, form=form, players=players)
|
||||
|
||||
@app.route('/bridzik/<player>/guess', methods=['POST'])
|
||||
def guess(player):
|
||||
@@ -57,3 +63,20 @@ def play_card(player):
|
||||
except BridzikException:
|
||||
flash('Nie je možné zahrať kartu.')
|
||||
return redirect(url_for('status', player=player))
|
||||
|
||||
|
||||
@app.route('/bridzik/admin', methods=['GET', 'POST'])
|
||||
def admin():
|
||||
form = AdminForm()
|
||||
if form.validate_on_submit():
|
||||
players[0] = form.player0.data
|
||||
players[1] = form.player1.data
|
||||
players[2] = form.player2.data
|
||||
players[3] = form.player3.data
|
||||
return redirect(url_for('admin'))
|
||||
else:
|
||||
form.player0.data = players[0]
|
||||
form.player1.data = players[1]
|
||||
form.player2.data = players[2]
|
||||
form.player3.data = players[3]
|
||||
return render_template('admin.html', form=form)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#header {
|
||||
display: flex;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
#header>div {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
border: 2px solid grey;
|
||||
}
|
||||
|
||||
.state_row_header {
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.points {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 250px;
|
||||
grid-template-rows: 1fr;
|
||||
grid-gap: 10px;
|
||||
}
|
||||
|
||||
.card_display {
|
||||
width: 82px;
|
||||
height: 150px;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Bridžik admin</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="" method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
<p>
|
||||
{{ form.player0.label }}:
|
||||
{{ form.player0(size=15) }}
|
||||
{% for error in form.player0.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
{{ form.player1.label }}:
|
||||
{{ form.player1(size=15) }}
|
||||
{% for error in form.player1.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
{{ form.player2.label }}:
|
||||
{{ form.player2(size=15) }}
|
||||
{% for error in form.player2.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
{{ form.player3.label }}:
|
||||
{{ form.player3(size=15) }}
|
||||
{% for error in form.player3.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>{{ form.submit() }}</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
+115
-113
@@ -1,8 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Bridžik</title>
|
||||
<link href="/static/style.css" rel="stylesheet">
|
||||
{% if not action%}
|
||||
<meta http-equiv="refresh" content="1">
|
||||
<meta http-equiv="refresh" content="2">
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
@@ -19,132 +20,133 @@
|
||||
{% if 'active_player' not in status %}
|
||||
<h1>Hra sa skončila.</h1>
|
||||
{% else %}
|
||||
<table style="width: auto;">
|
||||
<td>
|
||||
<h1>Na ťahu je: {{ status['active_player'] }}</h1>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<h1>Tipy:</h1>
|
||||
<div id="header">
|
||||
<div>
|
||||
<p id="active_player">Na ťahu je: {{ players[status['active_player']] }}</p>
|
||||
</div>
|
||||
|
||||
<div id="active_round_guesses">
|
||||
<p></p>
|
||||
<table style="width: auto;">
|
||||
<th>0</th>
|
||||
<th>1</th>
|
||||
<th>2</th>
|
||||
<th>3</th>
|
||||
<tr>
|
||||
{% for player in status['active_round_guesses'] %}
|
||||
<td>{{ status['active_round_guesses'][player] }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
||||
{% if status['active_round_stashes'] %}
|
||||
<td>
|
||||
<h1>Kôpky v tomto kole:</h1>
|
||||
<table style="width: auto;">
|
||||
<th>0</th>
|
||||
<th>1</th>
|
||||
<th>2</th>
|
||||
<th>3</th>
|
||||
<thead>
|
||||
<th></th>
|
||||
<th class="state_column_header">{{ players[0] }}</th>
|
||||
<th class="state_column_header">{{ players[1] }}</th>
|
||||
<th class="state_column_header">{{ players[2] }}</th>
|
||||
<th class="state_column_header">{{ players[3] }}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
{% for player in status['active_round_stashes'] %}
|
||||
<td>{{ player }}</td>
|
||||
<th class="state_row_header">Tipy v tomto kole:</th>
|
||||
{% for player in status['active_round_guesses'] %}
|
||||
<td class="points">{{ status['active_round_guesses'][player] }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
{% if action == 'guess' %}
|
||||
<hr>
|
||||
<h1>Zadaj tip:</h1>
|
||||
{% include "_guess_form.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% if status['active_stash'] %}
|
||||
<hr>
|
||||
<h1>Aktuálna kôpka:</h1>
|
||||
<table style="width: auto;">
|
||||
{% for player in range(status['active_stash']['first_player'], status['active_stash']['first_player'] + 4) %}
|
||||
<th>{{ player % 4 }}</th>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
{% for player in range(status['active_stash']['first_player'], status['active_stash']['first_player'] + 4) %}
|
||||
{% if status['active_stash']['cards'][player % 4] %}
|
||||
<td>
|
||||
<img src="/static/cards/{{ status['active_stash']['cards'][player % 4] }}.png" width="80" height="auto">
|
||||
</td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% if status['active_round_stashes'] %}
|
||||
<tr>
|
||||
<th class="state_row_header">Kôpky v tomto kole:</th>
|
||||
{% for player in status['active_round_stashes'] %}
|
||||
<td class="points">{{ player }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
{% if action != 'play' %}
|
||||
<h1>Moje karty:</h1>
|
||||
<table id="player_hand">
|
||||
{% for card in status['player_cards'] %}
|
||||
<td>
|
||||
<img src="/static/cards/{{ card }}.png" width="80" height="auto">
|
||||
</td>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% else %}
|
||||
<h1>{{ form.card.label }}:</h1>
|
||||
<form action="{{ url_for('play_card', player=player) }}" method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
<p>
|
||||
<table style="width: auto">
|
||||
<div id="wrapper">
|
||||
<div id="table">
|
||||
{% if action == 'guess' %}
|
||||
<h1>Zadaj tip:</h1>
|
||||
{% include "_guess_form.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% if status['active_stash'] %}
|
||||
<h1>Aktuálna kôpka:</h1>
|
||||
<table style="width: auto;">
|
||||
{% for player in range(status['active_stash']['first_player'], status['active_stash']['first_player'] + 4) %}
|
||||
<th>{{ players[player % 4] }}</th>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
{% for player in range(status['active_stash']['first_player'], status['active_stash']['first_player'] + 4) %}
|
||||
<td class="card_display">
|
||||
{% if status['active_stash']['cards'][player % 4] %}
|
||||
<img src="/static/cards/{{ status['active_stash']['cards'][player % 4] }}.png" width="80" height="auto">
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<hr>
|
||||
{% if action != 'play' %}
|
||||
<h1>Moje karty:</h1>
|
||||
<table id="player_hand">
|
||||
{% for card in status['player_cards'] %}
|
||||
<td>
|
||||
<img src="/static/cards/{{ card }}.png" width="80" height="auto">
|
||||
</td>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
{% for card in status['player_cards'] %}
|
||||
<td>
|
||||
<input id="card-{{ loop.index }}" name="card" type="radio" value="{{ card }}">
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
{% for error in form.card.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
{{ form.submit() }}
|
||||
</p>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<hr>
|
||||
<h1>Výsledky</h1>
|
||||
<table style="width: auto;">
|
||||
{% for series in status['standings'] %}
|
||||
<tr>
|
||||
<th>0</th>
|
||||
<th>1</th>
|
||||
<th>2</th>
|
||||
<th>3</th>
|
||||
</tr>
|
||||
{% if series %}
|
||||
{% for round in series %}
|
||||
{% if round %}
|
||||
<tr>
|
||||
{% for player in round %}
|
||||
<td>{{ player }}</td>
|
||||
|
||||
{% else %}
|
||||
<h1>{{ form.card.label }}:</h1>
|
||||
<form action="{{ url_for('play_card', player=player) }}" method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
<p>
|
||||
<table style="width: auto">
|
||||
{% for card in status['player_cards'] %}
|
||||
<td>
|
||||
<img src="/static/cards/{{ card }}.png" width="80" height="auto">
|
||||
</td>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
{% for card in status['player_cards'] %}
|
||||
<td>
|
||||
<input id="card-{{ loop.index }}" name="card" type="radio" value="{{ card }}">
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
{% for error in form.card.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{{ form.submit() }}
|
||||
</p>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="standings">
|
||||
<h1>Výsledky</h1>
|
||||
<table style="width: auto;">
|
||||
{% for series in status['standings'] %}
|
||||
<tr>
|
||||
<th>{{ players[0] }}</th>
|
||||
<th>{{ players[1] }}</th>
|
||||
<th>{{ players[2] }}</th>
|
||||
<th>{{ players[3] }}</th>
|
||||
</tr>
|
||||
{% if series %}
|
||||
{% for round in series %}
|
||||
{% if round %}
|
||||
<tr>
|
||||
{% for player in round %}
|
||||
<td class="points">{{ player }}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user