mirror of
https://github.com/Matewoo/pdf-writer.git
synced 2026-11-18 18:32:44 +01:00
add loadWeekData
This commit is contained in:
+70
-16
@@ -145,7 +145,8 @@
|
||||
<div id="dayForm0" class="day-form active">
|
||||
<input type="text" class="input-field-14" name="dateTitle0" style="bottom: 68%; left: 13.4%"
|
||||
placeholder="Datum">
|
||||
<input type="checkbox" class="input-field-13" name="halal0" style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="checkbox" class="input-field-13" name="halal0"
|
||||
style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="text" class="input-field-12" name="meatMain0" style="bottom: 55%; left: 14%"
|
||||
placeholder="Fleischgericht">
|
||||
<input type="text" class="input-field-12" name="meatSide0" style="bottom: 50.2%; left: 14%"
|
||||
@@ -156,13 +157,14 @@
|
||||
placeholder="Veggie">
|
||||
<input type="text" class="input-field-12" name="veggiSide0" style="bottom: 20.8%; left: 14%"
|
||||
placeholder="Beilage">
|
||||
<input type="text" class="input-field-10" name="veggiPrice0" style="bottom: 15.5%; left: 14%"
|
||||
placeholder="Preis">
|
||||
<input type="text" class="input-field-10" name="veggiPrice0"
|
||||
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
||||
</div>
|
||||
<div id="dayForm1" class="day-form">
|
||||
<input type="text" class="input-field-14" name="dateTitle1" style="bottom: 68%; left: 13.4%"
|
||||
placeholder="Datum">
|
||||
<input type="checkbox" class="input-field-13" name="halal1" style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="checkbox" class="input-field-13" name="halal1"
|
||||
style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="text" class="input-field-12" name="meatMain1" style="bottom: 55%; left: 14%"
|
||||
placeholder="Fleischgericht">
|
||||
<input type="text" class="input-field-12" name="meatSide1" style="bottom: 50.2%; left: 14%"
|
||||
@@ -173,13 +175,14 @@
|
||||
placeholder="Veggie">
|
||||
<input type="text" class="input-field-12" name="veggiSide1" style="bottom: 20.8%; left: 14%"
|
||||
placeholder="Beilage">
|
||||
<input type="text" class="input-field-10" name="veggiPrice1" style="bottom: 15.5%; left: 14%"
|
||||
placeholder="Preis">
|
||||
<input type="text" class="input-field-10" name="veggiPrice1"
|
||||
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
||||
</div>
|
||||
<div id="dayForm2" class="day-form">
|
||||
<input type="text" class="input-field-14" name="dateTitle2" style="bottom: 68%; left: 13.4%"
|
||||
placeholder="Datum">
|
||||
<input type="checkbox" class="input-field-13" name="halal2" style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="checkbox" class="input-field-13" name="halal2"
|
||||
style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="text" class="input-field-12" name="meatMain2" style="bottom: 55%; left: 14%"
|
||||
placeholder="Fleischgericht">
|
||||
<input type="text" class="input-field-12" name="meatSide2" style="bottom: 50.2%; left: 14%"
|
||||
@@ -190,13 +193,14 @@
|
||||
placeholder="Veggie">
|
||||
<input type="text" class="input-field-12" name="veggiSide2" style="bottom: 20.8%; left: 14%"
|
||||
placeholder="Beilage">
|
||||
<input type="text" class="input-field-10" name="veggiPrice2" style="bottom: 15.5%; left: 14%"
|
||||
placeholder="Preis">
|
||||
<input type="text" class="input-field-10" name="veggiPrice2"
|
||||
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
||||
</div>
|
||||
<div id="dayForm3" class="day-form">
|
||||
<input type="text" class="input-field-14" name="dateTitle3" style="bottom: 68%; left: 13.4%"
|
||||
placeholder="Datum">
|
||||
<input type="checkbox" class="input-field-13" name="halal3" style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="checkbox" class="input-field-13" name="halal3"
|
||||
style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="text" class="input-field-12" name="meatMain3" style="bottom: 55%; left: 14%"
|
||||
placeholder="Fleischgericht">
|
||||
<input type="text" class="input-field-12" name="meatSide3" style="bottom: 50.2%; left: 14%"
|
||||
@@ -207,13 +211,14 @@
|
||||
placeholder="Veggie">
|
||||
<input type="text" class="input-field-12" name="veggiSide3" style="bottom: 20.8%; left: 14%"
|
||||
placeholder="Beilage">
|
||||
<input type="text" class="input-field-10" name="veggiPrice3" style="bottom: 15.5%; left: 14%"
|
||||
placeholder="Preis">
|
||||
<input type="text" class="input-field-10" name="veggiPrice3"
|
||||
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
||||
</div>
|
||||
<div id="dayForm4" class="day-form">
|
||||
<input type="text" class="input-field-14" name="dateTitle4" style="bottom: 68%; left: 13.4%"
|
||||
placeholder="Datum">
|
||||
<input type="checkbox" class="input-field-13" name="halal4" style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="checkbox" class="input-field-13" name="halal4"
|
||||
style="bottom: 62.2%; left: 22.1%">
|
||||
<input type="text" class="input-field-12" name="meatMain4" style="bottom: 55%; left: 14%"
|
||||
placeholder="Fleischgericht">
|
||||
<input type="text" class="input-field-12" name="meatSide4" style="bottom: 50.2%; left: 14%"
|
||||
@@ -224,8 +229,8 @@
|
||||
placeholder="Veggie">
|
||||
<input type="text" class="input-field-12" name="veggiSide4" style="bottom: 20.8%; left: 14%"
|
||||
placeholder="Beilage">
|
||||
<input type="text" class="input-field-10" name="veggiPrice4" style="bottom: 15.5%; left: 14%"
|
||||
placeholder="Preis">
|
||||
<input type="text" class="input-field-10" name="veggiPrice4"
|
||||
style="bottom: 15.5%; left: 14%" placeholder="Preis">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -313,6 +318,10 @@
|
||||
currentDayIndex = 0; // Reset to Monday
|
||||
updateWeekDisplay();
|
||||
updateDayDisplay();
|
||||
const weekNumber = getWeekNumber(currentWeek);
|
||||
const year = currentWeek.getFullYear();
|
||||
const week = `KW${weekNumber} ${year}`;
|
||||
loadWeekData(week);
|
||||
}
|
||||
|
||||
function nextWeek() {
|
||||
@@ -320,10 +329,16 @@
|
||||
currentDayIndex = 0; // Reset to Monday
|
||||
updateWeekDisplay();
|
||||
updateDayDisplay();
|
||||
const weekNumber = getWeekNumber(currentWeek);
|
||||
const year = currentWeek.getFullYear();
|
||||
const week = `KW${weekNumber} ${year}`;
|
||||
loadWeekData(week);
|
||||
}
|
||||
|
||||
function saveWeek() {
|
||||
const weekNumber = getWeekNumber(currentWeek);
|
||||
const year = currentWeek.getFullYear();
|
||||
const week = `KW${weekNumber} ${year}`;
|
||||
const entries = [];
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
@@ -351,7 +366,7 @@
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ weekNumber, entries })
|
||||
body: JSON.stringify({ week, entries })
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
@@ -363,9 +378,48 @@
|
||||
});
|
||||
}
|
||||
|
||||
function loadWeekData(week) {
|
||||
fetch(`/load-week?week=${encodeURIComponent(week)}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Clear all input fields
|
||||
for (let i = 0; i < 5; i++) {
|
||||
document.querySelector(`input[name="dateTitle${i}"]`).value = '';
|
||||
document.querySelector(`input[name="meatMain${i}"]`).value = '';
|
||||
document.querySelector(`input[name="meatSide${i}"]`).value = '';
|
||||
document.querySelector(`input[name="halal${i}"]`).checked = false;
|
||||
document.querySelector(`input[name="meatPrice${i}"]`).value = '';
|
||||
document.querySelector(`input[name="veggiMain${i}"]`).value = '';
|
||||
document.querySelector(`input[name="veggiSide${i}"]`).value = '';
|
||||
document.querySelector(`input[name="veggiPrice${i}"]`).value = '';
|
||||
}
|
||||
|
||||
// Fill input fields with loaded data
|
||||
data.forEach(entry => {
|
||||
const dayIndex = entry.day_index;
|
||||
document.querySelector(`input[name="dateTitle${dayIndex}"]`).value = entry.date_title;
|
||||
document.querySelector(`input[name="meatMain${dayIndex}"]`).value = entry.meat_main;
|
||||
document.querySelector(`input[name="meatSide${dayIndex}"]`).value = entry.meat_side;
|
||||
document.querySelector(`input[name="halal${dayIndex}"]`).checked = entry.halal === 1;
|
||||
document.querySelector(`input[name="meatPrice${dayIndex}"]`).value = entry.meat_price;
|
||||
document.querySelector(`input[name="veggiMain${dayIndex}"]`).value = entry.veggi_main;
|
||||
document.querySelector(`input[name="veggiSide${dayIndex}"]`).value = entry.veggi_side;
|
||||
document.querySelector(`input[name="veggiPrice${dayIndex}"]`).value = entry.veggi_price;
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error loading week:', error);
|
||||
alert('Fehler beim Laden der Woche');
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize the display when page loads
|
||||
updateWeekDisplay();
|
||||
updateDayDisplay();
|
||||
const weekNumber = getWeekNumber(currentWeek);
|
||||
const year = currentWeek.getFullYear();
|
||||
const week = `KW${weekNumber} ${year}`;
|
||||
loadWeekData(week);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ const db = new Database('menu.db');
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS menu_entries (
|
||||
date TEXT PRIMARY KEY,
|
||||
week_number INTEGER,
|
||||
week TEXT,
|
||||
day_index INTEGER,
|
||||
date_title TEXT,
|
||||
meat_main TEXT,
|
||||
@@ -40,10 +40,10 @@ app.get('/', (req, res) => {
|
||||
});
|
||||
|
||||
app.post('/save-week', (req, res) => {
|
||||
const { weekNumber, entries } = req.body;
|
||||
const { week, entries } = req.body;
|
||||
|
||||
const insert = db.prepare(`
|
||||
INSERT OR REPLACE INTO menu_entries (date, week_number, day_index, date_title, meat_main, meat_side, halal, meat_price, veggi_main, veggi_side, veggi_price)
|
||||
INSERT OR REPLACE INTO menu_entries (date, week, day_index, date_title, meat_main, meat_side, halal, meat_price, veggi_main, veggi_side, veggi_price)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
|
||||
@@ -51,7 +51,7 @@ app.post('/save-week', (req, res) => {
|
||||
for (const entry of entries) {
|
||||
insert.run(
|
||||
entry.date,
|
||||
weekNumber,
|
||||
week,
|
||||
entry.dayIndex,
|
||||
entry.dateTitle,
|
||||
entry.meatMain,
|
||||
@@ -74,6 +74,18 @@ app.post('/save-week', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/load-week', (req, res) => {
|
||||
const { week } = req.query;
|
||||
|
||||
try {
|
||||
const entries = db.prepare('SELECT * FROM menu_entries WHERE week = ?').all(week);
|
||||
res.json(entries);
|
||||
} catch (error) {
|
||||
console.error('Error loading week:', error);
|
||||
res.status(500).json({ error: 'Fehler beim Laden der Woche' });
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(4000, () => {
|
||||
console.log('Server is listening on port 4000');
|
||||
});
|
||||
Reference in New Issue
Block a user