burningTyger 5 years ago
parent
commit
d30c3f0048

+ 253 - 0
components/projektwoche-lehrer.svelte

@@ -0,0 +1,253 @@
+<h2 class="title">Beschreibung der einzelnen Projekte</h2>
+{#each projekte as p}
+  <div class="card">
+    <header class="card-header">
+      <p class="card-header-title has-background-primary">{p.titel}</p>
+    </header>
+    <div class="card-content">
+      <div class="content">
+      <dl>
+        <dt class="has-text-weight-bold">Beschreibung</dt>
+        <dd>{p.beschreibung}</dd>
+        <dt class="has-text-weight-bold">Projektleitung</dt>
+        <dd>{p.leitung}</dd>
+        <dt class="has-text-weight-bold">Bildungsbeitrag</dt>
+        <dd>{p.bildung}</dd>
+        <dt class="has-text-weight-bold">Schulnähe</dt>
+        <dd><span class="tag" class:is-danger={!p.schulnah} class:is-success={p.schulnah}>{p.schulnah ? 'JA':'NEIN'}</span></dd>
+        <dt class="has-text-weight-bold">Projektort</dt>
+        <dd>{p.ort}</dd>
+        <dt class="has-text-weight-bold">Vortreffen</dt>
+        <dd><span class="tag" class:is-danger={!p.vortermin} class:is-success={p.vortermin}>{p.vortermin ? 'JA':'NEIN'}</span></dd>
+        <dt class="has-text-weight-bold">Benötigtes Material</dt>
+        <dd>{p.material || 'keines'}</dd>
+        <dt class="has-text-weight-bold">Kostenbeitrag</dt>
+        <dd><span class="tag" class:is-danger={p.kosten} class:is-success={!p.kosten}>{p.kosten ? p.kosten:'keine'}</span></dd>
+      </dl>
+      <hr>
+      <dl>
+        {#if p.woche}
+          <dt class="has-text-weight-bold">Teilnehmer Woche</dt>
+          <dd><span class={`tag is-${p.gewaehlt_woche >= p.max_teilnehmer ? 'danger':'success'}`}>{`${p.gewaehlt_woche}/${p.max_teilnehmer}`}</span></dd>
+        {/if}
+        {#if p.mo_di}
+          <dt class="has-text-weight-bold">Teilnehmer Mo/Di</dt>
+          <dd><span class={`tag is-${p.gewaehlt_mo_di >= p.max_teilnehmer ? 'danger':'success'}`}>{`${p.gewaehlt_mo_di}/${p.max_teilnehmer}`}</span></dd>
+        {/if}
+        {#if p.mi_do}
+          <dt class="has-text-weight-bold">Teilnehmer Mi/Do</dt>
+          <dd><span class={`tag is-${p.gewaehlt_mi_do >= p.max_teilnehmer ? 'danger':'success'}`}>{`${p.gewaehlt_mi_do}/${p.max_teilnehmer}`}</span></dd>
+        {/if}
+        <dt class="has-text-weight-bold">Info an Organisationsteam</dt>
+        <dd>{p.info_an_organisationsteam || '–'}</dd>
+        <dt class="has-text-weight-bold">Medienwunsch</dt>
+        <dd>{p.medienwunsch || '–'}</dd>
+        <dt class="has-text-weight-bold">Raumwunsch</dt>
+        <dd>{p.raumwunsch || '–'}</dd>
+        <dt class="has-text-weight-bold">Präsentation</dt>
+        <dd>{p.presi || '–'}</dd>
+      </dl>
+      </div>
+    </div>
+    <footer class="card-footer">
+      <p class="card-footer-item">
+        <button class="button is-info" on:click={() => modal_toggle(p)}>Bearbeiten</button>
+      </p>
+      <p class="card-footer-item">
+        <button class="button is-danger" on:click={() => loeschen(p)}>Löschen</button>
+      </p>
+    </footer>
+  </div>
+  <br>
+{/each}
+{#if modal}
+  <div class="modal" class:is-active={modal}>
+    <div class="modal-background"></div>
+    <div class="modal-content">
+      <header class="modal-card-head">
+        <span class="modal-card-title is-clipped">Bearbeiten</span>
+        <button class="delete" aria-label="close" on:click={() => modal = !modal}></button>
+      </header>
+      <section class="modal-card-body">
+<div class="field">
+    <label class="label">Projekttitel</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.titel}>
+      </div>
+</div>
+<div class="field">
+    <label class="label">Leitung (vollst. Name)</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.leitung}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Kurzbeschreibung des Projekts und ggf. weitere Informationen</label>
+      <div class="control">
+        <textarea class="textarea">{pp.beschreibung}</textarea>
+      </div>
+</div>
+<div class="field">
+    <label class="label">Beitrag zur kulturellen/politischen Bildung</label>
+      <div class="control">
+        <textarea class="textarea">{pp.bildung}</textarea>
+      </div>
+</div>
+<div class="field">
+    <label class="label">Max Teilnehmerzahl</label>
+      <div class="control">
+        <input class="input" type="number" bind:value={pp.max_teilnehmer}>
+      </div>
+</div>
+<div class="field">
+  <div class="control">
+    <label class="label">Findet das Projekt in Schulnähe statt?</label>
+      <input type="checkbox" name="schulnah" bind:checked={pp.schulnah}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Ort</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.ort}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Treffpunkt und Uhrzeit am Morgen des ersten Projekttags</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.treffpunkt}>
+  </div>
+</div>
+<div class="field is-horizontal">
+  <div class="control">
+    <label class="label">Wochenprojekt</label>
+      <input type="checkbox" name="woche" bind:checked={pp.woche}>
+  </div>
+</div>
+<div class="field">
+  <div class="control">
+    <label class="label">Montag/Dienstag</label>
+      <input type="checkbox" name="mo_di" bind:checked={pp.mo_di}>
+  </div>
+</div>
+<div class="field">
+  <div class="control">
+    <label class="label">Mittwoch/Donnerstag</label>
+      <input type="checkbox" name="mi_do" bind:checked={pp.mi_do}>
+  </div>
+</div>
+<div class="field">
+  <div class="control">
+    <label class="label">Soll für ein Vorgespräch am Mittwoch 2.10.19 ein Raum reserviert werden?</label>
+      <input type="checkbox" name="vortermin" bind:checked={pp.vortermin}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Mitzubringende besondere Materialien</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.material}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Kosten</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.kosten}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Zusätzliche Info für das Organisationsteam</label>
+      <div class="control">
+        <textarea class="textarea">{pp.info_an_organisationsteam}</textarea>
+      </div>
+</div>
+<div class="field">
+    <label class="label">Raumwunsch</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.raumwunsch}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Medienwunsch</label>
+      <div class="control">
+        <input class="input" type="text" bind:value={pp.medienwunsch}>
+  </div>
+</div>
+<div class="field">
+    <label class="label">Präsentationsbeitrag</label>
+      <div class="control">
+        <textarea class="textarea">{pp.presi}</textarea>
+      </div>
+</div>
+      </section>
+      <footer class="modal-card-foot">
+        <span class="card-footer-item">
+          <button class="button is-info" on:click={() => speichern(pp)}>Aktualisieren</button>
+        </span>
+        <span class="card-footer-item">
+          <button on:click={() => modal=false} class="button is-danger">Abbrechen</button>
+        </span>
+      </footer>
+    </div>
+  </div>
+{/if}
+<script>
+  export let privat
+  let projekte = []
+  let pp
+  let modal = false
+  const { Pool } = R('pg')
+  const _ = R('lodash')
+  const pool = new Pool({ connectionString: privat.mein_bk_db})
+  function projekte_laden () {
+    pool.query(`SELECT *,
+                  (SELECT COUNT(*)
+                    FROM wahlen
+                    WHERE projekte.id = wahlen.woche
+                  ) as gewaehlt_woche,
+                  (SELECT COUNT(*)
+                    FROM wahlen
+                    WHERE projekte.id = wahlen.mo_di
+                  ) as gewaehlt_mo_di,
+                  (SELECT COUNT(*)
+                    FROM wahlen
+                    WHERE projekte.id = wahlen.mi_do
+                  ) as gewaehlt_mi_do
+                FROM projekte`,
+      (err, resp) => projekte = resp.rows)
+  }
+  projekte_laden()
+  function modal_toggle (p) {
+    pp = p
+    modal = true
+  }
+  function loeschen (p) {
+    const query = `DELETE FROM projekte
+                   WHERE id = $1`
+    pool.query(query, [p.id], (err, res) => {
+      if (err) {
+        console.log(err)
+        return
+      }
+      projekte = projekte.filter(pp => pp !== p)
+    })
+  }
+  function speichern (pp) {
+    const query = `UPDATE projekte
+                   SET (titel, leitung, beschreibung, bildung, max_teilnehmer,
+                     schulnah, ort, treffpunkt, woche, mo_di, mi_do, vortermin,
+                     material, kosten, info_an_organisationsteam, raumwunsch,
+                     medienwunsch, presi) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
+                   WHERE projekte.id = $19
+                   RETURNING *`
+    const value = [pp.titel, pp.leitung, pp.beschreibung, pp.bildung, pp.max_teilnehmer,
+                   pp.schulnah, pp.ort, pp.treffpunkt, pp.woche, pp.mo_di, pp.mi_do, pp.vortermin,
+                   pp.material, pp.kosten, pp.info_an_organisationsteam, pp.raumwunsch,
+                   pp.medienwunsch, pp.presi,
+                   pp.id]
+    pool.query(query, value, (err, res) => {
+      err && console.log(err)
+      pp = res[0]
+      projekte = projekte
+      modal = false
+    })
+  }
+</script>

+ 67 - 34
components/projektwoche.svelte → components/projektwoche-schueler.svelte

@@ -2,6 +2,7 @@
   <div class="column is-two-thirds">
   <div class="column is-two-thirds">
     {#each Object.entries(schueler) as [klasse, schuelers]}
     {#each Object.entries(schueler) as [klasse, schuelers]}
       <h3 class="title">{klasse}</h3>
       <h3 class="title">{klasse}</h3>
+      <h3 class="subtitle has-background-warning">{unterwegs(klasse)}</h3>
       <table class="table is-striped">
       <table class="table is-striped">
         <thead>
         <thead>
           <tr>
           <tr>
@@ -38,12 +39,12 @@
           </tr>
           </tr>
         </thead>
         </thead>
         <tbody>
         <tbody>
-          {#each klassen as k,i}
+          {#each klassen && Object.entries(klassen) as [klasse, abwesenheit]}
             <tr>
             <tr>
-              <td>{k.klasse}</td>
-              <td class={`has-text-${k.abwesenheit === 0 ? 'danger':'success'}`} style="cursor: pointer;" on:click={() => switcher(i,0)}>{k.abwesenheit === 0 ? '✘':'✔'}</td>
-              <td class={`has-text-${k.abwesenheit === 1 ? 'danger':'success'}`} style="cursor: pointer;" on:click={() => switcher(i,1)}>{k.abwesenheit === 1 ? '✘':'✔'}</td>
-              <td class={`has-text-${k.abwesenheit === 2 ? 'danger':'success'}`} style="cursor: pointer;" on:click={() => switcher(i,2)}>{k.abwesenheit === 2 ? '✘':'✔'}</td>
+              <td>{klasse}</td>
+              <td class={`has-text-${abwesenheit === 0 ? 'danger':'success'}`} style="cursor: pointer;" on:click={() => switcher(klasse,0)}>{abwesenheit === 0 ? '✘':'✔'}</td>
+              <td class={`has-text-${abwesenheit === 1 ? 'danger':'success'}`} style="cursor: pointer;" on:click={() => switcher(klasse,1)}>{abwesenheit === 1 ? '✘':'✔'}</td>
+              <td class={`has-text-${abwesenheit === 2 ? 'danger':'success'}`} style="cursor: pointer;" on:click={() => switcher(klasse,2)}>{abwesenheit === 2 ? '✘':'✔'}</td>
             </tr>
             </tr>
           {/each}
           {/each}
         </tbody>
         </tbody>
@@ -133,37 +134,58 @@
 <script>
 <script>
   export let schueler, privat
   export let schueler, privat
   let projekte = [];
   let projekte = [];
-  let klassen = [];
+  let klassen = {}
   let modal = false, modal_s, selected_woche, selected_mo_di, selected_mi_do;
   let modal = false, modal_s, selected_woche, selected_mo_di, selected_mi_do;
   function modalset (s) {
   function modalset (s) {
     modal = true
     modal = true
     modal_s=s
     modal_s=s
   }
   }
   const { Pool } = R('pg')
   const { Pool } = R('pg')
+  const _ = R('lodash')
   const pool = new Pool({ connectionString: privat.mein_bk_db})
   const pool = new Pool({ connectionString: privat.mein_bk_db})
-  import { onMount, onDestroy } from 'svelte';
-    pool.query(`SELECT id, titel, leitung, woche, mo_di, mi_do, max_teilnehmer,
-                  (SELECT COUNT(*)
-                    FROM wahlen
-                    WHERE projekte.id = wahlen.woche
-                  ) as gewaehlt_woche,
-                  (SELECT COUNT(*)
-                    FROM wahlen
-                    WHERE projekte.id = wahlen.mo_di
-                  ) as gewaehlt_mo_di,
-                  (SELECT COUNT(*)
-                    FROM wahlen
-                    WHERE projekte.id = wahlen.mi_do
-                  ) as gewaehlt_mi_do
-                FROM projekte`,
-      (err, resp) => projekte = resp.rows)
-    pool.query(`SELECT * FROM klassen ORDER BY klasse`,
-      (err, resp) => klassen = resp.rows)
-  function wahl (s) {
-    if (s.woche === s.mo_di && s.woche === s.mi_do) return 'danger'
-    else if (typeof(s.mo_di) !== typeof(s.mi_do)) return 'warning'
-    else if ([s.mo_di, s.mi_do, s.woche].includes(0)) return 'info'
-    else return 'success'
+  function projekte_laden () {
+  pool.query(`SELECT id, titel, leitung, woche, mo_di, mi_do, max_teilnehmer,
+                (SELECT COUNT(*)
+                  FROM wahlen
+                  WHERE projekte.id = wahlen.woche
+                ) as gewaehlt_woche,
+                (SELECT COUNT(*)
+                  FROM wahlen
+                  WHERE projekte.id = wahlen.mo_di
+                ) as gewaehlt_mo_di,
+                (SELECT COUNT(*)
+                  FROM wahlen
+                  WHERE projekte.id = wahlen.mi_do
+                ) as gewaehlt_mi_do
+              FROM projekte`,
+    (err, resp) => projekte = resp.rows)
+  }
+  projekte_laden()
+  pool.query(`SELECT * FROM klassen ORDER BY klasse`,
+    (err, resp) => resp.rows.forEach(k => { klassen[k.klasse] = k.abwesenheit }))
+  $: wahl = s => {
+    const abwesenheit = klassen[s.Klasse]
+    if (abwesenheit === null) {
+      if (s.woche === s.mo_di && s.woche === s.mi_do) return 'danger'
+      else if (typeof(s.mo_di) !== typeof(s.mi_do)) return 'warning'
+      else if ([s.mo_di, s.mi_do, s.woche].includes(0)) return 'info'
+      else return 'success'
+    } else if (abwesenheit === 0) {
+      if (s.woche === s.mo_di && s.woche === s.mi_do) return 'success'
+      else return 'info'
+    } else if (abwesenheit === 1) {
+      if (s.woche === s.mo_di && s.woche === s.mi_do) return 'danger'
+      else if (typeof(s.woche) === 'number' && (typeof(s.mo_di) === 'number'|| typeof(s.mi_do) === 'number')) return 'info'
+      else if (typeof(s.mi_do) === 'number') return 'success'
+      else if (s.mo_di === 0 || s.woche === 0) return 'warning'
+      else return 'danger'
+    } else if (abwesenheit === 2) {
+      if (s.woche === s.mo_di && s.woche === s.mi_do) return 'danger'
+      else if (typeof(s.woche) === 'number' && (typeof(s.mo_di) === 'number'|| typeof(s.mi_do) === 'number')) return 'info'
+      else if (typeof(s.mo_di) === 'number') return 'success'
+      else if (s.mi_do === 0 || s.woche === 0) return 'warning'
+      else return 'danger'
+    }
   }
   }
   async function wahl_aendern () {
   async function wahl_aendern () {
     const text = `INSERT INTO wahlen(schueler_hashid, woche, mo_di, mi_do)
     const text = `INSERT INTO wahlen(schueler_hashid, woche, mo_di, mi_do)
@@ -175,25 +197,36 @@
     try {
     try {
       const res = await pool.query(text, values)
       const res = await pool.query(text, values)
       const data = res.rows[0]
       const data = res.rows[0]
+      projekte_laden()
       Object.assign(modal_s, data)
       Object.assign(modal_s, data)
       schueler = schueler
       schueler = schueler
     } catch(err) {
     } catch(err) {
       console.log(err.stack)
       console.log(err.stack)
     }
     }
   }
   }
-  async function switcher(i, art) {
-    const abwesenheit = klassen[i].abwesenheit === null || klassen[i].abwesenheit !== art ? art : null
+  async function switcher(k, art) {
+    const abwesenheit = klassen[k] === null || klassen[k] !== art ? art : null
     const text = `UPDATE klassen SET abwesenheit = $1
     const text = `UPDATE klassen SET abwesenheit = $1
                   WHERE klasse = $2
                   WHERE klasse = $2
                   RETURNING abwesenheit`
                   RETURNING abwesenheit`
-    const values = [abwesenheit, klassen[i].klasse]
+    const values = [abwesenheit, k]
     try {
     try {
       const res = await pool.query(text, values)
       const res = await pool.query(text, values)
       const data = res.rows[0]
       const data = res.rows[0]
-      Object.assign(klassen[i], data)
-      klassen = klassen
+      klassen[k] = data.abwesenheit
     } catch(err) {
     } catch(err) {
       console.log(err.stack)
       console.log(err.stack)
     }
     }
   }
   }
+  $: unterwegs = klasse => {
+    if (!klassen) return ''
+    let out
+    switch (klassen[klasse]) {
+      case null: return ''; break;
+      case 0: out = 'Montag bis Freitag'; break;
+      case 1: out = 'Montag und Dienstag'; break;
+      case 2: out = 'Mittwoch und Donnerstag'; break;
+    }
+    return `Die Klasse ist ${out} unterwegs`
+  }
 </script>
 </script>

+ 59 - 0
components/projektwoche-uebersicht.svelte

@@ -0,0 +1,59 @@
+<div class="field is-horizontal">
+  <div class="field-body">
+    <div class="field">
+      <p class="control is-expanded has-icons-left">
+        <label class="label is-small">Beginn der Prowo-Wahl</label>
+        <input type="datetime-local" bind:value={wahlbeginn_prowo} class="input is-small">
+      </p>
+    </div>
+    <div class="field">
+      <p class="control is-expanded has-icons-left">
+        <label class="label is-small">Ende der Prowo-Wahl</label>
+        <input type="datetime-local" bind:value={wahlende_prowo} class="input is-small">
+      </p>
+    </div>
+  </div>
+</div>
+<div class="field">
+  <p class="control is-expanded has-icons-left">
+    <label class="label is-small">Thema der Prowo</label>
+    <input type="text" bind:value={thema_prowo} class="input is-expanded is-small">
+  </p>
+</div>
+<div class="field">
+  <button class="is-small button is-default" on:click={changeDate}> Wahlzeitraum ändern </button>
+  {#if check}<span class="tag is-success">✓</span>{/if}
+</div>
+
+<script>
+  export let schueler, privat, einstellungen
+  let check
+  const { Pool } = R('pg')
+  const pool = new Pool({ connectionString: privat.mein_bk_db})
+  $: wahlbeginn_prowo = wahlbeginn_prowo || setDateTime(einstellungen.wahlbeginn_prowo)
+  $: wahlende_prowo = wahlende_prowo || setDateTime(einstellungen.wahlende_prowo)
+  $: thema_prowo = thema_prowo || einstellungen.thema_prowo || ''
+  const changeDate = async _ => {
+    const query = `UPDATE einstellungen
+                    SET wahlbeginn_prowo=$1, wahlende_prowo=$2, thema_prowo=$3
+                  RETURNING wahlbeginn_prowo, wahlende_prowo, thema_prowo`
+    const values=[new Date(wahlbeginn_prowo), new Date(wahlende_prowo), thema_prowo]
+    try {
+      const res = await pool.query(query, values)
+      const data = res.rows[0]
+      einstellungen.wahlbeginn_prowo = data.wahlbeginn_prowo
+      einstellungen.wahlende_prowo = data.wahlende_prowo
+      einstellungen.thema_prowo = data.thema_prowo
+      einstellungen = einstellungen
+      check = true
+    } catch(err) {
+      console.log(err.stack)
+    }
+  }
+
+  function setDateTime (date) {
+    if (!date) return
+    const d = new Date(date)
+    return d.toISOString().replace('Z','')
+  };
+</script>

+ 103 - 1
components/svwahl.svelte

@@ -1 +1,103 @@
-svwahl
+<div class="field is-horizontal">
+  <div class="field-body">
+    <div class="field">
+      <p class="control is-expanded has-icons-left">
+        <label class="label is-small">Beginn der SV-Wahl</label>
+        <input type="datetime-local" bind:value={wahlbeginn_sv} class="input is-small">
+      </p>
+    </div>
+    <div class="field">
+      <p class="control is-expanded has-icons-left">
+        <label class="label is-small">Ende der SV-Wahl</label>
+        <input type="datetime-local" bind:value={wahlende_sv} class="input is-small">
+      </p>
+    </div>
+  </div>
+</div>
+<div class="field">
+  <p class="control is-expanded has-icons-left">
+    <label class="label is-small">Datum der ersten Schulkonferenz</label>
+    <input type="datetime-local" bind:value={erste_schuko} class="input is-small">
+  </p>
+</div>
+<div class="field">
+  <button class="is-small button is-default" on:click={changeDate}> Wahlzeitraum ändern </button>
+  {#if check}<span class="tag is-success">✓</span>{/if}
+</div>
+
+<div class="columns">
+  <div class="column is-two-thirds">
+    {#each Object.entries(schueler) as [klasse, schuelers]}
+      <h3 class="title">{klasse}</h3>
+      <table class="table is-striped">
+        <thead>
+          <tr>
+            <th>ID</th>
+            <th>Name</th>
+            <th>Vorname</th>
+            <th>Wahlstatus</th>
+          </tr>
+        </thead>
+        <tbody>
+          {#each schuelers as s,i}
+            <tr>
+              <td>{s.hashid}</td>
+              <td>{s.Name}</td>
+              <td>{s.Vorname}</td>
+              <td class:has-background-success={s.schuko||s.sprecher}>
+                Schuko: <input checked={s.schuko} type="checkbox" on:click={()=>check_aktiv(s, 'schuko')}>
+                Sprecher: <input checked={s.sprecher} type="checkbox" on:click={()=>check_aktiv(s, 'sprecher')}>
+              </td>
+            </tr>
+          {/each}
+        </tbody>
+      </table>
+    {/each}
+  </div>
+</div>
+<script>
+  export let schueler, privat, einstellungen
+  let check
+  const { Pool } = R('pg')
+  const pool = new Pool({ connectionString: privat.mein_bk_db})
+  $: wahlbeginn_sv = wahlbeginn_sv || setDateTime(einstellungen.wahlbeginn_sv)
+  $: wahlende_sv = wahlende_sv || setDateTime(einstellungen.wahlende_sv)
+  $: erste_schuko = erste_schuko || setDateTime(einstellungen.erste_schuko)
+  const changeDate = async _ => {
+    const query = `UPDATE einstellungen
+                   SET wahlbeginn_sv=$1, wahlende_sv=$2, erste_schuko=$3
+                   RETURNING wahlbeginn_sv, wahlende_sv, erste_schuko`
+    const values=[new Date(wahlbeginn_sv), new Date(wahlende_sv), new Date(erste_schuko)]
+    try {
+      const res = await pool.query(query, values)
+      const data = res.rows[0]
+      einstellungen.wahlbeginn_sv = data.wahlbeginn_sv
+      einstellungen.wahlende_sv = data.wahlende_sv
+      einstellungen.erste_schuko = data.erste_schuko
+      einstellungen = einstellungen
+      check = true
+    } catch(err) {
+      console.log(err.stack)
+    }
+  }
+  const check_aktiv = async (s, art) => {
+    const query = `UPDATE schueler SET ${art}=$1
+                   WHERE hashid=$2
+                   RETURNING ${art}`
+    const values=[!s.schuko, s.hashid]
+    try {
+      const res = await pool.query(query, values)
+      console.log(res)
+      const data = res.rows[0]
+      s[art] = data[art]
+      schueler = schueler
+    } catch(err) {
+      console.log(err.stack)
+    }
+  }
+  function setDateTime (date) {
+    if (!date) return
+    const d = new Date(date)
+    return d.toISOString().replace('Z','')
+  };
+</script>

+ 33 - 22
Übersicht.svelte

@@ -17,11 +17,13 @@
       <div class="tabs">
       <div class="tabs">
         <ul>
         <ul>
           <li class:is-active={active === Vouchers}><a on:click={() => active=Vouchers}>WLAN</a></li>
           <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>
+          <li class:is-active={active === ProjektwocheSchueler}><a on:click={() => active=ProjektwocheSchueler}>Projektwoche Schüler</a></li>
+          <li class:is-active={active === ProjektwocheLehrer}><a on:click={() => active=ProjektwocheLehrer}>Projektwoche Lehrer</a></li>
+          <li class:is-active={active === ProjektwocheUebersicht}><a on:click={() => active=ProjektwocheUebersicht}>Projektwoche Übersicht</a></li>
+          <li class:is-active={active === SVWahl}><a on:click={() => active=SVWahl}>SV-Wahl</a></li>
         </ul>
         </ul>
       </div>
       </div>
-      <svelte:component this={active} schueler={schueler_filter} {privat}/>
+      <svelte:component this={active} schueler={schueler_filter} {privat} {einstellungen}/>
     </div>
     </div>
   </section>
   </section>
 
 
@@ -32,34 +34,45 @@
 <script>
 <script>
   import Hashids from 'hashids'
   import Hashids from 'hashids'
   import Vouchers from './components/vouchers.svelte'
   import Vouchers from './components/vouchers.svelte'
-  import Projektwoche from './components/projektwoche.svelte'
-  import Svwahl from './components/svwahl.svelte'
+  import ProjektwocheSchueler from './components/projektwoche-schueler.svelte'
+  import ProjektwocheLehrer from './components/projektwoche-lehrer.svelte'
+  import ProjektwocheUebersicht from './components/projektwoche-uebersicht.svelte'
+  import SVWahl from './components/svwahl.svelte'
   export let schueler, knexConfig, privat
   export let schueler, knexConfig, privat
-  let active = Vouchers
+  let active = SVWahl
   let suche = ''
   let suche = ''
 
 
   const { Pool } = R('pg')
   const { Pool } = R('pg')
   const _ = R('lodash')
   const _ = R('lodash')
-  const Schueler = R('schild').Schueler
-  Schueler.knex(R('knex')(knexConfig))
+  const mysql = R('mysql')
   const hashids = new Hashids(privat.salt, 5, 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789')
   const hashids = new Hashids(privat.salt, 5, 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789')
   const h = (id) => hashids.encode(id)
   const h = (id) => hashids.encode(id)
   let schueler_entfernt = [], schueler_lokal = []
   let schueler_entfernt = [], schueler_lokal = []
+  let merged =[]
+  let einstellungen = {}
   const pool = new Pool({ connectionString: privat.mein_bk_db})
   const pool = new Pool({ connectionString: privat.mein_bk_db})
+  pool.query(`SELECT * FROM einstellungen`).then(res => einstellungen = res.rows[0])
   async function query () {
   async function query () {
-    const resp = await 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`)
+    const resp = await pool.query(`SELECT schueler.*,
+                                          wlan.voucher,
+                                          wahlen.*
+                                   FROM schueler
+                                   LEFT JOIN wlan ON schueler.hashid = wlan.schueler_hashid
+                                   LEFT JOIN wahlen ON schueler.hashid = wahlen.schueler_hashid`)
     schueler_entfernt = resp.rows
     schueler_entfernt = resp.rows
+    merged = mergeById(schueler_lokal, schueler_entfernt)
   }
   }
-  async function lokal () {
-   schueler_lokal = await Schueler.query()
-          .where('Status', '2')
-          .andWhere('Geloescht', '-')
-          .andWhere('Gesperrt', '-')
-          .select('ID', 'Name', 'Vorname', 'Klasse')
-          .orderBy('Klasse')
-          .orderBy('Name')
+  function lokal () {
+    const connection = mysql.createConnection(knexConfig.connection)
+    connection.connect()
+    connection.query(`SELECT ID, Name, Vorname, Klasse
+                      FROM schueler
+                      WHERE Status = 2 AND Geloescht = "-" AND Gesperrt = "-"
+                      ORDER BY Klasse, Name ASC`,
+      (e, res) => {
+        schueler_lokal = res
+      })
+    connection.end()
   }
   }
   query() && lokal()
   query() && lokal()
   function diff (eins, zwei) {
   function diff (eins, zwei) {
@@ -74,8 +87,6 @@
         ...itm
         ...itm
     }));
     }));
   function update_db () {}
   function update_db () {}
-  let merged
-  $: merged = mergeById(schueler_lokal, schueler_entfernt)
-  let schueler_filter
+  // let schueler_filter
   $: schueler_filter = _.groupBy(merged.filter(s => s.Vorname.startsWith(suche) || s.Name.startsWith(suche)), 'Klasse')
   $: schueler_filter = _.groupBy(merged.filter(s => s.Vorname.startsWith(suche) || s.Name.startsWith(suche)), 'Klasse')
 </script>
 </script>