Errorhandling und Speicher-Bestätigung
This commit is contained in:
parent
917fa0250e
commit
dde15591aa
69
app.js
69
app.js
|
@ -234,6 +234,9 @@ app.post('/login', async (req, res) => {
|
|||
if (user.is_active) {
|
||||
req.session.userId = user.id;
|
||||
req.session.userName = user.username;
|
||||
req.session.activeRiege = 1;
|
||||
req.session.activeTab = 'geraete';
|
||||
req.session.message = [ title = '', message = '', type = 'none' ];
|
||||
if (user.admin_status === 'expired') {
|
||||
await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]);
|
||||
req.session.role='user';
|
||||
|
@ -420,6 +423,7 @@ app.post('/profile', requireAuth, async (req, res) => {
|
|||
|
||||
app.post('/update-training', requireAuth, async (req, res) => {
|
||||
const { trainingId, type, spielName } = req.body;
|
||||
req.session.activeTab = 'spiel';
|
||||
let spielId;
|
||||
|
||||
const spiel = await pool.query(`SELECT * FROM spiele WHERE name = $1`, [spielName]);
|
||||
|
@ -439,6 +443,7 @@ app.post('/update-training', requireAuth, async (req, res) => {
|
|||
} else if (type === 'aufwaermen') {
|
||||
await pool.query('UPDATE trainings SET aufwaermen = $1 WHERE id = $2', [ spielId, trainingId ]);
|
||||
}
|
||||
req.session.message = [title = '', body = '', type = 'none'];
|
||||
res.redirect('/training');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@ -449,7 +454,7 @@ app.post('/update-training', requireAuth, async (req, res) => {
|
|||
|
||||
app.post('/update-leader', requireAuth , async (req, res) => {
|
||||
const { trainingId, type, leaderId } = req.body;
|
||||
|
||||
req.session.activeTab = 'spiel';
|
||||
try {
|
||||
if (type === 'aufwaermleiter') {
|
||||
await pool.query('UPDATE trainings SET aufwaermleiter = $1 WHERE id = $2', [leaderId, trainingId]);
|
||||
|
@ -562,6 +567,8 @@ app.get('/training', requireAuth, async (req, res) => {
|
|||
previousTraining,
|
||||
nextTraining,
|
||||
riegen,
|
||||
activeRiege: req.session.activeRiege,
|
||||
activeTab: req.session.activeTab,
|
||||
moment
|
||||
});
|
||||
} catch (error) {
|
||||
|
@ -601,8 +608,8 @@ app.get('/riege', requireAuth, async (req, res) => {
|
|||
res.render('riegen', { riegen: riegen, session: req.session });
|
||||
} catch (error) {
|
||||
console.error('Error fetching riegen:', error);
|
||||
const message = 'Error fetching riegen:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.render('error', {session: req.session});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -618,8 +625,8 @@ app.get('/teilnehmer', requireAuth, async (req, res) => {
|
|||
res.render('teilnehmer', { teilnehmende, session: req.session });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.render('error', { session: req.session });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -629,6 +636,7 @@ app.get('/mitglied/:id', requireAuth, async (req, res) => {
|
|||
const userResult = await pool.query('SELECT * FROM teilnehmende WHERE id = $1', [id]);
|
||||
const riegeResult = await pool.query('SELECT * FROM riegen WHERE fremdid_teilnehmende = $1', [id]);
|
||||
const riege = riegeResult.rows[0].riegennummer;
|
||||
req.session.activeRiege = riege;
|
||||
const numberResult = await pool.query('SELECT telefonnummern.*, telverbindung.bezeichnung FROM telefonnummern JOIN telverbindung ON telefonnummern.verbindung = telverbindung.id WHERE telefonnummern.fid_teilnehmer = $1', [id]);
|
||||
const numbers = numberResult.rows
|
||||
if (userResult.rows.length > 0) {
|
||||
|
@ -644,12 +652,13 @@ app.get('/mitglied/:id', requireAuth, async (req, res) => {
|
|||
session: req.session
|
||||
});
|
||||
} else {
|
||||
res.status(400).send('Mitglied existiert nicht');
|
||||
req.session.message = ['Error', 'Mitglied existiert nicht' , 'error'];
|
||||
res.redirect('/teilnehmer')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in Mitglied:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', 'Mitglied existiert nicht' , 'error'];
|
||||
res.redirect('/teilnehmer');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -675,13 +684,14 @@ app.post('/update-mitglied', requireAdmin, async (req, res) => {
|
|||
res.redirect('/mitglied/' + id);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.redirect('/mitglied/' + id);
|
||||
}
|
||||
});
|
||||
|
||||
// Login und Registrierung anzeigen
|
||||
app.get('/login', (req, res) => {
|
||||
req.session.message=['', '', 'none'];
|
||||
res.render('login', {session: req.session}); // Stelle sicher, dass es eine login.ejs gibt
|
||||
});
|
||||
|
||||
|
@ -698,8 +708,8 @@ app.get('/spiele', async (req, res) => {
|
|||
res.render('spiele', { spiele, session: req.session });
|
||||
} catch (error) {
|
||||
console.error('Error in Mitglied:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.render('spiele', { spiele, session: req.session });
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -715,12 +725,17 @@ app.get('/spiel/:id', async (req, res) => {
|
|||
const { id } = req.params;
|
||||
try {
|
||||
const spieleResult = await pool.query('SELECT * FROM spiele WHERE id = $1', [id]);
|
||||
if (spieleResult.rows.length > 0) {
|
||||
const spiel = spieleResult.rows[0];
|
||||
res.render('spiel', { spiel, session: req.session });
|
||||
} else {
|
||||
req.session.message = ['Error', 'Spiel existiert nicht', 'error'];
|
||||
res.redirect('/spiele');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in Mitglied:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
console.error('Error in Spiele:', error);
|
||||
req.session.message = ['Error', 'Spiel existiert nicht' , 'error'];
|
||||
res.redirect('/spiele');
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -729,17 +744,19 @@ app.post('/edit-spiel', requireAuth, async (req, res) => {
|
|||
const { material, dauer, regeln, variationen, type, id } = req.body;
|
||||
try {
|
||||
const queryResult = await pool.query('UPDATE spiele set material = $1, regeln = $2, dauer = $3, variationen = $4, type = $5 Where id = $6 ', [material, regeln, dauer, variationen, type, id]);
|
||||
req.session.message = ['Erfolg', 'Das Spiel wurde gespeichert', 'success'];
|
||||
res.redirect('/spiel/' + id);
|
||||
} catch (error) {
|
||||
console.error('Error in edit Spiel:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.redirect('/spiel/' + id);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// Startseite
|
||||
app.get('/', (req, res) => {
|
||||
req.session.message = ['', '', 'none']
|
||||
res.render('index', {session: req.session});
|
||||
});
|
||||
|
||||
|
@ -749,11 +766,12 @@ app.get('/changelog', async (req, res) => {
|
|||
try {
|
||||
const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;');
|
||||
const changes = changeResult.rows;
|
||||
req.session.message = ['Erfolg', 'Log gespeichert' , 'success'];
|
||||
res.render('changelog', { changes, session: req.session });
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.redirect('/changelog');
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -767,22 +785,25 @@ app.post('/changelog', requireAdmin, async (req, res) => {
|
|||
res.render('changelog', { changes, session: req.session });
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.render('changelog', { changes, session: req.session });
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/anwesend', requireAuth, async (req, res) => {
|
||||
const { anw, trainingId } = req.body;
|
||||
const { anw, trainingId, riege } = req.body;
|
||||
req.session.activeTab = 'anwesend';
|
||||
req.session.message = [title = 'Erfolg', body = 'Die Anwesenheit wurde gespeichert', type = 'success'];
|
||||
try {
|
||||
for (const teilnehmer of anw) {
|
||||
await pool.query('INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)', [teilnehmer, trainingId]);
|
||||
}
|
||||
req.session.activeRiege = riege;
|
||||
res.redirect('/training');
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
const message = 'Error:' + error;
|
||||
res.render('error', {session: req.session, message});
|
||||
req.session.message = ['Error', error , 'error'];
|
||||
res.redirect('/training');
|
||||
}})
|
||||
|
||||
const server = app.listen(port, '0.0.0.0', () => {
|
||||
|
|
|
@ -63,3 +63,29 @@
|
|||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
|
||||
<symbol id="check-circle-fill" viewBox="0 0 16 16">
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
|
||||
</symbol>
|
||||
<symbol id="info-fill" viewBox="0 0 16 16">
|
||||
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/>
|
||||
</symbol>
|
||||
<symbol id="exclamation-triangle-fill" viewBox="0 0 16 16">
|
||||
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
|
||||
</symbol>
|
||||
</svg>
|
||||
|
||||
<% if (session.message){ %>
|
||||
<% if (session && session.message[2] === 'success') { %>
|
||||
<div class="alert alert-success" role="alert">
|
||||
</svg> <%= session.message[0] %> - <%= session.message[1] %>
|
||||
</div>
|
||||
<% session.message[2] = 'none' %>
|
||||
<% } %>
|
||||
<% if (session && session.message[2] === 'error') { %>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
</svg> <%= session.message[0] %> - <%= session.message[1] %>
|
||||
</div>
|
||||
<% session.message[2] = 'none' %>
|
||||
<% } %>
|
||||
<% } %>
|
|
@ -14,18 +14,18 @@
|
|||
<!-- 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 <%= activeTab === 'geraete' ? '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>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<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 <%= activeTab === 'spiel' ? 'active' : '' %>" 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>
|
||||
</li><li class="nav-item" role="presentation">
|
||||
<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>
|
||||
<button class="nav-link <%= activeTab === 'anwesend' ? 'active' : '' %>" 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) { %>
|
||||
<div class="tab-content" id="myTabContent">
|
||||
<div class="tab-pane fade show active" id="geraete" role="tabpanel" aria-labelledby="tab-geraete">
|
||||
<div class="tab-pane fade <%= activeTab === 'geraete' ? 'show active' : '' %>" id="geraete" role="tabpanel" aria-labelledby="tab-geraete">
|
||||
<h2> Geräte </h2>
|
||||
<ul>
|
||||
<li>Riege 1: <%= training.geraet_riege_1_name %></li>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<li>Riege 5: <%= training.geraet_riege_5_name %></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="spiel" role="tabpanel" aria-labelledby="tab-spiel">
|
||||
<div class="tab-pane fade <%= activeTab === 'spiel' ? 'show active' : '' %>" id="spiel" role="tabpanel" aria-labelledby="tab-spiel">
|
||||
<div id="aufwaermen">
|
||||
<h3>Aufwärmen:</h3>
|
||||
|
||||
|
@ -118,14 +118,14 @@
|
|||
|
||||
|
||||
</div>
|
||||
<div class="tab-pane fade active" id="anwesend" role="tabpanel" aria-labelledby="tab-anwesend">
|
||||
<div class="tab-pane fade <%= activeTab === 'anwesend' ? 'show 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>
|
||||
<button class="nav-link <%= activeRiege == riegennummer ? '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>
|
||||
|
@ -133,7 +133,7 @@
|
|||
<!-- 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 %>">
|
||||
<div class="tab-pane fade <%= activeRiege == riegennummer ? 'show active' : '' %>" id="riege-<%= riegennummer %>" role="tabpanel" aria-labelledby="tab-<%= riegennummer %>">
|
||||
<form method="post" action="/anwesend">
|
||||
<table>
|
||||
|
||||
|
@ -156,6 +156,7 @@
|
|||
|
||||
</table>
|
||||
<input type="hidden" name="trainingId" value="<%= training.id %>">
|
||||
<input type="hidden" name="riege" value="<%= riegennummer %>">
|
||||
<button type="submit">Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue