This commit is contained in:
+3
-2
@@ -123,9 +123,10 @@ async function start() {
|
|||||||
|
|
||||||
// Home page
|
// Home page
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
const { Hunts } = require('./models');
|
const { Hunts, Scans } = require('./models');
|
||||||
const hunts = Hunts.getAll();
|
const hunts = Hunts.getAll();
|
||||||
res.render('home', { title: 'Loot Hunt', hunts });
|
const recentActivity = Scans.getRecentActivity(5);
|
||||||
|
res.render('home', { title: 'Loot Hunt', hunts, recentActivity });
|
||||||
});
|
});
|
||||||
|
|
||||||
// 404 handler
|
// 404 handler
|
||||||
|
|||||||
@@ -329,6 +329,22 @@ const Scans = {
|
|||||||
GROUP BY u.id
|
GROUP BY u.id
|
||||||
ORDER BY total_points DESC
|
ORDER BY total_points DESC
|
||||||
`).all();
|
`).all();
|
||||||
|
},
|
||||||
|
|
||||||
|
getRecentActivity(limit = 5) {
|
||||||
|
return db.prepare(`
|
||||||
|
SELECT s.points_awarded, s.scanned_at,
|
||||||
|
u.username,
|
||||||
|
p.card_number,
|
||||||
|
h.name as hunt_name, h.short_name as hunt_short_name, h.package_count
|
||||||
|
FROM scans s
|
||||||
|
JOIN users u ON s.user_id = u.id
|
||||||
|
JOIN packages p ON s.package_id = p.id
|
||||||
|
JOIN hunts h ON p.hunt_id = h.id
|
||||||
|
WHERE s.points_awarded > 0
|
||||||
|
ORDER BY s.scanned_at DESC
|
||||||
|
LIMIT ?
|
||||||
|
`).all(limit);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,21 @@
|
|||||||
</a>
|
</a>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
<% if (typeof recentActivity !== 'undefined' && recentActivity && recentActivity.length > 0) { %>
|
||||||
|
<h2 style="margin-top: 2rem; margin-bottom: 1rem;">Recent Activity</h2>
|
||||||
|
<div class="card">
|
||||||
|
<% recentActivity.forEach(a => { %>
|
||||||
|
<div style="display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid #eee;">
|
||||||
|
<span class="points-badge" style="font-size: 0.85rem; padding: 0.25rem 0.6rem;">+<%= a.points_awarded %></span>
|
||||||
|
<div style="flex: 1; min-width: 0;">
|
||||||
|
<div style="font-weight: 600;"><a href="/player/<%= a.username %>" style="text-decoration: none; color: inherit;"><%= a.username %></a> found <a href="/hunt/<%= a.hunt_short_name %>/<%= a.card_number %>" style="color: var(--primary);">#<%= a.card_number %></a> in <a href="/hunt/<%= a.hunt_short_name %>" style="color: var(--primary);"><%= a.hunt_name %></a></div>
|
||||||
|
<div style="font-size: 0.8rem; color: var(--muted);"><%= new Date(a.scanned_at).toLocaleString() %></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% }) %>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%- include('partials/footer') %>
|
<%- include('partials/footer') %>
|
||||||
|
|||||||
Reference in New Issue
Block a user