feat: browse nav + pageTree ancestors
This commit is contained in:
@@ -45,6 +45,8 @@ defaults:
|
||||
company: ''
|
||||
contentLicense: ''
|
||||
logoUrl: https://static.requarks.io/logo/wikijs-butterfly.svg
|
||||
nav:
|
||||
mode: 'MIXED'
|
||||
theming:
|
||||
theme: 'default'
|
||||
iconset: 'md'
|
||||
|
8
server/db/migrations-sqlite/2.3.23.js
Normal file
8
server/db/migrations-sqlite/2.3.23.js
Normal file
@@ -0,0 +1,8 @@
|
||||
exports.up = knex => {
|
||||
return knex.schema
|
||||
.alterTable('pageTree', table => {
|
||||
table.json('ancestors')
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => { }
|
8
server/db/migrations/2.3.23.js
Normal file
8
server/db/migrations/2.3.23.js
Normal file
@@ -0,0 +1,8 @@
|
||||
exports.up = knex => {
|
||||
return knex.schema
|
||||
.alterTable('pageTree', table => {
|
||||
table.json('ancestors')
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => { }
|
@@ -4,18 +4,21 @@ const graphHelper = require('../../helpers/graph')
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async navigation() { return {} }
|
||||
async navigation () { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async navigation() { return {} }
|
||||
async navigation () { return {} }
|
||||
},
|
||||
NavigationQuery: {
|
||||
async tree(obj, args, context, info) {
|
||||
async tree (obj, args, context, info) {
|
||||
return WIKI.models.navigation.getTree({ cache: false, locale: 'all' })
|
||||
},
|
||||
config (obj, args, context, info) {
|
||||
return WIKI.config.nav
|
||||
}
|
||||
},
|
||||
NavigationMutation: {
|
||||
async updateTree(obj, args, context) {
|
||||
async updateTree (obj, args, context) {
|
||||
try {
|
||||
await WIKI.models.navigation.query().patch({
|
||||
config: args.tree
|
||||
@@ -28,6 +31,20 @@ module.exports = {
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
},
|
||||
async updateConfig (obj, args, context) {
|
||||
try {
|
||||
WIKI.config.nav = {
|
||||
mode: args.mode
|
||||
}
|
||||
await WIKI.configSvc.saveToDb(['nav'])
|
||||
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Navigation config updated successfully')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -196,27 +196,41 @@ module.exports = {
|
||||
* FETCH PAGE TREE
|
||||
*/
|
||||
async tree (obj, args, context, info) {
|
||||
let results = []
|
||||
let conds = {
|
||||
localeCode: args.locale
|
||||
}
|
||||
if (args.parent) {
|
||||
conds.parent = (args.parent < 1) ? null : args.parent
|
||||
} else if (args.path) {
|
||||
// conds.parent = (args.parent < 1) ? null : args.parent
|
||||
}
|
||||
switch (args.mode) {
|
||||
case 'FOLDERS':
|
||||
conds.isFolder = true
|
||||
results = await WIKI.models.knex('pageTree').where(conds)
|
||||
break
|
||||
case 'PAGES':
|
||||
await WIKI.models.knex('pageTree').where(conds).andWhereNotNull('pageId')
|
||||
break
|
||||
default:
|
||||
results = await WIKI.models.knex('pageTree').where(conds)
|
||||
break
|
||||
let curPage = null
|
||||
|
||||
if (!args.locale) { args.locale = WIKI.config.lang.code }
|
||||
|
||||
if (args.path && !args.parent) {
|
||||
curPage = await WIKI.models.knex('pageTree').first('parent', 'ancestors').where({
|
||||
path: args.path,
|
||||
localeCode: args.locale
|
||||
})
|
||||
if (curPage) {
|
||||
args.parent = curPage.parent || 0
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
const results = await WIKI.models.knex('pageTree').where(builder => {
|
||||
builder.where('localeCode', args.locale)
|
||||
switch (args.mode) {
|
||||
case 'FOLDERS':
|
||||
builder.andWhere('isFolder', true)
|
||||
break
|
||||
case 'PAGES':
|
||||
builder.andWhereNotNull('pageId')
|
||||
break
|
||||
}
|
||||
if (!args.parent || args.parent < 1) {
|
||||
builder.whereNull('parent')
|
||||
} else {
|
||||
builder.where('parent', args.parent)
|
||||
if (args.includeAncestors && curPage && curPage.ancestors.length > 0) {
|
||||
builder.orWhereIn('id', curPage.ancestors)
|
||||
}
|
||||
}
|
||||
}).orderBy([{ column: 'isFolder', order: 'desc' }, 'title'])
|
||||
return results.filter(r => {
|
||||
return WIKI.auth.checkAccess(context.req.user, ['read:pages'], {
|
||||
path: r.path,
|
||||
|
@@ -16,6 +16,7 @@ extend type Mutation {
|
||||
|
||||
type NavigationQuery {
|
||||
tree: [NavigationTree]!
|
||||
config: NavigationConfig!
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@@ -26,6 +27,9 @@ type NavigationMutation {
|
||||
updateTree(
|
||||
tree: [NavigationTreeInput]!
|
||||
): DefaultResponse @auth(requires: ["manage:navigation", "manage:system"])
|
||||
updateConfig(
|
||||
mode: NavigationMode!
|
||||
): DefaultResponse @auth(requires: ["manage:navigation", "manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@@ -59,3 +63,13 @@ input NavigationItemInput {
|
||||
targetType: String
|
||||
target: String
|
||||
}
|
||||
|
||||
type NavigationConfig {
|
||||
mode: NavigationMode!
|
||||
}
|
||||
|
||||
enum NavigationMode {
|
||||
NONE
|
||||
TREE
|
||||
MIXED
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ type PageQuery {
|
||||
parent: Int
|
||||
mode: PageTreeMode!
|
||||
locale: String!
|
||||
includeParents: Boolean
|
||||
includeAncestors: Boolean
|
||||
): [PageTreeItem] @auth(requires: ["manage:system", "read:pages"])
|
||||
|
||||
links(
|
||||
|
@@ -19,6 +19,7 @@ module.exports = async (pageId) => {
|
||||
let currentPath = ''
|
||||
let depth = 0
|
||||
let parentId = null
|
||||
let ancestors = []
|
||||
for (const part of pagePaths) {
|
||||
depth++
|
||||
const isFolder = (depth < pagePaths.length)
|
||||
@@ -39,7 +40,8 @@ module.exports = async (pageId) => {
|
||||
isPrivate: !isFolder && page.isPrivate,
|
||||
privateNS: !isFolder ? page.privateNS : null,
|
||||
parent: parentId,
|
||||
pageId: isFolder ? null : page.id
|
||||
pageId: isFolder ? null : page.id,
|
||||
ancestors: JSON.stringify(ancestors)
|
||||
})
|
||||
parentId = pik
|
||||
} else if (isFolder && !found.isFolder) {
|
||||
@@ -48,6 +50,7 @@ module.exports = async (pageId) => {
|
||||
} else {
|
||||
parentId = found.id
|
||||
}
|
||||
ancestors.push(parentId)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user