From e94f8ef94c40dc42e64d723af71599ae735720f5 Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 6 Mar 2022 20:36:21 +0000 Subject: [PATCH] Added class stat data, and amended pluralisation logic --- routes/admin.js | 7 ++++--- routes/class.js | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/routes/admin.js b/routes/admin.js index 95cdee5..c7b1e8e 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -26,17 +26,18 @@ router.get('/dashboard', async (req, res) => { stats: [ { value: classes.length, - text: 'Class' + (classes.length > 1 ? 'es' : '') + text: 'Class' + + (classes.length !== 1 ? 'es' : '') }, { value: recentTests.length, text: 'Completed Test' + - (recentTests.length > 1 ? 's' : '') + (recentTests.length !== 1 ? 's' : '') }, { value: upcomingTests.length, text: 'Upcoming Test' + - (upcomingTests.length > 1 ? 's' : '') + (upcomingTests.length !== 1 ? 's' : '') }, { value: '90%', diff --git a/routes/class.js b/routes/class.js index 7a47450..7254e66 100644 --- a/routes/class.js +++ b/routes/class.js @@ -35,31 +35,36 @@ router.get('/class/:id', async (req, res) => { return res.redirect('/admin/classes'); const linkRoot = `/class/${c.id}`; + const upcomingTests = await c.getTests({ range: 'after' }); + const recentTests = await c.getTests({ range: 'before' }); + const testCount = recentTests.length + upcomingTests.length; return res.render('class', { - title: `Stratos - Class - ${c.name}`, + title: `Stratos - ${c.name}`, current: 'Classes', name: req.session.fullName, className: c.name, teachers: c.teachers, members: c.students, - recentTests: await c.getTests({ range: 'before' }), - upcomingTests: await c.getTests({ range: 'after' }), + recentTests: recentTests, + upcomingTests: upcomingTests, contactLink: `${linkRoot}/contact`, testsLink: `${linkRoot}/tests`, reportsLink: `${linkRoot}/reports`, stats: [ { - value: 5, - text: 'Tests' + value: testCount, + text: 'Test' + (testCount !== 1 ? 's' : '') }, { - value: 3, - text: 'Tests completed' + value: recentTests.length, + text: 'Completed test' + + (recentTests.length !== 1 ? 's' : '') }, { - value: 2, - text: 'Tests upcoming' + value: upcomingTests.length, + text: 'Upcoming test' + + (upcomingTests.length !== 1 ? 's' : '') }, { value: '72%',