projektwoche-uebersicht.svelte 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <div class="field is-horizontal">
  2. <div class="field-body">
  3. <div class="field">
  4. <p class="control is-expanded has-icons-left">
  5. <label class="label is-small">Beginn der Prowo-Wahl</label>
  6. <input type="datetime-local" bind:value={wahlbeginn_prowo} class="input is-small">
  7. </p>
  8. </div>
  9. <div class="field">
  10. <p class="control is-expanded has-icons-left">
  11. <label class="label is-small">Ende der Prowo-Wahl</label>
  12. <input type="datetime-local" bind:value={wahlende_prowo} class="input is-small">
  13. </p>
  14. </div>
  15. </div>
  16. </div>
  17. <div class="field">
  18. <p class="control is-expanded has-icons-left">
  19. <label class="label is-small">Thema der Prowo</label>
  20. <input type="text" bind:value={thema_prowo} class="input is-expanded is-small">
  21. </p>
  22. </div>
  23. <div class="field">
  24. <button class="is-small button is-default" on:click={changeDate}> Wahlzeitraum ändern </button>
  25. {#if check}<span class="tag is-success">✓</span>{/if}
  26. </div>
  27. <script>
  28. export let schueler, privat, einstellungen
  29. let check
  30. const { Pool } = R('pg')
  31. const pool = new Pool({ connectionString: privat.mein_bk_db})
  32. $: wahlbeginn_prowo = wahlbeginn_prowo || setDateTime(einstellungen.wahlbeginn_prowo)
  33. $: wahlende_prowo = wahlende_prowo || setDateTime(einstellungen.wahlende_prowo)
  34. $: thema_prowo = thema_prowo || einstellungen.thema_prowo || ''
  35. const changeDate = async _ => {
  36. const query = `UPDATE einstellungen
  37. SET wahlbeginn_prowo=$1, wahlende_prowo=$2, thema_prowo=$3
  38. RETURNING wahlbeginn_prowo, wahlende_prowo, thema_prowo`
  39. const values=[new Date(wahlbeginn_prowo), new Date(wahlende_prowo), thema_prowo]
  40. try {
  41. const res = await pool.query(query, values)
  42. const data = res.rows[0]
  43. einstellungen.wahlbeginn_prowo = data.wahlbeginn_prowo
  44. einstellungen.wahlende_prowo = data.wahlende_prowo
  45. einstellungen.thema_prowo = data.thema_prowo
  46. einstellungen = einstellungen
  47. check = true
  48. } catch(err) {
  49. console.log(err.stack)
  50. }
  51. }
  52. function setDateTime (date) {
  53. if (!date) return
  54. const d = new Date(date)
  55. return d.toISOString().replace('Z','')
  56. };
  57. </script>