implement dailyDish generator

This commit is contained in:
Mateo Körber Belmonte
2025-02-19 22:55:11 +01:00
parent d179de6147
commit 69ccbd3ee1
7 changed files with 444 additions and 7 deletions
+61
View File
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Speiseplan Generator</title>
<meta name="google" content="notranslate">
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<div class="container">
<div class="week-controls">
<button onclick="previousWeek()">&lt; Vorherige Woche</button>
<span id="currentWeek"></span>
<button onclick="nextWeek()">Nächste Woche &gt;</button>
</div>
<div class="day-controls">
<button onclick="previousDay()">&lt; Vorheriger Tag</button>
<span id="currentDay"></span>
<button onclick="nextDay()">Nächster Tag &gt;</button>
</div>
<div class="template-container">
<div class="template-page dailyDish-bg">
<div class="form-overlay">
<form id="menuForm">
<script>
for (let i = 0; i < 5; i++) {
document.write(`
<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">
<select class="input-field-19-h" name="halalVeggi${i}" style="bottom: 43.5%; left: 58%">
<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="dailyMain${i}" style="bottom: 30.5%; left: 13.4%" 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-14-i" name="dailyPrice${i}" style="bottom: 13.3%; left: 13.4%" placeholder="Preis">
</div>
`);
}
</script>
</form>
</div>
</div>
</div>
<div class="bottom-controls">
<button onclick="saveWeek()">Woche speichern</button>
<button onclick="generatePDF()">PDF generieren</button>
</div>
</div>
<script src="../src/dailyDish.js"></script>
</body>
</html>
@@ -5,7 +5,7 @@
<meta charset="UTF-8">
<title>Speiseplan Generator</title>
<meta name="google" content="notranslate">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
@@ -23,7 +23,7 @@
</div>
<div class="template-container">
<div class="template-page">
<div class="template-page menu-bg">
<div class="form-overlay">
<form id="menuForm">
<script>
@@ -56,7 +56,7 @@
</div>
</div>
<script src="src/menu.js"></script>
<script src="../src/menu.js"></script>
</body>
View File
+250
View File
@@ -0,0 +1,250 @@
let currentWeek = new Date();
currentWeek.setDate(currentWeek.getDate() - currentWeek.getDay() + 1); // Set to Monday
let currentDayIndex = 0; // 0 = Monday, 4 = Friday
function getWeekNumber(date) {
const target = new Date(date.valueOf());
const dayNumber = (date.getDay() + 6) % 7;
target.setDate(target.getDate() - dayNumber + 3);
const firstThursday = target.valueOf();
target.setMonth(0, 1);
if (target.getDay() !== 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - target) / 604800000);
}
function updateWeekDisplay() {
const startOfWeek = new Date(currentWeek);
const endOfWeek = new Date(currentWeek);
endOfWeek.setDate(startOfWeek.getDate() + 4); // Friday
const weekNumber = getWeekNumber(startOfWeek);
const startDate = startOfWeek.toLocaleDateString('de-DE', {
day: '2-digit',
month: '2-digit',
year: '2-digit'
});
const endDate = endOfWeek.toLocaleDateString('de-DE', {
day: '2-digit',
month: '2-digit',
year: '2-digit'
});
document.getElementById('currentWeek').textContent =
`KW${weekNumber} ${startDate} - ${endDate}`;
}
function updateDayDisplay() {
const currentDate = new Date(currentWeek);
currentDate.setDate(currentDate.getDate() + currentDayIndex);
const dayName = currentDate.toLocaleDateString('de-DE', { weekday: 'long' });
const dateStr = currentDate.toLocaleDateString('de-DE', {
day: '2-digit',
month: '2-digit',
year: '2-digit'
});
document.getElementById('currentDay').textContent = `${dayName} ${dateStr}`;
// Show the correct form for the current day
document.querySelectorAll('.day-form').forEach((form, index) => {
form.classList.toggle('active', index === currentDayIndex);
});
}
function previousDay() {
if (currentDayIndex > 0) {
currentDayIndex--;
updateDayDisplay();
}
}
function nextDay() {
if (currentDayIndex < 4) {
currentDayIndex++;
updateDayDisplay();
}
}
function previousWeek() {
currentWeek.setDate(currentWeek.getDate() - 7);
currentDayIndex = 0; // Reset to Monday
updateWeekDisplay();
updateDayDisplay();
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber} ${year}`;
loadWeekData(week);
}
function nextWeek() {
currentWeek.setDate(currentWeek.getDate() + 7);
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++) {
const currentDate = new Date(currentWeek);
currentDate.setDate(currentDate.getDate() + i);
// Anpassen der Werte entsprechend der daily_entries Tabelle
const halalVeggiValue = document.querySelector(`select[name="halalVeggi${i}"]`).value;
const entry = {
date: currentDate.toISOString().split('T')[0],
week: week,
dayIndex: i,
dateTitle: document.querySelector(`input[name="dateTitle${i}"]`).value,
dailyMain: document.querySelector(`input[name="dailyMain${i}"]`).value,
dailySide: document.querySelector(`input[name="dailySide${i}"]`).value,
halal: halalVeggiValue === 'halal' ? 1 : 0,
veggi: halalVeggiValue === 'veggi' ? 1 : 0,
dailyPrice: document.querySelector(`input[name="dailyPrice${i}"]`).value
};
entries.push(entry);
}
fetch('/save-week-daily', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ week, entries })
})
.then(response => response.json())
.then(data => {
alert(data.message);
})
.catch(error => {
console.error('Error saving week:', error);
alert('Fehler beim Speichern der Woche');
});
}
function loadWeekData(week) {
fetch(`/load-week-daily?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="dailyMain${i}"]`).value = '';
document.querySelector(`input[name="dailySide${i}"]`).value = '';
document.querySelector(`select[name="halalVeggi${i}"]`).value = '';
document.querySelector(`input[name="dailyPrice${i}"]`).value = '';
}
// Fill input fields with loaded data
const loadedDays = new Set(data.map(entry => entry.day_index));
data.forEach(entry => {
const dayIndex = entry.day_index;
const dateTitleInput = document.querySelector(`input[name="dateTitle${dayIndex}"]`);
const dailyPriceInput = document.querySelector(`input[name="dailyPrice${dayIndex}"]`);
const halalVeggiSelect = document.querySelector(`select[name="halalVeggi${dayIndex}"]`);
dateTitleInput.value = entry.date_title;
document.querySelector(`input[name="dailyMain${dayIndex}"]`).value = entry.daily_main;
document.querySelector(`input[name="dailySide${dayIndex}"]`).value = entry.daily_side;
dailyPriceInput.value = entry.daily_price;
if (entry.halal) {
halalVeggiSelect.value = 'halal';
} else if (entry.veggi) {
halalVeggiSelect.value = 'veggi';
} else {
halalVeggiSelect.value = '';
}
// Automatically fill dateTitle if empty
if (!dateTitleInput.value) {
const currentDate = new Date(currentWeek);
currentDate.setDate(currentDate.getDate() + dayIndex);
const dayName = currentDate.toLocaleDateString('de-DE', { weekday: 'long' }).toUpperCase();
const dateStr = currentDate.toLocaleDateString('de-DE', {
day: '2-digit',
month: 'long'
}).toUpperCase();
dateTitleInput.value = `${dayName}, ${dateStr}`;
}
// Automatically fill dailyPrice if empty
if (!dailyPriceInput.value) {
dailyPriceInput.value = "6,50 € / 4,80 €";
}
});
// Automatically fill dateTitle, dailyPrice if not in DB
for (let i = 0; i < 5; i++) {
if (!loadedDays.has(i)) {
const dateTitleInput = document.querySelector(`input[name="dateTitle${i}"]`);
const dailyPriceInput = document.querySelector(`input[name="dailyPrice${i}"]`);
if (!dateTitleInput.value) {
const currentDate = new Date(currentWeek);
currentDate.setDate(currentDate.getDate() + i);
const dayName = currentDate.toLocaleDateString('de-DE', { weekday: 'long' }).toUpperCase();
const dateStr = currentDate.toLocaleDateString('de-DE', {
day: '2-digit',
month: 'long'
}).toUpperCase();
dateTitleInput.value = `${dayName}, ${dateStr}`;
}
if (!dailyPriceInput.value) {
dailyPriceInput.value = "6,50 € / 4,80 €";
}
}
}
})
.catch(error => {
console.error('Error loading week:', error);
alert('Fehler beim Laden der Woche.\n\nBitte kontaktieren Sie Ihren zuständigen Systemadministrator.');
});
}
function generatePDF() {
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber}-${year}`;
fetch('/generate-pdf', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ week })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('PDF erfolgreich generiert');
} else {
const errorMessage = data.error || 'Unbekannter Fehler';
alert(`Fehler beim Generieren der PDF:\n\n${errorMessage}\n\nBitte kontaktieren Sie Ihren zuständigen Systemadministrator.`);
}
})
.catch(error => {
console.error('Error generating PDF:', error);
alert('Fehler beim Generieren der PDF');
});
}
// Initialize the display when page loads
updateWeekDisplay();
updateDayDisplay();
const weekNumber = getWeekNumber(currentWeek);
const year = currentWeek.getFullYear();
const week = `KW${weekNumber} ${year}`;
loadWeekData(week);
+1 -1
View File
@@ -220,7 +220,7 @@ function loadWeekData(week) {
})
.catch(error => {
console.error('Error loading week:', error);
alert('Fehler beim Laden der Woche');
alert('Fehler beim Laden der Woche!\n\nBitte kontaktieren Sie Ihren zuständigen Systemadministrator.');
});
}
+63
View File
@@ -64,10 +64,18 @@ button {
position: relative;
height: 0;
padding-bottom: 60%;
}
.menu-bg {
background: url('/resources/img/speiseplan_vorlage_Seite_1.png') no-repeat center;
background-size: contain;
}
.dailyDish-bg {
background: url('/resources/img/tagesgericht.png') no-repeat center;
background-size: contain;
}
.form-overlay {
position: absolute;
top: 0;
@@ -131,6 +139,61 @@ button {
font-family: 'Fira Sans', sans-serif
}
.input-field-20 {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 32px;
color: rgb(159, 28, 12);
font-weight: bold;
width: 333px;
font-family: 'Fira Sans', sans-serif
}
.input-field-19-b {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 30px;
font-weight: bold;
width: 500px;
font-family: 'Fira Sans', sans-serif
}
.input-field-19 {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 30px;
width: 500px;
font-family: 'Fira Sans', sans-serif
}
.input-field-19-h {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 36px;
color: #00B050;
font-weight: 500;
font-family: 'Fira Sans', sans-serif
}
.input-field-14-i {
position: absolute;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.07);
padding: 2px 4px;
font-size: 23px;
font-style: italic;
width: 333px;
font-family: 'Fira Sans', sans-serif
}
.bottom-controls {
text-align: center;
margin: 20px 0;