fix: tags input normalization
This commit is contained in:
parent
488ec4a3af
commit
77548c8778
@ -80,19 +80,14 @@
|
|||||||
v-combobox(
|
v-combobox(
|
||||||
:label='$t(`editor:props.tags`)'
|
:label='$t(`editor:props.tags`)'
|
||||||
outlined
|
outlined
|
||||||
v-model='tags'
|
v-model='newTag'
|
||||||
:hint='$t(`editor:props.tagsHint`)'
|
:hint='$t(`editor:props.tagsHint`)'
|
||||||
:items='newTagSuggestions'
|
:items='newTagSuggestions'
|
||||||
:loading='$apollo.queries.newTagSuggestions.loading'
|
:loading='$apollo.queries.newTagSuggestions.loading'
|
||||||
persistent-hint
|
persistent-hint
|
||||||
deletable-chips
|
|
||||||
hide-no-data
|
hide-no-data
|
||||||
hide-selected
|
|
||||||
:search-input.sync='newTagSearch'
|
:search-input.sync='newTagSearch'
|
||||||
multiple
|
|
||||||
)
|
)
|
||||||
template(v-slot:selection='{ attrs, item, parent, selected }')
|
|
||||||
span
|
|
||||||
v-tab-item
|
v-tab-item
|
||||||
v-card-text
|
v-card-text
|
||||||
.overline.pb-5 {{$t('editor:props.publishState')}} #[v-chip.ml-3(label, color='grey', small, outlined).white--text coming soon]
|
.overline.pb-5 {{$t('editor:props.publishState')}} #[v-chip.ml-3(label, color='grey', small, outlined).white--text coming soon]
|
||||||
@ -306,14 +301,20 @@ export default {
|
|||||||
// this.$tours['editorPropertiesTour'].start()
|
// this.$tours['editorPropertiesTour'].start()
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
newTag(newValue, oldValue) {
|
||||||
|
const tagClean = _.trim(newValue || '').toLowerCase()
|
||||||
|
if (tagClean && tagClean.length > 0) {
|
||||||
|
if (!_.includes(this.tags, tagClean)) {
|
||||||
|
this.tags = [...this.tags, tagClean]
|
||||||
|
}
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.newTag = null
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addTag () {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.tags.push(this.newTag)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
removeTag (tag) {
|
removeTag (tag) {
|
||||||
this.tags = _.without(this.tags, tag)
|
this.tags = _.without(this.tags, tag)
|
||||||
},
|
},
|
||||||
|
@ -110,7 +110,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args.tags && args.tags.length > 0) {
|
if (args.tags && args.tags.length > 0) {
|
||||||
queryBuilder.whereIn('tags.tag', args.tags)
|
queryBuilder.whereIn('tags.tag', args.tags.map(t => _.trim(t).toLowerCase()))
|
||||||
}
|
}
|
||||||
const orderDir = args.orderByDirection === 'DESC' ? 'desc' : 'asc'
|
const orderDir = args.orderByDirection === 'DESC' ? 'desc' : 'asc'
|
||||||
switch (args.orderBy) {
|
switch (args.orderBy) {
|
||||||
@ -177,14 +177,15 @@ module.exports = {
|
|||||||
* SEARCH TAGS
|
* SEARCH TAGS
|
||||||
*/
|
*/
|
||||||
async searchTags (obj, args, context, info) {
|
async searchTags (obj, args, context, info) {
|
||||||
|
const query = _.trim(args.query)
|
||||||
const results = await WIKI.models.tags.query()
|
const results = await WIKI.models.tags.query()
|
||||||
.column('tag')
|
.column('tag')
|
||||||
.where(builder => {
|
.where(builder => {
|
||||||
builder.andWhere(builderSub => {
|
builder.andWhere(builderSub => {
|
||||||
if (WIKI.config.db.type === 'postgres') {
|
if (WIKI.config.db.type === 'postgres') {
|
||||||
builderSub.where('tag', 'ILIKE', `%${args.query}%`)
|
builderSub.where('tag', 'ILIKE', `%${query}%`)
|
||||||
} else {
|
} else {
|
||||||
builderSub.where('tag', 'LIKE', `%${args.query}%`)
|
builderSub.where('tag', 'LIKE', `%${query}%`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -400,8 +401,8 @@ module.exports = {
|
|||||||
const affectedRows = await WIKI.models.tags.query()
|
const affectedRows = await WIKI.models.tags.query()
|
||||||
.findById(args.id)
|
.findById(args.id)
|
||||||
.patch({
|
.patch({
|
||||||
tag: args.tag,
|
tag: _.trim(args.tag).toLowerCase(),
|
||||||
title: args.title
|
title: _.trim(args.title)
|
||||||
})
|
})
|
||||||
if (affectedRows < 1) {
|
if (affectedRows < 1) {
|
||||||
throw new Error('This tag does not exist.')
|
throw new Error('This tag does not exist.')
|
||||||
|
@ -55,7 +55,7 @@ module.exports = class Tag extends Model {
|
|||||||
|
|
||||||
// Format tags
|
// Format tags
|
||||||
|
|
||||||
tags = _.uniq(tags.map(t => t.toLowerCase()))
|
tags = _.uniq(tags.map(t => _.trim(t).toLowerCase()))
|
||||||
|
|
||||||
// Create missing tags
|
// Create missing tags
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user