diff --git a/assets/helper.js b/assets/helper.js new file mode 100644 index 00000000..b8f16b2a --- /dev/null +++ b/assets/helper.js @@ -0,0 +1,38 @@ +import { take, get } from 'lodash' + +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(), highlight: { color: 'green', fillMode: 'outline' } }) + + function getColor (event) { + const color = { class: 'vc-rounded-full', color: 'blue', fillMode: 'normal' } + const tag = get(event, 'tags[0]') + if (!tag) { return color } + const idx = tags.indexOf(tag) + if (idx < 0) { return color } + color.color = colors[idx] + return color + } + + 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: getColor(e), + dates: { start: new Date(e.start_datetime * 1000), end: new Date(e.end_datetime * 1000) } + }))) + + return attributes +} diff --git a/components/Calendar.vue b/components/Calendar.vue index aaa643e1..ac89e7e3 100644 --- a/components/Calendar.vue +++ b/components/Calendar.vue @@ -16,7 +16,7 @@