-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a simple leaderboard on the homepage.
- Loading branch information
Showing
9 changed files
with
550 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
}, | ||
"dependencies": { | ||
"express": "^4.19.2", | ||
"mysql2": "^3.11.0" | ||
"mysql2": "^3.11.0", | ||
"pug": "^3.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
font-family: sans-serif; | ||
font-size: 16px; | ||
line-height: 1.4; | ||
margin: 0; | ||
} | ||
|
||
h1, h2 { | ||
margin: 0; | ||
line-height: 1; | ||
word-wrap: break-word; | ||
} | ||
|
||
h1 { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.header { | ||
background: #333; | ||
color: #fafafa; | ||
padding: 4rem 1rem; | ||
text-align: center; | ||
} | ||
|
||
.leaderboard { | ||
max-width: 750px; | ||
padding-inline: 1rem; | ||
margin-inline: auto; | ||
margin-block: 1rem; | ||
} | ||
|
||
.leaderboard > div { | ||
display: grid; | ||
grid-template-columns: 1.5rem 1fr 3rem; | ||
gap: .5rem; | ||
padding: .5rem; | ||
} | ||
|
||
.leaderboard > div:not(:last-child) { | ||
border-bottom: 1px solid #ccc; | ||
} | ||
|
||
.leaderboard > div:hover { | ||
background: #333; | ||
color: #fafafa; | ||
} | ||
|
||
.leaderboard-number, | ||
.leaderboard-video-count { | ||
text-align: right; | ||
} | ||
|
||
.leaderboard-nickname { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const leaderboard = require('../../services/leaderboard'); | ||
|
||
/* GET leaderboard */ | ||
router.get('/', async function(req, res, next) { | ||
try { | ||
res.json(await leaderboard.get(req.query.page)); | ||
} catch (err) { | ||
console.error(`Error while getting leaderboard `, err.message); | ||
next(err); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const leaderboard = require('../services/leaderboard'); | ||
|
||
router.get("/", async (req, res) => { | ||
const users = await leaderboard.getTop50(); | ||
|
||
return res.render('home', { users }); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const db = require('./db'); | ||
const helper = require('../helper'); | ||
const config = require('../config'); | ||
|
||
const sql = `SELECT nickname, COUNT(DISTINCT videoId) AS video_count FROM user_video | ||
INNER JOIN ircbot.user ON ircbot.user_video.userId = ircbot.user.userId GROUP BY user_video.userId | ||
ORDER BY video_count DESC LIMIT ?,?`; | ||
|
||
async function get(page = 1){ | ||
const offset = helper.getOffset(page, config.listPerPage); | ||
const rows = await db.query(sql, [offset, config.listPerPage]); | ||
const data = helper.emptyOrRows(rows); | ||
const meta = {page}; | ||
|
||
return { | ||
data, | ||
meta | ||
} | ||
} | ||
|
||
async function getTop50() { | ||
const rows = await db.query(sql, ['0', '50']); | ||
const data = helper.emptyOrRows(rows); | ||
|
||
return { | ||
data, | ||
} | ||
} | ||
|
||
module.exports = { | ||
get, | ||
getTop50, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
doctype html | ||
html(lang="en") | ||
head | ||
meta(charset="UTF-8") | ||
meta(name="viewport", content="width=device-width, initial-scale=1") | ||
link(rel="stylesheet", href="/app.css") | ||
title MusicBox Leaderboard | ||
body | ||
header(class="header") | ||
hgroup | ||
h1 MusicBox Leaderboard | ||
h2 Top 50 | ||
section(class="leaderboard") | ||
each user, index in users.data | ||
div | ||
span(class="leaderboard-number")= index + 1 + "." | ||
span(class="leaderboard-nickname")= user.nickname | ||
span(class="leaderboard-video-count")= user.video_count |