feat: navigation save / load
This commit is contained in:
@@ -12,22 +12,16 @@ module.exports = {
|
||||
},
|
||||
NavigationQuery: {
|
||||
async tree(obj, args, context, info) {
|
||||
// let renderers = await WIKI.models.renderers.getRenderers()
|
||||
return []
|
||||
return WIKI.models.navigation.getTree()
|
||||
}
|
||||
},
|
||||
NavigationMutation: {
|
||||
async updateTree(obj, args, context) {
|
||||
try {
|
||||
// for (let rdr of args.renderers) {
|
||||
// await WIKI.models.storage.query().patch({
|
||||
// isEnabled: rdr.isEnabled,
|
||||
// config: _.reduce(rdr.config, (result, value, key) => {
|
||||
// _.set(result, `${value.key}`, value.value)
|
||||
// return result
|
||||
// }, {})
|
||||
// }).where('key', rdr.key)
|
||||
// }
|
||||
await WIKI.models.navigation.query().patch({
|
||||
config: args.tree
|
||||
}).where('key', 'site')
|
||||
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
|
||||
}
|
||||
|
@@ -16,12 +16,18 @@ module.exports = class Navigation extends Model {
|
||||
|
||||
properties: {
|
||||
key: {type: 'string'},
|
||||
config: {type: 'object'}
|
||||
config: {type: 'array', items: {type: 'object'}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async getTree() {
|
||||
return WIKI.models.navigation.query()
|
||||
const navTree = await WIKI.models.navigation.query().findOne('key', 'site')
|
||||
if (navTree) {
|
||||
return navTree.config
|
||||
} else {
|
||||
WIKI.logger.warn('Site Navigation is missing or corrupted.')
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -201,6 +201,23 @@ module.exports = () => {
|
||||
})
|
||||
await guestUser.$relatedQuery('groups').relate(guestGroup.id)
|
||||
|
||||
// Create site nav
|
||||
|
||||
WIKI.logger.info('Creating default site navigation')
|
||||
await WIKI.models.navigation.query().delete().where({ key: 'site' })
|
||||
await WIKI.models.navigation.query().insert({
|
||||
key: 'site',
|
||||
config: JSON.stringify([
|
||||
{
|
||||
icon: 'home',
|
||||
kind: 'link',
|
||||
label: 'Home',
|
||||
target: '/',
|
||||
targetType: 'home'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
WIKI.logger.info('Setup is complete!')
|
||||
res.json({
|
||||
ok: true,
|
||||
|
Reference in New Issue
Block a user