Anwesenheit loggen
This commit is contained in:
parent
8a58352fbe
commit
d88d3680e6
52
app.js
52
app.js
|
@ -182,6 +182,15 @@ const getRiegenMitgliederSortedByAge = async () => {
|
||||||
return result.rows;
|
return result.rows;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getAnwesenheit = function (id, anwesend) {
|
||||||
|
for (let item of anwesend) {
|
||||||
|
if (item.fid_teilnehmer === id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// Registrierung
|
// Registrierung
|
||||||
app.post('/register', async (req, res) => {
|
app.post('/register', async (req, res) => {
|
||||||
const { username, email, password } = req.body;
|
const { username, email, password } = req.body;
|
||||||
|
@ -492,6 +501,8 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
const training =await getTraining(selectedDate);
|
const training =await getTraining(selectedDate);
|
||||||
|
|
||||||
const trainingsResult = await pool.query('SELECT datum FROM trainings ORDER BY datum ASC');
|
const trainingsResult = await pool.query('SELECT datum FROM trainings ORDER BY datum ASC');
|
||||||
|
const anwesendResult = await pool.query('SELECT * FROM anwesend WHERE fid_training = $1',[ training.id ]);
|
||||||
|
anwesend=anwesendResult.rows;
|
||||||
const trainingsDates = trainingsResult.rows.map(tr => ({
|
const trainingsDates = trainingsResult.rows.map(tr => ({
|
||||||
datum: formatDate(tr.datum),
|
datum: formatDate(tr.datum),
|
||||||
rawDatum: tr.datum
|
rawDatum: tr.datum
|
||||||
|
@ -503,6 +514,33 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
const previousTraining = previousTrainingResult.rows.length > 0 ? previousTrainingResult.rows[0] : null;
|
const previousTraining = previousTrainingResult.rows.length > 0 ? previousTrainingResult.rows[0] : null;
|
||||||
const nextTraining = nextTrainingResult.rows.length > 0 ? nextTrainingResult.rows[0] : null;
|
const nextTraining = nextTrainingResult.rows.length > 0 ? nextTrainingResult.rows[0] : null;
|
||||||
|
|
||||||
|
// Abrufen der Riegendaten einschließlich der Teilnehmer und deren Altersberechnung
|
||||||
|
const result = await pool.query(`
|
||||||
|
SELECT r.riegennummer, t.id, t.name, t.vorname, t.nachname, t.geburtsdatum, r.helfer
|
||||||
|
FROM riegen r
|
||||||
|
JOIN teilnehmende t ON r.fremdID_Teilnehmende = t.id
|
||||||
|
ORDER BY r.riegennummer, t.geburtsdatum ASC
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Gruppieren der Riegenteilnehmer nach Riegennummer
|
||||||
|
const riegen = {};
|
||||||
|
result.rows.forEach(row => {
|
||||||
|
const age = calculateAge(row.geburtsdatum);
|
||||||
|
const tnAnwesend = getAnwesenheit(row.id, anwesend);
|
||||||
|
if (!riegen[row.riegennummer]) {
|
||||||
|
riegen[row.riegennummer] = [];
|
||||||
|
}
|
||||||
|
riegen[row.riegennummer].push({
|
||||||
|
id: row.id,
|
||||||
|
name: row.name,
|
||||||
|
vorname: row.vorname,
|
||||||
|
nachname: row.nachname,
|
||||||
|
age: age,
|
||||||
|
helfer: row.helfer,
|
||||||
|
anwesend: tnAnwesend
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (training) {
|
if (training) {
|
||||||
training.datum = formatDate(training.datum);
|
training.datum = formatDate(training.datum);
|
||||||
}
|
}
|
||||||
|
@ -523,6 +561,7 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
session: req.session,
|
session: req.session,
|
||||||
previousTraining,
|
previousTraining,
|
||||||
nextTraining,
|
nextTraining,
|
||||||
|
riegen,
|
||||||
moment
|
moment
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -733,6 +772,19 @@ app.post('/changelog', requireAdmin, async (req, res) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post('/anwesend', requireAuth, async (req, res) => {
|
||||||
|
const { anw, trainingId } = req.body;
|
||||||
|
try {
|
||||||
|
for (const teilnehmer of anw) {
|
||||||
|
await pool.query('INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)', [teilnehmer, trainingId]);
|
||||||
|
}
|
||||||
|
res.redirect('/training');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
const message = 'Error:' + error;
|
||||||
|
res.render('error', {session: req.session, message});
|
||||||
|
}})
|
||||||
|
|
||||||
const server = app.listen(port, '0.0.0.0', () => {
|
const server = app.listen(port, '0.0.0.0', () => {
|
||||||
console.log(`Server is running on http://localhost:${port}/`);
|
console.log(`Server is running on http://localhost:${port}/`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,20 @@
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Nav tabs -->
|
||||||
|
<ul class="nav nav-tabs" id="myTab" role="tablist">
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link active" id="tab-geraete" data-bs-toggle="tab" data-bs-target="#geraete" type="button" role="tab" aria-controls="geraete" aria-selected="true">Geräteplan</button>
|
||||||
|
<button class="nav-link" id="tab-spiel" data-bs-toggle="tab" data-bs-target="#spiel" type="button" role="tab" aria-controls="spiel" aria-selected="false">Aufwärmen / Spiel</button>
|
||||||
|
<button class="nav-link" id="tab-anwesend" data-bs-toggle="tab" data-bs-target="#anwesend" type="button" role="tab" aria-controls="anwesend" aria-selected="false">Anwesenheit</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<% if (training) { %>
|
<% if (training) { %>
|
||||||
|
<div class="tab-content" id="myTabContent">
|
||||||
|
<div class="tab-pane fade show active" id="geraete" role="tabpanel" aria-labelledby="tab-geraete">
|
||||||
<h2> Geräte </h2>
|
<h2> Geräte </h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Riege 1: <%= training.geraet_riege_1_name %></li>
|
<li>Riege 1: <%= training.geraet_riege_1_name %></li>
|
||||||
|
@ -20,7 +33,8 @@
|
||||||
<li>Riege 4: <%= training.geraet_riege_4_name %></li>
|
<li>Riege 4: <%= training.geraet_riege_4_name %></li>
|
||||||
<li>Riege 5: <%= training.geraet_riege_5_name %></li>
|
<li>Riege 5: <%= training.geraet_riege_5_name %></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="spiel" role="tabpanel" aria-labelledby="tab-spiel">
|
||||||
<div id="aufwaermen">
|
<div id="aufwaermen">
|
||||||
<h3>Aufwärmen:</h3>
|
<h3>Aufwärmen:</h3>
|
||||||
|
|
||||||
|
@ -101,6 +115,62 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade active" id="anwesend" role="tabpanel" aria-labelledby="tab-anwesend">
|
||||||
|
<h3>Anwesenheit</h3>
|
||||||
|
|
||||||
|
<!-- Nav tabs -->
|
||||||
|
<ul class="nav nav-tabs" id="RiegenTab" role="tablist">
|
||||||
|
<% Object.keys(riegen).forEach((riegennummer, index) => { %>
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link <%= index === 0 ? 'active' : '' %>" id="tab-<%= riegennummer %>" data-bs-toggle="tab" data-bs-target="#riege-<%= riegennummer %>" type="button" role="tab" aria-controls="riege-<%= riegennummer %>" aria-selected="<%= index === 0 ? 'true' : 'false' %>">Riege <%= riegennummer %></button>
|
||||||
|
</li>
|
||||||
|
<% }) %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<!-- Tab panes -->
|
||||||
|
<div class="tab-content" id="myTabContent">
|
||||||
|
<% Object.keys(riegen).forEach((riegennummer, index) => { %>
|
||||||
|
<div class="tab-pane fade <%= index === 0 ? 'show active' : '' %>" id="riege-<%= riegennummer %>" role="tabpanel" aria-labelledby="tab-<%= riegennummer %>">
|
||||||
|
<form method="post" action="/anwesend">
|
||||||
|
<table>
|
||||||
|
|
||||||
|
<% riegen[riegennummer].forEach(teilnehmer => { if(teilnehmer.helfer) { %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= teilnehmer.vorname %> <%= teilnehmer.nachname %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="anw" <%= teilnehmer.anwesend ? 'checked' : '' %> value="<%= teilnehmer.id %>">
|
||||||
|
<% }}) %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% riegen[riegennummer].forEach(teilnehmer => { if(!teilnehmer.helfer) { %>
|
||||||
|
<tr>
|
||||||
|
<td><%= teilnehmer.vorname %> <%= teilnehmer.nachname %> </td><td> <input type="checkbox" name="anw" <%= teilnehmer.anwesend ? 'checked' : '' %> value="<%= teilnehmer.id %>"></td>
|
||||||
|
</tr>
|
||||||
|
<% }}) %>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<input type="hidden" name="trainingId" value="<%= training.id %>">
|
||||||
|
<button type="submit">Speichern</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<% }) %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<% } else { %>
|
||||||
|
<p>Kein Training gefunden für das ausgewählte Datum.</p>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
<div>
|
||||||
<form method="GET" action="/training">
|
<form method="GET" action="/training">
|
||||||
<label for="training-date">Datum wählen:</label>
|
<label for="training-date">Datum wählen:</label>
|
||||||
<select id="training-date" name="date" onchange="this.form.submit()">
|
<select id="training-date" name="date" onchange="this.form.submit()">
|
||||||
|
@ -112,9 +182,8 @@
|
||||||
</select>
|
</select>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<% } else { %>
|
</div>
|
||||||
<p>Kein Training gefunden für das ausgewählte Datum.</p>
|
|
||||||
<% } %>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue