burningTyger 5 anni fa
parent
commit
06af98a437

+ 156 - 0
components/einstellungen.svelte

@@ -0,0 +1,156 @@
+<div class="box">
+  <h3 class="title">Projektwoche</h3>
+  <div class="field">
+    <label class="checkbox">
+      <input type="checkbox" bind:checked={prowo_anzeigen}>
+      Projektwochen-Seite anzeigen
+    </label>
+  </div>
+  <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_prowo}> Wahlzeitraum ändern </button>
+    {#if check_prowo}<span class="tag is-success">✓</span>{/if}
+  </div>
+</div>
+<div class="box">
+  <h3 class="title">SV-Wahl</h3>
+  <div class="field">
+    <label class="checkbox">
+      <input type="checkbox" bind:checked={sv_anzeigen}>
+      SV-Seite anzeigen
+    </label>
+  </div>
+  <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_sv}> Wahlzeitraum ändern </button>
+    {#if check_sv}<span class="tag is-success">✓</span>{/if}
+  </div>
+</div>
+<div class="box">
+  <h3 class="title">Datenbank zurücksetzen</h3>
+  <div class="field">
+    <button class="button is-danger" on:click={db_reset}>Die Datenbank vollständig zurücksetzen</button>
+    {#if check_db}<span class="tag is-success">✓</span>{/if}
+  </div>
+</div>
+
+<script>
+  export let schueler, privat, einstellungen = {}
+  let check_sv, check_prowo, check_db
+  const { Pool } = R('pg')
+  const pool = new Pool({ connectionString: privat.mein_bk_db})
+  let sv_anzeigen      = einstellungen.sv_anzeigen
+  let prowo_anzeigen   = einstellungen.prowo_anzeigen
+  let wahlbeginn_prowo = setDateTime(einstellungen.wahlbeginn_prowo)
+  let wahlende_prowo   = setDateTime(einstellungen.wahlende_prowo)
+  let thema_prowo      = einstellungen.thema_prowo || ''
+  let wahlbeginn_sv    = setDateTime(einstellungen.wahlbeginn_sv)
+  let wahlende_sv      = setDateTime(einstellungen.wahlende_sv)
+  let erste_schuko     = setDateTime(einstellungen.erste_schuko)
+  $: pool.query(`UPDATE einstellungen SET prowo_anzeigen=$1`, [prowo_anzeigen])
+  $: pool.query(`UPDATE einstellungen SET sv_anzeigen=$1`, [sv_anzeigen])
+  const changeDate_prowo = 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]
+      console.log(res)
+      einstellungen.wahlbeginn_prowo = data.wahlbeginn_prowo
+      einstellungen.wahlende_prowo = data.wahlende_prowo
+      einstellungen.thema_prowo = data.thema_prowo
+      einstellungen = einstellungen
+      check_prowo = true
+    } catch(err) {
+      console.log(err.stack)
+    }
+  }
+  const changeDate_sv = 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_sv = true
+    } catch(err) {
+      console.log(err.stack)
+    }
+  }
+  const db_reset = async _ => {
+    const query = `BEGIN;
+                     DELETE FROM schueler;
+                     DELETE FROM wahlen;
+                     DELETE FROM klassen;
+                     DELETE FROM lehrer;
+                     DELETE FROM sprecher;
+                     DELETE FROM schuko;
+                     DELETE FROM verbindungslehrer;
+                     DELETE FROM wlan;
+                     DELETE FROM infos;
+                   COMMIT;`
+                    //  DELETE FROM projekte,
+                    //  DELETE FROM einstellungen,
+    try {
+      const res = await pool.query(query)
+      check_db = true
+    } catch(err) {
+      console.log(err.stack)
+    }
+  }
+
+  function setDateTime (date) {
+    if (!date) return
+    const d = new Date(date)
+    return d.toISOString().replace('Z','')
+  };
+</script>

+ 0 - 60
components/projektwoche-uebersicht.svelte

@@ -1,60 +0,0 @@
-<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})
-  let wahlbeginn_prowo = setDateTime(einstellungen.wahlbeginn_prowo)
-  let wahlende_prowo = setDateTime(einstellungen.wahlende_prowo)
-  let 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]
-      console.log(res)
-      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>

+ 0 - 53
components/svwahl.svelte

@@ -1,30 +1,3 @@
-<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]}
@@ -56,29 +29,8 @@
 </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) => {
     console.log(s)
     const query = `INSERT INTO schueler(id, ${art}, vorname, klasse)
@@ -98,9 +50,4 @@
       console.log(err.stack)
     }
   }
-  function setDateTime (date) {
-    if (!date) return
-    const d = new Date(date)
-    return d.toISOString().replace('Z','')
-  };
 </script>

+ 35 - 8
Übersicht.svelte

@@ -16,11 +16,11 @@
   <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 === 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>
+        <li class:is-active={active === Vouchers} on:click={() => active=Vouchers}>WLAN</li>
+        <li class:is-active={active === ProjektwocheSchueler} on:click={() => active=ProjektwocheSchueler}>Projektwoche Schüler</li>
+        <li class:is-active={active === ProjektwocheLehrer} on:click={() => active=ProjektwocheLehrer}>Projektwoche Lehrer</li>
+        <li class:is-active={active === SVWahl} on:click={() => active=SVWahl}>SV-Wahl</li>
+        <li class:is-active={active === Einstellungen} on:click={() => active=Einstellungen}>Einstellungen</li>
       </ul>
     </div>
     <svelte:component this={active} schueler={schueler_filter} {privat} {einstellungen} {knexConfig}/>
@@ -29,20 +29,40 @@
 
 <style>
   @import 'node_modules/bulma/css/bulma.css';
+  .tabs li.is-active {
+    border-bottom-color: #3273dc;
+    color: #3273dc;
+  }
+  .tabs li:hover {
+    border-bottom-color: #3273dc;
+  }
+  .tabs li {
+    align-items: center;
+    border-bottom-color: #dbdbdb;
+    border-bottom-style: solid;
+    border-bottom-width: 1px;
+    color: #4a4a4a;
+    display: flex;
+    justify-content: center;
+    margin-bottom: -1px;
+    padding: 0.5em 1em;
+    vertical-align: top;
+    cursor: pointer;
+    text-decoration: none;
+  }
 </style>
 
 <script>
   import Vouchers from './components/vouchers.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'
+  import Einstellungen from './components/einstellungen.svelte'
   export let schueler, knexConfig, privat
   let active
   let suche = ''
 
   const { Pool } = R('pg')
-  const _ = R('lodash')
   const mysql = R('mysql')
   let schueler_entfernt = [], schueler_lokal = []
   let einstellungen
@@ -74,9 +94,16 @@
         schueler_lokal = res
       })
   }
+const groupBy = (arr, id) => arr.reduce(
+  (entryMap, f) => {
+    const fx = id.split('.').reduce((p,c)=>p&&p[c]||null, f)
+    return entryMap.set(fx, [...entryMap.get(fx)||[], f])
+  },
+  new Map()
+)
   hole_lokale_schueler()
   $: merged = schueler_lokal.map(itm => ({
       ...schueler_entfernt.find((item) => (item.id === itm.id) && item),
       ...itm}))
-  $: schueler_filter = _.groupBy(merged.filter(s => s.vollname.includes(suche.toLowerCase())), 'Klasse')
+  $: schueler_filter = Object.fromEntries(groupBy(merged.filter(s => s.vollname.includes(suche.toLowerCase())), 'Klasse'))
 </script>