2019-04-03 00:25:12 +02:00
|
|
|
<template lang="pug">
|
2019-05-30 12:04:14 +02:00
|
|
|
#calendar
|
|
|
|
v-calendar(
|
2019-04-29 00:27:29 +02:00
|
|
|
title-position='left'
|
|
|
|
locale='it'
|
|
|
|
is-dark
|
2019-04-03 00:25:12 +02:00
|
|
|
:attributes='attributes'
|
|
|
|
:from-page.sync='page'
|
2019-05-30 12:04:14 +02:00
|
|
|
is-expanded
|
|
|
|
show-clear-margin
|
|
|
|
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'
|
2019-04-03 00:25:12 +02:00
|
|
|
import moment from 'dayjs'
|
|
|
|
import { intersection } from 'lodash'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Calendar',
|
|
|
|
data () {
|
|
|
|
const month = moment().month()+1
|
|
|
|
const year = moment().year()
|
|
|
|
return {
|
|
|
|
page: { month, year},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
page () {
|
|
|
|
this.updateEvents(this.page)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(['updateEvents']),
|
2019-05-30 12:04:14 +02:00
|
|
|
click (day) {
|
|
|
|
const element = document.getElementById(day.day)
|
|
|
|
if (element) element.scrollIntoView(); //Even IE6 supports this
|
2019-04-29 00:27:29 +02:00
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
eventToAttribute(event) {
|
|
|
|
let e = {
|
|
|
|
key: event.id,
|
|
|
|
customData: event,
|
|
|
|
order: event.start_datetime,
|
|
|
|
}
|
2019-04-29 00:27:29 +02:00
|
|
|
const day = moment(event.start_datetime).date()
|
2019-04-03 00:25:12 +02:00
|
|
|
let color = event.tags && event.tags.length && event.tags[0].color ? event.tags[0].color : 'rgba(170,170,250,0.7)'
|
|
|
|
if (event.past) color = 'rgba(200,200,200,0.5)'
|
|
|
|
if (event.multidate) {
|
|
|
|
e.dates = {
|
|
|
|
start: event.start_datetime, end: event.end_datetime
|
|
|
|
}
|
|
|
|
e.highlight = { backgroundColor: color,
|
2019-05-30 12:04:14 +02:00
|
|
|
// borderColor: 'transparent',
|
2019-04-03 00:25:12 +02:00
|
|
|
borderWidth: '4px' }
|
|
|
|
} else {
|
|
|
|
e.dates = event.start_datetime
|
|
|
|
e.dot = { backgroundColor: color, borderColor: color, borderWidth: '3px' }
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2019-05-30 12:04:14 +02:00
|
|
|
...mapGetters(['filteredEvents']),
|
2019-04-03 00:25:12 +02:00
|
|
|
attributes () {
|
|
|
|
return [
|
2019-04-29 00:27:29 +02:00
|
|
|
{ key: 'today', dates: new Date(),
|
2019-04-03 00:25:12 +02:00
|
|
|
highlight: {
|
|
|
|
backgroundColor: '#aaffaa'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...this.filteredEvents.map(this.eventToAttribute)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#calendar {
|
2019-05-30 12:04:14 +02:00
|
|
|
margin: 0 auto;
|
|
|
|
max-width: 500px;
|
|
|
|
align-self: center;
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|