feat: page tree browser

This commit is contained in:
NGPixel 2019-10-12 00:55:43 -04:00
parent 7a3198c306
commit 3de0e1499a
3 changed files with 103 additions and 41 deletions

View File

@ -1,7 +1,7 @@
<template lang="pug"> <template lang="pug">
v-dialog(v-model='isShown', max-width='850px') v-dialog(v-model='isShown', max-width='850px')
v-card.page-selector v-card.page-selector
.dialog-header.is-dark .dialog-header.is-blue
v-icon.mr-3(color='white') mdi-page-next-outline v-icon.mr-3(color='white') mdi-page-next-outline
.body-1 Select Page Location .body-1 Select Page Location
v-spacer v-spacer
@ -15,45 +15,53 @@
.d-flex(style='min-height:400px;') .d-flex(style='min-height:400px;')
v-flex.grey(xs4, :class='darkMode ? `darken-4` : `lighten-3`') v-flex.grey(xs4, :class='darkMode ? `darken-4` : `lighten-3`')
v-toolbar(color='grey darken-3', dark, dense, flat) v-toolbar(color='grey darken-3', dark, dense, flat)
.body-2 Folders .body-2 Virtual Folders
//- v-spacer v-spacer
//- v-btn(icon): v-icon create_new_folder v-btn(icon, tile)
v-icon mdi-help-box
v-treeview( v-treeview(
v-model='tree' :active.sync='currentNode'
:items='treeFolders' :open.sync='openNodes'
:items='tree'
:load-children='fetchFolders' :load-children='fetchFolders'
dense
expand-icon='mdi-menu-down-outline'
item-id='path'
item-text='title'
activatable activatable
open-on-click
hoverable hoverable
) )
template(slot='prepend', slot-scope='{ item, open, leaf }') template(slot='prepend', slot-scope='{ item, open, leaf }')
v-icon mdi-{{ open ? 'folder-open' : 'folder' }} v-icon mdi-{{ open ? 'folder-open' : 'folder' }}
v-flex(xs8) v-flex(xs8)
v-toolbar(color='grey darken-2', dark, dense, flat) v-toolbar(color='blue darken-2', dark, dense, flat)
.body-2 Pages .body-2 Pages
v-spacer v-spacer
v-btn(icon): v-icon mdi-forward v-btn(icon, tile): v-icon mdi-content-save-move-outline
v-btn(icon): v-icon mdi-delete v-btn(icon, tile): v-icon mdi-trash-can-outline
v-list(dense) v-list.py-0(dense, v-if='currentPages.length > 0')
v-list-item v-list-item-group(
v-list-item-icon: v-icon mdi-file-document-box v-model='currentPage'
v-list-item-title File A color='primary'
v-divider )
v-list-item template(v-for='(page, idx) of currentPages')
v-list-item-icon: v-icon mdi-file-document-box v-list-item(:key='page.id', :value='page.path')
v-list-item-title File B v-list-item-icon: v-icon mdi-file-document-box
v-divider v-list-item-title {{page.title}}
v-list-item v-divider(v-if='idx < pages.length - 1')
v-list-item-icon: v-icon mdi-file-document-box v-alert.animated.fadeIn(
v-list-item-title File C v-else
v-divider text
v-list-item color='orange'
v-list-item-icon: v-icon mdi-file-document-box prominent
v-list-item-title File D icon='mdi-alert'
v-card-actions.grey.pa-2(:class='darkMode ? `darken-3-d5` : `lighten-1`') )
.body-2 This folder is empty.
v-card-actions.grey.pa-2(:class='darkMode ? `darken-2` : `lighten-1`')
v-select( v-select(
solo solo
dark dark
flat
background-color='grey darken-3-d2' background-color='grey darken-3-d2'
hide-details hide-details
single-line single-line
@ -62,6 +70,7 @@
v-model='currentLocale' v-model='currentLocale'
) )
v-text-field( v-text-field(
ref='pathIpt'
solo solo
hide-details hide-details
prefix='/' prefix='/'
@ -73,13 +82,15 @@
v-card-chin v-card-chin
v-spacer v-spacer
v-btn(text, @click='close') Cancel v-btn(text, @click='close') Cancel
v-btn.px-4(color='primary', @click='open') v-btn.px-4(color='primary', @click='open', :disabled='!isValidPath')
v-icon(left) mdi-check v-icon(left) mdi-check
span Select span Select
</template> </template>
<script> <script>
import _ from 'lodash'
import { get } from 'vuex-pathify' import { get } from 'vuex-pathify'
import pageTreeQuery from 'gql/common/common-pages-query-tree.gql'
/* global siteLangs, siteConfig */ /* global siteLangs, siteConfig */
@ -111,8 +122,15 @@ export default {
searchLoading: false, searchLoading: false,
currentLocale: siteConfig.lang, currentLocale: siteConfig.lang,
currentPath: 'new-page', currentPath: 'new-page',
tree: [], currentPage: null,
treeChildren: [], currentNode: [0],
openNodes: [0],
tree: [{
id: 0,
title: '/ (root',
children: []
}],
pages: [],
namespaces: siteLangs.length ? siteLangs.map(ns => ns.code) : [siteConfig.lang] namespaces: siteLangs.length ? siteLangs.map(ns => ns.code) : [siteConfig.lang]
} }
}, },
@ -122,21 +140,33 @@ export default {
get() { return this.value }, get() { return this.value },
set(val) { this.$emit('input', val) } set(val) { this.$emit('input', val) }
}, },
treeFolders() { currentPages () {
return [ return _.filter(this.pages, ['parent', _.head(this.currentNode) || 0])
{ },
id: '/', isValidPath () {
name: '/ (root)', return this.currentPath && this.currentPath.length > 2
children: []
}
]
} }
}, },
watch: { watch: {
isShown(newValue, oldValue) { isShown (newValue, oldValue) {
if (newValue && !oldValue) { if (newValue && !oldValue) {
this.currentPath = this.path this.currentPath = this.path
this.currentLocale = this.locale this.currentLocale = this.locale
_.delay(() => {
this.$refs.pathIpt.focus()
})
}
},
currentNode (newValue, oldValue) {
if (newValue.length < 1) { // force a selection
this.$nextTick(() => {
this.currentNode = oldValue
})
}
},
currentPage (newValue, oldValue) {
if (!_.isEmpty(newValue)) {
this.currentPath = newValue
} }
} }
}, },
@ -153,8 +183,28 @@ export default {
this.close() this.close()
} }
}, },
async fetchFolders(item) { async fetchFolders (item) {
console.info(item) this.searchLoading = true
const resp = await this.$apollo.query({
query: pageTreeQuery,
fetchPolicy: 'network-only',
variables: {
parent: item.id,
mode: 'ALL',
locale: this.currentLocale
}
})
const items = _.get(resp, 'data.pages.tree', [])
const itemFolders = _.filter(items, ['isFolder', true]).map(f => ({...f, children: []}))
const itemPages = _.filter(items, ['isFolder', false])
if (itemFolders.length > 0) {
item.children = itemFolders
} else {
item.children = undefined
}
this.pages.push(...itemPages)
this.searchLoading = false
} }
} }
} }

View File

@ -0,0 +1,11 @@
query ($parent: Int!, $mode: PageTreeMode!, $locale: String!) {
pages {
tree(parent: $parent, mode: $mode, locale: $locale) {
id
path
title
isFolder
parent
}
}
}

View File

@ -141,6 +141,7 @@ module.exports = {
}) })
}).map(r => ({ }).map(r => ({
...r, ...r,
parent: r.parent || 0,
locale: r.localeCode locale: r.localeCode
})) }))
} }