feat: tags autocomplete in page properties
This commit is contained in:
@@ -129,6 +129,24 @@ module.exports = {
|
||||
async tags (obj, args, context, info) {
|
||||
return WIKI.models.tags.query().orderBy('tag', 'asc')
|
||||
},
|
||||
/**
|
||||
* SEARCH TAGS
|
||||
*/
|
||||
async searchTags (obj, args, context, info) {
|
||||
const results = await WIKI.models.tags.query()
|
||||
.column('tag')
|
||||
.where(builder => {
|
||||
builder.andWhere(builderSub => {
|
||||
if (WIKI.config.db.type === 'postgres') {
|
||||
builderSub.where('tag', 'ILIKE', `%${args.query}%`)
|
||||
} else {
|
||||
builderSub.where('tag', 'LIKE', `%${args.query}%`)
|
||||
}
|
||||
})
|
||||
})
|
||||
.limit(5)
|
||||
return results.map(r => r.tag)
|
||||
},
|
||||
/**
|
||||
* FETCH PAGE TREE
|
||||
*/
|
||||
|
@@ -41,6 +41,10 @@ type PageQuery {
|
||||
|
||||
tags: [PageTag]! @auth(requires: ["manage:system", "read:pages"])
|
||||
|
||||
searchTags(
|
||||
query: String!
|
||||
): [String]! @auth(requires: ["manage:system", "read:pages"])
|
||||
|
||||
tree(
|
||||
path: String
|
||||
parent: Int
|
||||
|
@@ -53,6 +53,10 @@ module.exports = class Tag extends Model {
|
||||
static async associateTags ({ tags, page }) {
|
||||
let existingTags = await WIKI.models.tags.query().column('id', 'tag')
|
||||
|
||||
// Format tags
|
||||
|
||||
tags = _.uniq(tags.map(t => t.toLowerCase()))
|
||||
|
||||
// Create missing tags
|
||||
|
||||
const newTags = _.filter(tags, t => !_.some(existingTags, ['tag', t])).map(t => ({
|
||||
|
@@ -30,7 +30,6 @@ module.exports = {
|
||||
if (opts.path) {
|
||||
builder.andWhere('path', 'like', `${opts.path}%`)
|
||||
}
|
||||
// TODO: Add user permissions filtering
|
||||
builder.andWhere(builderSub => {
|
||||
if (WIKI.config.db.type === 'postgres') {
|
||||
builderSub.where('title', 'ILIKE', `%${q}%`)
|
||||
|
Reference in New Issue
Block a user