add banner page
This commit is contained in:
parent
c29a3d26a1
commit
645342ba52
2 changed files with 114 additions and 1 deletions
41
src/main.v
41
src/main.v
|
@ -151,7 +151,9 @@ fn get_ppu() !f64 {
|
||||||
mut people := sql db {
|
mut people := sql db {
|
||||||
select from Person where status == 3
|
select from Person where status == 3
|
||||||
}!
|
}!
|
||||||
|
if people.len == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
people.sort(a.order_time < b.order_time)
|
people.sort(a.order_time < b.order_time)
|
||||||
time_range := people.last().order_time - people.first().order_time
|
time_range := people.last().order_time - people.first().order_time
|
||||||
return people.len / time_range.hours()
|
return people.len / time_range.hours()
|
||||||
|
@ -171,6 +173,28 @@ fn get_mean_time_between_pannenkoeken() !time.Duration {
|
||||||
return stats.mean(arrays.window(people, size: 2).map(it[0].delivery_time - it[1].delivery_time))
|
return stats.mean(arrays.window(people, size: 2).map(it[0].delivery_time - it[1].delivery_time))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_last_done_person() ![]Person {
|
||||||
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
|
people := sql db {
|
||||||
|
select from Person where status == 3 order by delivery_time desc limit 1
|
||||||
|
}!
|
||||||
|
return people
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_next_person() ![]Person {
|
||||||
|
mut db := create_db_connection()!
|
||||||
|
defer {
|
||||||
|
db.close() or { panic(err) }
|
||||||
|
}
|
||||||
|
people := sql db {
|
||||||
|
select from Person where status < 3 order by id limit 1
|
||||||
|
}!
|
||||||
|
return people
|
||||||
|
}
|
||||||
|
|
||||||
fn status_update(user_id int) !Person {
|
fn status_update(user_id int) !Person {
|
||||||
mut db := create_db_connection()!
|
mut db := create_db_connection()!
|
||||||
defer {
|
defer {
|
||||||
|
@ -279,6 +303,21 @@ pub fn (mut app App) home() vweb.Result {
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@['/banner'; get]
|
||||||
|
pub fn (mut app App) banner() vweb.Result {
|
||||||
|
last_done := get_last_done_person() or {
|
||||||
|
app.set_status(400, '')
|
||||||
|
return app.text('${err}')
|
||||||
|
}
|
||||||
|
next_person := get_next_person() or {
|
||||||
|
app.set_status(400, '')
|
||||||
|
return app.text('${err}')
|
||||||
|
}
|
||||||
|
now := time.now()
|
||||||
|
|
||||||
|
return $vweb.html()
|
||||||
|
}
|
||||||
|
|
||||||
@['/status_update'; post]
|
@['/status_update'; post]
|
||||||
pub fn (mut app App) status_update() vweb.Result {
|
pub fn (mut app App) status_update() vweb.Result {
|
||||||
if person := status_update(app.form['id'].int()) {
|
if person := status_update(app.form['id'].int()) {
|
||||||
|
|
74
src/templates/banner.html
Normal file
74
src/templates/banner.html
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.5">
|
||||||
|
<title>🥞wachtrij</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/tuicss@@2.1.1/dist/tuicss.min.css" rel="stylesheet" />
|
||||||
|
<style>
|
||||||
|
.tui-window {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.col {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td,
|
||||||
|
th {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tui-table tbody tr td {
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
setInterval(function(){
|
||||||
|
location.reload()
|
||||||
|
}, 1000)
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="tui-bg-green-black">
|
||||||
|
<div style="margin: auto; width: 60%; margin-top: 40px;">
|
||||||
|
<div class="container" style="width: 100%">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col m12">
|
||||||
|
<div class="tui-window red-168">
|
||||||
|
<fieldset class="tui-fieldset">
|
||||||
|
<h1>Previous pancake</h1>
|
||||||
|
@if last_done.len > 0
|
||||||
|
@{now - last_done[0].delivery_time}
|
||||||
|
@else
|
||||||
|
No pancakes done yet
|
||||||
|
@end
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col m12">
|
||||||
|
<div class="tui-window red-168">
|
||||||
|
<fieldset class="tui-fieldset">
|
||||||
|
<h1>NEXT UP</h1>
|
||||||
|
@if next_person.len > 0
|
||||||
|
@{next_person[0].name}
|
||||||
|
@else
|
||||||
|
Nobody in the queue
|
||||||
|
@end
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in a new issue