gancio-upstream/assets/helper.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-04-26 23:13:59 +02:00
import dayjs from 'dayjs'
2021-03-10 16:09:35 +01:00
2022-09-05 15:28:00 +02:00
export function attributesFromEvents(_events) {
// merge events with same date
2021-03-10 16:09:35 +01:00
let attributes = []
2021-04-26 23:13:59 +02:00
const now = dayjs().unix()
2022-09-05 15:28:00 +02:00
for (let e of _events) {
const key = dayjs.unix(e.start_datetime).tz().format('MMDD') // Math.floor(e.start_datetime/(3600*24)) // dayjs.unix(e.start_datetime).tz().format('YYYYMMDD')
2022-09-05 15:28:00 +02:00
const c = (e.end_datetime || e.start_datetime) < now ? 'vc-past' : ''
2023-01-09 16:55:02 +01:00
if (e.multidate === true) {
2022-09-05 15:28:00 +02:00
attributes.push({
dates: { start: new Date(e.start_datetime * 1000), end: new Date(e.end_datetime * 1000) },
highlight: {
start: { fillMode: 'outline' },
base: { fillMode: 'light' },
end: { fillMode: 'outline' },
}
})
continue
}
2021-03-10 16:09:35 +01:00
const i = attributes.find(a => a.day === key)
if (!i) {
2022-09-05 15:28:00 +02:00
attributes.push({
day: key, key: e.id, n: 1, dates: new Date(e.start_datetime * 1000),
dot: { color: 'teal', class: c }
})
continue
}
2021-03-10 16:09:35 +01:00
i.n++
2022-09-05 15:28:00 +02:00
if (i.n >= 20) {
i.dot = { color: 'purple', class: c }
2022-09-05 15:28:00 +02:00
} else if (i.n >= 10) {
i.dot = { color: 'red', class: c }
} else if (i.n >= 5) {
i.dot = { color: 'orange', class: c }
} else if (i.n >= 3) {
i.dot = { color: 'yellow', class: c }
} else {
i.dot = { color: 'teal', class: c }
}
}
2021-03-10 16:09:35 +01:00
// add a bar to highlight today
attributes.push({ key: 'today', dates: new Date(), highlight: { color: 'green', fillMode: 'outline' } })
2021-03-10 16:09:35 +01:00
return attributes
}