This commit is contained in:
2024-09-03 17:09:28 +02:00
parent 4e5c27d920
commit 91d32f2f71
5 changed files with 83 additions and 10 deletions

View File

@ -120,7 +120,11 @@ app.get("/person/:id", async (req, res) => {
return;
}
ejs.renderFile('src/templates/person.ejs', { person: person }, function (err, str) {
let points = await db.query.pointsTable.findMany({
where: eq(pointsTable.personId, id)
});
ejs.renderFile('src/templates/person.ejs', { person: person, points: JSON.stringify(points) }, function (err, str) {
if (err) {
res.status(500).send(err);
}

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="/bootstrap.min.css" />
<script src="/bootstrap.bundle.min.css"></script>
<script src="/bootstrap.bundle.min.js"></script>
<title>Index</title>
</head>

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="/bootstrap.min.css" />
<script src="/bootstrap.bundle.min.css"></script>
<script src="/bootstrap.bundle.min.js"></script>
<title>Index</title>
</head>

View File

@ -5,18 +5,67 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="/bootstrap.min.css" />
<script src="/bootstrap.bundle.min.css"></script>
<script src="/bootstrap.bundle.min.js"></script>
<script src="/chart.js"></script>
<title>Person <%= person.name %></title>
</head>
<body data-bs-theme="dark">
<a href="/">Index</a>
<a href="/gamble/<%= person.personId %>">gamble</a>
<p>
Name: <%= person.name %>
</p>
<p>
Points: <%= person.pointsTotal %>
</p>
<div class="container">
<div class="row">
<div class="col col-12 col-lg-4">
<div class="h-100 d-flex flex-column justify-content-center">
<div class="border rounded p-3 m-1">
Name: <%= person.name %>
</div>
<div class="border rounded p-3 m-1">
Points: <%= person.pointsTotal %>
</div>
</div>
</div>
<div class="col col-12 col-lg-8 text-center">
<canvas id="chart"></canvas>
</div>
</div>
</div>
<script>
Chart.defaults.borderColor = '#777';
Chart.defaults.color = '#fff';
const rawPoints = <%- points %>;
let points = {
0: 0
};
let runningSum = 0;
for (let i = 0; i < rawPoints.length; i++) {
runningSum += rawPoints[i].points;
points[i+1] = runningSum;
}
console.log(points);
const ctx = document.getElementById('chart');
new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Body',
data: points,
borderWidth: 2
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
</body>
</html>

20
www/chart.js Normal file

File diff suppressed because one or more lines are too long