mirror of
https://github.com/sstent/foodplanner.git
synced 2026-01-25 11:11:36 +00:00
added container and nomad
This commit is contained in:
@@ -38,6 +38,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-6">
|
||||
<h3>Template Import</h3>
|
||||
<form action="/templates/upload" method="post" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">CSV File</label>
|
||||
<input type="file" class="form-control" name="file" accept=".csv" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary mb-4">Upload Templates CSV</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4" id="upload-results" style="display: none;">
|
||||
<div class="alert alert-success">
|
||||
<strong>Upload Results:</strong>
|
||||
|
||||
@@ -181,6 +181,144 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Edit Template Modal -->
|
||||
<div class="modal fade" id="editTemplateModal" tabindex="-1" aria-labelledby="editTemplateModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editTemplateModalLabel">Edit Template</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="editTemplateForm">
|
||||
<input type="hidden" id="editTemplateId" name="template_id">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="editTemplateName" class="form-label">Template Name</label>
|
||||
<input type="text" class="form-control" id="editTemplateName" name="name" required>
|
||||
</div>
|
||||
|
||||
<h6 class="mb-3">Assign Meals to Meal Times</h6>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editBreakfast" class="form-label">Breakfast</label>
|
||||
<select class="form-control meal-select" id="editBreakfast" name="breakfast">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editLunch" class="form-label">Lunch</label>
|
||||
<select class="form-control meal-select" id="editLunch" name="lunch">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editDinner" class="form-label">Dinner</label>
|
||||
<select class="form-control meal-select" id="editDinner" name="dinner">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editSnack1" class="form-label">Snack 1</label>
|
||||
<select class="form-control meal-select" id="editSnack1" name="snack1">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editSnack2" class="form-label">Snack 2</label>
|
||||
<select class="form-control meal-select" id="editSnack2" name="snack2">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editBeverage1" class="form-label">Beverage 1</label>
|
||||
<select class="form-control meal-select" id="editBeverage1" name="beverage1">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editBeverage2" class="form-label">Beverage 2</label>
|
||||
<select class="form-control meal-select" id="editBeverage2" name="beverage2">
|
||||
<option value="">Select meal...</option>
|
||||
{% for meal in meals %}
|
||||
<option value="{{ meal.id }}">{{ meal.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Update Template</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Create from Template Modal -->
|
||||
<div class="modal fade" id="createFromTemplateModal" tabindex="-1" aria-labelledby="createFromTemplateModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="createFromTemplateModalLabel">Create New Template from Existing</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="createFromTemplateForm">
|
||||
<input type="hidden" id="sourceTemplateId" name="source_template_id">
|
||||
<div class="modal-body">
|
||||
<p>This will create a new template with the same meal assignments as the selected template.</p>
|
||||
<div class="mb-3">
|
||||
<label for="newTemplateName" class="form-label">New Template Name</label>
|
||||
<input type="text" class="form-control" id="newTemplateName" name="new_name" required placeholder="Enter name for the new template">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Create Template</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentTemplateId = null;
|
||||
|
||||
@@ -198,6 +336,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
e.preventDefault();
|
||||
useTemplate();
|
||||
});
|
||||
|
||||
// Handle template editing
|
||||
document.getElementById('editTemplateForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
editTemplate();
|
||||
});
|
||||
|
||||
// Handle create from template
|
||||
document.getElementById('createFromTemplateForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
createFromTemplate();
|
||||
});
|
||||
});
|
||||
|
||||
function loadTemplates() {
|
||||
@@ -230,6 +380,12 @@ function loadTemplates() {
|
||||
<button class="btn btn-sm btn-outline-primary me-2" onclick="useTemplateModal(${template.id})">
|
||||
<i class="bi bi-play-circle"></i> Use
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-secondary me-2" onclick="editTemplateModal(${template.id})">
|
||||
<i class="bi bi-pencil"></i> Edit
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-info me-2" onclick="createFromTemplateModal(${template.id})">
|
||||
<i class="bi bi-copy"></i> Create from This
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteTemplate(${template.id})">
|
||||
<i class="bi bi-trash"></i> Delete
|
||||
</button>
|
||||
@@ -366,6 +522,141 @@ function confirmOverwrite(overwriteData) {
|
||||
});
|
||||
}
|
||||
|
||||
function editTemplateModal(templateId) {
|
||||
console.log('editTemplateModal called with templateId:', templateId);
|
||||
// Fetch template data
|
||||
fetch(`/templates/${templateId}`)
|
||||
.then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log('Response data:', data);
|
||||
// Check if this is an error response (has status field)
|
||||
if (data.status === 'error') {
|
||||
alert('Error loading template: ' + (data.message || 'Unknown error'));
|
||||
return;
|
||||
}
|
||||
|
||||
// This is a successful response with template data
|
||||
if (data.id && data.name) {
|
||||
// Populate form
|
||||
document.getElementById('editTemplateId').value = templateId;
|
||||
document.getElementById('editTemplateName').value = data.name;
|
||||
|
||||
// Clear all selects first
|
||||
const mealTimes = ['Breakfast', 'Lunch', 'Dinner', 'Snack 1', 'Snack 2', 'Beverage 1', 'Beverage 2'];
|
||||
const selectIds = ['editBreakfast', 'editLunch', 'editDinner', 'editSnack1', 'editSnack2', 'editBeverage1', 'editBeverage2'];
|
||||
|
||||
selectIds.forEach(id => {
|
||||
document.getElementById(id).value = '';
|
||||
});
|
||||
|
||||
// Populate meal assignments
|
||||
if (data.meals && Array.isArray(data.meals)) {
|
||||
data.meals.forEach(meal => {
|
||||
const selectId = 'edit' + meal.meal_time.replace(' ', '');
|
||||
const select = document.getElementById(selectId);
|
||||
if (select) {
|
||||
select.value = meal.meal_id;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Show modal
|
||||
new bootstrap.Modal(document.getElementById('editTemplateModal')).show();
|
||||
} else {
|
||||
alert('Error: Invalid response format from server');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error loading template');
|
||||
});
|
||||
}
|
||||
|
||||
function createFromTemplateModal(templateId) {
|
||||
document.getElementById('sourceTemplateId').value = templateId;
|
||||
document.getElementById('newTemplateName').value = '';
|
||||
new bootstrap.Modal(document.getElementById('createFromTemplateModal')).show();
|
||||
}
|
||||
|
||||
function editTemplate() {
|
||||
const form = document.getElementById('editTemplateForm');
|
||||
const formData = new FormData(form);
|
||||
|
||||
// Build meal assignments string
|
||||
const mealTimes = ['breakfast', 'lunch', 'dinner', 'snack1', 'snack2', 'beverage1', 'beverage2'];
|
||||
const assignments = [];
|
||||
|
||||
mealTimes.forEach(mealTime => {
|
||||
const mealId = formData.get(mealTime);
|
||||
if (mealId) {
|
||||
const displayName = mealTime.charAt(0).toUpperCase() + mealTime.slice(1).replace('1', ' 1').replace('2', ' 2');
|
||||
assignments.push(`${displayName}:${mealId}`);
|
||||
}
|
||||
});
|
||||
|
||||
const data = {
|
||||
template_id: formData.get('template_id'),
|
||||
name: formData.get('name'),
|
||||
meal_assignments: assignments.join(',')
|
||||
};
|
||||
|
||||
fetch('/templates/edit', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams(data)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
bootstrap.Modal.getInstance(document.getElementById('editTemplateModal')).hide();
|
||||
loadTemplates();
|
||||
} else {
|
||||
alert('Error updating template: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error updating template');
|
||||
});
|
||||
}
|
||||
|
||||
function createFromTemplate() {
|
||||
const form = document.getElementById('createFromTemplateForm');
|
||||
const formData = new FormData(form);
|
||||
|
||||
const data = {
|
||||
source_template_id: formData.get('source_template_id'),
|
||||
new_name: formData.get('new_name')
|
||||
};
|
||||
|
||||
fetch('/templates/create_from_template', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams(data)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
bootstrap.Modal.getInstance(document.getElementById('createFromTemplateModal')).hide();
|
||||
form.reset();
|
||||
loadTemplates();
|
||||
} else {
|
||||
alert('Error creating template: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error creating template');
|
||||
});
|
||||
}
|
||||
|
||||
function deleteTemplate(templateId) {
|
||||
if (!confirm('Are you sure you want to delete this template?')) {
|
||||
return;
|
||||
|
||||
@@ -181,6 +181,118 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Edit Weekly Menu Modal -->
|
||||
<div class="modal fade" id="editWeeklyMenuModal" tabindex="-1" aria-labelledby="editWeeklyMenuModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="editWeeklyMenuModalLabel">Edit Weekly Menu</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form id="editWeeklyMenuForm">
|
||||
<input type="hidden" id="editWeeklyMenuId" name="weekly_menu_id">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label for="editWeeklyMenuName" class="form-label">Weekly Menu Name</label>
|
||||
<input type="text" class="form-control" id="editWeeklyMenuName" name="name" required>
|
||||
</div>
|
||||
|
||||
<h6 class="mb-3">Assign Templates to Days</h6>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editMonday" class="form-label">Monday</label>
|
||||
<select class="form-control template-select" id="editMonday" name="monday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editTuesday" class="form-label">Tuesday</label>
|
||||
<select class="form-control template-select" id="editTuesday" name="tuesday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editWednesday" class="form-label">Wednesday</label>
|
||||
<select class="form-control template-select" id="editWednesday" name="wednesday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editThursday" class="form-label">Thursday</label>
|
||||
<select class="form-control template-select" id="editThursday" name="thursday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editFriday" class="form-label">Friday</label>
|
||||
<select class="form-control template-select" id="editFriday" name="friday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editSaturday" class="form-label">Saturday</label>
|
||||
<select class="form-control template-select" id="editSaturday" name="saturday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="editSunday" class="form-label">Sunday</label>
|
||||
<select class="form-control template-select" id="editSunday" name="sunday">
|
||||
<option value="">Select template...</option>
|
||||
{% for template in templates %}
|
||||
<option value="{{ template.id }}">{{ template.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentWeeklyMenuId = null;
|
||||
|
||||
@@ -193,6 +305,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
createWeeklyMenu();
|
||||
});
|
||||
|
||||
// Handle weekly menu editing
|
||||
document.getElementById('editWeeklyMenuForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
editWeeklyMenu();
|
||||
});
|
||||
|
||||
// Handle weekly menu application
|
||||
document.getElementById('applyWeeklyMenuForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -233,6 +351,9 @@ function loadWeeklyMenus() {
|
||||
<button class="btn btn-sm btn-outline-primary me-2" onclick="applyWeeklyMenuModal(${weeklyMenu.id})">
|
||||
<i class="bi bi-play-circle"></i> Apply
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-secondary me-2" onclick="editWeeklyMenuModal(${weeklyMenu.id})">
|
||||
<i class="bi bi-pencil"></i> Edit
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteWeeklyMenu(${weeklyMenu.id})">
|
||||
<i class="bi bi-trash"></i> Delete
|
||||
</button>
|
||||
@@ -391,6 +512,71 @@ function deleteWeeklyMenu(weeklyMenuId) {
|
||||
alert('Error deleting weekly menu');
|
||||
});
|
||||
}
|
||||
|
||||
function editWeeklyMenuModal(weeklyMenuId) {
|
||||
// Fetch weekly menu data
|
||||
fetch(`/weeklymenu/${weeklyMenuId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
// Populate the form
|
||||
document.getElementById('editWeeklyMenuId').value = data.id;
|
||||
document.getElementById('editWeeklyMenuName').value = data.name;
|
||||
|
||||
// Reset all selects
|
||||
const selects = ['editMonday', 'editTuesday', 'editWednesday', 'editThursday', 'editFriday', 'editSaturday', 'editSunday'];
|
||||
selects.forEach(selectId => {
|
||||
document.getElementById(selectId).value = '';
|
||||
});
|
||||
|
||||
// Set template assignments
|
||||
const assignments = data.template_assignments;
|
||||
if (assignments[0]) document.getElementById('editMonday').value = assignments[0];
|
||||
if (assignments[1]) document.getElementById('editTuesday').value = assignments[1];
|
||||
if (assignments[2]) document.getElementById('editWednesday').value = assignments[2];
|
||||
if (assignments[3]) document.getElementById('editThursday').value = assignments[3];
|
||||
if (assignments[4]) document.getElementById('editFriday').value = assignments[4];
|
||||
if (assignments[5]) document.getElementById('editSaturday').value = assignments[5];
|
||||
if (assignments[6]) document.getElementById('editSunday').value = assignments[6];
|
||||
|
||||
// Show modal
|
||||
new bootstrap.Modal(document.getElementById('editWeeklyMenuModal')).show();
|
||||
} else {
|
||||
alert('Error loading weekly menu: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error loading weekly menu');
|
||||
});
|
||||
}
|
||||
|
||||
function editWeeklyMenu() {
|
||||
const form = document.getElementById('editWeeklyMenuForm');
|
||||
const formData = new FormData(form);
|
||||
|
||||
fetch('/weeklymenu/edit', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: new URLSearchParams(formData)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
bootstrap.Modal.getInstance(document.getElementById('editWeeklyMenuModal')).hide();
|
||||
form.reset();
|
||||
loadWeeklyMenus();
|
||||
} else {
|
||||
alert('Error updating weekly menu: ' + data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error updating weekly menu');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Hidden script to pass weekly menus data -->
|
||||
|
||||
Reference in New Issue
Block a user