Übersicht.svelte 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <section class="section">
  2. <div class="container">
  3. <h1 class="title">Mein BK</h1>
  4. <div>
  5. <span class="tag is-success" on:click={()=>hole_lokale_schueler()} style="cursor: pointer;">
  6. {schueler_lokal.length} Schüler in der Datenbank
  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} on:click={() => active=Vouchers}>WLAN</li>
  20. <li class:is-active={active === ProjektwocheSchueler} on:click={() => active=ProjektwocheSchueler}>Projektwoche Schüler</li>
  21. <li class:is-active={active === ProjektwocheLehrer} on:click={() => active=ProjektwocheLehrer}>Projektwoche Lehrer</li>
  22. <li class:is-active={active === SVWahl} on:click={() => active=SVWahl}>SV-Wahl</li>
  23. <li class:is-active={active === Einstellungen} on:click={() => active=Einstellungen}>Einstellungen</li>
  24. <li class:is-active={active === Fehler} on:click={() => active=Fehler}>Fehler</li>
  25. </ul>
  26. </div>
  27. <svelte:component this={active} schueler={schueler_filter} {privat} {einstellungen} {knexConfig}/>
  28. </div>
  29. </section>
  30. <style>
  31. @import 'node_modules/bulma/css/bulma.css';
  32. .tabs li.is-active {
  33. border-bottom-color: #3273dc;
  34. color: #3273dc;
  35. }
  36. .tabs li:hover {
  37. border-bottom-color: #3273dc;
  38. }
  39. .tabs li {
  40. align-items: center;
  41. border-bottom-color: #dbdbdb;
  42. border-bottom-style: solid;
  43. border-bottom-width: 1px;
  44. color: #4a4a4a;
  45. display: flex;
  46. justify-content: center;
  47. margin-bottom: -1px;
  48. padding: 0.5em 1em;
  49. vertical-align: top;
  50. cursor: pointer;
  51. text-decoration: none;
  52. }
  53. </style>
  54. <script>
  55. import Vouchers from './components/vouchers.svelte'
  56. import ProjektwocheSchueler from './components/projektwoche-schueler.svelte'
  57. import ProjektwocheLehrer from './components/projektwoche-lehrer.svelte'
  58. import SVWahl from './components/svwahl.svelte'
  59. import Einstellungen from './components/einstellungen.svelte'
  60. import Fehler from './components/fehler.svelte'
  61. export let schueler, knexConfig, privat
  62. let active
  63. let suche = ''
  64. const { Pool } = R('pg')
  65. const mysql = R('mysql')
  66. let schueler_entfernt = [], schueler_lokal = []
  67. let einstellungen
  68. const postgres = new Pool({ connectionString: privat.mein_bk_db})
  69. postgres.query(`SELECT * FROM einstellungen`)
  70. .then(res => {
  71. einstellungen = res.rows[0]
  72. einstellungen || postgres.query(`INSERT INTO einstellungen DEFAULT VALUES RETURNING *`)
  73. .then(res => einstellungen = res.rows[0])
  74. })
  75. postgres.query(`SELECT schueler.*,
  76. wlan.voucher,
  77. wahlen.*
  78. FROM schueler
  79. LEFT JOIN wlan ON schueler.id = wlan.schueler_id
  80. LEFT JOIN wahlen ON schueler.id = wahlen.schueler_id`)
  81. .then(resp => {
  82. schueler_entfernt = resp.rows
  83. })
  84. const mysql_connection = mysql.createConnection(knexConfig.connection)
  85. mysql_connection.connect()
  86. function hole_lokale_schueler () {
  87. mysql_connection.query(`SELECT ID AS id, Name, Vorname, Klasse,
  88. CONCAT (LOWER (Vorname), ' ', LOWER (Name)) AS vollname
  89. FROM schueler
  90. WHERE Status = 2 AND Geloescht = "-" AND Gesperrt = "-"
  91. ORDER BY Klasse, Name ASC`,
  92. (e, res) => {
  93. schueler_lokal = res
  94. })
  95. }
  96. const groupBy = (arr, id) => arr.reduce(
  97. (entryMap, f) => {
  98. const fx = id.split('.').reduce((p,c)=>p&&p[c]||null, f)
  99. return entryMap.set(fx, [...entryMap.get(fx)||[], f])
  100. },
  101. new Map()
  102. )
  103. hole_lokale_schueler()
  104. $: merged = schueler_lokal.map(itm => ({
  105. ...schueler_entfernt.find((item) => (item.id === itm.id) && item),
  106. ...itm}))
  107. $: schueler_filter = Object.fromEntries(groupBy(merged.filter(s => s.vollname.includes(suche.toLowerCase())), 'Klasse'))
  108. </script>