fix ics and rss export with filters
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,6 +6,9 @@ node_modules
|
|||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
|
||||||
|
config.development.js
|
||||||
|
config.production.js
|
||||||
|
|
||||||
# Log files
|
# Log files
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ api.get('/event/meta', eventController.getMeta)
|
|||||||
api.route('/event/:event_id')
|
api.route('/event/:event_id')
|
||||||
.get(eventController.get)
|
.get(eventController.get)
|
||||||
|
|
||||||
|
// api.get('/export/feed', exportController.feed)
|
||||||
api.get('/export/feed', exportController.feed)
|
// api.get('/export/ics', exportController.ics)
|
||||||
api.get('/export/ics', exportController.ics)
|
api.get('/export/:type', exportController.export)
|
||||||
|
|
||||||
api.route('/event/:year/:month')
|
api.route('/event/:year/:month')
|
||||||
.get(eventController.getAll)
|
.get(eventController.getAll)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const eventController = {
|
|||||||
{ start_datetime: { [Sequelize.Op.lte]: end } }
|
{ start_datetime: { [Sequelize.Op.lte]: end } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
order: [['createdAt', 'ASC']],
|
order: [['start_datetime', 'ASC']],
|
||||||
include: [User, Comment, Tag, Place]
|
include: [User, Comment, Tag, Place]
|
||||||
})
|
})
|
||||||
res.json(events)
|
res.json(events)
|
||||||
|
|||||||
@@ -1,43 +1,62 @@
|
|||||||
const jwt = require('jsonwebtoken')
|
const { Event, Comment, Tag, Place } = require('../model')
|
||||||
const { User, Event, Comment, Tag, Place } = require('../model')
|
|
||||||
const config = require('../config')
|
|
||||||
const mail = require('../mail')
|
|
||||||
const moment = require('moment')
|
|
||||||
const Sequelize = require('sequelize')
|
const Sequelize = require('sequelize')
|
||||||
|
const config = require('../config')
|
||||||
|
const moment = require('moment')
|
||||||
const ics = require('ics')
|
const ics = require('ics')
|
||||||
|
|
||||||
const exportController = {
|
const exportController = {
|
||||||
async getAll (req, res) {
|
async export (req, res) {
|
||||||
|
console.log('type ', req.params.type)
|
||||||
|
const type = req.params.type
|
||||||
|
const tags = req.query.tags
|
||||||
|
const places = req.query.places
|
||||||
|
const whereTag = {}
|
||||||
|
const wherePlace = {}
|
||||||
|
const yesterday = moment().subtract('1', 'day')
|
||||||
|
if (tags) {
|
||||||
|
whereTag.tag = tags.split(',')
|
||||||
|
}
|
||||||
|
if (places) {
|
||||||
|
wherePlace.name = places.split(',')
|
||||||
|
}
|
||||||
|
console.log(wherePlace.name)
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
where: {
|
order: [['start_datetime', 'ASC']],
|
||||||
[Sequelize.Op.and]: [
|
where: { start_datetime: { [Sequelize.Op.gte]: yesterday } },
|
||||||
{ start_datetime: { [Sequelize.Op.gte]: start } },
|
include: [Comment, {
|
||||||
{ start_datetime: { [Sequelize.Op.lte]: end } }
|
model: Tag,
|
||||||
]
|
where: whereTag
|
||||||
},
|
}, { model: Place, where: wherePlace } ]
|
||||||
order: [['createdAt', 'DESC']],
|
|
||||||
include: [User, Comment, Tag, Place]
|
|
||||||
})
|
})
|
||||||
res.json(events)
|
switch (type) {
|
||||||
|
case 'feed':
|
||||||
|
return exportController.feed(res, events)
|
||||||
|
case 'ics':
|
||||||
|
return exportController.ics(res, events)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async feed (req, res) {
|
async feed (res, events) {
|
||||||
const events = await Event.findAll({include: [Comment, Tag, Place]})
|
|
||||||
res.type('application/rss+xml; charset=UTF-8')
|
res.type('application/rss+xml; charset=UTF-8')
|
||||||
res.render('feed/rss.pug', {events, config, moment})
|
res.render('feed/rss.pug', { events, config, moment })
|
||||||
},
|
},
|
||||||
async ics (req, res) {
|
|
||||||
const events = await Event.findAll({include: [Comment, Tag, Place]})
|
async ics (res, events) {
|
||||||
console.log(events)
|
const eventsMap = events.map(e => {
|
||||||
const eventsMap = events.map(e => ({
|
const tmpStart = moment(e.start_datetime)
|
||||||
start: [2019, 2, 2],
|
const tmpEnd = moment(e.end_datetime)
|
||||||
end: [2019, 2, 3],
|
const start = [tmpStart.year(), tmpStart.month() + 1, tmpStart.date(), tmpStart.hour(), tmpStart.minute()]
|
||||||
|
const end = [tmpEnd.year(), tmpEnd.month() + 1, tmpEnd.date(), tmpEnd.hour(), tmpEnd.minute()]
|
||||||
|
return {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
title: e.title,
|
title: e.title,
|
||||||
description: e.description,
|
description: e.description,
|
||||||
location: e.place.name
|
location: e.place.name + ' ' + e.place.address
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
res.type('text/calendar; charset=UTF-8')
|
res.type('text/calendar; charset=UTF-8')
|
||||||
const { error, value } = ics.createEvents(eventsMap)
|
const { error, value } = ics.createEvents(eventsMap)
|
||||||
console.log(value)
|
console.log(error, value)
|
||||||
res.send(value)
|
res.send(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const mail = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
from: 'Gancio <eventi@cisti.org>'
|
from: `${config.title} <${config.admin}>`
|
||||||
},
|
},
|
||||||
send: true,
|
send: true,
|
||||||
i18n: {},
|
i18n: {},
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const beConf = require('../config/config.' + env + '.json')
|
|||||||
const conf = {
|
const conf = {
|
||||||
// environment
|
// environment
|
||||||
title: beConf.title,
|
title: beConf.title,
|
||||||
|
description: beConf.description,
|
||||||
|
|
||||||
// base url
|
// base url
|
||||||
baseurl: beConf.baseurl,
|
baseurl: beConf.baseurl,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
b-modal(hide-footer hide-header
|
b-modal(hide-footer hide-header
|
||||||
@hide='$router.go(-1)' size='lg' :visible='true' v-if='type')
|
@hide='$router.replace("/")' size='lg' :visible='true' v-if='type')
|
||||||
h3.text-center Export {{type}}
|
h3.text-center Export {{type}}
|
||||||
b-input-group.mb-2(v-if='showLink')
|
b-input-group.mb-2(v-if='showLink')
|
||||||
b-form-input( v-model='link' autocomplete='off')
|
b-form-input( v-model='link' autocomplete='off')
|
||||||
@@ -18,21 +18,43 @@
|
|||||||
el-switch(v-model='mail.reminder' :active-text="$t('send_reminder')")
|
el-switch(v-model='mail.reminder' :active-text="$t('send_reminder')")
|
||||||
b-form-input.mt-1(v-model='mail.mail' :placeholder="$t('Insert your address')")
|
b-form-input.mt-1(v-model='mail.mail' :placeholder="$t('Insert your address')")
|
||||||
b-button.mt-1.float-right(variant='success' @click='activate_email') {{$t('Send')}}
|
b-button.mt-1.float-right(variant='success' @click='activate_email') {{$t('Send')}}
|
||||||
|
|
||||||
|
b-form(v-if="type==='embed'" style='max-width: 400px;')
|
||||||
|
el-switch(v-model='export_list' :active-text="$t('export_list')")
|
||||||
|
b-card(v-if='export_list' no-body header='Eventi')
|
||||||
|
b-list-group(flush)
|
||||||
|
b-list-group-item.flex-column.align-items-start(v-for="event in filteredEvents"
|
||||||
|
:href='`/event/${event.id}`')
|
||||||
|
b-media
|
||||||
|
img(v-if='event.image_path' slot="aside" :src="imgPath(event)" alt="Media Aside" style='max-height: 60px')
|
||||||
|
small.float-right {{event.start_datetime|short_datetime}}
|
||||||
|
h5.mb-1 {{event.title}}
|
||||||
|
small.mb-1 {{event.description}}
|
||||||
|
b-badge.float-right.ml-1(v-for='tag in event.tags') {{tag.tag}}
|
||||||
|
small.float-right(v-b-popover.hover='event.place.address') {{event.place.name}}
|
||||||
|
Calendar(v-else)
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import config from '../../config'
|
import config from '../../config'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import filters from '../filters'
|
||||||
|
import Calendar from '@/components/Calendar'
|
||||||
|
import {intersection} from 'lodash'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Export',
|
name: 'Export',
|
||||||
|
components: { Calendar },
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
type: '',
|
type: '',
|
||||||
link: '',
|
link: '',
|
||||||
mail: {}
|
mail: {},
|
||||||
|
export_list: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
filters,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.type = this.$route.params.type
|
this.type = this.$route.params.type
|
||||||
this.link = this.loadLink()
|
this.link = this.loadLink()
|
||||||
@@ -47,10 +69,27 @@ export default {
|
|||||||
loadLink () {
|
loadLink () {
|
||||||
const filters = this.filters.tags.join(',')
|
const filters = this.filters.tags.join(',')
|
||||||
return `${config.apiurl}/export/${this.type}/${filters}`
|
return `${config.apiurl}/export/${this.type}/${filters}`
|
||||||
}
|
},
|
||||||
|
imgPath (event) {
|
||||||
|
return event.image_path && config.apiurl + '/../' + event.image_path
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['filters', 'user', 'logged']),
|
...mapState(['filters', 'user', 'logged', 'events']),
|
||||||
|
filteredEvents () {
|
||||||
|
if (!this.filters.tags.length && !this.filters.places.length) return this.events
|
||||||
|
return this.events.filter(e => {
|
||||||
|
if (this.filters.tags.length) {
|
||||||
|
const m = intersection(e.tags.map(t => t.tag), this.filters.tags)
|
||||||
|
if (m.length>0) return true
|
||||||
|
}
|
||||||
|
if (this.filters.places.length) {
|
||||||
|
if (this.filters.places.find(p => p === e.place.name))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
},
|
||||||
showLink () {
|
showLink () {
|
||||||
return (['feed', 'ics'].indexOf(this.type)>-1)
|
return (['feed', 'ics'].indexOf(this.type)>-1)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -138,8 +138,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
update (e) {
|
update (e, value) {
|
||||||
if (this.multiple && e.data === ',') {
|
if (this.multiple && this.search[this.search.length-1] === ',') {
|
||||||
this.search = this.search.substr(0, this.search.length-1)
|
this.search = this.search.substr(0, this.search.length-1)
|
||||||
this.hit(e)
|
this.hit(e)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ import Settings from '@/components/Settings'
|
|||||||
import newEvent from '@/components/newEvent'
|
import newEvent from '@/components/newEvent'
|
||||||
import eventDetail from '@/components/EventDetail'
|
import eventDetail from '@/components/EventDetail'
|
||||||
import Home from '@/components/Home'
|
import Home from '@/components/Home'
|
||||||
import Event from '@/components/event'
|
import Event from '@/components/Event'
|
||||||
|
|
||||||
module.exports = { Home, eventDetail, newEvent, Settings, Login, Register, Event }
|
export default { Home, eventDetail, newEvent, Settings, Login, Register, Event }
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ export default {
|
|||||||
datetime (value) {
|
datetime (value) {
|
||||||
return moment(value).format('ddd, D MMMM HH:mm')
|
return moment(value).format('ddd, D MMMM HH:mm')
|
||||||
},
|
},
|
||||||
|
short_datetime (value) {
|
||||||
|
return moment(value).format('D/MM HH:mm')
|
||||||
|
},
|
||||||
hour (value) {
|
hour (value) {
|
||||||
return moment(value).format('HH:mm')
|
return moment(value).format('HH:mm')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user