Add base template and unuasble style

This commit is contained in:
Michał Gdula 2023-05-05 02:11:10 +03:00
parent 8bf194f936
commit 0af071992b
10 changed files with 94 additions and 53 deletions

View file

@ -10,7 +10,7 @@ COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
RUN mkdir /storage RUN mkdir /storage
COPY ./highscore . COPY ./server .
RUN chmod +x ./run.sh RUN chmod +x ./run.sh
CMD ["./run.sh"] CMD ["./run.sh"]

View file

@ -10,10 +10,9 @@ BEARER_TOKEN = env('BEARER_TOKEN')
user = env('DB_USER') user = env('DB_USER')
password = env('DB_PASSWORD') password = env('DB_PASSWORD')
host = env('DB_HOST') host = env('DB_HOST')
port = env('DB_PORT')
database = env('DB_NAME') database = env('DB_NAME')
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}" SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{user}:{password}@{host}:5432/{database}"
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_POOL_RECYCLE = 621 SQLALCHEMY_POOL_RECYCLE = 621

View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# Wait for database to start # Wait for database to start
until pg_isready -d $DB_NAME -h $DB_HOST -p $DB_PORT -U $DB_USER until pg_isready -d $DB_NAME -h $DB_HOST -U $DB_USER
do do
echo "Waiting for database to start... (5s)" echo "Waiting for database to start... (5s)"
sleep 5 sleep 5
@ -10,14 +10,14 @@ done
echo "Database is ready!" echo "Database is ready!"
# Check if migrastions folder exists # Check if migrastions folder exists
if [ ! -d "migrations" ] if [ ! -d "/data/storage/migrations" ];
then then
echo "Creating tables..." echo "Creating tables..."
flask --app server db init flask --app server db init
fi fi
# Check if there are any changes to the database # Check if there are any changes to the database
if -n flask --app server db check if $(flask --app server db check);
then then
echo "Database changes detected! Migrating..." echo "Database changes detected! Migrating..."
flask --app server db migrate flask --app server db migrate

View file

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Front Rooms Highscores</title>
<style>
@import url('https://fonts.cdnfonts.com/css/cmu-serif');
* {
font-family: 'CMU Serif', serif;
}
body, html {
margin: 0;
padding: 0;
min-height: 100vh;
display: flex;
background-color: #000;
color: #fff;
}
.app {
margin: auto;
padding: 1rem;
text-align: center;
min-width: 621px;
border: 3px solid yellow;
}
</style>
</head>
<body>
<div class="app">
<h1>Front Rooms Highscores</h1>
<p>Created by Bradley, Mia, Bartek & Michał</p>
<nav>
<ul>
<li><a href="Easy">Easy</a></li>
<li><a href="Normal">Normal</a></li>
<li><a href="Hard">Hard</a></li>
</ul>
</nav>
{% block content %}{% endblock %}
</div>
</body>
</html>

View file

@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block content %}
{% if show_sub %}
<nav>
<ul>
<li><a href="Level1">Level 1</a></li>
<li><a href="Level2">Level 2</a></li>
<li><a href="Level3">Level 3</a></li>
</ul>
</nav>
{% endif %}
<table>
<tr>
<th>Score</th>
<th>Difficulty</th>
<th>Achievements</th>
<th>Player</th>
</tr>
{% for score in top_scores %}
<tr>
<td>{{ score.score }}</td>
<td>{{ score.difficulty }}</td>
<td>{{ score.achievements }}</td>
<td>{{ score.user.steam_name }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View file

@ -1,4 +1,4 @@
from flask import Blueprint, jsonify, render_template_string, request, abort from flask import Blueprint, jsonify, request, render_template
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField from wtforms import StringField, IntegerField
from wtforms.validators import DataRequired from wtforms.validators import DataRequired
@ -23,40 +23,7 @@ class ScoreForm(FlaskForm):
@cache.cached(timeout=60) @cache.cached(timeout=60)
def index(): def index():
top_scores = Scores.query.order_by(Scores.score.desc()).limit(10).all() top_scores = Scores.query.order_by(Scores.score.desc()).limit(10).all()
users = Users.query.all() return render_template('scores.html', top_scores=top_scores, show_sub=True)
return render_template_string('''
<h1>Top Scores</h1>
<table>
<tr>
<th>Score</th>
<th>Difficulty</th>
<th>Achievements</th>
<th>Player</th>
</tr>
{% for score in top_scores %}
<tr>
<td>{{ score.score }}</td>
<td>{{ score.difficulty }}</td>
<td>{{ score.achievements }}</td>
<td>{{ score.user.steam_name }}</td>
</tr>
{% endfor %}
</table>
<h1>Players</h1>
<table>
<tr>
<th>Steam ID</th>
<th>Steam Name</th>
</tr>
{% for user in users %}
<tr>
<td>{{ user.steam_uuid }}</td>
<td>{{ user.steam_name }}</td>
</tr>
{% endfor %}
</table>
''', top_scores=top_scores, users=users)
@blueprint.route('/post', methods=['POST']) @blueprint.route('/post', methods=['POST'])

View file

@ -3,7 +3,7 @@ version: "3.9"
services: services:
caddy: caddy:
image: caddy:alpine image: caddy:alpine
restart: always restart: unless-stopped
ports: ports:
- 80:80 - 80:80
- 443:443 - 443:443
@ -18,33 +18,26 @@ services:
db: db:
image: postgres:alpine image: postgres:alpine
restart: always restart: unless-stopped
ports:
- 5432:5432
volumes: volumes:
- ./Postgres/data:/var/lib/postgresql/data - ./Postgres/data:/var/lib/postgresql/data
environment: environment:
POSTGRES_USER: root POSTGRES_USER: pguser
POSTGRES_PASSWORD: secret POSTGRES_PASSWORD: secret
POSTGRES_DB: database POSTGRES_DB: database
POSTGRES_PORT: 5432
links: links:
- highscore - highscore
highscore: highscore:
build: ./Highscore-Server build: ./Highscore-Server
restart: always restart: unless-stopped
volumes: volumes:
- ./Highscore-Server/data:/data/storage - ./Highscore-Server/data:/data/storage
- ./Highscore-Server/logs:/data/logs - ./Highscore-Server/logs:/data/logs
# Pass in the code to the container so I don't
# have to rebuild it every time during development
- ./Highscore-Server/highscore:/data/highscore
environment: environment:
FLASK_KEY: secret FLASK_KEY: secret
BEARER_TOKEN: 1234 BEARER_TOKEN: 1234
DB_USER: root DB_USER: pguser
DB_PASSWORD: secret DB_PASSWORD: secret
DB_HOST: db DB_HOST: db
DB_PORT: 5432
DB_NAME: database DB_NAME: database