show total reminders and intervals on admin dash

This commit is contained in:
jude 2023-07-10 09:59:11 +01:00
parent dda8bd3e10
commit 1a1a0fdefb
3 changed files with 38 additions and 0 deletions

View File

@ -133,6 +133,30 @@ pub async fn bot_data(cookies: &CookieJar<'_>, pool: &State<Pool<MySql>>) -> Jso
.await .await
.unwrap(); .unwrap();
let interval_count = sqlx::query!(
"SELECT COUNT(1) AS count
FROM reminders
WHERE
`interval_seconds` IS NOT NULL OR
`interval_months` IS NOT NULL OR
`interval_days` IS NOT NULL"
)
.fetch_one(pool.inner())
.await
.unwrap();
let reminder_count = sqlx::query!(
"SELECT COUNT(1) AS count
FROM reminders
WHERE
`interval_seconds` IS NULL AND
`interval_months` IS NULL AND
`interval_days` IS NULL"
)
.fetch_one(pool.inner())
.await
.unwrap();
Ok(json!({ Ok(json!({
"backlog": backlog.backlog, "backlog": backlog.backlog,
"scheduleShort": { "scheduleShort": {
@ -142,6 +166,10 @@ pub async fn bot_data(cookies: &CookieJar<'_>, pool: &State<Pool<MySql>>) -> Jso
"scheduleLong": { "scheduleLong": {
"once": schedule_once_long, "once": schedule_once_long,
"interval": schedule_interval_long, "interval": schedule_interval_long,
},
"count": {
"reminders": reminder_count.count,
"intervals": interval_count.count,
} }
})) }))
} }

View File

@ -3,6 +3,8 @@ document.addEventListener("DOMContentLoaded", () => {
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((data) => { .then((data) => {
document.querySelector("#backlog").textContent = data.backlog; document.querySelector("#backlog").textContent = data.backlog;
document.querySelector("#reminders").textContent = data.count.reminders;
document.querySelector("#intervals").textContent = data.count.intervals;
new Chart(document.getElementById("schedule"), { new Chart(document.getElementById("schedule"), {
type: "bar", type: "bar",

View File

@ -46,6 +46,14 @@
<p>Backlog</p> <p>Backlog</p>
<p class="figure-num" id="backlog">?</p> <p class="figure-num" id="backlog">?</p>
</div> </div>
<div class="stat-box figure">
<p>Reminders</p>
<p class="figure-num" id="reminders">?</p>
</div>
<div class="stat-box figure">
<p>Intervals</p>
<p class="figure-num" id="intervals">?</p>
</div>
</div> </div>
<div class="stat-row"> <div class="stat-row">
<div class="stat-box" style="height: 400px;"> <div class="stat-box" style="height: 400px;">