feat: tags autocomplete in page properties

This commit is contained in:
NGPixel
2020-02-02 16:24:27 -05:00
parent a1e0e4f27a
commit f4e3fd0954
5 changed files with 80 additions and 7 deletions

View File

@@ -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
*/

View File

@@ -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

View File

@@ -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 => ({

View File

@@ -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}%`)