Fixed db issues for docker. Improved index.html for mobile.
This commit is contained in:
parent
31daee2dd8
commit
91832fd5bc
4 changed files with 420 additions and 349 deletions
|
|
@ -15,4 +15,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||
COPY . /app/
|
||||
|
||||
# We'll run the server via docker-compose command, but this is a default
|
||||
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
|
||||
CMD ["python", "manage.py", "runserver", "0.0.0.0:8001"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
version: '3.8'
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
db:
|
||||
|
|
@ -7,9 +7,9 @@ services:
|
|||
restart: always
|
||||
environment:
|
||||
MYSQL_DATABASE: workouts
|
||||
MYSQL_ROOT_PASSWORD: rootpassword
|
||||
MYSQL_USER: user
|
||||
MYSQL_PASSWORD: userpassword
|
||||
MYSQL_ROOT_PASSWORD: Throwaway
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
networks:
|
||||
|
|
@ -18,19 +18,21 @@ services:
|
|||
web:
|
||||
build: .
|
||||
container_name: workouts_web
|
||||
working_dir: /app/zed_workouts
|
||||
command: >
|
||||
sh -c "python manage.py migrate &&
|
||||
python manage.py runserver 0.0.0.0:8000"
|
||||
sh -c "sleep 10 &&
|
||||
python manage.py migrate &&
|
||||
python manage.py runserver 0.0.0.0:8001"
|
||||
volumes:
|
||||
- .:/app
|
||||
ports:
|
||||
- "8000:8000"
|
||||
- "8001:8001"
|
||||
depends_on:
|
||||
- db
|
||||
environment:
|
||||
- DB_NAME=workouts
|
||||
- DB_USER=user
|
||||
- DB_PASSWORD=userpassword
|
||||
- DB_USER=root
|
||||
- DB_PASSWORD=Throwaway
|
||||
- DB_HOST=db
|
||||
networks:
|
||||
- workout_net
|
||||
|
|
|
|||
|
|
@ -1,313 +1,383 @@
|
|||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Zed Workouts</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
.table-input { width: 100%; border: none; background: transparent; }
|
||||
.hidden-inputs { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-light p-4">
|
||||
<div class="container bg-white p-4 rounded shadow">
|
||||
<h2 class="mb-4">Workout Tracker</h2>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
/>
|
||||
<title>Zed Workouts</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<style>
|
||||
:root {
|
||||
--ios-blue: #007aff;
|
||||
}
|
||||
|
||||
<!-- SECTION 1: Template Selection -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label"><strong>Template</strong></label>
|
||||
<select id="templateSelect" class="form-select" onchange="filterExercises()">
|
||||
<option value="">Select...</option>
|
||||
<option value="Chest">Chest</option>
|
||||
<option value="Back">Back</option>
|
||||
<option value="Legs">Legs</option>
|
||||
</select>
|
||||
body {
|
||||
font-family:
|
||||
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||
Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* General Input Styling */
|
||||
.table-input {
|
||||
width: 100%;
|
||||
border: 1px solid #ced4da;
|
||||
background: #fff;
|
||||
padding: 8px 4px;
|
||||
border-radius: 4px;
|
||||
font-size: 16px; /* Essential for iOS to prevent zoom */
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Mobile Optimization (< 600px) */
|
||||
@media (max-width: 600px) {
|
||||
.container {
|
||||
padding: 8px !important;
|
||||
}
|
||||
h2,
|
||||
h4 {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
/* Hide the Group/Type columns to save horizontal space */
|
||||
.col-grp,
|
||||
.col-ty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.table td,
|
||||
.table th {
|
||||
padding: 6px 2px !important;
|
||||
font-size: 13px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* Proportional Column Widths */
|
||||
.col-ex {
|
||||
width: 40%;
|
||||
}
|
||||
.col-set {
|
||||
width: 10%;
|
||||
}
|
||||
.col-rp {
|
||||
width: 15%;
|
||||
}
|
||||
.col-wt {
|
||||
width: 15%;
|
||||
}
|
||||
.col-nt {
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
/* Desktop Polish */
|
||||
@media (min-width: 768px) {
|
||||
.table-input {
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
}
|
||||
.table-input:focus {
|
||||
border: 1px solid var(--ios-blue);
|
||||
background: #fff;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.hidden-inputs {
|
||||
display: none;
|
||||
}
|
||||
.text-truncate-mobile {
|
||||
max-width: 100px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-light p-2 p-md-4">
|
||||
<div class="container bg-white p-3 p-md-4 rounded shadow">
|
||||
<h2 class="mb-3">Workout Tracker</h2>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-12 col-md-4">
|
||||
<label class="form-label"><strong>Template</strong></label>
|
||||
<select
|
||||
id="templateSelect"
|
||||
class="form-select form-select-lg"
|
||||
onchange="filterExercises()"
|
||||
>
|
||||
<option value="">Select...</option>
|
||||
<option value="Chest">Chest</option>
|
||||
<option value="Back">Back</option>
|
||||
<option value="Legs">Legs</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col-4">
|
||||
<label class="small">Primary</label>
|
||||
<select
|
||||
id="primarySelect"
|
||||
class="form-select form-select-sm"
|
||||
></select>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label class="small">Secondary</label>
|
||||
<select
|
||||
id="secondarySelect"
|
||||
class="form-select form-select-sm"
|
||||
></select>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label class="small">Core</label>
|
||||
<select
|
||||
id="coreSelect"
|
||||
class="form-select form-select-sm"
|
||||
></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="btn btn-primary w-100 mb-4"
|
||||
onclick="generateTable()"
|
||||
>
|
||||
Generate Table
|
||||
</button>
|
||||
|
||||
<h4 class="mb-2">Current Block</h4>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-bordered">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th class="col-ex">Exercise</th>
|
||||
<th class="col-grp">Group</th>
|
||||
<th class="col-set">Set</th>
|
||||
<th class="col-rp">Reps</th>
|
||||
<th class="col-wt">Weight</th>
|
||||
<th class="col-nt">Note</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="activeTableBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-warning w-100 mb-4" onclick="saveBlock()">
|
||||
Save Block
|
||||
</button>
|
||||
|
||||
<hr />
|
||||
|
||||
<h4 class="mb-2">Extra Exercise</h4>
|
||||
<select
|
||||
id="adhocSelect"
|
||||
class="form-select mb-2"
|
||||
onchange="generateAdhocRows()"
|
||||
>
|
||||
<option value="">Add individual exercise...</option>
|
||||
</select>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-bordered">
|
||||
<tbody id="adhocTableBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button
|
||||
id="saveAdhocBtn"
|
||||
class="btn btn-outline-warning w-100 mb-4 d-none"
|
||||
onclick="saveAdhocBlock()"
|
||||
>
|
||||
Save Extra
|
||||
</button>
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input
|
||||
type="hidden"
|
||||
name="template_name"
|
||||
id="formTemplateName"
|
||||
/>
|
||||
|
||||
<h4 class="mt-4">Final Log</h4>
|
||||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr class="small text-muted">
|
||||
<th>Exercise</th>
|
||||
<th>Set</th>
|
||||
<th>Reps</th>
|
||||
<th>Weight</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="logTableBody"></tbody>
|
||||
</table>
|
||||
|
||||
<div id="hiddenInputs" class="hidden-inputs"></div>
|
||||
<button type="submit" class="btn btn-success btn-lg w-100 mt-3">
|
||||
End Workout
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Exercise Selection -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-4">
|
||||
<label>Primary Group</label>
|
||||
<select id="primarySelect" class="form-select"></select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label>Secondary Group</label>
|
||||
<select id="secondarySelect" class="form-select"></select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label>Core Group</label>
|
||||
<select id="coreSelect" class="form-select"></select>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const exercises = {{ exercises_json|safe }};
|
||||
const templates = {{ templates_json|safe }};
|
||||
|
||||
<button class="btn btn-primary mb-4" onclick="generateTable()">Generate Table</button>
|
||||
function filterExercises() {
|
||||
const template = document.getElementById('templateSelect').value;
|
||||
document.getElementById('formTemplateName').value = template;
|
||||
|
||||
<!-- SECTION 3: Active Supersets Table -->
|
||||
<h4>Current Block (4 Sets)</h4>
|
||||
<table class="table table-bordered">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Exercise</th>
|
||||
<th>Group</th>
|
||||
<th>Set</th>
|
||||
<th>Reps</th>
|
||||
<th>Weight</th>
|
||||
<th>Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="activeTableBody"></tbody>
|
||||
</table>
|
||||
let primaryType = [], secondaryType = [];
|
||||
if (template === 'Chest') { primaryType = ['Chest']; secondaryType = ['Arms', 'Triceps']; }
|
||||
else if (template === 'Back') { primaryType = ['Back']; secondaryType = ['Arms', 'Biceps']; }
|
||||
else if (template === 'Legs') { primaryType = ['Legs']; secondaryType = ['Shoulders', 'Calves']; }
|
||||
|
||||
<button class="btn btn-warning mb-4" onclick="saveBlock()">Save Block (Clear Table)</button>
|
||||
populateDropdown('primarySelect', 'Primary', primaryType);
|
||||
populateDropdown('secondarySelect', 'Secondary', secondaryType);
|
||||
populateDropdown('coreSelect', 'Core', ['Abs', 'Core']);
|
||||
loadTemplateData(template);
|
||||
}
|
||||
|
||||
<hr class="my-4">
|
||||
function populateDropdown(id, group, types) {
|
||||
const select = document.getElementById(id);
|
||||
select.innerHTML = '<option value="">...</option>';
|
||||
exercises.forEach(ex => {
|
||||
if (ex.group === group && (types.length === 0 || types.includes(ex.type))) {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = ex.exercise;
|
||||
opt.text = ex.exercise;
|
||||
opt.dataset.type = ex.type;
|
||||
select.appendChild(opt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
<!-- SECTION 3.5: Ad-Hoc Input -->
|
||||
<h4>Add Extra Exercise (4 Sets)</h4>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6">
|
||||
<label>Select Exercise</label>
|
||||
<select id="adhocSelect" class="form-select" onchange="generateAdhocRows()">
|
||||
<option value="">Select...</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-bordered">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Exercise</th>
|
||||
<th>Group</th>
|
||||
<th>Set</th>
|
||||
<th>Reps</th>
|
||||
<th>Weight</th>
|
||||
<th>Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="adhocTableBody"></tbody>
|
||||
</table>
|
||||
<button class="btn btn-warning mb-4" onclick="saveAdhocBlock()">Save Extra Exercise</button>
|
||||
<hr class="my-4">
|
||||
|
||||
<!-- SECTION 4: Final Submission -->
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="template_name" id="formTemplateName">
|
||||
|
||||
<h4>Completed Workout Log</h4>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr><th>Exercise</th><th>Set</th><th>Reps</th><th>Weight</th><th>Notes</th></tr>
|
||||
</thead>
|
||||
<tbody id="logTableBody"></tbody>
|
||||
</table>
|
||||
|
||||
<!-- Hidden inputs container for POST data -->
|
||||
<div id="hiddenInputs" class="hidden-inputs"></div>
|
||||
|
||||
<button type="submit" class="btn btn-success btn-lg w-100 mt-3">End Workout (Submit)</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const exercises = {{ exercises_json|safe }};
|
||||
const templates = {{ templates_json|safe }};
|
||||
|
||||
function filterExercises() {
|
||||
const template = document.getElementById('templateSelect').value;
|
||||
document.getElementById('formTemplateName').value = template;
|
||||
|
||||
// Simple mapping logic: Chest Template implies Chest exercises for Primary, etc.
|
||||
// You can customize this logic as needed.
|
||||
let primaryType = [], secondaryType = [];
|
||||
|
||||
if (template === 'Chest') { primaryType = ['Chest']; secondaryType = ['Arms', 'Triceps']; }
|
||||
else if (template === 'Back') { primaryType = ['Back']; secondaryType = ['Arms', 'Biceps']; }
|
||||
else if (template === 'Legs') { primaryType = ['Legs']; secondaryType = ['Shoulders', 'Calves']; }
|
||||
|
||||
populateDropdown('primarySelect', 'Primary', primaryType);
|
||||
populateDropdown('secondarySelect', 'Secondary', secondaryType);
|
||||
populateDropdown('coreSelect', 'Core', ['Abs', 'Core']);
|
||||
loadTemplateData(template);
|
||||
}
|
||||
|
||||
function populateDropdown(id, group, types) {
|
||||
const select = document.getElementById(id);
|
||||
select.innerHTML = '<option value="">Select...</option>';
|
||||
exercises.forEach(ex => {
|
||||
if (ex.group === group && (types.length === 0 || types.includes(ex.type))) {
|
||||
function populateAdhocDropdown() {
|
||||
const select = document.getElementById('adhocSelect');
|
||||
const sorted = [...exercises].sort((a,b) => a.exercise.localeCompare(b.exercise));
|
||||
sorted.forEach(ex => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = ex.exercise;
|
||||
opt.text = ex.exercise;
|
||||
opt.dataset.type = ex.type;
|
||||
opt.dataset.group = ex.group;
|
||||
select.appendChild(opt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function populateAdhocDropdown() {
|
||||
const select = document.getElementById('adhocSelect');
|
||||
const sorted = [...exercises].sort((a,b) => a.exercise.localeCompare(b.exercise));
|
||||
sorted.forEach(ex => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = ex.exercise;
|
||||
opt.text = ex.exercise;
|
||||
opt.dataset.type = ex.type;
|
||||
opt.dataset.group = ex.group;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
function loadTemplateData(templateName) {
|
||||
const tbody = document.getElementById('activeTableBody');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
const data = templates[templateName];
|
||||
if (data && data.length > 0) {
|
||||
data.forEach(row => {
|
||||
// Try to sync dropdowns based on first occurrence
|
||||
if (row.group === 'Primary') setDropdownIfEmpty('primarySelect', row.exercise);
|
||||
if (row.group === 'Secondary') setDropdownIfEmpty('secondarySelect', row.exercise);
|
||||
if (row.group === 'Core') setDropdownIfEmpty('coreSelect', row.exercise);
|
||||
|
||||
const html = `
|
||||
<tr>
|
||||
<td>${row.exercise}<input type="hidden" class="d-ex" value="${row.exercise}"></td>
|
||||
<td>${row.group}<input type="hidden" class="d-gr" value="${row.group}">
|
||||
<input type="hidden" class="d-ty" value="${row.type}"></td>
|
||||
<td>${row.set}<input type="hidden" class="d-st" value="${row.set}"></td>
|
||||
<td><input type="number" class="table-input d-rp" value="${row.reps}"></td>
|
||||
<td><input type="number" class="table-input d-wt" step="0.5" value="${row.weight}"></td>
|
||||
<td><input type="text" class="table-input d-nt" value="${row.notes || ''}" placeholder="Notes"></td>
|
||||
</tr>`;
|
||||
tbody.insertAdjacentHTML('beforeend', html);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setDropdownIfEmpty(id, value) {
|
||||
const select = document.getElementById(id);
|
||||
if (select && select.value === "") select.value = value;
|
||||
}
|
||||
|
||||
function generateTable() {
|
||||
const tbody = document.getElementById('activeTableBody');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
// Get current template data to seed values
|
||||
const templateName = document.getElementById('templateSelect').value;
|
||||
const templateData = templates[templateName] || [];
|
||||
|
||||
const selects = [
|
||||
{ el: document.getElementById('primarySelect'), group: 'Primary' },
|
||||
{ el: document.getElementById('secondarySelect'), group: 'Secondary' },
|
||||
{ el: document.getElementById('coreSelect'), group: 'Core' }
|
||||
];
|
||||
|
||||
// Validate selection
|
||||
if (selects.some(s => !s.el.value)) { alert("Please select all 3 exercises."); return; }
|
||||
|
||||
for (let set = 1; set <= 4; set++) {
|
||||
selects.forEach(s => {
|
||||
const opt = s.el.options[s.el.selectedIndex];
|
||||
const exName = s.el.value;
|
||||
|
||||
// Look for existing data in the template for this exercise/set
|
||||
const match = templateData.find(row => row.exercise === exName && row.set === set);
|
||||
const rReps = match ? match.reps : 0;
|
||||
const rWeight = match ? match.weight : 0;
|
||||
const rNotes = match ? (match.notes || '') : '';
|
||||
|
||||
const row = `
|
||||
<tr>
|
||||
<td>${exName}<input type="hidden" class="d-ex" value="${exName}"></td>
|
||||
<td>${s.group}<input type="hidden" class="d-gr" value="${s.group}">
|
||||
<input type="hidden" class="d-ty" value="${opt.dataset.type}"></td>
|
||||
<td>${set}<input type="hidden" class="d-st" value="${set}"></td>
|
||||
<td><input type="number" class="table-input d-rp" value="${rReps}"></td>
|
||||
<td><input type="number" class="table-input d-wt" step="0.5" value="${rWeight}"></td>
|
||||
<td><input type="text" class="table-input d-nt" value="${rNotes}" placeholder="Notes"></td>
|
||||
</tr>`;
|
||||
tbody.insertAdjacentHTML('beforeend', row);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function generateAdhocRows() {
|
||||
const select = document.getElementById('adhocSelect');
|
||||
const tbody = document.getElementById('adhocTableBody');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
if (!select.value) return;
|
||||
|
||||
const opt = select.options[select.selectedIndex];
|
||||
const exName = select.value;
|
||||
const gr = opt.dataset.group;
|
||||
const ty = opt.dataset.type;
|
||||
|
||||
for (let set = 1; set <= 4; set++) {
|
||||
const row = `
|
||||
function getRowHtml(exName, group, type, set, reps=0, weight=0, notes='') {
|
||||
return `
|
||||
<tr>
|
||||
<td>${exName}<input type="hidden" class="d-ex" value="${exName}"></td>
|
||||
<td>${gr}<input type="hidden" class="d-gr" value="${gr}">
|
||||
<input type="hidden" class="d-ty" value="${ty}"></td>
|
||||
<td>${set}<input type="hidden" class="d-st" value="${set}"></td>
|
||||
<td><input type="number" class="table-input d-rp" value="0"></td>
|
||||
<td><input type="number" class="table-input d-wt" step="0.5" value="0"></td>
|
||||
<td><input type="text" class="table-input d-nt" value="" placeholder="Notes"></td>
|
||||
<td class="col-ex text-truncate-mobile">${exName}<input type="hidden" class="d-ex" value="${exName}"></td>
|
||||
<td class="col-grp">${group}<input type="hidden" class="d-gr" value="${group}"><input type="hidden" class="d-ty" value="${type}"></td>
|
||||
<td class="col-set">${set}<input type="hidden" class="d-st" value="${set}"></td>
|
||||
<td class="col-rp"><input type="number" inputmode="numeric" class="table-input d-rp" value="${reps}"></td>
|
||||
<td class="col-wt"><input type="number" inputmode="decimal" class="table-input d-wt" step="0.5" value="${weight}"></td>
|
||||
<td class="col-nt"><input type="text" class="table-input d-nt" value="${notes}" placeholder="..."></td>
|
||||
</tr>`;
|
||||
tbody.insertAdjacentHTML('beforeend', row);
|
||||
}
|
||||
}
|
||||
|
||||
function saveBlock() {
|
||||
processSaveBlock('activeTableBody');
|
||||
}
|
||||
function loadTemplateData(templateName) {
|
||||
const tbody = document.getElementById('activeTableBody');
|
||||
tbody.innerHTML = '';
|
||||
const data = templates[templateName];
|
||||
if (data) {
|
||||
data.forEach(row => {
|
||||
if (row.group === 'Primary') setDropdownIfEmpty('primarySelect', row.exercise);
|
||||
if (row.group === 'Secondary') setDropdownIfEmpty('secondarySelect', row.exercise);
|
||||
if (row.group === 'Core') setDropdownIfEmpty('coreSelect', row.exercise);
|
||||
tbody.insertAdjacentHTML('beforeend', getRowHtml(row.exercise, row.group, row.type, row.set, row.reps, row.weight, row.notes));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function saveAdhocBlock() {
|
||||
processSaveBlock('adhocTableBody');
|
||||
document.getElementById('adhocSelect').value = '';
|
||||
}
|
||||
function setDropdownIfEmpty(id, value) {
|
||||
const select = document.getElementById(id);
|
||||
if (select && select.value === "") select.value = value;
|
||||
}
|
||||
|
||||
function processSaveBlock(tableId) {
|
||||
const activeBody = document.getElementById(tableId);
|
||||
const logBody = document.getElementById('logTableBody');
|
||||
const hiddenDiv = document.getElementById('hiddenInputs');
|
||||
function generateTable() {
|
||||
const tbody = document.getElementById('activeTableBody');
|
||||
tbody.innerHTML = '';
|
||||
const templateName = document.getElementById('templateSelect').value;
|
||||
const templateData = templates[templateName] || [];
|
||||
const selects = [
|
||||
{ el: document.getElementById('primarySelect'), group: 'Primary' },
|
||||
{ el: document.getElementById('secondarySelect'), group: 'Secondary' },
|
||||
{ el: document.getElementById('coreSelect'), group: 'Core' }
|
||||
];
|
||||
|
||||
// Move rows from active table to log and create hidden inputs
|
||||
activeBody.querySelectorAll('tr').forEach(row => {
|
||||
const ex = row.querySelector('.d-ex').value;
|
||||
const gr = row.querySelector('.d-gr').value;
|
||||
const ty = row.querySelector('.d-ty').value;
|
||||
const st = row.querySelector('.d-st').value;
|
||||
const rp = row.querySelector('.d-rp').value;
|
||||
const wt = row.querySelector('.d-wt').value;
|
||||
const nt = row.querySelector('.d-nt').value;
|
||||
if (selects.some(s => !s.el.value)) { alert("Select 3 exercises"); return; }
|
||||
|
||||
// Visual Log
|
||||
const logRow = `<tr><td>${ex}</td><td>${st}</td><td>${rp}</td><td>${wt}</td><td>${nt}</td></tr>`;
|
||||
logBody.insertAdjacentHTML('beforeend', logRow);
|
||||
for (let set = 1; set <= 4; set++) {
|
||||
selects.forEach(s => {
|
||||
const opt = s.el.options[s.el.selectedIndex];
|
||||
const match = templateData.find(row => row.exercise === s.el.value && row.set === set);
|
||||
tbody.insertAdjacentHTML('beforeend', getRowHtml(s.el.value, s.group, opt.dataset.type, set, match?.reps || 0, match?.weight || 0, match?.notes || ''));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Hidden Inputs for POST
|
||||
const inputs = `
|
||||
<input type="hidden" name="exercise[]" value="${ex}">
|
||||
<input type="hidden" name="group[]" value="${gr}">
|
||||
<input type="hidden" name="type[]" value="${ty}">
|
||||
<input type="hidden" name="set[]" value="${st}">
|
||||
<input type="hidden" name="reps[]" value="${rp}">
|
||||
<input type="hidden" name="weight[]" value="${wt}">
|
||||
<input type="hidden" name="notes[]" value="${nt}">
|
||||
`;
|
||||
hiddenDiv.insertAdjacentHTML('beforeend', inputs);
|
||||
});
|
||||
function generateAdhocRows() {
|
||||
const select = document.getElementById('adhocSelect');
|
||||
const tbody = document.getElementById('adhocTableBody');
|
||||
tbody.innerHTML = '';
|
||||
if (!select.value) { document.getElementById('saveAdhocBtn').classList.add('d-none'); return; }
|
||||
|
||||
// Clear Active Table
|
||||
activeBody.innerHTML = '';
|
||||
}
|
||||
document.getElementById('saveAdhocBtn').classList.remove('d-none');
|
||||
const opt = select.options[select.selectedIndex];
|
||||
for (let set = 1; set <= 4; set++) {
|
||||
tbody.insertAdjacentHTML('beforeend', getRowHtml(select.value, opt.dataset.group, opt.dataset.type, set));
|
||||
}
|
||||
}
|
||||
|
||||
populateAdhocDropdown();
|
||||
</script>
|
||||
</body>
|
||||
function saveBlock() { processSaveBlock('activeTableBody'); }
|
||||
function saveAdhocBlock() {
|
||||
processSaveBlock('adhocTableBody');
|
||||
document.getElementById('adhocSelect').value = '';
|
||||
document.getElementById('saveAdhocBtn').classList.add('d-none');
|
||||
}
|
||||
|
||||
function processSaveBlock(tableId) {
|
||||
const activeBody = document.getElementById(tableId);
|
||||
const logBody = document.getElementById('logTableBody');
|
||||
const hiddenDiv = document.getElementById('hiddenInputs');
|
||||
|
||||
activeBody.querySelectorAll('tr').forEach(row => {
|
||||
const data = {
|
||||
ex: row.querySelector('.d-ex').value,
|
||||
gr: row.querySelector('.d-gr').value,
|
||||
ty: row.querySelector('.d-ty').value,
|
||||
st: row.querySelector('.d-st').value,
|
||||
rp: row.querySelector('.d-rp').value,
|
||||
wt: row.querySelector('.d-wt').value,
|
||||
nt: row.querySelector('.d-nt').value
|
||||
};
|
||||
|
||||
logBody.insertAdjacentHTML('beforeend', `<tr><td>${data.ex}</td><td>${data.st}</td><td>${data.rp}</td><td>${data.wt}</td></tr>`);
|
||||
hiddenDiv.insertAdjacentHTML('beforeend', `
|
||||
<input type="hidden" name="exercise[]" value="${data.ex}">
|
||||
<input type="hidden" name="group[]" value="${data.gr}">
|
||||
<input type="hidden" name="type[]" value="${data.ty}">
|
||||
<input type="hidden" name="set[]" value="${data.st}">
|
||||
<input type="hidden" name="reps[]" value="${data.rp}">
|
||||
<input type="hidden" name="weight[]" value="${data.wt}">
|
||||
<input type="hidden" name="notes[]" value="${data.nt}">
|
||||
`);
|
||||
});
|
||||
activeBody.innerHTML = '';
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
}
|
||||
|
||||
populateAdhocDropdown();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ For the full list of settings and their values, see
|
|||
https://docs.djangoproject.com/en/6.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
|
@ -21,54 +21,54 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-a%mr&&f^u06y=$!cylb-wv&w3^booxo*48hymemf$ldj=$vkb%'
|
||||
SECRET_KEY = "django-insecure-a%mr&&f^u06y=$!cylb-wv&w3^booxo*48hymemf$ldj=$vkb%"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'tracker',
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"tracker",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'zed_workouts.urls'
|
||||
ROOT_URLCONF = "zed_workouts.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'zed_workouts.wsgi.application'
|
||||
WSGI_APPLICATION = "zed_workouts.wsgi.application"
|
||||
|
||||
|
||||
# Database
|
||||
|
|
@ -79,50 +79,49 @@ WSGI_APPLICATION = 'zed_workouts.wsgi.application'
|
|||
# 'ENGINE': 'django.db.backends.sqlite3',
|
||||
# 'NAME': BASE_DIR / 'db.sqlite3',
|
||||
# }
|
||||
#}
|
||||
# }
|
||||
|
||||
# Database connector for docker container
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': os.environ.get('DB_NAME', 'workouts'),
|
||||
'USER': os.environ.get('DB_USER', 'user'),
|
||||
'PASSWORD': os.environ.get('DB_PASSWORD', 'userpassword'),
|
||||
'HOST': os.environ.get('DB_HOST', 'db'),
|
||||
'PORT': '3306',
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.mysql",
|
||||
"NAME": os.environ.get("DB_NAME", "workouts"),
|
||||
"USER": os.environ.get("DB_USER", "user"),
|
||||
"PASSWORD": os.environ.get("DB_PASSWORD", "userpassword"),
|
||||
"HOST": os.environ.get("DB_HOST", "db"),
|
||||
"PORT": "3306",
|
||||
}
|
||||
}
|
||||
|
||||
# Database connector for local mysql instance
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'workouts',
|
||||
'USER': 'root',
|
||||
'PASSWORD': 'Throwaway',
|
||||
'HOST': 'localhost', # Or your DB server IP
|
||||
'PORT': '3306', # Default MySQL port
|
||||
'OPTIONS': {
|
||||
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
|
||||
},
|
||||
}
|
||||
}
|
||||
# DATABASES = {
|
||||
# "default": {
|
||||
# "ENGINE": "django.db.backends.mysql",
|
||||
# "NAME": "workouts",
|
||||
# "USER": "root",
|
||||
# "PASSWORD": "Throwaway",
|
||||
# "HOST": "localhost", # Or your DB server IP
|
||||
# "PORT": "3306", # Default MySQL port
|
||||
# "OPTIONS": {
|
||||
# "init_command": "SET sql_mode='STRICT_TRANS_TABLES'",
|
||||
# },
|
||||
# }
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
|
|
@ -130,9 +129,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = "UTC"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
|
@ -142,4 +141,4 @@ USE_TZ = True
|
|||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_URL = "static/"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue