Commit d2218cff authored by les's avatar les
Browse files

cleaner next/prev event

parent c953fbf3
All notable changes to this project will be documented in this file.
### UNRELEASED
-
### 0.23.0
- send AP Event Object instead of Note
- show only future unconfirmed events in admin panel
......
......@@ -2,13 +2,13 @@
el-container#eventDetail.h-event
el-header
span.title.p-summary.p-name {{event.title}}
.title {{event.title}}
#arrow
nuxt-link.mr-1(:to='`/event/${prev}`')
el-button(circle plain size='small' icon='el-icon-arrow-left' :disabled='!prev')
nuxt-link(:to='`/event/${next}`')
el-button(circle plain size='small' :disabled='!next' icon='el-icon-arrow-right')
nuxt-link.mr-1(:to='`/event/${event.prev}`')
el-button(circle plain size='small' icon='el-icon-arrow-left' :disabled='!event.prev')
nuxt-link(:to='`/event/${event.next}`')
el-button(circle plain size='small' :disabled='!event.next' icon='el-icon-arrow-right')
el-main
el-dialog.embedDialog(:visible.sync='showEmbed')
......@@ -87,7 +87,7 @@
</template>
<script>
import { mapState, mapGetters } from 'vuex'
import { mapState } from 'vuex'
import EventAdmin from './eventAdmin'
import EmbedEvent from './embedEvent'
import FollowMe from '../../components/FollowMe'
......@@ -192,42 +192,10 @@ export default {
}
},
computed: {
...mapGetters(['filteredEvents']),
...mapState(['settings']),
plainDescription () {
return htmlToText.fromString(this.event.description.replace('\n', '').slice(0, 1000))
},
next () {
let found = false
const event = this.filteredEvents.find(e => {
if (found) {
return e
}
found =
e.start_datetime === this.event.start_datetime &&
e.id === this.event.id
})
if (!event) {
return false
}
return event.id
},
prev () {
let event = false
this.filteredEvents.find(e => {
if (
e.start_datetime === this.event.start_datetime &&
e.id === this.event.id
) {
return true
}
event = e
})
if (!event) {
return false
}
return event.id
},
imgPath () {
return '/media/' + this.event.image_path
},
......
......@@ -91,6 +91,7 @@ const eventController = {
const is_admin = req.user && req.user.is_admin
const id = Number(req.params.event_id)
let event
try {
event = await Event.findByPk(id, {
attributes: {
......@@ -113,8 +114,36 @@ const eventController = {
} catch (e) {
return res.sendStatus(400)
}
if (!event) {
return res.sendStatus(400)
}
// get prev and next event
const next = await Event.findOne({
attributes: ['id'],
where: {
is_visible: true,
parentId: null,
start_datetime: { [Op.gt]: event.start_datetime }
},
order: [['start_datetime', 'ASC']]
})
const prev = await Event.findOne({
attributes: ['id'],
where: {
is_visible: true,
parentId: null,
start_datetime: { [Op.lt]: event.start_datetime }
},
order: [['start_datetime', 'DESC']]
})
if (event && (event.is_visible || is_admin)) {
event = event.get()
event.next = next && next.id
event.prev = prev && prev.id
event.tags = event.tags.map(t => t.tag)
if (format === 'json') {
res.json(event)
......
......@@ -115,11 +115,12 @@ const Helpers = {
return res.data
})
.catch(e => {
debug(e)
debug(`[ERR] ${URL}: ${e}`)
return false
})
if (fedi_user) {
debug(`Create a new AP User => ${URL}`)
fedi_user = await APUser.create({ ap_id: URL, object: fedi_user })
}
return fedi_user
......@@ -136,6 +137,7 @@ const Helpers = {
if (instance) { return instance }
}
// TODO: is this a standard? don't think so
instance = await axios.get(`${instance_url}/api/v1/instance`, { headers: { Accept: 'application/json' } })
.then(res => res.data)
.then(instance => {
......@@ -169,7 +171,7 @@ const Helpers = {
}
// little hack -> https://github.com/joyent/node-http-signature/pull/83
req.headers.authorization = 'Signature ' + req.headers.signature
// req.headers.authorization = 'Signature ' + req.headers.signature
req.fedi_user = user
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment