Übersicht.svelte 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <section class="section">
  2. <div class="container">
  3. <h1 class="title">Mein BK</h1>
  4. <div>
  5. <span class="tag is-success" class:is-danger={!diff(schueler_lokal, schueler_entfernt)} style="cursor: pointer;">
  6. {diff(schueler_lokal, schueler_entfernt) ? `${schueler_lokal.length} Schüler in der Datenbank` : 'Schülerdaten müssen aktualisiert werden'}
  7. </span>
  8. </div>
  9. <br>
  10. <div class="field">
  11. <div class="control">
  12. <input class="input" type="text" placeholder="Filter" bind:value={suche}>
  13. </div>
  14. </div>
  15. </div>
  16. <div class="container">
  17. <div class="tabs">
  18. <ul>
  19. <li class:is-active={active === Vouchers}><a on:click={() => active=Vouchers}>WLAN</a></li>
  20. <li class:is-active={active === ProjektwocheSchueler}><a on:click={() => active=ProjektwocheSchueler}>Projektwoche Schüler</a></li>
  21. <li class:is-active={active === ProjektwocheLehrer}><a on:click={() => active=ProjektwocheLehrer}>Projektwoche Lehrer</a></li>
  22. <li class:is-active={active === ProjektwocheUebersicht}><a on:click={() => active=ProjektwocheUebersicht}>Projektwoche Übersicht</a></li>
  23. <li class:is-active={active === SVWahl}><a on:click={() => active=SVWahl}>SV-Wahl</a></li>
  24. </ul>
  25. </div>
  26. <svelte:component this={active} schueler={schueler_filter} {privat} {einstellungen}/>
  27. </div>
  28. </section>
  29. <style>
  30. @import 'node_modules/bulma/css/bulma.css';
  31. </style>
  32. <script>
  33. import Vouchers from './components/vouchers.svelte'
  34. import ProjektwocheSchueler from './components/projektwoche-schueler.svelte'
  35. import ProjektwocheLehrer from './components/projektwoche-lehrer.svelte'
  36. import ProjektwocheUebersicht from './components/projektwoche-uebersicht.svelte'
  37. import SVWahl from './components/svwahl.svelte'
  38. export let schueler, knexConfig, privat
  39. let active
  40. let suche = ''
  41. const { Pool } = R('pg')
  42. const _ = R('lodash')
  43. const mysql = R('mysql')
  44. let schueler_entfernt = [], schueler_lokal = []
  45. let einstellungen
  46. const pool = new Pool({ connectionString: privat.mein_bk_db})
  47. pool.query(`SELECT * FROM einstellungen`).then(res => einstellungen = res.rows[0])
  48. if (!einstellungen) pool.query(`INSERT INTO einstellungen DEFAULT VALUES RETURNING *`).then(res => einstellungen = res.rows[0])
  49. pool.query(`SELECT schueler.*,
  50. wlan.voucher,
  51. wahlen.*
  52. FROM schueler
  53. LEFT JOIN wlan ON schueler.id = wlan.schueler_id
  54. LEFT JOIN wahlen ON schueler.id = wahlen.schueler_id`)
  55. .then(resp => {
  56. schueler_entfernt = resp.rows
  57. })
  58. const connection = mysql.createConnection(knexConfig.connection)
  59. connection.connect()
  60. connection.query(`SELECT ID AS id, Name, Vorname, Klasse
  61. FROM schueler
  62. WHERE Status = 2 AND Geloescht = "-" AND Gesperrt = "-"
  63. ORDER BY Klasse, Name ASC`,
  64. (e, res) => {
  65. schueler_lokal = res
  66. })
  67. connection.end()
  68. function diff (eins, zwei) {
  69. let a = new Set(eins);
  70. let b = new Set(zwei);
  71. return new Set(
  72. [...a].filter(x => !b.has(x)));
  73. }
  74. $: merged = schueler_lokal.map(itm => ({
  75. ...schueler_entfernt.find((item) => (item.id === itm.id) && item),
  76. ...itm}))
  77. $: schueler_filter = _.groupBy(merged.filter(s => s.Vorname.startsWith(suche) || s.Name.startsWith(suche)), 'Klasse')
  78. function update_db () {}
  79. </script>