From ad014db451bd09c62a5f7320681d9bd8f062f95d Mon Sep 17 00:00:00 2001 From: lesion Date: Wed, 18 Sep 2024 15:45:08 +0200 Subject: [PATCH] fix: show frequent tags by default when filling tags without typing, fix #452 --- pages/add/_edit.vue | 3 +++ server/api/controller/tag.js | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pages/add/_edit.vue b/pages/add/_edit.vue index d2294500..50481268 100644 --- a/pages/add/_edit.vue +++ b/pages/add/_edit.vue @@ -177,6 +177,9 @@ export default { disableAddress: false } }, + mounted () { + this.$nextTick( async () => this.tags = await this.$axios.$get('/tag') ) + }, head() { return { title: `${this.settings.title} - ${this.$t('common.add_event')}` diff --git a/server/api/controller/tag.js b/server/api/controller/tag.js index affbb19a..122e4e6c 100644 --- a/server/api/controller/tag.js +++ b/server/api/controller/tag.js @@ -72,13 +72,15 @@ module.exports = { * sorted by usage */ async search (req, res) { - const search = req.query.search + const search = req?.query?.search + let where = { } + if (search) { + where = { tag: { [Op.like]: `%${search}%` } } + } const tags = await Tag.findAll({ order: [[fn('COUNT', col('tag.tag')), 'DESC']], attributes: ['tag'], - where: { - tag: { [Op.like]: `%${search}%` } - }, + where, include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }], group: ['tag.tag'], limit: 10,