12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- {#await gruppe}Warte auf Daten…
- {:then schueler_lokal}
- <section class="section">
- <div class="container">
- <h1 class="title">Mein BK</h1>
- <span class="tag is-success" class:is-danger={!diff(schueler_lokal, schueler_entfernt)} on:click={update_db}>
- {diff(schueler_lokal, schueler_entfernt) ? `${schueler_lokal.length} Schüler in der Datenbank` : 'Schülerdaten müssen aktualisiert werden'}
- </span><button on:click={query}>Neu laden</button>
- </div>
- <div class="container">
- <div class="tabs">
- <ul>
- <li class:is-active={active === Vouchers}><a on:click={() => active=Vouchers}>WLAN</a></li>
- <li class:is-active={active === Projektwoche}><a on:click={() => active=Projektwoche}>Projektwoche</a></li>
- <li class:is-active={active === Svwahl}><a on:click={() => active=Svwahl}>SV-Wahl</a></li>
- </ul>
- </div>
- <svelte:component this={active} schueler={_.groupBy(mergeById(schueler_lokal, schueler_entfernt), 'Klasse')} {privat}/>
- </div>
- </section>
- {:catch error}Fehler
- {/await}
- <style>
- @import 'node_modules/bulma/css/bulma.css';
- </style>
- <script>
- import Hashids from 'hashids'
- import Vouchers from './components/vouchers.svelte'
- import Projektwoche from './components/projektwoche.svelte'
- import Svwahl from './components/svwahl.svelte'
- export let schueler, knexConfig, privat
- let active = Vouchers
- const { Pool } = R('pg')
- const _ = R('lodash')
- const Schueler = R('schild').Schueler
- Schueler.knex(R('knex')(knexConfig))
- const hashids = new Hashids(privat.salt, 5, 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789')
- const h = (id) => hashids.encode(id)
- let schueler_entfernt = []
- const pool = new Pool({ connectionString: privat.mein_bk_db})
- function query () {
- pool.query(`SELECT schueler.hashid, wlan.voucher, wahlen.* FROM schueler
- LEFT JOIN wlan ON schueler.hashid = wlan.schueler_hashid
- LEFT JOIN wahlen ON schueler.hashid = wahlen.schueler_hashid`,
- (err, resp) => schueler_entfernt = resp.rows)
- }
- query()
- const gruppe = Schueler.query()
- .where('Status', '2')
- .andWhere('Geloescht', '-')
- .andWhere('Gesperrt', '-')
- .select('ID', 'Name', 'Vorname', 'Klasse')
- .orderBy('Klasse')
- .orderBy('Name')
- function diff (eins, zwei) {
- let a = new Set(eins);
- let b = new Set(zwei);
- return new Set(
- [...a].filter(x => !b.has(x)));
- }
- const mergeById = (a1, a2) =>
- a1.map(itm => ({
- ...a2.find((item) => (item.hashid === h(itm.ID)) && item),
- ...itm
- }));
- function update_db () {}
- </script>
|