gancio/components/Calendar.vue

96 lines
2.5 KiB
Vue
Raw Normal View History

2019-04-03 00:25:12 +02:00
<template lang="pug">
2019-05-30 12:04:14 +02:00
#calendar
v-calendar(
title-position='left'
is-dark
@update:from-page='updatePage'
2020-01-15 23:17:38 +01:00
:columns="$screens({ default: 1, lg: 2 })"
:locale='$i18n.locale'
2019-04-03 00:25:12 +02:00
:attributes='attributes'
transition='fade'
2019-05-30 12:04:14 +02:00
is-expanded
is-inline
@dayclick='click')
2019-04-03 00:25:12 +02:00
</template>
<script>
2019-05-30 12:04:14 +02:00
import { mapState, mapActions, mapGetters } from 'vuex'
2020-01-15 23:17:38 +01:00
import moment from 'moment-timezone'
import { take, get } from 'lodash'
2019-04-03 00:25:12 +02:00
export default {
name: 'Calendar',
data () {
2019-09-11 19:12:24 +02:00
const month = moment().month() + 1
2019-04-03 00:25:12 +02:00
const year = moment().year()
return {
2019-09-11 19:12:24 +02:00
page: { month, year }
2019-04-03 00:25:12 +02:00
}
},
computed: {
...mapGetters(['filteredEventsWithPast']),
...mapState(['tags', 'filters', 'in_past']),
2019-08-09 13:21:32 +02:00
// TODO: could be better
2019-04-03 00:25:12 +02:00
attributes () {
2020-01-21 00:39:05 +01:00
const colors = ['green', 'orange', 'yellow', 'teal', 'indigo', 'blue', 'red', 'purple', 'pink', 'gray']
2019-09-11 19:12:24 +02:00
const tags = take(this.tags, 10).map(t => t.tag)
let attributes = []
2019-09-11 19:12:24 +02:00
attributes.push({ key: 'today', dates: new Date(), highlight: { color: 'green' } })
const that = this
2019-09-11 19:12:24 +02:00
function getColor (event) {
const color = { class: event.past && !that.filters.show_past_events && !that.in_past ? 'past-event vc-rounded-full' : 'vc-rounded-full', color: 'blue' }
2019-07-13 01:02:11 +02:00
const tag = get(event, 'tags[0]')
2019-09-11 19:12:24 +02:00
if (!tag) { return color }
2019-06-26 14:44:21 +02:00
const idx = tags.indexOf(tag)
2019-09-11 19:12:24 +02:00
if (idx < 0) { return color }
2019-06-26 14:44:21 +02:00
color.color = colors[idx]
return color
}
attributes = attributes.concat(this.filteredEventsWithPast
.filter(e => !e.multidate)
2019-08-09 13:21:32 +02:00
.map(e => {
return {
2019-09-11 19:12:24 +02:00
key: e.id,
dot: getColor(e),
2019-09-11 19:12:24 +02:00
dates: new Date(e.start_datetime * 1000)
}
}))
attributes = attributes.concat(this.filteredEventsWithPast
.filter(e => e.multidate)
2020-01-15 23:17:38 +01:00
.map(e => ({
key: e.id,
2019-09-11 19:12:24 +02:00
highlight: getColor(e),
2020-01-15 23:17:38 +01:00
dates: { start: new Date(e.start_datetime * 1000), end: new Date(e.end_datetime * 1000) }
})))
2019-09-11 19:12:24 +02:00
return attributes
2019-04-03 00:25:12 +02:00
}
},
methods: {
...mapActions(['updateEvents', 'showPastEvents']),
updatePage (page) {
this.updateEvents(page)
},
click (day) {
const element = document.getElementById(day.day)
if (element) { element.scrollIntoView() } // Even IE6 supports this
}
2019-04-03 00:25:12 +02:00
}
}
</script>
<style>
2019-06-11 17:24:48 +02:00
.vc-opacity-0 {
2020-01-15 23:17:38 +01:00
opacity: 0.3 !important;
2019-06-11 17:24:48 +02:00
}
2020-01-15 23:17:38 +01:00
2019-06-26 14:44:21 +02:00
.past-event {
2020-01-15 23:17:38 +01:00
opacity: 0.3;
2019-06-26 14:44:21 +02:00
}
2019-04-03 00:25:12 +02:00
</style>