Skip to content

Commit 295d56f

Browse files
committed
Improve frontend graphics
1 parent 521f7b4 commit 295d56f

File tree

14 files changed

+145
-47
lines changed

14 files changed

+145
-47
lines changed

.dockerignore

Whitespace-only changes.

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
2727
&& curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
2828
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner
2929

30+
# Set up Cron
31+
RUN apt-get -y install cron
32+
COPY tasks /etc/cron.d/tasks
33+
RUN chmod 0644 /etc/cron.d/tasks && crontab /etc/cron.d/tasks
34+
3035
# Copy the app files
3136
COPY ./api /app
3237
COPY ./frontend /frontend
@@ -49,4 +54,5 @@ RUN rm -rf /usr/local/bin/node \
4954

5055
WORKDIR /app
5156
EXPOSE 8000
52-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
57+
COPY docker-entrypoint.sh /docker-entrypoint.sh
58+
ENTRYPOINT ["/docker-entrypoint.sh"]

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ main:
55

66
run:
77
@cd api && uvicorn main:app --host 0.0.0.0 --port 8000
8+
9+
docker:
10+
@cd api && python3 tasks.py && rm -rf remote/templates && rm -rf build && cd .. && docker build -t codeday-posters .
11+
12+
run-docker:
13+
@docker run -it -p "8000:8000" codeday-posters

api/generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
)
1010

1111
class PosterGenerator:
12-
def __init__(self, data, promo):
12+
def __init__(self, data, promo=None, promoFor=None):
1313
self.supported_formats = ['svg', 'pdf', 'png']
1414
self.promo = promo
15+
self.promoFor = promoFor
1516

1617
self.data = data
1718
for key in data:
@@ -28,7 +29,7 @@ def __init__(self, data, promo):
2829

2930
def get_cache(self, file_format, template_name='', full=True):
3031
basedir = os.path.dirname(os.path.realpath(__file__)) if full else ''
31-
return '{}/generated/{}/{}/{}'.format(basedir, self.current_event['id'], file_format, template_name.replace('svg', file_format))
32+
return '{}/generated/{}/{}/{}_{}_{}'.format(basedir, self.current_event['id'], file_format, self.promo, self.promoFor, template_name.replace('svg', file_format))
3233

3334
def make_poster(self, template_name, file_format):
3435
file_format = file_format.lower()

api/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
from jinja2 import Environment, FileSystemLoader, select_autoescape
55

66
from starlette.middleware.cors import CORSMiddleware
7-
from starlette.responses import HTMLResponse, FileResponse
7+
from starlette.responses import HTMLResponse, FileResponse, JSONResponse
88
from starlette.staticfiles import StaticFiles
99

1010
from generator import PosterGenerator
11-
from cron import sync_templates, cleanup
11+
from tasks import sync_templates, cleanup
1212

1313
sync_templates()
1414
cleanup()
1515

1616
env = Environment(
17-
loader= FileSystemLoader('./posterTemplates'),
17+
loader= FileSystemLoader('./remote/templates/template'),
1818
autoescape=select_autoescape(['svg'])
1919
)
2020

@@ -39,21 +39,21 @@ def file_get_contents(filename):
3939
def root():
4040
return HTMLResponse(file_get_contents("./build/index.html"))
4141

42-
@app.get('/cron')
43-
def cron():
42+
@app.get('/sync')
43+
def sync():
4444
sync_templates()
4545
cleanup()
4646
return HTMLResponse('ok')
4747

4848
@app.get("/render/{id}/{template}/{file_format}")
49-
def generate(id, template, file_format='svg', promo=None):
49+
def generate(id, template, file_format='svg', promo=None, promoFor=None):
5050
eventRequest = requests.get('https://clear.codeday.org/api/region/{}'.format(id))
5151
try:
5252
eventJson = json.loads(eventRequest.text)
5353
except:
5454
return "No event found with id {}".format(id),404
5555

