Fotoliste.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. {#await promise}
  2. {:then fotos}
  3. {#each _.chunk(fotos, 25) as slice}
  4. <div class="page grid" orientation="portrait" size="A4">
  5. <div class="main">
  6. <h5>{slice[0].Klasse}</h5>
  7. Stand: {datum(new Date())}
  8. <div class="grid">
  9. {#each slice as s}
  10. <div>
  11. <img src="data:image/jpg;base64,{s && buffer(s.schuelerfoto.Foto)}" alt="Foto" style="width: 120px">
  12. <br>
  13. {s.Name}, {s.Vorname}
  14. </div>
  15. {/each}
  16. </div>
  17. </div>
  18. </div>
  19. {/each}
  20. {/await}
  21. <script>
  22. import { beforeUpdate } from 'svelte'
  23. import { datum } from './helfer'
  24. export let schueler, knexConfig
  25. const SchuelerFoto = R.models.Schueler
  26. const _ = R.lodash
  27. let promise
  28. SchuelerFoto.knex(R.knex(knexConfig))
  29. const buffer = (d) => Buffer.from(d, 'binary').toString('base64')
  30. // laut @rich_harris sollte *promise* auch ohne `beforeUpdate` aktualisiert werden.
  31. beforeUpdate(() => {
  32. promise = SchuelerFoto.query().whereIn('ID', schueler.map(s => s.ID)).eager('[schuelerfoto]')
  33. })
  34. </script>
  35. <style>
  36. @import 'css/main.css';
  37. .grid {
  38. display: grid;
  39. grid-template-columns: repeat(5, 1fr);
  40. grid-gap: 10px;
  41. }
  42. </style>