2020-01-15 23:51:09 +01:00
|
|
|
import moment from 'moment-timezone'
|
2019-05-30 12:04:14 +02:00
|
|
|
import intersection from 'lodash/intersection'
|
2019-07-11 23:31:37 +02:00
|
|
|
import find from 'lodash/find'
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-04-03 00:25:12 +02:00
|
|
|
export const state = () => ({
|
2019-06-25 01:05:38 +02:00
|
|
|
locale: '',
|
2019-09-17 16:05:46 +02:00
|
|
|
user_locale: {},
|
2019-04-03 00:25:12 +02:00
|
|
|
events: [],
|
|
|
|
tags: [],
|
|
|
|
places: [],
|
2019-07-13 01:02:11 +02:00
|
|
|
settings: {
|
2019-10-20 14:22:55 +02:00
|
|
|
instance_timezone: 'Europe/Rome',
|
2019-12-04 00:50:15 +01:00
|
|
|
instance_name: '',
|
2019-07-13 01:02:11 +02:00
|
|
|
allow_registration: true,
|
|
|
|
allow_anon_event: true,
|
|
|
|
allow_recurrent_event: true,
|
|
|
|
recurrent_event_visible: false,
|
2019-10-22 01:01:41 +02:00
|
|
|
enable_federation: false,
|
2019-12-04 00:50:15 +01:00
|
|
|
enable_resources: false,
|
|
|
|
hide_boosts: true
|
2019-07-13 01:02:11 +02:00
|
|
|
},
|
2019-09-19 19:20:16 +02:00
|
|
|
in_past: false,
|
2019-04-03 00:25:12 +02:00
|
|
|
filters: {
|
|
|
|
tags: [],
|
2019-06-06 23:54:32 +02:00
|
|
|
places: [],
|
|
|
|
show_past_events: false,
|
|
|
|
show_recurrent_events: false,
|
|
|
|
show_pinned_event: false
|
2019-06-07 17:02:33 +02:00
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = {
|
2019-05-30 12:12:51 +02:00
|
|
|
|
2019-06-26 15:44:26 +02:00
|
|
|
// filter matches search tag/place
|
2019-09-11 19:12:24 +02:00
|
|
|
filteredEvents: state => {
|
2019-07-11 23:31:37 +02:00
|
|
|
const search_for_tags = !!state.filters.tags.length
|
|
|
|
const search_for_places = !!state.filters.places.length
|
|
|
|
|
|
|
|
return state.events.filter(e => {
|
|
|
|
// filter past events
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!state.filters.show_past_events && e.past) { return false }
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-07-11 23:31:37 +02:00
|
|
|
// filter recurrent events
|
2020-01-30 12:37:19 +01:00
|
|
|
if (!state.filters.show_recurrent_events && e.parentId) { return false }
|
2019-07-11 23:31:37 +02:00
|
|
|
|
2020-02-09 18:18:30 +01:00
|
|
|
if (search_for_places && !state.filters.places.includes(e.place.id)) {
|
|
|
|
return false
|
2019-07-11 23:31:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (search_for_tags) {
|
2020-02-09 18:18:30 +01:00
|
|
|
const common_tags = intersection(e.tags, state.filters.tags)
|
|
|
|
if (common_tags.length === 0) { return false }
|
2019-07-11 23:31:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!search_for_places && !search_for_tags) { return true }
|
|
|
|
|
2020-02-09 18:18:30 +01:00
|
|
|
return true
|
2019-07-11 23:31:37 +02:00
|
|
|
})
|
2019-06-26 15:44:26 +02:00
|
|
|
},
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-07-11 23:31:37 +02:00
|
|
|
// filter matches search tag/place including past events
|
2019-09-11 19:12:24 +02:00
|
|
|
filteredEventsWithPast: state => {
|
2019-07-11 23:31:37 +02:00
|
|
|
const search_for_tags = !!state.filters.tags.length
|
|
|
|
const search_for_places = !!state.filters.places.length
|
|
|
|
|
|
|
|
return state.events.filter(e => {
|
|
|
|
// filter recurrent events
|
2020-01-30 12:37:19 +01:00
|
|
|
if (!state.filters.show_recurrent_events && e.parentId) { return false }
|
2019-06-26 15:44:26 +02:00
|
|
|
|
2020-02-09 18:18:30 +01:00
|
|
|
if (search_for_places && !state.filters.places.includes(e.place.id)) {
|
|
|
|
return false
|
2019-07-11 23:31:37 +02:00
|
|
|
}
|
2019-06-26 15:44:26 +02:00
|
|
|
|
2019-07-11 23:31:37 +02:00
|
|
|
if (search_for_tags) {
|
2020-02-09 18:18:30 +01:00
|
|
|
const common_tags = intersection(e.tags, state.filters.tags)
|
|
|
|
if (common_tags.length === 0) { return false }
|
2019-07-11 23:31:37 +02:00
|
|
|
}
|
|
|
|
|
2020-02-09 18:18:30 +01:00
|
|
|
return true
|
2019-07-11 23:31:37 +02:00
|
|
|
})
|
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
2019-09-11 19:12:24 +02:00
|
|
|
setEvents (state, events) {
|
2019-06-26 15:44:26 +02:00
|
|
|
// set`past` and `newDay` flags to event
|
|
|
|
let lastDay = null
|
2019-07-27 13:05:02 +02:00
|
|
|
state.events = events.map(e => {
|
|
|
|
const currentDay = moment.unix(e.start_datetime).date()
|
2019-06-26 15:44:26 +02:00
|
|
|
e.newDay = (!lastDay || lastDay !== currentDay) && currentDay
|
2019-07-15 23:35:59 +02:00
|
|
|
lastDay = currentDay
|
2019-09-11 19:12:24 +02:00
|
|
|
const end_datetime = e.end_datetime || e.start_datetime + 3600 * 2
|
2019-07-27 13:05:02 +02:00
|
|
|
const past = ((moment().unix()) - end_datetime) > 0
|
2019-05-30 12:04:14 +02:00
|
|
|
e.past = !!past
|
|
|
|
return e
|
|
|
|
})
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
addEvent (state, event) {
|
2019-04-03 00:25:12 +02:00
|
|
|
state.events.push(event)
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
updateEvent (state, event) {
|
2019-04-03 00:25:12 +02:00
|
|
|
state.events = state.events.map((e) => {
|
2019-09-11 19:12:24 +02:00
|
|
|
if (e.id !== event.id) { return e }
|
2019-04-03 00:25:12 +02:00
|
|
|
return event
|
|
|
|
})
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
delEvent (state, eventId) {
|
2019-05-30 12:04:14 +02:00
|
|
|
state.events = state.events.filter(ev => {
|
|
|
|
return ev.id !== eventId
|
|
|
|
})
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
update (state, { tags, places }) {
|
2019-04-03 00:25:12 +02:00
|
|
|
state.tags = tags
|
|
|
|
state.places = places
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setSearchTags (state, tags) {
|
2019-04-03 00:25:12 +02:00
|
|
|
state.filters.tags = tags
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setSearchPlaces (state, places) {
|
2019-04-03 00:25:12 +02:00
|
|
|
state.filters.places = places
|
2019-05-30 12:04:14 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
showPastEvents (state, show) {
|
2019-06-09 00:45:50 +02:00
|
|
|
state.filters.show_past_events = show
|
2019-06-06 23:54:32 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
showRecurrentEvents (state, show) {
|
2019-07-11 23:31:37 +02:00
|
|
|
state.filters.show_recurrent_events = show
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setSettings (state, settings) {
|
2019-06-06 23:54:32 +02:00
|
|
|
state.settings = settings
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setSetting (state, setting) {
|
2019-06-21 23:52:18 +02:00
|
|
|
state.settings[setting.key] = setting.value
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setLocale (state, locale) {
|
2019-06-25 01:05:38 +02:00
|
|
|
state.locale = locale
|
2019-09-19 16:23:46 +02:00
|
|
|
},
|
2019-09-19 19:20:16 +02:00
|
|
|
setPast (state, in_past) {
|
|
|
|
state.in_past = in_past
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
2020-01-15 23:51:09 +01:00
|
|
|
// this method is called server side only for each request for nuxt
|
|
|
|
// we use it to get configuration from db, set locale, etc...
|
2020-01-27 00:47:03 +01:00
|
|
|
nuxtServerInit ({ commit }, { req }) {
|
|
|
|
commit('setSettings', req.settings)
|
2020-01-15 23:51:09 +01:00
|
|
|
|
2020-01-27 00:47:03 +01:00
|
|
|
commit('setEvents', req.events)
|
|
|
|
commit('update', req.meta)
|
2020-01-15 23:51:09 +01:00
|
|
|
|
2019-07-14 01:44:28 +02:00
|
|
|
// apply settings
|
2020-01-27 00:47:03 +01:00
|
|
|
commit('showRecurrentEvents', req.settings.allow_recurrent_event && req.settings.recurrent_event_visible)
|
2019-06-21 23:52:18 +02:00
|
|
|
},
|
2020-01-21 01:24:32 +01:00
|
|
|
async updateEvents ({ commit }, page) {
|
|
|
|
const [month, year] = [moment().month(), moment().year()]
|
|
|
|
const in_past = page.year < year || (page.year === year && page.month <= month)
|
|
|
|
// commit('setPast', in_past)
|
|
|
|
const start_datetime = moment().year(page.year).month(page.month - 1).startOf('month').startOf('week').unix()
|
2020-01-15 23:51:09 +01:00
|
|
|
const query = `start=${start_datetime}`
|
|
|
|
const events = await this.$axios.$get(`/event?${query}`)
|
2019-04-26 23:14:43 +02:00
|
|
|
commit('setEvents', events)
|
2020-01-21 01:24:32 +01:00
|
|
|
commit('showPastEvents', in_past)
|
2019-04-26 23:14:43 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async updateMeta ({ commit }) {
|
2019-04-23 15:45:52 +02:00
|
|
|
const { tags, places } = await this.$axios.$get('/event/meta')
|
2019-04-03 00:25:12 +02:00
|
|
|
commit('update', { tags, places })
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async addEvent ({ commit }, formData) {
|
2020-01-31 14:56:31 +01:00
|
|
|
const event = await this.$axios.$post('/event', formData)
|
2019-05-30 12:12:51 +02:00
|
|
|
if (event.user) {
|
|
|
|
commit('addEvent', event)
|
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async updateEvent ({ commit }, formData) {
|
2020-01-31 14:56:31 +01:00
|
|
|
const event = await this.$axios.$put('/event', formData)
|
2019-05-30 12:12:51 +02:00
|
|
|
if (event.user) {
|
|
|
|
commit('updateEvent', event)
|
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
delEvent ({ commit }, eventId) {
|
2019-04-03 00:25:12 +02:00
|
|
|
commit('delEvent', eventId)
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setSearchTags ({ commit }, tags) {
|
2019-04-03 00:25:12 +02:00
|
|
|
commit('setSearchTags', tags)
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
setSearchPlaces ({ commit }, places) {
|
2019-04-03 00:25:12 +02:00
|
|
|
commit('setSearchPlaces', places)
|
2019-05-30 12:04:14 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
showPastEvents ({ commit }, show) {
|
2019-05-30 12:04:14 +02:00
|
|
|
commit('showPastEvents', show)
|
2019-06-06 23:54:32 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
showRecurrentEvents ({ commit }, show) {
|
2019-07-11 23:31:37 +02:00
|
|
|
commit('showRecurrentEvents', show)
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async setSetting ({ commit }, setting) {
|
|
|
|
await this.$axios.$post('/settings', setting)
|
2019-06-21 23:52:18 +02:00
|
|
|
commit('setSetting', setting)
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|