2019-04-03 00:25:12 +02:00
|
|
|
import moment from 'dayjs'
|
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
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!state.filters.show_recurrent_events && e.recurrent) { return false }
|
2019-07-11 23:31:37 +02:00
|
|
|
|
|
|
|
if (search_for_places) {
|
2019-09-11 19:12:24 +02:00
|
|
|
if (find(state.filters.places, p => p === e.place.id)) { return true }
|
2019-07-11 23:31:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (search_for_tags) {
|
2019-09-11 19:12:24 +02:00
|
|
|
const common_tags = intersection(e.tags, state.filters.tags)
|
|
|
|
if (common_tags.length > 0) { return true }
|
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 }
|
|
|
|
|
2019-07-11 23:31:37 +02:00
|
|
|
return false
|
|
|
|
})
|
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 => {
|
|
|
|
const match = false
|
|
|
|
|
|
|
|
// filter recurrent events
|
2019-09-11 19:12:24 +02:00
|
|
|
if (!state.filters.show_recurrent_events && e.recurrent) { return false }
|
2019-06-26 15:44:26 +02:00
|
|
|
|
2019-07-11 23:31:37 +02:00
|
|
|
if (!match && search_for_places) {
|
2019-09-11 19:12:24 +02:00
|
|
|
if (find(state.filters.places, p => p === e.place.id)) { return true }
|
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) {
|
2019-09-11 19:12:24 +02:00
|
|
|
const common_tags = intersection(e.tags, state.filters.tags)
|
|
|
|
if (common_tags.length > 0) { return true }
|
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 }
|
|
|
|
|
2019-07-11 23:31:37 +02:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
}
|
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
|
|
|
},
|
|
|
|
setUserLocale (state, user_locale) {
|
|
|
|
state.user_locale = user_locale
|
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 = {
|
2019-06-21 23:52:18 +02:00
|
|
|
// this method is called server side only for each request
|
2019-07-11 23:31:37 +02:00
|
|
|
// we use it to get configuration from db, setting locale, etc...
|
2019-10-28 17:33:20 +01:00
|
|
|
nuxtServerInit ({ commit }, { app, store, req }) {
|
2019-10-30 14:58:40 +01:00
|
|
|
if (req.user) {
|
|
|
|
this.$auth.setUser(req.user)
|
|
|
|
}
|
2019-10-11 18:34:14 +02:00
|
|
|
const settings = req.settings
|
2019-06-25 01:05:38 +02:00
|
|
|
commit('setSettings', settings)
|
2019-07-14 01:44:28 +02:00
|
|
|
// apply settings
|
2019-07-23 01:31:43 +02:00
|
|
|
commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible)
|
2019-06-21 23:52:18 +02:00
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async updateEvents ({ commit }, page) {
|
2019-09-19 19:20:16 +02:00
|
|
|
const month = moment().month()
|
|
|
|
const year = moment().year()
|
2019-10-28 17:33:20 +01:00
|
|
|
commit('setPast', page.year < year || (page.year === year && page.month <= month))
|
2019-06-07 17:02:33 +02:00
|
|
|
const events = await this.$axios.$get(`/event/${page.month - 1}/${page.year}`)
|
2019-04-26 23:14:43 +02:00
|
|
|
commit('setEvents', events)
|
|
|
|
},
|
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) {
|
2019-05-30 12:12:51 +02:00
|
|
|
const event = await this.$axios.$post('/user/event', formData)
|
|
|
|
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) {
|
2019-04-23 15:45:52 +02:00
|
|
|
const event = await this.$axios.$put('/user/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
|
|
|
}
|