hmt 3 anni fa
parent
commit
29078152f5
1 ha cambiato i file con 18 aggiunte e 36 eliminazioni
  1. 18 36
      components/teams.svelte

+ 18 - 36
components/teams.svelte

@@ -2,19 +2,21 @@
   export let schueler, privat, einstellungen = {};
   let teams_anzeigen = einstellungen.teams_anzeigen;
   let schueler_verbergen;
+  let lehrer = []
   $: pool.query(`UPDATE einstellungen SET teams_anzeigen=$1`, [teams_anzeigen])
   const { Pool } = R("pg");
   const pool = new Pool({ connectionString: privat.mein_bk_db });
-  async function hole_lehrer() {
-    const query = `SELECT * from lehrer`;
-    try {
-      const res = await pool.query(query);
-      console.log(res.rows);
-      return res.rows;
-    } catch (e) {
-      console.log(e);
-      return [];
-    }
+  const query = `SELECT * from lehrer`;
+  pool.query(query).then(res => lehrer = res.rows)
+  async function update_lehrer (l) {
+    await pool.query(`UPDATE lehrer SET konto=$1 WHERE id=$2`, [!l.konto, l.id])
+    l.konto = !l.konto
+    lehrer = lehrer
+  }
+  async function update_schueler (s) {
+    await pool.query(`UPDATE schueler SET konto=$1 WHERE id=$2`, [!s.konto, s.id])
+    s.konto = !s.konto
+    schueler = schueler
   }
 </script>
 
@@ -53,22 +55,13 @@
               <tr>
                 <td>{s.Name}</td>
                 <td>{s.Vorname}</td>
-                <td>
+                <td class="is-clickable">
                   <span
                     class="tag"
+                    on:click={_=>update_schueler(s)}
                     class:is-warning={s.konto === undefined || s.konto === null}
                     class:is-danger={s.konto === false}
                     class:is-success={s.konto}>Konto</span>
-                  <span
-                    class="tag"
-                    class:is-warning={s.video === undefined || s.video === null}
-                    class:is-danger={s.video === false}
-                    class:is-success={s.video}>Video</span>
-                  <span
-                    class="tag"
-                    class:is-warning={s.video === undefined || s.audio === null}
-                    class:is-danger={s.audio === false}
-                    class:is-success={s.audio}>Audio</span>
                 </td>
               </tr>
             {/each}
@@ -78,9 +71,7 @@
     </div>
   </div>
 {/if}
-{#await hole_lehrer()}
-  Hole Lehrerdaten
-{:then lehrer}
+{#if lehrer}
   <div class="columns">
     <div class="column is-two-thirds">
       <h3 class="title">Lehrer</h3>
@@ -95,22 +86,13 @@
           {#each lehrer as l}
             <tr>
               <td>{l.name}</td>
-              <td>
+              <td class="is-clickable">
                 <span
                 class="tag"
+                on:click={_=>update_lehrer(l)}
                 class:is-warning={l.konto === undefined || l.konto === null}
                 class:is-danger={l.konto === false}
                 class:is-success={l.konto}>Konto</span>
-              <span
-                class="tag"
-                class:is-warning={l.video === undefined || l.video === null}
-                class:is-danger={l.video === false}
-                class:is-success={l.video}>Video</span>
-              <span
-                class="tag"
-                class:is-warning={l.audio === undefined || l.audio === null}
-                class:is-danger={l.audio === false}
-                class:is-success={l.audio}>Audio</span>
               </td>
             </tr>
           {/each}
@@ -118,4 +100,4 @@
       </table>
     </div>
   </div>
-{/await}
+{/if}