2020-11-13 00:12:05 +01:00
< template lang = "pug" >
2022-11-10 08:48:48 +01:00
v - container . px - 2. px - sm - 6. pt - 0
2020-11-13 00:12:05 +01:00
2022-04-27 11:58:58 +02:00
//- Announcements
2022-11-10 08:48:48 +01:00
# announcements . mt - 2. mt - sm - 4 ( v - if = 'announcements.length' )
2022-04-27 11:58:58 +02:00
Announcement ( v - for = 'announcement in announcements' : key = '`a_${announcement.id}`' : announcement = 'announcement' )
2020-11-13 00:12:05 +01:00
2022-11-19 13:20:37 +01:00
div . mt - 2. mt - sm - 4 ( v - if = 'collections.length' )
v - btn . mr - 2 ( outlined v - for = 'collection in collections' color = 'primary' : key = 'collection.id' : to = '`/collection/${encodeURIComponent(collection.name)}`' ) { { collection . name } }
2022-04-27 11:58:58 +02:00
//- Calendar and search bar
2022-11-09 19:47:13 +01:00
//- v-row.ma-2(v-if='!settings.hide_calendar')
//- .calh.col-xl-5.col-lg-5.col-md-7.col-sm-10.col-xs-12.pa-0.mx-sm-2.mx-0.my-0.mt-sm-2
2022-11-10 08:48:48 +01:00
. calh . mt - 2. mt - sm - 4 ( v - if = '!settings.hide_calendar' )
2022-11-09 19:47:13 +01:00
//- this is needed as v-calendar does not support SSR
//- https://github.com/nathanreyes/v-calendar/issues/336
client - only ( placeholder = 'Loading...' )
Calendar ( @ dayclick = 'dayChange' @ monthchange = 'monthChange' : events = 'events' )
2020-11-13 00:12:05 +01:00
2022-11-09 10:19:12 +01:00
//- .col.pt-0.pt-md-2.mt-4.ma-md-0.pb-0
//- //- v-btn(to='/search' color='primary' ) {{$t('common.search')}}
//- v-form(to='/search' action='/search' method='GET')
//- v-col(cols=12)
//- v-switch(
//- v-if='settings.allow_recurrent_event'
//- v-model='show_recurrent'
//- inset color='primary'
//- hide-details
//- :label="$t('event.show_recurrent')")
//- v-col.mb-4(cols=12)
//- v-text-field(name='search' :label='$t("common.search")' outlined rounded hide-details :append-icon='mdiMagnify')
2022-08-14 14:40:41 +02:00
v - chip ( v - if = 'selectedDay' close : close - icon = 'mdiCloseCircle' @ click : close = 'dayChange()' ) { { selectedDay } }
2020-11-13 00:12:05 +01:00
2022-04-27 11:58:58 +02:00
//- Events
2022-11-10 08:48:48 +01:00
# events . mt - sm - 4. mt - 2
2022-05-31 15:32:38 +02:00
Event ( : event = 'event' @ destroy = 'destroy' v - for = '(event, idx) in visibleEvents' : lazy = 'idx>2' : key = 'event.id' )
2019-04-03 00:25:12 +02:00
< / template >
2020-11-13 00:12:05 +01:00
2019-05-30 12:04:14 +02:00
< script >
2022-05-31 15:32:38 +02:00
import { mapState } from 'vuex'
2020-11-13 00:12:05 +01:00
import dayjs from 'dayjs'
import Event from '@/components/Event'
import Announcement from '@/components/Announcement'
2020-12-04 17:28:54 +01:00
import Calendar from '@/components/Calendar'
2022-08-14 14:40:41 +02:00
import { mdiMagnify , mdiCloseCircle } from '@mdi/js'
2019-05-30 12:04:14 +02:00
export default {
name : 'Index' ,
2022-06-01 14:10:04 +02:00
components : { Event , Announcement , Calendar } ,
2021-09-27 11:12:14 +02:00
middleware : 'setup' ,
2022-11-10 08:48:48 +01:00
async asyncData ( { $api , $axios } ) {
const [ collections , events ] = await Promise . all ( [
$axios . $get ( 'collections' ) . catch ( _e => [ ] ) ,
$api . getEvents ( {
start : dayjs ( ) . startOf ( 'month' ) . unix ( ) ,
end : null ,
show _recurrent : true
} ) ] )
return { events , collections }
2020-11-13 00:12:05 +01:00
} ,
2022-08-14 14:40:41 +02:00
data ( { $store } ) {
2020-11-13 00:12:05 +01:00
return {
2022-08-14 14:40:41 +02:00
mdiMagnify , mdiCloseCircle ,
2021-04-26 23:18:50 +02:00
isCurrentMonth : true ,
now : dayjs ( ) . unix ( ) ,
2022-04-27 11:58:58 +02:00
date : dayjs . tz ( ) . format ( 'YYYY-MM-DD' ) ,
2020-11-13 00:12:05 +01:00
events : [ ] ,
2021-04-26 23:18:50 +02:00
start : dayjs ( ) . startOf ( 'month' ) . unix ( ) ,
2020-11-13 00:12:05 +01:00
end : null ,
2022-08-14 14:40:41 +02:00
selectedDay : null ,
2022-11-10 08:48:48 +01:00
show _recurrent : $store . state . settings . recurrent _event _visible ,
collections : [ ]
2020-11-13 00:12:05 +01:00
}
2019-06-06 23:54:32 +02:00
} ,
2021-03-05 14:20:23 +01: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 } ,
{ hid : 'og-title' , property : 'og:title' , content : this . settings . title } ,
{ hid : 'og-url' , property : 'og:url' , content : this . settings . baseurl } ,
2021-07-28 10:02:04 +02:00
{ property : 'og:image' , content : this . settings . baseurl + '/logo.png' }
2021-03-05 14:20:23 +01:00
] ,
link : [
2022-11-06 00:19:13 +01:00
{ rel : 'apple-touch-icon' , href : this . settings . baseurl + '/logo.png' } ,
2022-06-11 12:00:47 +02:00
{ rel : 'alternate' , type : 'application/rss+xml' , title : this . settings . title , href : this . settings . baseurl + '/feed/rss' } ,
{ rel : 'alternate' , type : 'text/calendar' , title : this . settings . title , href : this . settings . baseurl + '/feed/ics' }
2021-03-05 14:20:23 +01:00
]
}
2021-01-11 00:17:56 +01:00
} ,
2021-04-26 23:18:50 +02:00
computed : {
2022-05-31 15:32:38 +02:00
... mapState ( [ 'settings' , 'announcements' ] ) ,
2021-04-26 23:18:50 +02:00
visibleEvents ( ) {
const now = dayjs ( ) . unix ( )
if ( this . selectedDay ) {
2022-08-07 21:49:59 +02:00
const min = dayjs . tz ( this . selectedDay ) . startOf ( 'day' ) . unix ( )
const max = dayjs . tz ( this . selectedDay ) . endOf ( 'day' ) . unix ( )
2022-09-14 12:01:08 +02:00
return this . events . filter ( e => ( e . start _datetime <= max && ( e . end _datetime || e . start _datetime ) >= min ) && ( this . show _recurrent || ! e . parentId ) )
2021-04-26 23:18:50 +02:00
} else if ( this . isCurrentMonth ) {
2022-11-04 12:22:21 +01:00
return this . events . filter ( e => ( ( e . end _datetime ? e . end _datetime > now : e . start _datetime + 3 * 60 * 60 > now ) && ( this . show _recurrent || ! e . parentId ) ) )
2021-04-26 23:18:50 +02:00
} else {
2022-08-14 14:40:41 +02:00
return this . events . filter ( e => this . show _recurrent || ! e . parentId )
2021-04-26 23:18:50 +02:00
}
2021-04-14 01:35:18 +02:00
}
} ,
2020-11-13 00:12:05 +01:00
methods : {
2021-06-07 00:00:57 +02:00
destroy ( id ) {
this . events = this . events . filter ( e => e . id !== id )
} ,
2021-01-22 23:08:38 +01:00
updateEvents ( ) {
2021-04-26 23:18:50 +02:00
this . events = [ ]
2021-01-22 23:08:38 +01:00
return this . $api . getEvents ( {
2020-11-13 00:12:05 +01:00
start : this . start ,
end : this . end ,
2021-04-26 23:18:50 +02:00
show _recurrent : true
2021-01-22 23:08:38 +01:00
} ) . then ( events => {
this . events = events
2021-03-05 14:20:23 +01:00
this . $nuxt . $loading . finish ( )
2020-11-13 00:12:05 +01:00
} )
} ,
2020-12-04 17:28:54 +01:00
monthChange ( { year , month } ) {
2021-04-26 23:18:50 +02:00
2021-03-05 14:20:23 +01:00
this . $nuxt . $loading . start ( )
2021-04-26 23:18:50 +02:00
// unselect current selected day
2020-11-13 00:12:05 +01:00
this . selectedDay = null
// check if current month is selected
2022-04-27 11:58:58 +02:00
if ( month - 1 === dayjs . tz ( ) . month ( ) && year === dayjs . tz ( ) . year ( ) ) {
2021-04-26 23:18:50 +02:00
this . isCurrentMonth = true
2021-05-08 11:47:56 +02:00
this . start = dayjs ( ) . startOf ( 'month' ) . unix ( )
2022-04-27 11:58:58 +02:00
this . date = dayjs . tz ( ) . format ( 'YYYY-MM-DD' )
2020-11-13 00:12:05 +01:00
} else {
2021-04-26 23:18:50 +02:00
this . isCurrentMonth = false
2020-11-13 00:12:05 +01:00
this . date = ''
this . start = dayjs ( ) . year ( year ) . month ( month - 1 ) . startOf ( 'month' ) . unix ( ) // .startOf('week').unix()
}
2021-03-08 14:38:47 +01:00
this . end = dayjs ( ) . year ( year ) . month ( month ) . endOf ( 'month' ) . unix ( ) // .endOf('week').unix()
2020-11-13 00:12:05 +01:00
this . updateEvents ( )
} ,
dayChange ( day ) {
2022-04-27 11:58:58 +02:00
this . selectedDay = day ? dayjs . tz ( day ) . format ( 'YYYY-MM-DD' ) : null
2020-11-13 00:12:05 +01:00
}
2020-01-15 23:47:17 +01:00
}
2019-05-30 12:04:14 +02:00
}
< / script >