diff --git a/assets/helper.js b/assets/helper.js index 01b9c1bc..aaa1dd02 100644 --- a/assets/helper.js +++ b/assets/helper.js @@ -1,56 +1,39 @@ -import take from 'lodash/take' -import get from 'lodash/get' import dayjs from 'dayjs' -export function attributesFromEvents (_events, _tags) { - const colors = ['blue', 'orange', 'yellow', 'teal', 'indigo', 'green', 'red', 'purple', 'pink', 'gray'] - const tags = take(_tags, 10).map(t => t.tag) - let attributes = [] - attributes.push({ key: 'today', dates: new Date(), bar: { color: 'green', fillMode: 'outline' } }) - const now = dayjs().unix() +export function attributesFromEvents (_events) { - function getColor (event, where) { - const color = { class: 'vc-rounded-full', color: 'blue', fillMode: where === 'base' ? 'light' : 'solid' } - const tag = get(event, 'tags[0]') - if (event.start_datetime < now) { - if (event.multidate) { - color.fillMode = where === 'base' ? 'light' : 'outline' - if (where === 'base') { - color.class += ' vc-past' - } - } else { - color.class += ' vc-past' - } + // const colors = ['teal', 'green', 'yellow', 'teal', 'indigo', 'green', 'red', 'purple', 'pink', 'gray'] + // merge events with same date + let attributes = [] + const now = dayjs().unix() + for(let e of _events) { + const key = dayjs.unix(e.start_datetime).format('YYYYMMDD') + const c = e.start_datetime < now ? 'vc-past' : '' + + const i = attributes.find(a => a.day === key) + if (!i) { + attributes.push({ day: key, key: e.id, n: 1, dates: new Date(e.start_datetime * 1000), + dot: { color: 'teal', class: c } }) + continue } - if (!tag) { return color } - const idx = tags.indexOf(tag) - if (idx < 0) { return color } - color.color = colors[idx] - // if (event.start_datetime < now) { color.class += ' vc-past' } - return color + + i.n++ + if (i.n >= 20 ) { + i.dot = { color: 'purple', class: c } + } 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 } + } + } - attributes = attributes.concat(_events - .filter(e => !e.multidate) - .map(e => { - return { - key: e.id, - dot: getColor(e), - dates: new Date(e.start_datetime * 1000) - } - })) - - attributes = attributes.concat(_events - .filter(e => e.multidate) - .map(e => ({ - key: e.id, - highlight: { - start: getColor(e), - base: getColor(e, 'base'), - end: getColor(e) - }, - dates: { start: new Date(e.start_datetime * 1000), end: new Date(e.end_datetime * 1000) } - }))) + // add a bar to highlight today + attributes.push({ key: 'today', dates: new Date(), highlight: { color: 'green', fillMode: 'outline' } }) return attributes } diff --git a/components/Calendar.vue b/components/Calendar.vue index 1451b976..66d7c2d8 100644 --- a/components/Calendar.vue +++ b/components/Calendar.vue @@ -16,7 +16,7 @@