refactoring tags page / controller
This commit is contained in:
@@ -11,11 +11,24 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
import Event from '@/components/Event'
|
import Event from '@/components/Event'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Tag',
|
name: 'Tag',
|
||||||
components: { Event },
|
components: { Event },
|
||||||
|
head ({ $route }) {
|
||||||
|
const tag = $route.params.tag
|
||||||
|
const title = `${this.settings.title} #${tag}`
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
link: [
|
||||||
|
{ rel: 'alternate', type: 'application/rss+xml', title, href: this.settings.baseurl + `/feed/rss/tag/${tag}` },
|
||||||
|
{ rel: 'alternate', type: 'text/calendar', title, href: this.settings.baseurl + `/feed/ics/tag/${tag}` }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: mapState(['settings']),
|
||||||
async asyncData ({ $axios, params, error }) {
|
async asyncData ({ $axios, params, error }) {
|
||||||
try {
|
try {
|
||||||
const tag = params.tag
|
const tag = params.tag
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const dayjs = require('dayjs')
|
|
||||||
const Tag = require('../models/tag')
|
const Tag = require('../models/tag')
|
||||||
const Event = require('../models/event')
|
const Event = require('../models/event')
|
||||||
|
const { where, fn, col, Op } = require('sequelize')
|
||||||
|
const exportController = require('./export')
|
||||||
const eventController = require('./event')
|
const eventController = require('./event')
|
||||||
const Sequelize = require('sequelize')
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// async getEvents (req, res) {
|
// async getEvents (req, res) {
|
||||||
@@ -18,14 +18,37 @@ module.exports = {
|
|||||||
// return res.json({ events, place })
|
// return res.json({ events, place })
|
||||||
// },
|
// },
|
||||||
|
|
||||||
async get (req, res) {
|
// /feed/rss/tag/tagname
|
||||||
|
// /feed/ics/tag/tagname
|
||||||
|
// /feed/json/tag/tagname
|
||||||
|
async getEvents (req, res) {
|
||||||
|
const format = req.params.format || 'json'
|
||||||
|
const tags = req.params.tag
|
||||||
|
const events = await eventController._select({ tags, show_recurrent: true })
|
||||||
|
|
||||||
|
switch (format) {
|
||||||
|
case 'rss':
|
||||||
|
return exportController.feed(req, res, events,
|
||||||
|
`${res.locals.settings.title} - Tag #${tags}`,
|
||||||
|
`${res.locals.settings.baseurl}/feed/rss/tag/${tags}`)
|
||||||
|
case 'ics':
|
||||||
|
return exportController.ics(req, res, events)
|
||||||
|
default:
|
||||||
|
return res.json(events)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* search for tags by query string
|
||||||
|
* sorted by usage
|
||||||
|
*/
|
||||||
|
async search (req, res) {
|
||||||
const search = req.query.search
|
const search = req.query.search
|
||||||
console.error(search)
|
|
||||||
const tags = await Tag.findAll({
|
const tags = await Tag.findAll({
|
||||||
order: [[Sequelize.fn('COUNT', Sequelize.col('tag.tag')), 'DESC']],
|
order: [[fn('COUNT', col('tag.tag')), 'DESC']],
|
||||||
attributes: ['tag'],
|
attributes: ['tag'],
|
||||||
where: {
|
where: {
|
||||||
tag: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('tag')), 'LIKE', '%' + search + '%'),
|
tag: where(fn('LOWER', col('tag')), 'LIKE', '%' + search + '%'),
|
||||||
},
|
},
|
||||||
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
|
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
|
||||||
group: ['tag.tag'],
|
group: ['tag.tag'],
|
||||||
@@ -35,13 +58,4 @@ module.exports = {
|
|||||||
|
|
||||||
return res.json(tags.map(t => t.tag))
|
return res.json(tags.map(t => t.tag))
|
||||||
}
|
}
|
||||||
|
|
||||||
// async getPlaces (req, res) {
|
|
||||||
// const search = req.params.search
|
|
||||||
// const places = await Place.findAll({ where: {
|
|
||||||
// [Op.or]: [
|
|
||||||
// { name: }
|
|
||||||
// ]
|
|
||||||
// }})
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user