Jahreswechsel
This commit is contained in:
parent
11e1e7462a
commit
48eddac62d
50
app.js
50
app.js
|
@ -156,6 +156,31 @@ const getTraining = async (kw, jahr) => {
|
|||
return result.rows[0];
|
||||
};
|
||||
|
||||
const getTrainingbyID = async (id) => {
|
||||
const result = await pool.query(
|
||||
`
|
||||
SELECT tr.*, g1.name AS geraet_riege_1_name, g2.name AS geraet_riege_2_name,
|
||||
g3.name AS geraet_riege_3_name, g4.name AS geraet_riege_4_name,
|
||||
g5.name AS geraet_riege_5_name,
|
||||
t1.name AS aufwaermleiter_name, t2.name AS spielleiter_name,
|
||||
sp1.name AS aufwaermen_name, sp2.name AS spiel_name
|
||||
FROM trainings tr
|
||||
LEFT JOIN geraete g1 ON tr.geraet_riege_1 = g1.id
|
||||
LEFT JOIN geraete g2 ON tr.geraet_riege_2 = g2.id
|
||||
LEFT JOIN geraete g3 ON tr.geraet_riege_3 = g3.id
|
||||
LEFT JOIN geraete g4 ON tr.geraet_riege_4 = g4.id
|
||||
LEFT JOIN geraete g5 ON tr.geraet_riege_5 = g5.id
|
||||
LEFT JOIN teilnehmende t1 ON tr.aufwaermleiter = t1.id
|
||||
LEFT JOIN teilnehmende t2 ON tr.spielleiter = t2.id
|
||||
LEFT JOIN spiele sp1 ON tr.aufwaermen = sp1.id
|
||||
LEFT JOIN spiele sp2 ON tr.spiel = sp2.id
|
||||
WHERE tr.id=$1
|
||||
`,
|
||||
[id]
|
||||
);
|
||||
return result.rows[0];
|
||||
};
|
||||
|
||||
// Funktion zum Laden aller Spiele
|
||||
const getAllSpiele = async () => {
|
||||
const result = await pool.query(`
|
||||
|
@ -670,24 +695,28 @@ app.get("/training", requireAuth, async (req, res) => {
|
|||
let dateParam = req.query.date;
|
||||
let kwParam = req.query.kw;
|
||||
let jahrParam = req.query.jahr;
|
||||
let idParam = req.query.id;
|
||||
let selectedDate;
|
||||
let selectedKW;
|
||||
let selectetYear;
|
||||
let training;
|
||||
|
||||
if (kwParam) {
|
||||
if (idParam) {
|
||||
training = await getTrainingbyID(idParam);
|
||||
} else if (kwParam) {
|
||||
selectedKW = kwParam;
|
||||
if (jahrParam) {
|
||||
selectedYear = jahrParam;
|
||||
} else {
|
||||
selectedYear = moment().year();
|
||||
}
|
||||
training = await getTraining(selectedKW, selectedYear);
|
||||
} else {
|
||||
selectedKW = moment().isoWeek();
|
||||
}
|
||||
|
||||
if (jahrParam) {
|
||||
selectedYear = jahrParam;
|
||||
} else {
|
||||
selectedYear = moment().year();
|
||||
training = await getTraining(selectedKW, selectedYear);
|
||||
}
|
||||
|
||||
const training = await getTraining(selectedKW, selectedYear);
|
||||
|
||||
const anwesendResult = await pool.query(
|
||||
"SELECT * FROM anwesend WHERE fid_training = $1",
|
||||
[training.id]
|
||||
|
@ -695,10 +724,12 @@ app.get("/training", requireAuth, async (req, res) => {
|
|||
anwesend = anwesendResult.rows;
|
||||
const anzahl = anwesend.length;
|
||||
const trainingsResult = await pool.query(
|
||||
"SELECT kw, jahr FROM trainings ORDER BY kw ASC"
|
||||
"SELECT id, kw, jahr FROM trainings ORDER BY jahr DESC, kw DESC"
|
||||
);
|
||||
const trainingsDates = trainingsResult.rows.map((tr) => ({
|
||||
kw: tr.kw,
|
||||
id: tr.id,
|
||||
jahr: tr.jahr,
|
||||
datum: formatDate(getdayOfWeek(tr.kw, tr.jahr)),
|
||||
}));
|
||||
|
||||
|
@ -1191,5 +1222,6 @@ app.post("/feature", requireAdmin, async (req, res) => {
|
|||
});
|
||||
|
||||
const server = app.listen(port, "0.0.0.0", () => {
|
||||
console.log(`Server is running on ${process.env.HOST}:${port}/`);
|
||||
log.Info(`Server is running on ${process.env.HOST}:${port}/`);
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<%- include('partials/header') %>
|
||||
<h1>
|
||||
<div>
|
||||
<% if (previousTraining) { %>
|
||||
<a href="/training?kw=<%= previousTraining.kw %>"> < </a>
|
||||
<% if (previousTraining) { %>
|
||||
<a href="/training?kw=<%= previousTraining.kw %>&jahr=<%= previousTraining.jahr %>"> < </a>
|
||||
<% } %>
|
||||
Training <%= moment(training.datum).format('DD.MM.YYYY') %>
|
||||
<% if (nextTraining) { %>
|
||||
<a href="/training?kw=<%= nextTraining.kw %>"> > </a>
|
||||
<a href="/training?kw=<%= nextTraining.kw %>&jahr=<%= nextTraining.jahr %>"> > </a>
|
||||
<% } %>
|
||||
</h1>
|
||||
</div>
|
||||
|
@ -272,9 +272,9 @@
|
|||
<div>
|
||||
<form method="GET" action="/training">
|
||||
<label for="training-date">Datum wählen:</label>
|
||||
<select id="training-date" name="kw" onchange="this.form.submit()">
|
||||
<select id="training-date" name="id" onchange="this.form.submit()">
|
||||
<% trainingsDates.forEach(date => { %>
|
||||
<option value="<%= date.kw %>" <%= selectedKW === date.kw ? 'selected' : '' %>>
|
||||
<option value="<%= date.id %>" <%= selectedKW === date.kw ? 'selected' : '' %>>
|
||||
<%= date.datum %> %>
|
||||
</option>
|
||||
<% }) %>
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<h1>
|
||||
<div>
|
||||
<% if (previousTraining) { %>
|
||||
<a href="/training?kw=<%= previousTraining.kw %>"> < </a>
|
||||
<a href="/training?kw=<%= previousTraining.kw %>&jahr=<%= previousTraining.jahr %>"> < </a>
|
||||
<% } %>
|
||||
Training <%= moment(training.datum).format('DD.MM.YYYY') %>
|
||||
<% if (nextTraining) { %>
|
||||
<a href="/training?kw=<%= nextTraining.kw %>"> > </a>
|
||||
<a href="/training?kw=<%= nextTraining.kw %>&jahr=<%= nextTraining.jahr %>"> > </a>
|
||||
<% } %>
|
||||
</h1>
|
||||
</div>
|
||||
|
@ -387,9 +387,9 @@
|
|||
<div>
|
||||
<form method="GET" action="/training">
|
||||
<label for="training-date">Datum wählen:</label>
|
||||
<select id="training-date" name="kw" onchange="this.form.submit()">
|
||||
<select id="training-date" name="id" onchange="this.form.submit()">
|
||||
<% trainingsDates.forEach(date => { %>
|
||||
<option value="<%= date.kw %>" <%= selectedKW === date.kw ? 'selected' : '' %>>
|
||||
<option value="<%= date.id %>" <%= selectedKW === date.kw && selectedYear == date.jahr ? 'selected' : '' %>>
|
||||
<%= date.datum %> %>
|
||||
</option>
|
||||
<% }) %>
|
||||
|
|
Loading…
Reference in New Issue