2025-01-27 18:50:24 +01:00
|
|
|
let prevMonthBtn, nextMonthBtn, month
|
|
|
|
let prevWeekBtn, nextWeekBtn, week
|
2025-01-26 02:01:38 +01:00
|
|
|
let curYear = new Date().getFullYear()
|
|
|
|
let curMonth = new Date().getMonth()
|
2025-01-27 18:50:24 +01:00
|
|
|
let curWeekDate = new Date()
|
|
|
|
|
2025-01-26 02:01:38 +01:00
|
|
|
function prevMonth() {
|
|
|
|
curMonth = curMonth - 1
|
|
|
|
if (curMonth < 0) {
|
|
|
|
curMonth += 12
|
|
|
|
curYear -= 1
|
|
|
|
}
|
2025-01-27 18:50:24 +01:00
|
|
|
updateListMonthly()
|
2025-01-26 02:01:38 +01:00
|
|
|
}
|
|
|
|
function nextMonth() {
|
|
|
|
curMonth = curMonth + 1
|
|
|
|
if (curMonth >= 12) {
|
|
|
|
curMonth -= 12
|
|
|
|
curYear += 1
|
|
|
|
}
|
2025-01-27 18:50:24 +01:00
|
|
|
updateListMonthly()
|
|
|
|
}
|
|
|
|
function prevWeek() {
|
|
|
|
curWeekDate = new Date(curWeekDate.valueOf() - 7 * DAY_MS)
|
|
|
|
updateListWeekly()
|
|
|
|
}
|
|
|
|
function nextWeek() {
|
|
|
|
curWeekDate = new Date(curWeekDate.valueOf() + 7 * DAY_MS)
|
|
|
|
updateListWeekly()
|
2025-01-26 02:01:38 +01:00
|
|
|
}
|
|
|
|
|
2025-01-27 18:50:24 +01:00
|
|
|
function updateListMonthly() {
|
2025-01-26 02:01:38 +01:00
|
|
|
let year = curYear.toString().padStart(4, "0")
|
|
|
|
let month = (curMonth + 1).toString().padStart(2, "0")
|
|
|
|
let today = new Date()
|
|
|
|
let txt = MONTHS[curMonth]
|
|
|
|
if (today.getFullYear() !== curYear) {
|
|
|
|
txt += " " + year.toString().padStart(4, "0")
|
|
|
|
}
|
|
|
|
document.getElementById("month").innerText = txt
|
|
|
|
|
|
|
|
fetch(`stats/by-month/${year}/${month}/`).then(res => {
|
|
|
|
return res.json()
|
|
|
|
}).then(res => {
|
|
|
|
if (res.status !== "success") {
|
|
|
|
return
|
|
|
|
}
|
2025-01-27 18:50:24 +01:00
|
|
|
setListElements(res.data.parents)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateListWeekly() {
|
2025-02-02 15:15:25 +01:00
|
|
|
let weekNum = curWeekDate.getWeek()
|
2025-01-27 18:50:24 +01:00
|
|
|
let weekDay = (curWeekDate.getDay() + 6) % 7
|
|
|
|
let startDate = new Date(curWeekDate.valueOf() - weekDay * DAY_MS)
|
|
|
|
let endDate = new Date(startDate.valueOf() + 6 * DAY_MS)
|
|
|
|
|
|
|
|
let today = new Date()
|
2025-02-02 15:15:25 +01:00
|
|
|
let date = `${MONTHS[startDate.getMonth()]} ${startDate.getDate()}`
|
2025-01-27 18:50:24 +01:00
|
|
|
if (startDate.getFullYear() !== today.getFullYear()) {
|
2025-02-02 15:15:25 +01:00
|
|
|
date += " " + startDate.getFullYear().toString().padStart(4, "0")
|
2025-01-27 18:50:24 +01:00
|
|
|
}
|
2025-02-02 15:15:25 +01:00
|
|
|
document.getElementById("week").innerText = `Week ${weekNum} (${date})`
|
2025-01-27 18:50:24 +01:00
|
|
|
|
|
|
|
fetch(`stats/between/${formatDate(startDate)}/${formatDate(endDate)}/`).then(res => {
|
|
|
|
return res.json()
|
|
|
|
}).then(res => {
|
|
|
|
if (res.status !== "success") {
|
2025-01-26 02:01:38 +01:00
|
|
|
return
|
|
|
|
}
|
2025-01-27 18:50:24 +01:00
|
|
|
setListElements(res.data.parents)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setListElements(data) {
|
|
|
|
data = data.filter(parent => parent.duration !== null)
|
|
|
|
let list = document.getElementById("list")
|
|
|
|
let template = document.querySelector(".by-range .template.row").cloneNode(true)
|
|
|
|
template.classList.remove("template")
|
|
|
|
list.innerHTML = ""
|
|
|
|
if (data.length === 0) {
|
|
|
|
let noData = document.querySelector(".by-range .template.no-data").cloneNode(true)
|
|
|
|
noData.classList.remove("template")
|
|
|
|
list.appendChild(noData)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data.forEach(parent => {
|
|
|
|
let row = template.cloneNode(true)
|
|
|
|
row.querySelector(".name").innerText = `${parent.name} (${parent.project_num})`
|
|
|
|
row.querySelector(".duration").innerText = formatDuration(parent.duration)
|
|
|
|
list.appendChild(row)
|
2025-01-26 02:01:38 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", () => {
|
2025-01-27 18:50:24 +01:00
|
|
|
prevMonthBtn = document.getElementById("prev-month")
|
|
|
|
nextMonthBtn = document.getElementById("next-month")
|
2025-01-26 02:01:38 +01:00
|
|
|
month = document.getElementById("month")
|
|
|
|
|
2025-01-27 18:50:24 +01:00
|
|
|
prevWeekBtn = document.getElementById("prev-week")
|
|
|
|
nextWeekBtn = document.getElementById("next-week")
|
|
|
|
week = document.getElementById("week")
|
|
|
|
|
|
|
|
prevMonthBtn.addEventListener("click", () => prevMonth())
|
|
|
|
nextMonthBtn.addEventListener("click", () => nextMonth())
|
|
|
|
prevWeekBtn.addEventListener("click", () => prevWeek())
|
|
|
|
nextWeekBtn.addEventListener("click", () => nextWeek())
|
|
|
|
|
|
|
|
let monthGrp = document.getElementById("month-sel")
|
|
|
|
let weekGrp = document.getElementById("week-sel")
|
|
|
|
|
|
|
|
rangeSel = document.getElementById("range-sel")
|
|
|
|
rangeSel.addEventListener("change", () => {
|
|
|
|
let mode = rangeSel.value
|
|
|
|
if (mode === "weekly") {
|
|
|
|
monthGrp.classList.add("hidden")
|
|
|
|
weekGrp.classList.remove("hidden")
|
|
|
|
updateListWeekly()
|
|
|
|
} else {
|
|
|
|
monthGrp.classList.remove("hidden")
|
|
|
|
weekGrp.classList.add("hidden")
|
|
|
|
updateListMonthly()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
updateListMonthly()
|
2025-01-26 02:01:38 +01:00
|
|
|
})
|