Übersicht.svelte 4.3 KB

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