gancio-upstream/components/Calendar.vue

98 lines
2.4 KiB
Vue
Raw Normal View History

2020-12-03 01:05:26 +01:00
<template lang="pug">
#calendar
v-calendar(
title-position='left'
:is-dark="settings['theme.is_dark']"
2021-01-11 00:17:56 +01:00
:columns="2"
2020-12-03 01:05:26 +01:00
@update:from-page='updatePage'
:locale='$i18n.locale'
:attributes='attributes'
transition='fade'
is-expanded
is-inline
@dayclick='click')
</template>
<script>
2020-12-04 17:24:52 +01:00
import { mapState, mapActions } from 'vuex'
2020-12-03 01:05:26 +01:00
import dayjs from 'dayjs'
import { take, get } from 'lodash'
export default {
name: 'Calendar',
props: {
2021-01-11 00:17:56 +01:00
events: { type: Array, default: () => [] }
2020-12-03 01:05:26 +01:00
},
data () {
const month = dayjs().month() + 1
const year = dayjs().year()
return {
page: { month, year }
}
},
computed: {
...mapState(['tags', 'filters', 'in_past', 'settings']),
// TODO: could be better
attributes () {
2021-01-11 00:17:56 +01:00
return []
2020-12-04 17:24:52 +01:00
const colors = ['blue', 'orange', 'yellow', 'teal', 'indigo', 'green', 'red', 'purple', 'pink', 'gray']
2020-12-03 01:05:26 +01:00
const tags = take(this.tags, 10).map(t => t.tag)
let attributes = []
2020-12-04 17:24:52 +01:00
attributes.push({ key: 'today', dates: new Date(), highlight: { color: 'green', fillMode: 'outline' } })
2020-12-03 01:05:26 +01:00
function getColor (event) {
2021-01-11 00:17:56 +01:00
const color = { class: 'vc-rounded-full', color: 'blue', fillMode: 'normal' }
2020-12-03 01:05:26 +01:00
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(this.events
.filter(e => !e.multidate)
.map(e => {
return {
key: e.id,
dot: getColor(e),
dates: new Date(e.start_datetime * 1000)
}
}))
attributes = attributes.concat(this.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
}
},
methods: {
...mapActions(['updateEvents', 'showPastEvents']),
updatePage (page) {
this.$emit('monthchange', page)
},
click (day) {
this.$emit('dayclick', day)
// const element = document.getElementById(day.day)
// if (element) { element.scrollIntoView() } // Even IE6 supports this
}
}
}
</script>
<style>
.vc-opacity-0 {
opacity: 0.3 !important;
}
.past-event {
opacity: 0.3;
}
</style>