Allg Fotoliste.svelte 1.3 KB

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