Add door sign generator (resolves #10)

This commit is contained in:
Oskar Winkels 2020-12-05 19:26:02 +01:00
parent fade25b71d
commit 34b1e2ad20
7 changed files with 197 additions and 7 deletions

View File

@ -61,9 +61,14 @@ Edit `config.ini` to your liking. Restart the backend by restarting the `uwsgi`
service, e.g. `sudo systemctl restart ftracker` or `sudo service ftracker
restart`
## Open Sources
This project uses the `QRCode.js` library (Copyright (C) 2012 davidshimjs)
licensed under the MIT License, see `web/qrcodejs/LICENSE`. Thanks!
## License
Licensed under GNU GPL v3, see
FTracker is licensed under the GNU GPL v3 license, see
[LICENSE.md](https://git.fasttube.de/FaSTTUBe/ft-corona-tracker/src/branch/master/LICENSE.md)
for details.

View File

@ -1,3 +1,4 @@
import os
from .core import *
# Start the flask server if run from terminal
@ -7,12 +8,15 @@ if __name__ == "__main__":
def get_root():
return app.send_static_file('index.html')
@app.route('/view')
def get_view():
return app.send_static_file('view.html')
@app.route('/<path:path>')
def get_file(path):
def get_path(path):
fpath = f"{app.static_folder}/{path}"
# Prettier URLs by auto-loading <path>.html
# Our nginx config does this as well
if not os.path.isfile(fpath):
return app.send_static_file(path + '.html')
return app.send_static_file(path)
# Just allow everything to avoid the hassle when running locally.

158
web/QRgen.html Normal file
View File

@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<title>FTracker</title>
<meta name="theme-color" content="#c50e1f">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
background: #ddd;
font-family: sans-serif;
}
h1 {
margin: 0;
padding: 16px;
text-transform: uppercase;
color: #eee;
background: #c50e1f;
text-align: center;
}
form {
padding: 16px;
max-width: 512px;
margin: auto;
}
input {
border: none;
padding: 16px;
margin: 4px 0;
font-size: 16px;
}
input[type=text] {
color: #000;
width: calc(100% - 32px);
}
input[type=submit] {
background: #c50e1f;
text-transform: uppercase;
font-weight: bold;
color: #fff;
width: 100%;
cursor: pointer;
}
.print {
display: none;
text-align: center;
}
.print * {
display: inline-block;
margin: 42px auto;
}
.print .link {
font-size: 24px;
}
@media print {
.print h1 {
margin-top: 64px;
color: #000;
}
}
</style>
</head>
<body>
<main id="formView">
<h1>FTracker<br>Door Sign Genrator</h1>
<form id="roomform">
<label>
Room Nr/Name:<br>
<input type="text" name="room" id="room" placeholder="123" required>
</label>
<input type="submit" value="Print">
</form>
</main>
<main id="printA" class="print">
<h1 class="title"></h1><br>
<div class="qr"></div><br>
<span class="link"></span><br>
<span>
Made with FTracker<br>
https://git.fasttube.de/FaSTTUBe/ftracker<br>
&copy; 2020 Oskar / FaSTTUBe
</span>
</main>
<main id="printD" class="print">
<h1 class="title"></h1><br>
<div class="qr"></div><br>
<span class="link"></span><br>
<span>
Made with FTracker<br>
https://git.fasttube.de/FaSTTUBe/ftracker<br>
&copy; 2020 Oskar / FaSTTUBe
</span>
</main>
<script src="/qrcodejs/qrcode.min.js"></script>
<script>
var fv = document.getElementById('formView')
var pa = document.getElementById('printA')
var pd = document.getElementById('printD')
var rform = document.getElementById('roomform')
rform.onsubmit = function(e) {
e.preventDefault()
var room = e.srcElement[0].value
writePage(pa, room, 'arrival')
writePage(pd, room, 'departure')
printPage(pa, 'ftracker-arrival-'+room)
printPage(pd, 'ftracker-departure-'+room)
}
function writePage(el, room, type) {
var base = location.href.split('/').slice(0,3).join('/')
var url = base + '/?' + type + '=' + room
var title = el.querySelector('.title')
var qr = el.querySelector('.qr')
var link = el.querySelector('.link')
title.innerHTML =
'Scan here to log ' + type + '<br> in room ' + room
link.innerHTML = url
qr.innerHTML = ''
new QRCode(qr, {
text: url,
width: 320,
height: 320
})
}
function printPage(el, name) {
var t = document.title
document.title = name
fv.style.display = 'none'
el.style.display = 'block'
window.print()
el.style.display = 'none'
fv.style.display = 'block'
document.title = t
}
</script>
</body>
</html>

View File

@ -22,6 +22,8 @@
}
form {
padding: 16px;
max-width: 512px;
margin: auto;
}
label {
display: block;
@ -55,6 +57,7 @@
font-weight: bold;
color: #fff;
width: 100%;
cursor: pointer;
}
input[type=checkbox] {
transform: translateY(-3px);
@ -134,10 +137,11 @@
probably contact an admin or a dev nearby :(<br><br>\
Here are a few links for testing:<br>\
<a href="/view">View Data</a>, \
<a href="/QRgen">Door Sign Generator</a>, \
<a href="/?arrival=42">Test Arrival</a>, \
<a href="/?departure=42">Test Departure</a><br><br>\
© 2020 made by <a target="_blank" href="mailto:&#111;&#46;&#119;&#105;&#110;&#107;&#101;&#108;&#115;&#64;&#102;&#97;&#115;&#116;&#116;&#117;&#98;&#101;&#46;&#100;&#101;">Oskar</a> \
for <a target="_blank" href="//fasttube.de">FaSTTUBe</a>. \
for <a target="_blank" href="//fasttube.de">FaSTTUBe</a>.<br> \
For source code & licensing see <a href="//git.fasttube.de/FaSTTUBe/ftracker">git repo</a>'
}

4
web/qrcodejs/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.DS_Store
.idea
.project

14
web/qrcodejs/LICENSE Normal file
View File

@ -0,0 +1,14 @@
The MIT License (MIT)
---------------------
Copyright (c) 2012 davidshimjs
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1
web/qrcodejs/qrcode.min.js vendored Normal file

File diff suppressed because one or more lines are too long