teams.svelte 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <script>
  2. export let schueler, privat, einstellungen;
  3. let schueler_verbergen;
  4. let lehrer = [];
  5. let liste_export = false;
  6. const { Pool } = R("pg");
  7. const pool = new Pool({ connectionString: privat.mein_bk_db });
  8. const query = `SELECT * from lehrer`;
  9. pool.query(query).then((res) => (lehrer = res.rows));
  10. async function update_teams() {
  11. pool.query(`UPDATE einstellungen SET teams_anzeigen=$1`, [
  12. !einstellungen.teams_anzeigen,
  13. ]);
  14. einstellungen.teams_anzeigen = !einstellungen.teams_anzeigen;
  15. }
  16. async function update_lehrer(l) {
  17. await pool.query(`UPDATE lehrer SET konto=$1 WHERE id=$2`, [
  18. !l.konto,
  19. l.id,
  20. ]);
  21. l.konto = !l.konto;
  22. lehrer = lehrer;
  23. }
  24. async function update_schueler(s) {
  25. await pool.query(`UPDATE schueler SET konto=$1 WHERE id=$2`, [
  26. !s.konto,
  27. s.id,
  28. ]);
  29. s.konto = !s.konto;
  30. schueler = schueler;
  31. }
  32. </script>
  33. <h3 class="title">Einverständniserklärungen Teams</h3>
  34. <div class="field">
  35. <label class="checkbox">
  36. <input
  37. type="checkbox"
  38. bind:checked={einstellungen.teams_anzeigen}
  39. on:click={update_teams}
  40. />
  41. Teams-Seite für Schüler anzeigen
  42. </label>
  43. </div>
  44. <div class="field">
  45. <label class="checkbox">
  46. <input type="checkbox" bind:checked={schueler_verbergen} />
  47. Schüler verbergen
  48. </label>
  49. </div>
  50. <div class="field">
  51. <label class="checkbox">
  52. <input
  53. type="checkbox"
  54. bind:checked={liste_export}
  55. on:click={(_) => (liste_export = !liste_export)}
  56. />
  57. Export anzeigen
  58. </label>
  59. </div>
  60. {#if !schueler_verbergen}
  61. <div class="columns">
  62. <div class="column is-two-thirds">
  63. {#each Object.entries(schueler) as [klasse, schueler]}
  64. <h3 class="title">{klasse}</h3>
  65. <table class="table is-striped">
  66. <thead>
  67. <tr>
  68. <th>Name</th>
  69. <th>Vorname</th>
  70. <th>Auswahlstatus</th>
  71. </tr>
  72. </thead>
  73. <tbody>
  74. {#each schueler as s}
  75. <tr>
  76. <td>{s.Name}</td>
  77. <td>{s.Vorname}</td>
  78. <td class="is-clickable" class:is-danger={!s.alter} class:is-warning={s.alter?.years > 0 && s.alter?.years < 18}>
  79. <span
  80. class="tag"
  81. on:click={(_) => update_schueler(s)}
  82. class:is-warning={s.konto === undefined || s.konto === null}
  83. class:is-danger={s.konto === false}
  84. class:is-success={s.konto}>Konto</span
  85. >
  86. </td>
  87. </tr>
  88. {/each}
  89. </tbody>
  90. </table>
  91. {/each}
  92. </div>
  93. </div>
  94. {/if}
  95. {#if lehrer}
  96. <div class="columns">
  97. <div class="column is-two-thirds">
  98. <h3 class="title">Lehrer</h3>
  99. <table class="table is-striped">
  100. <thead>
  101. <tr>
  102. <th>Name</th>
  103. <th>Auswahlstatus</th>
  104. </tr>
  105. </thead>
  106. <tbody>
  107. {#each lehrer as l}
  108. <tr>
  109. <td>{l.name}</td>
  110. <td class="is-clickable">
  111. <span
  112. class="tag"
  113. on:click={(_) => update_lehrer(l)}
  114. class:is-warning={l.konto === undefined || l.konto === null}
  115. class:is-danger={l.konto === false}
  116. class:is-success={l.konto}>Konto</span
  117. >
  118. </td>
  119. </tr>
  120. {/each}
  121. </tbody>
  122. </table>
  123. </div>
  124. </div>
  125. {/if}
  126. {#if liste_export}
  127. <pre>
  128. {#each Object.entries(schueler) as [klasse, schueler]}
  129. {#each schueler as s}
  130. {#if s.konto}
  131. {`b${s.id}@${privat.domain},${s.Name},${s.Vorname},${s.Vorname} ${s.Name},schueler,,,,,,,,Bielefeld,NW,,DE`}<br>
  132. {/if}
  133. {/each}
  134. {/each}
  135. </pre>
  136. {/if}