Übersicht.svelte 4.9 KB

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