set filter dates for server stats

This commit is contained in:
iamBadgers
2024-05-20 18:18:43 -07:00
parent 333b1d5799
commit 41ba017174

View File

@@ -79,9 +79,7 @@ import axios from 'axios'
const dateSelect = ref(-1)
const dateItems = [
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
]
const dateItems = buildDateItems()
const gameStats = ref({})
@@ -99,11 +97,38 @@ async function loadData() {
roleStats.value = roleStatsResponse.data
}
function buildDateItems() {
const items = [{title: "All Time", value: -1}]
const date = new Date()
while (date.getUTCFullYear() != 2023 || date.getUTCMonth() != 0) {
console.log(buildDateEntry(date))
items.push(buildDateEntry(date))
date.setUTCMonth(date.getUTCMonth() - 1)
}
items.push(buildDateEntry(date))
return items
}
function buildDateEntry(date: Date) {
const monthId = dateToMonthId(date)
return {
title: date.toLocaleString('en-us',{month:'short', year:'numeric'}),
value: monthId
}
}
function dateToMonthId(date: Date) {
return (((date.getUTCFullYear() - 2023) * 12) + (date.getUTCMonth()))
}
watch(dateSelect, async (newValue, oldValue) => {
loadData()
})
onMounted(async () => {
loadData()
console.log(buildDateItems())
})
</script>