56-
return PosterGenerator(eventJson, promo).make_poster('{}.svg'.format(template),file_format)
56+
return PosterGenerator(eventJson, promo, promoFor).make_poster('{}.svg'.format(template),file_format)
5757

5858
@app.get('/render_all/{id}')
5959
def generate_all(id, promo=None):
@@ -66,6 +66,6 @@ def generate_all(id, promo=None):
6666

6767
return FileResponse(shutil.make_archive('zip/{}'.format(id), 'zip', 'generated/{}'.format(eventJson.current_event['id'])), filename='{}.zip'.format(id))
6868

69-
@app.get('/api/listTemplates/', response_class=HTMLResponse)
69+
@app.get('/api/list-templates', response_class=HTMLResponse)
7070
def listTemplates():
71-
return json.dumps([t.replace('.svg', '') for t in env.list_templates()])
71+
return JSONResponse([t.replace('.svg', '') for t in env.list_templates()])

api/cron.py renamed to api/tasks.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ def sync_templates():
2222

2323
def cleanup():
2424
for dir in ('generated', 'zip'):
25-
for subdir in os.listdir(dir):
26-
path = os.path.realpath(os.path.join(dir, subdir))
27-
if (os.path.basename(path) != '.gitkeep'):
28-
if (os.path.isdir(path)):
29-
shutil.rmtree(path)
30-
else:
31-
os.remove(path)
25+
if (os.path.exists(dir)):
26+
for subdir in os.listdir(dir):
27+
path = os.path.realpath(os.path.join(dir, subdir))
28+
if (os.path.basename(path) != '.gitkeep'):
29+
if (os.path.isdir(path)):
30+
shutil.rmtree(path)
31+
else:
32+
os.remove(path)
33+
34+
if __name__ == "__main__":
35+
print("Running tasks...")
36+
sync_templates()
37+
cleanup()

docker-entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
cron -f &
3+
uvicorn main:app --host 0.0.0.0 --port 8000

frontend/package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/eventDropdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const EventDropdown = props => {
1616
return <Loading />;
1717
} else {
1818
return (
19-
<div style={{zIndex: 100}}>
19+
<div style={{zIndex: 1000, position: 'relative'}}>
2020
<Select
2121
value={inputValue}
2222
options={props.regions.map(item => ({value: item.webname, label: item.name}))}

frontend/src/index.css

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,22 @@ img {
3434
-ms-transform: scale(1.15); /* IE 9 */
3535
-webkit-transform: scale(1.15); /* Safari and Chrome */
3636
position: relative;
37-
z-index: 9999;
37+
z-index: 600;
38+
}
39+
40+
.downloadLink {
41+
width: 50%;
42+
display: inline-block;
43+
text-align: center;
44+
background-color: #eee;
45+
border-right: 1px solid #fff;
46+
position: relative;
47+
top: -0.3em;
48+
padding: 0.2em;
49+
color: #000;
50+
text-decoration: none;
51+
box-sizing: border-box;
52+
text-transform: uppercase;
3853
}
3954

4055
.posterGallery {
@@ -43,4 +58,27 @@ img {
4358
display: flex;
4459
flex-wrap: wrap;
4560
justify-content: center;
61+
position: absolute;
62+
}
63+
64+
.promoInfo {
65+
border-color: #ccc;
66+
border-radius: 4px;
67+
border-style: solid;
68+
border-width: 1px;
69+
min-height: 38px;
70+
outline: currentcolor none 0px !important;
71+
position: relative;
72+
transition: all 100ms ease 0s;
73+
box-sizing: border-box;
74+
padding: 8px;
75+
color: #808080;
76+
}
77+
78+
.promoInfo input {
79+
border: none;
80+
border-bottom: 1px solid #000;
81+
color: #000;
82+
padding-left: 0.5em;
83+
padding-right: 0.5em;
4684
}

0 commit comments

Comments
 (0)