1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <div class="columns">
- <div class="column is-two-thirds">
- {#each Object.entries(schueler) as [klasse, schueler]}
- <h3 class="title">{klasse}</h3>
- <table class="table is-striped">
- <thead>
- <tr>
- <th>Name</th>
- <th>Vorname</th>
- <th>Voucher</th>
- </tr>
- </thead>
- <tbody>
- {#each schueler as s}
- <tr>
- <td>{s.Name}</td>
- <td>{s.Vorname}</td>
- <td><span class={s.voucher && "tag is-info is-medium"}>{s.voucher || ''}</span></td>
- </tr>
- {/each}
- </tbody>
- </table>
- {/each}
- </div>
- <div class="column">
- <h3 class="title">Voucher austauschen</h3>
- <div class="field">
- <label class="label">
- Voucher als Liste zeilenweise in das Textfeld einfügen. Alte Voucher
- werden entfernt und durch die neuen ersetzt.
- </label>
- <div class="control">
- <textarea class="textarea" bind:value={vouchers} rows="10" cols="20"></textarea>
- </div>
- </div>
- <div class="field is-grouped">
- <div class="control">
- <button class="button is-link" on:click={()=>update_vouchers()}>Aktualisieren</button>
- </div>
- </div>
- </div>
- </div>
- <script>
- import Papa from '../papaparse.min.js'
- export let schueler, privat
- const { Pool } = R('pg')
- const pool = new Pool({ connectionString: privat.mein_bk_db})
- let vouchers = ''
- const update_vouchers = async () => {
- const res = await Papa.parse(vouchers, {comments: '#'})
- const values = res.data.map(e => '(\'' + e[0].trim() + '\')').join(',')
- const query = `INSERT INTO wlan (voucher)
- VALUES ${values}
- RETURNING *`
- console.log(values)
- try {
- await pool.query(`DELETE FROM wlan`)
- const res = await pool.query(query)
- console.log(res.rows)
- } catch(err) {
- console.log(err.stack)
- }
- }
- </script>
|