Browse Source

feat: sidebar rendering

pull/760/head
Nicolas Giard 6 years ago
parent
commit
763bf4b903
7 changed files with 31 additions and 17 deletions
  1. 17
      client/themes/default/components/nav-sidebar.vue
  2. 1
      client/themes/default/components/page.vue
  3. 3
      server/controllers/common.js
  4. 1
      server/graph/resolvers/navigation.js
  5. 11
      server/models/navigation.js
  6. 2
      server/setup.js
  7. 13
      server/views/page.pug

17
client/themes/default/components/nav-sidebar.vue

@ -1,19 +1,6 @@
<template lang="pug">
v-list(dense, :class='color', :dark='dark')
v-list-tile.pt-2(href='/')
v-list-tile-avatar: v-icon home
v-list-tile-title Home
v-divider.my-2
v-subheader.pl-4 Navigation
v-list-tile
v-list-tile-avatar: v-icon stars
v-list-tile-title The Universe
v-list-tile
v-list-tile-avatar: v-icon directions_boat
v-list-tile-title Ships
v-list-tile
v-list-tile-avatar: v-icon local_airport
v-list-tile-title Airports
v-list.py-2(dense, :class='color', :dark='dark')
slot
</template>
<script>

1
client/themes/default/components/page.vue

@ -12,6 +12,7 @@
v-model='navShown'
)
nav-sidebar
slot(name='sidebar')
v-content
v-toolbar(color='grey lighten-3', flat, dense)

3
server/controllers/common.js

@ -75,7 +75,8 @@ router.get('/*', async (req, res, next) => {
isPrivate: false
})
if (page) {
res.render('page', { page })
const sidebar = await WIKI.models.navigation.getTree({ cache: true })
res.render('page', { page, sidebar })
} else if (pageArgs.path === 'home') {
res.render('welcome')
} else {

1
server/graph/resolvers/navigation.js

@ -21,6 +21,7 @@ module.exports = {
await WIKI.models.navigation.query().patch({
config: args.tree
}).where('key', 'site')
await WIKI.redis.set('nav:sidebar', JSON.stringify(args.tree), 'EX', 300)
return {
responseResult: graphHelper.generateSuccess('Navigation updated successfully')

11
server/models/navigation.js

@ -21,9 +21,18 @@ module.exports = class Navigation extends Model {
}
}
static async getTree() {
static async getTree({ cache = false } = {}) {
if (cache) {
const navTreeCached = await WIKI.redis.get('nav:sidebar')
if (navTreeCached) {
return JSON.parse(navTreeCached)
}
}
const navTree = await WIKI.models.navigation.query().findOne('key', 'site')
if (navTree) {
if (cache) {
await WIKI.redis.set('nav:sidebar', JSON.stringify(navTree.config), 'EX', 300)
}
return navTree.config
} else {
WIKI.logger.warn('Site Navigation is missing or corrupted.')

2
server/setup.js

@ -1,4 +1,5 @@
const path = require('path')
const uuid = require('uuid/v4')
/* global WIKI */
@ -209,6 +210,7 @@ module.exports = () => {
key: 'site',
config: [
{
id: uuid(),
icon: 'home',
kind: 'link',
label: 'Home',

13
server/views/page.pug

@ -16,4 +16,17 @@ block body
:author-id=page.authorId
:is-published=page.isPublished
)
template(slot='sidebar')
each navItem in sidebar
if navItem.kind === 'link'
v-list-tile(
href=navItem.target
)
v-list-tile-avatar
v-icon= navItem.icon
v-list-tile-title= navItem.label
else if navItem.kind === 'divider'
v-divider.my-2
else if navItem.kind === 'header'
v-subheader.pl-4= navItem.label
template(slot='contents')!= page.render
Loading…
Cancel
Save