add daily soup

This commit is contained in:
Mateo Körber Belmonte
2025-02-25 15:17:45 +01:00
parent 0ae6025026
commit 682745a1f8
3 changed files with 68 additions and 24 deletions
+16 -8
View File
@@ -50,9 +50,13 @@ db.exec(`
date_title TEXT, date_title TEXT,
daily_main TEXT, daily_main TEXT,
daily_side TEXT, daily_side TEXT,
halal BOOLEAN, daily_halal BOOLEAN,
veggi BOOLEAN, daily_veggi BOOLEAN,
daily_price TEXT daily_price TEXT,
daily_soup TEXT,
soup_halal BOOLEAN,
soup_veggi BOOLEAN,
soup_price TEXT
) )
`); `);
@@ -112,8 +116,8 @@ app.post('/save-week-daily', (req, res) => {
const { week, entries } = req.body; const { week, entries } = req.body;
const insert = db.prepare(` const insert = db.prepare(`
INSERT OR REPLACE INTO daily_entries (date, week, day_index, date_title, daily_main, daily_side, halal, veggi, daily_price) INSERT OR REPLACE INTO daily_entries (date, week, day_index, date_title, daily_main, daily_side, daily_halal, daily_veggi, daily_price, daily_soup, soup_halal, soup_veggi, soup_price)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`); `);
const transaction = db.transaction((entries) => { const transaction = db.transaction((entries) => {
@@ -125,9 +129,13 @@ app.post('/save-week-daily', (req, res) => {
entry.dateTitle, entry.dateTitle,
entry.dailyMain, entry.dailyMain,
entry.dailySide, entry.dailySide,
entry.halal, entry.dailyHalal,
entry.veggi, entry.dailyVeggi,
entry.dailyPrice entry.dailyPrice,
entry.dailySoup,
entry.soupHalal,
entry.soupVeggi,
entry.soupPrice
); );
} }
}); });
+13 -5
View File
@@ -31,15 +31,23 @@
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
document.write(` document.write(`
<div id="dayForm${i}" class="day-form ${i === 0 ? 'active' : ''}"> <div id="dayForm${i}" class="day-form ${i === 0 ? 'active' : ''}">
<input type="text" class="input-field-20" name="dateTitle${i}" style="bottom: 60.5%; left: 13.4%" placeholder="Datum"> <input type="text" class="input-field-20" name="dateTitle${i}" style="bottom: 65.5%; left: 13.2%" placeholder="Datum">
<select class="input-field-19-h" name="halalVeggi${i}" style="bottom: 43.5%; left: 58%"> <select class="input-field-19-h" name="dailyHalalVeggi${i}" style="bottom: 56.5%; left: 41.5%">
<option value="" style="color:red;">----</option> <option value="" style="color:red;">----</option>
<option value="halal" style="color:#00B050;">„HALAL“</option> <option value="halal" style="color:#00B050;">„HALAL“</option>
<option value="veggi" style="color:#00B050;">„veggi“</option> <option value="veggi" style="color:#00B050;">„veggi“</option>
</select> </select>
<input type="text" class="input-field-19-b" name="dailyMain${i}" style="bottom: 30.5%; left: 13.4%" placeholder="Tagesgericht"> <input type="text" class="input-field-19-b" name="dailyMain${i}" style="bottom: 48%; left: 13.2%" placeholder="Tagesgericht">
<input type="text" class="input-field-19" name="dailySide${i}" style="bottom: 24%; left: 13.4%" placeholder="Beilage"> <input type="text" class="input-field-19" name="dailySide${i}" style="bottom: 41.2%; left: 13.2%" placeholder="Beilage">
<input type="text" class="input-field-14-i" name="dailyPrice${i}" style="bottom: 13.3%; left: 13.4%" placeholder="Preis"> <input type="text" class="input-field-14-i" name="dailyPrice${i}" style="bottom: 33.3%; left: 13.2%" placeholder="Preis">
<select class="input-field-19-h" name="soupHalalVeggi${i}" style="bottom: 22.7%; left: 32.5%">
<option value="" style="color:red;">----</option>
<option value="halal" style="color:#00B050;">„HALAL“</option>
<option value="veggi" style="color:#00B050;">„veggi“</option>
</select>
<input type="text" class="input-field-19-b" name="dailySoup${i}" style="bottom: 14.5%; left: 13.2%" placeholder="Tagessuppe">
<input type="text" class="input-field-14-i" name="soupPrice${i}" style="bottom: 6.3%; left: 13.2%" placeholder="Preis">
</div> </div>
`); `);
} }
+39 -11
View File
@@ -100,7 +100,8 @@ function saveWeek() {
currentDate.setDate(currentDate.getDate() + i); currentDate.setDate(currentDate.getDate() + i);
// Anpassen der Werte entsprechend der daily_entries Tabelle // Anpassen der Werte entsprechend der daily_entries Tabelle
const halalVeggiValue = document.querySelector(`select[name="halalVeggi${i}"]`).value; const dailyHalalVeggiValue = document.querySelector(`select[name="dailyHalalVeggi${i}"]`).value;
const soupHalalVeggiValue = document.querySelector(`select[name="soupHalalVeggi${i}"]`).value;
const entry = { const entry = {
date: currentDate.toISOString().split('T')[0], date: currentDate.toISOString().split('T')[0],
week: week, week: week,
@@ -108,14 +109,20 @@ function saveWeek() {
dateTitle: document.querySelector(`input[name="dateTitle${i}"]`).value, dateTitle: document.querySelector(`input[name="dateTitle${i}"]`).value,
dailyMain: document.querySelector(`input[name="dailyMain${i}"]`).value, dailyMain: document.querySelector(`input[name="dailyMain${i}"]`).value,
dailySide: document.querySelector(`input[name="dailySide${i}"]`).value, dailySide: document.querySelector(`input[name="dailySide${i}"]`).value,
halal: halalVeggiValue === 'halal' ? 1 : 0, dailyHalal: dailyHalalVeggiValue === 'halal' ? 1 : 0,
veggi: halalVeggiValue === 'veggi' ? 1 : 0, dailyVeggi: dailyHalalVeggiValue === 'veggi' ? 1 : 0,
dailyPrice: document.querySelector(`input[name="dailyPrice${i}"]`).value dailyPrice: document.querySelector(`input[name="dailyPrice${i}"]`).value,
dailySoup: document.querySelector(`input[name="dailySoup${i}"]`).value,
soupHalal: soupHalalVeggiValue === 'halal' ? 1 : 0,
soupVeggi: soupHalalVeggiValue === 'veggi' ? 1 : 0,
soupPrice: document.querySelector(`input[name="soupPrice${i}"]`).value
}; };
entries.push(entry); entries.push(entry);
} }
console.log('Saving week data:', { week, entries });
fetch('/save-week-daily', { fetch('/save-week-daily', {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -142,8 +149,11 @@ function loadWeekData(week) {
document.querySelector(`input[name="dateTitle${i}"]`).value = ''; document.querySelector(`input[name="dateTitle${i}"]`).value = '';
document.querySelector(`input[name="dailyMain${i}"]`).value = ''; document.querySelector(`input[name="dailyMain${i}"]`).value = '';
document.querySelector(`input[name="dailySide${i}"]`).value = ''; document.querySelector(`input[name="dailySide${i}"]`).value = '';
document.querySelector(`select[name="halalVeggi${i}"]`).value = ''; document.querySelector(`select[name="dailyHalalVeggi${i}"]`).value = '';
document.querySelector(`input[name="dailyPrice${i}"]`).value = ''; document.querySelector(`input[name="dailyPrice${i}"]`).value = '';
document.querySelector(`input[name="dailySoup${i}"]`).value = '';
document.querySelector(`select[name="soupHalalVeggi${i}"]`).value = '';
document.querySelector(`input[name="soupPrice${i}"]`).value = '';
} }
// Fill input fields with loaded data // Fill input fields with loaded data
@@ -152,18 +162,29 @@ function loadWeekData(week) {
const dayIndex = entry.day_index; const dayIndex = entry.day_index;
const dateTitleInput = document.querySelector(`input[name="dateTitle${dayIndex}"]`); const dateTitleInput = document.querySelector(`input[name="dateTitle${dayIndex}"]`);
const dailyPriceInput = document.querySelector(`input[name="dailyPrice${dayIndex}"]`); const dailyPriceInput = document.querySelector(`input[name="dailyPrice${dayIndex}"]`);
const halalVeggiSelect = document.querySelector(`select[name="halalVeggi${dayIndex}"]`); const dailyHalalVeggiSelect = document.querySelector(`select[name="dailyHalalVeggi${dayIndex}"]`);
const soupPriceInput = document.querySelector(`input[name="soupPrice${dayIndex}"]`);
const soupHalalVeggiSelect = document.querySelector(`select[name="soupHalalVeggi${dayIndex}"]`);
dateTitleInput.value = entry.date_title; dateTitleInput.value = entry.date_title;
document.querySelector(`input[name="dailyMain${dayIndex}"]`).value = entry.daily_main; document.querySelector(`input[name="dailyMain${dayIndex}"]`).value = entry.daily_main;
document.querySelector(`input[name="dailySide${dayIndex}"]`).value = entry.daily_side; document.querySelector(`input[name="dailySide${dayIndex}"]`).value = entry.daily_side;
dailyPriceInput.value = entry.daily_price; dailyPriceInput.value = entry.daily_price;
if (entry.halal) { document.querySelector(`input[name="dailySoup${dayIndex}"]`).value = entry.daily_soup;
halalVeggiSelect.value = 'halal'; soupPriceInput.value = entry.soup_price;
} else if (entry.veggi) { if (entry.daily_halal) {
halalVeggiSelect.value = 'veggi'; dailyHalalVeggiSelect.value = 'halal';
} else if (entry.daily_veggi) {
dailyHalalVeggiSelect.value = 'veggi';
} else { } else {
halalVeggiSelect.value = ''; dailyHalalVeggiSelect.value = '';
}
if (entry.soup_halal) {
soupHalalVeggiSelect.value = 'halal';
} else if (entry.soup_veggi) {
soupHalalVeggiSelect.value = 'veggi';
} else {
soupHalalVeggiSelect.value = '';
} }
// Automatically fill dateTitle if empty // Automatically fill dateTitle if empty
@@ -182,6 +203,9 @@ function loadWeekData(week) {
if (!dailyPriceInput.value) { if (!dailyPriceInput.value) {
dailyPriceInput.value = "6,50 € / 4,80 €"; dailyPriceInput.value = "6,50 € / 4,80 €";
} }
if (!soupPriceInput.value) {
soupPriceInput.value = "3,50 € / 2,50 €";
}
}); });
// Automatically fill dateTitle, dailyPrice if not in DB // Automatically fill dateTitle, dailyPrice if not in DB
@@ -189,6 +213,7 @@ function loadWeekData(week) {
if (!loadedDays.has(i)) { if (!loadedDays.has(i)) {
const dateTitleInput = document.querySelector(`input[name="dateTitle${i}"]`); const dateTitleInput = document.querySelector(`input[name="dateTitle${i}"]`);
const dailyPriceInput = document.querySelector(`input[name="dailyPrice${i}"]`); const dailyPriceInput = document.querySelector(`input[name="dailyPrice${i}"]`);
const soupPriceInput = document.querySelector(`input[name="soupPrice${i}"]`);
if (!dateTitleInput.value) { if (!dateTitleInput.value) {
const currentDate = new Date(currentWeek); const currentDate = new Date(currentWeek);
@@ -204,6 +229,9 @@ function loadWeekData(week) {
if (!dailyPriceInput.value) { if (!dailyPriceInput.value) {
dailyPriceInput.value = "6,50 € / 4,80 €"; dailyPriceInput.value = "6,50 € / 4,80 €";
} }
if (!soupPriceInput.value) {
soupPriceInput.value = "3,50 € / 2,50 €";
}
} }
} }
}) })