Übersicht.svelte 3.9 KB

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