gancio-upstream/plugins/filters.js

56 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-04-03 00:25:12 +02:00
import Vue from 'vue'
2019-10-20 14:22:55 +02:00
import moment from 'moment-timezone'
2019-04-03 00:25:12 +02:00
2019-06-25 01:05:38 +02:00
export default ({ app, store }) => {
2019-10-20 14:22:55 +02:00
// set timezone to instance_timezone!!
// to show local time relative to event's place
// not where in the worlds I'm looking at the page from
moment.tz.setDefault(store.state.settings.instance_timezone)
2019-07-23 01:31:43 +02:00
// replace links with anchors
// TODO: remove fb tracking id
2019-10-20 14:22:55 +02:00
Vue.filter('linkify', value => value.replace(/(https?:\/\/([^\s]+))/g, '<a href="$1">$2</a>'))
2019-08-02 13:43:28 +02:00
Vue.filter('url2host', url => url.match(/^https?:\/\/(.[^/:]+)/i)[1])
2019-10-20 14:22:55 +02:00
Vue.filter('datetime', value => moment(value).locale(store.state.locale).format('ddd, D MMMM HH:mm'))
2019-07-23 01:31:43 +02:00
// shown in mobile homepage
2019-10-20 14:22:55 +02:00
Vue.filter('day', value => moment.unix(value).locale(store.state.locale).format('dddd, D MMM'))
2019-07-23 01:31:43 +02:00
2019-10-20 14:22:55 +02:00
Vue.filter('to', value => moment().to(value.start_datetime*1000))
2019-07-23 01:31:43 +02:00
// format event start/end datetime based on page
Vue.filter('when', (event, where) => {
moment.locale(store.state.locale)
2019-10-20 14:22:55 +02:00
const start = moment.unix(event.start_datetime)
const end = moment.unix(event.end_datetime)
2019-10-02 16:00:51 +02:00
2019-10-23 00:19:13 +02:00
const normal = `${start.format('dddd, D MMMM (HH:mm-')}${end.format('HH:mm) ')}`
2019-07-23 01:31:43 +02:00
// recurrent event
if (event.recurrent && where !== 'home') {
const { frequency, days, type } = JSON.parse(event.recurrent)
2019-09-11 19:12:24 +02:00
if (frequency === '1w' || frequency === '2w') {
const recurrent = app.i18n.tc(`event.recurrent_${frequency}_days`, days.length, { days: days.map(d => moment().day(d - 1).format('dddd')) })
2019-07-23 01:31:43 +02:00
return `${normal} - ${recurrent}`
} else if (frequency === '1m' || frequency === '2m') {
2019-09-11 19:12:24 +02:00
const d = type === 'ordinal' ? days : days.map(d => moment().day(d - 1).format('dddd'))
const recurrent = app.i18n.tc(`event.recurrent_${frequency}_${type}`, days.length, { days: d })
2019-07-23 01:31:43 +02:00
return `${normal} - ${recurrent}`
}
return 'recurrent '
}
// multidate
2019-05-30 12:04:14 +02:00
if (event.multidate) {
2019-06-26 14:44:21 +02:00
return `${start.format('ddd, D MMMM (HH:mm)')} - ${end.format('ddd, D MMMM')}`
2019-09-11 19:12:24 +02:00
}
2019-07-23 01:31:43 +02:00
// normal event
if (event.end_datetime && event.end_datetime !== event.start_datetime) {
return `${start.format('ddd, D MMMM (HH:mm-')}${end.format('HH:mm)')}`
}
return start.format('dddd, D MMMM (HH:mm)')
2019-05-30 12:04:14 +02:00
})
2019-06-07 17:02:33 +02:00
}