feat: navigation save / load
This commit is contained in:
parent
b870a4724d
commit
b26f30ae20
@ -8,6 +8,8 @@
|
|||||||
.headline.primary--text {{$t('navigation.title')}}
|
.headline.primary--text {{$t('navigation.title')}}
|
||||||
.subheading.grey--text {{$t('navigation.subtitle')}}
|
.subheading.grey--text {{$t('navigation.subtitle')}}
|
||||||
v-spacer
|
v-spacer
|
||||||
|
v-btn(outline, color='grey', @click='refresh', large)
|
||||||
|
v-icon refresh
|
||||||
v-btn(color='success', depressed, @click='save', large)
|
v-btn(color='success', depressed, @click='save', large)
|
||||||
v-icon(left) check
|
v-icon(left) check
|
||||||
span {{$t('common:actions.apply')}}
|
span {{$t('common:actions.apply')}}
|
||||||
@ -185,20 +187,38 @@ export default {
|
|||||||
async save() {
|
async save() {
|
||||||
this.$store.commit(`loadingStart`, 'admin-navigation-save')
|
this.$store.commit(`loadingStart`, 'admin-navigation-save')
|
||||||
try {
|
try {
|
||||||
await this.$apollo.mutate({
|
const resp = await this.$apollo.mutate({
|
||||||
mutation: treeSaveMutation,
|
mutation: treeSaveMutation,
|
||||||
variables: {
|
variables: {
|
||||||
tree: this.navTree
|
tree: this.navTree
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (_.get(resp, 'data.navigation.updateTree.responseResult.succeeded', false)) {
|
||||||
|
this.$store.commit('showNotification', {
|
||||||
|
message: this.$t('navigation.saveSuccess'),
|
||||||
|
style: 'success',
|
||||||
|
icon: 'check'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
throw new Error(_.get(resp, 'data.navigation.updateTree.responseResult.message', 'An unexpected error occured.'))
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.$store.commit('showNotification', {
|
this.$store.commit('showNotification', {
|
||||||
message: this.$t('navigation.saveSuccess'),
|
message: err.message,
|
||||||
style: 'success',
|
style: 'red',
|
||||||
icon: 'check'
|
icon: 'warning'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.$store.commit(`loadingStop`, 'admin-navigation-save')
|
this.$store.commit(`loadingStop`, 'admin-navigation-save')
|
||||||
|
},
|
||||||
|
async refresh() {
|
||||||
|
await this.$apollo.queries.navTree.refetch()
|
||||||
|
this.current = {}
|
||||||
|
this.$store.commit('showNotification', {
|
||||||
|
message: 'Navigation has been refreshed.',
|
||||||
|
style: 'success',
|
||||||
|
icon: 'cached'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
|
@ -12,22 +12,16 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
NavigationQuery: {
|
NavigationQuery: {
|
||||||
async tree(obj, args, context, info) {
|
async tree(obj, args, context, info) {
|
||||||
// let renderers = await WIKI.models.renderers.getRenderers()
|
return WIKI.models.navigation.getTree()
|
||||||
return []
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NavigationMutation: {
|
NavigationMutation: {
|
||||||
async updateTree(obj, args, context) {
|
async updateTree(obj, args, context) {
|
||||||
try {
|
try {
|
||||||
// for (let rdr of args.renderers) {
|
await WIKI.models.navigation.query().patch({
|
||||||
// await WIKI.models.storage.query().patch({
|
config: args.tree
|
||||||
// isEnabled: rdr.isEnabled,
|
}).where('key', 'site')
|
||||||
// config: _.reduce(rdr.config, (result, value, key) => {
|
|
||||||
// _.set(result, `${value.key}`, value.value)
|
|
||||||
// return result
|
|
||||||
// }, {})
|
|
||||||
// }).where('key', rdr.key)
|
|
||||||
// }
|
|
||||||
return {
|
return {
|
||||||
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
|
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,18 @@ module.exports = class Navigation extends Model {
|
|||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
key: {type: 'string'},
|
key: {type: 'string'},
|
||||||
config: {type: 'object'}
|
config: {type: 'array', items: {type: 'object'}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getTree() {
|
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)
|
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!')
|
WIKI.logger.info('Setup is complete!')
|
||||||
res.json({
|
res.json({
|
||||||
ok: true,
|
ok: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user