From 851334846deef4e4d51646aa2b17d307131be3ec Mon Sep 17 00:00:00 2001 From: Samuel Zielke Date: Thu, 10 Oct 2024 13:06:29 +0200 Subject: [PATCH] ADD FEATURE: Bibelstudien eintragen --- app/static/app/js/dbcontrol.js | 26 ++++++++++++------- app/static/app/js/home.js | 36 ++++++++++++++++++++++++-- app/static/app/js/welcomeControl.js | 2 +- app/templates/app/base.html | 39 +++++------------------------ app/templates/app/home.html | 4 +-- 5 files changed, 60 insertions(+), 47 deletions(-) diff --git a/app/static/app/js/dbcontrol.js b/app/static/app/js/dbcontrol.js index 827c050..84fc104 100644 --- a/app/static/app/js/dbcontrol.js +++ b/app/static/app/js/dbcontrol.js @@ -22,6 +22,11 @@ function initDB() { autoIncrement: true, }); + const settingsT = db.createObjectStore('settings', { + keyPath: 'id', + autoIncrement: true, + }) + // Spalten definieren store.createIndex('createdate', 'createdate', { unique: false }); store.createIndex('date', 'date', { unique: false }); @@ -29,6 +34,9 @@ function initDB() { store.createIndex('type', 'type', { unique: false }); store.createIndex('status', 'status', { unique: false }); store.createIndex('sondertext', 'sondertext', { unique: false }); + + settingsT.createIndex('SettingsID', 'SettingsID', { unique: false }); + settingsT.createIndex('SettingsValue', 'SettingsValue', { unique: false }); }; request.onsuccess = function (event) { @@ -44,10 +52,10 @@ function initDB() { } // Neuer Eintrag in die IndexedDB -function addEntry(data) { +function addEntry(data, table) { return new Promise((resolve, reject) => { - const transaction = db.transaction(['hours'], 'readwrite'); - const store = transaction.objectStore('hours'); + const transaction = db.transaction([table], 'readwrite'); + const store = transaction.objectStore(table); data.createdate = new Date(); const request = store.add(data); @@ -63,10 +71,10 @@ function addEntry(data) { } // Eintrag aktualisieren -function updateEntry(id, updatedData) { +function updateEntry(id, table, updatedData) { return new Promise((resolve, reject) => { - const transaction = db.transaction(['hours'], 'readwrite'); - const store = transaction.objectStore('hours'); + const transaction = db.transaction([table], 'readwrite'); + const store = transaction.objectStore(table); const getRequest = store.get(id); @@ -111,10 +119,10 @@ function deleteEntry(id) { } // Einträge abrufen -function getAllEntries() { +function getAllEntries(table) { return new Promise((resolve, reject) => { - const transaction = db.transaction(['hours'], 'readonly'); - const store = transaction.objectStore('hours'); + const transaction = db.transaction([table], 'readonly'); + const store = transaction.objectStore(table); const request = store.getAll(); diff --git a/app/static/app/js/home.js b/app/static/app/js/home.js index 4d2addb..808cfe7 100644 --- a/app/static/app/js/home.js +++ b/app/static/app/js/home.js @@ -2,6 +2,7 @@ const hours = document.getElementById('stunden'); const mins = document.getElementById('minuten'); const NewEntryButton = document.getElementById('newEntrySubmitButton') +const SETStudySaveButton = document.getElementById('SETStudySaveButton') var allowToSend = false; @@ -66,7 +67,7 @@ NewEntryButton.addEventListener('click', () => { sondertext: document.getElementById('sonstigesInput').value, } - addEntry(newEntryData).then((id) => { + addEntry(newEntryData, 'hours').then((id) => { // console.log('Eintrag hinzugefügt mit ID:', id); location.reload() }); @@ -78,6 +79,37 @@ NewEntryButton.addEventListener('click', () => { } }) +// SETTINGS ACTIONS + +SETStudySaveButton.addEventListener('click', () => { + + var actualSettings = 0 + + getAllEntries('settings') + .then(function(result) { + const SETDBData = result.find(element => element.SettingsID === 1) + actualSettingsEntryID = SETDBData ? SETDBData.id : undefined; + actualSettings = SETDBData ? SETDBData.SettingsValue : undefined; + + // AKTUELLE DATEN AUS FELD ÜBERNHEMEN + var ActInput = document.getElementById('studysinput').value + + const StudySettingsData = { + SettingsID: 1, + SettingsValue: parseInt(ActInput), + } + + // ÜBERPRÜFEN OB EIN EINTRAG MTI DER SETTINGS ID VORHANDEN IST - WENN JA DANN UPDATE WENN NEIN DANN NEUEN ERSTELLEN + if ( actualSettings != undefined ) { + updateEntry(actualSettingsEntryID, 'settings', StudySettingsData) + } else { + addEntry(StudySettingsData, 'settings') + } + }) + + SETStudySaveButton.classList.add('d-none') +}) + async function getActualDataAndFillView() { try { @@ -225,7 +257,7 @@ document.getElementById('editEntrySubmitButton').addEventListener('click', () => sonstigesText.style.display = 'none'; } - updateEntry(parseInt(ToEditID), { + updateEntry(parseInt(ToEditID), 'hours', { date: document.getElementById('editDatum').value, duration: (parseInt(edithours.value)*60) + parseInt(editMins.value), type: type, diff --git a/app/static/app/js/welcomeControl.js b/app/static/app/js/welcomeControl.js index ad2e5dd..42963c8 100644 --- a/app/static/app/js/welcomeControl.js +++ b/app/static/app/js/welcomeControl.js @@ -4,7 +4,7 @@ function setAllOk() { document.getElementById('welcome_content').style.display = 'none'; document.getElementById('dashboard').classList.remove('d-none'); document.getElementById('refresh_icon').classList.remove('d-none') - // document.getElementById('settings_icon').classList.remove('d-none') + document.getElementById('settings_icon').classList.remove('d-none') } document.getElementById("allOk").addEventListener('click', function(){ diff --git a/app/templates/app/base.html b/app/templates/app/base.html index 7acb362..9979acc 100644 --- a/app/templates/app/base.html +++ b/app/templates/app/base.html @@ -24,50 +24,23 @@ -
- + Settings SettingsClose - -->
- - -
Bericht
+
Einstellungen
  • Bibelstudien: - + +
  • - -
+
- diff --git a/app/templates/app/home.html b/app/templates/app/home.html index 2b77135..69a691d 100644 --- a/app/templates/app/home.html +++ b/app/templates/app/home.html @@ -254,7 +254,7 @@ /* Verarbeitung der Einstellungen */ - {{/* const settingsIcon = document.getElementById('settings_icon') + const settingsIcon = document.getElementById('settings_icon') settingsIcon.addEventListener('click', () => { document.getElementById('header-bg-block').classList.replace('HeaderDefaultHeightbg', 'openSettingsbg') document.getElementById('header-bg-block').classList.replace('closeSettingsbg', 'openSettingsbg') @@ -270,7 +270,7 @@ document.getElementById('settings_icon').classList.remove('d-none'); document.getElementById('settings_close_icon').classList.add('d-none'); document.getElementById('refresh_icon').style.opacity = 1; - }) */}} + })