-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAllg Fotoliste.svelte
47 lines (45 loc) · 1.25 KB
/
Allg Fotoliste.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{#each chunk(schueler, 25) as slice}
<div class="page grid" orientation="portrait" size="A4">
<div class="main">
<b>{slice[0].Klasse}</b>
Stand: {datum(new Date())}
<div class="grid" style="font-size: 0.8rem">
{#each slice as s}
<div>
{#await foto(s) then f}
<img src="data:image/jpg;base64,{f}" alt="Foto" style="width: 120px">
{:catch}
Kein Foto
{/await}
<br>
{s.Name}, {s.Vorname}
</div>
{/each}
</div>
</div>
</div>
{/each}
<script>
import { datum, chunk } from './helfer'
export let schueler, knexConfig
const mysql = R('mysql')
var connection = mysql.createConnection(knexConfig.connection)
connection.connect()
async function foto (s) {
return new Promise((resolve, reject) => {
connection.query('SELECT Foto FROM `schuelerfotos` WHERE `Schueler_ID` = ?', [s.ID],
(err, rows) => {
if (err || rows.length===0) return reject(err);
resolve(Buffer.from(rows[0].Foto, 'binary').toString('base64'));
});
});
}
</script>
<style>
@import 'css/main.css';
.grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-gap: 10px;
}
</style>