gancio/components/Home.vue

160 lines
4.6 KiB
Vue
Raw Normal View History

2019-04-03 00:25:12 +02:00
<template lang="pug">
2020-07-25 21:41:22 +02:00
v-container#home(fluid)
2020-10-16 14:47:18 +02:00
//- Announcements
2020-07-09 02:27:17 +02:00
Announcement(v-for='announcement in announcements' :key='`a_${announcement.id}`' :announcement='announcement')
2020-10-16 14:47:18 +02:00
2020-10-28 01:28:21 +01:00
v-row#calbarmb-2
.col-xl-5.col-lg-5.col-md-6.col-sm-12.col-xs-12
2020-10-25 00:30:28 +02:00
v-date-picker(
@update:picker-date='monthChange'
2020-10-28 01:28:21 +01:00
@click:date='dayChange'
2020-10-25 00:30:28 +02:00
:locale='settings.locale'
:events='calendarEvents'
2020-10-28 01:28:21 +01:00
:value='date'
2020-10-25 00:30:28 +02:00
landscape)
2020-10-16 14:47:18 +02:00
2020-01-15 23:33:30 +01:00
.col
2020-10-17 00:41:21 +02:00
Search(
:filters='filters'
2020-10-28 01:28:21 +01:00
@update='updateFilters')
v-chip(v-if='selectedDay' close @click:close='dayChange(selectedDay)') {{selectedDay}}
2019-05-30 12:12:51 +02:00
2020-02-09 18:15:44 +01:00
#events
2020-10-17 00:41:21 +02:00
Event(v-for='event in events'
2020-10-25 00:30:28 +02:00
:key='event.id' :event='event'
2020-10-17 00:41:21 +02:00
@tagclick='tagClick' @placeclick='placeClick')
2019-05-30 12:04:14 +02:00
2019-04-03 00:25:12 +02:00
</template>
<script>
2020-10-17 00:41:21 +02:00
import { mapState, mapActions } from 'vuex'
import dayjs from 'dayjs'
2019-04-03 00:25:12 +02:00
import Event from '@/components/Event'
import Announcement from '@/components/Announcement'
2019-04-03 00:25:12 +02:00
import Calendar from '@/components/Calendar'
2020-01-15 23:33:30 +01:00
import Search from '@/components/Search'
2019-04-03 00:25:12 +02:00
export default {
name: 'Home',
2020-10-25 00:30:28 +02:00
components: { Calendar, Event, Search, Announcement },
async asyncData ({ params }) {
const events = await this.$api.getEvents({
2020-10-28 01:28:21 +01:00
start: dayjs().unix(),
2020-10-25 00:30:28 +02:00
end: this.end,
places: this.filters.places,
tags: this.filters.tags
})
return { events }
},
2020-10-17 00:41:21 +02:00
data () {
return {
2020-10-25 00:30:28 +02:00
date: dayjs().format('YYYY-MM-DD'),
2020-10-17 00:41:21 +02:00
events: [],
2020-10-28 01:28:21 +01:00
start: dayjs().unix(),
2020-10-17 00:41:21 +02:00
end: null,
2020-10-25 00:30:28 +02:00
filters: { tags: [], places: [] },
2020-10-17 00:41:21 +02:00
selectedDay: null
}
},
2020-01-15 23:33:30 +01:00
computed: {
2020-10-25 00:30:28 +02:00
...mapState(['settings', 'announcements']),
calendarEvents () {
return this.events.map(e => dayjs.unix(e.start_datetime).format('YYYY-MM-DD'))
}
2020-10-17 00:41:21 +02:00
},
methods: {
...mapActions(['setFilters']),
async updateEvents () {
this.events = await this.$api.getEvents({
2020-10-25 00:30:28 +02:00
start: this.start,
end: this.end,
places: this.filters.places,
tags: this.filters.tags
2020-10-17 00:41:21 +02:00
})
2020-10-25 00:30:28 +02:00
// this.setFilters(this.filters)
2020-10-17 00:41:21 +02:00
},
placeClick (place_id) {
if (this.filters.places.includes(place_id)) {
this.filters.places = this.filters.places.filter(p_id => p_id !== place_id)
} else {
this.filters.places.push(place_id)
}
this.updateEvents()
2020-01-15 23:33:30 +01:00
},
2020-10-17 00:41:21 +02:00
tagClick (tag) {
if (this.filters.tags.includes(tag)) {
this.filters.tags = this.filters.tags.filter(t => t !== tag)
} else {
this.filters.tags.push(tag)
}
this.updateEvents()
},
updateFilters (filters) {
this.filters = filters
this.updateEvents()
},
2020-10-25 00:30:28 +02:00
monthChange (monthYear) {
2020-10-28 01:28:21 +01:00
this.selectedDay = null
2020-10-25 00:30:28 +02:00
const [year, month] = monthYear.split('-')
2020-10-28 01:28:21 +01:00
// check if current month is selected
if (month - 1 === dayjs().month()) {
this.start = dayjs().unix()
this.date = dayjs().format('YYYY-MM-DD')
} else {
this.date = ''
this.start = dayjs().year(year).month(month - 1).startOf('month').unix() // .startOf('week').unix()
}
// this.end = dayjs().year(year).month(month - 1).endOf('month').unix() // .endOf('week').unix()
this.end = null
2020-10-25 00:30:28 +02:00
this.updateEvents()
2020-10-17 00:41:21 +02:00
},
2020-10-28 01:28:21 +01:00
dayChange (day) {
if (this.selectedDay === day) {
2020-10-17 00:41:21 +02:00
this.selectedDay = null
2020-10-28 01:28:21 +01:00
this.date = dayjs().format('YYYY-MM-DD')
this.start = dayjs().unix() // .startOf('week').unix()
this.end = null
2020-10-17 00:41:21 +02:00
this.updateEvents()
return
}
2020-10-28 01:28:21 +01:00
this.start = dayjs(day).unix()
this.end = dayjs(day).endOf('day').unix()
this.date = dayjs(day).format('YYYY-MM-DD')
this.selectedDay = day
this.updateEvents()
2020-10-17 00:41:21 +02:00
}
2020-01-15 23:33:30 +01:00
},
2019-07-08 00:06:56 +02:00
head () {
return {
title: this.settings.title,
meta: [
// hid is used as unique identifier. Do not use `vmid` for it as it will not work
{ hid: 'description', name: 'description', content: this.settings.description },
{ hid: 'og-description', name: 'og:description', content: this.settings.description },
2019-09-11 19:12:24 +02:00
{ hid: 'og-title', property: 'og:title', content: this.settings.title },
{ hid: 'og-url', property: 'og:url', content: this.settings.baseurl },
2019-07-11 22:29:18 +02:00
{ property: 'og:image', content: this.settings.baseurl + '/favicon.ico' }
2019-09-17 18:16:59 +02:00
],
link: [
{ rel: 'alternate', type: 'application/rss+xml', title: this.settings.title, href: this.settings.baseurl + '/feed/rss' }
2019-07-08 00:06:56 +02:00
]
}
}
2019-04-03 00:25:12 +02:00
}
</script>
2020-02-09 18:15:44 +01:00
<style lang='less'>
2020-07-31 01:03:19 +02:00
#home {
max-width: 1400px;
}
2020-07-25 21:41:22 +02:00
2020-02-09 18:15:44 +01:00
#events {
2020-06-05 23:43:09 +02:00
margin: 0 auto;
2020-02-09 18:15:44 +01:00
display: flex;
flex-wrap: wrap;
justify-content: center;
}
2020-02-09 18:15:44 +01:00
</style>