You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.4 KiB

  1. <template lang="pug">
  2. .has-collapsable-nav
  3. ul.collapsable-nav(v-for='treeItem in tree', :class='{ "has-children": treeItem.hasChildren }', v-cloak)
  4. li(v-for='page in treeItem.pages', :class='{ "is-active": page.isActive }')
  5. a(v-on:click='mainAction(page)')
  6. template(v-if='page._id !== "home"')
  7. i(:class='{ "icon-folder2": page.isDirectory, "icon-file-text-o": !page.isDirectory }')
  8. span {{ page.title }}
  9. template(v-else)
  10. i.icon-home
  11. span {{ $t('nav.home') }}
  12. a.is-pagelink(v-if='page.isDirectory && page.isEntry', v-on:click='goto(page._id)')
  13. i.icon-file-text-o
  14. i.icon-arrow-right2
  15. </template>
  16. <script>
  17. export default {
  18. name: '',
  19. data () {
  20. return {
  21. tree: []
  22. }
  23. },
  24. methods: {
  25. fetch (basePath) {
  26. let self = this
  27. self.$store.dispatch('startLoading')
  28. self.$nextTick(() => {
  29. socket.emit('treeFetch', { basePath }, (data) => {
  30. if (self.tree.length > 0) {
  31. let branch = self._.last(self.tree)
  32. branch.hasChildren = true
  33. self._.find(branch.pages, { _id: basePath }).isActive = true
  34. }
  35. self.tree.push({
  36. hasChildren: false,
  37. pages: data
  38. })
  39. self.$store.dispatch('stopLoading')
  40. })
  41. })
  42. },
  43. goto (entryPath) {
  44. window.location.assign(siteRoot + '/' + entryPath)
  45. },
  46. unfold (entryPath) {
  47. let self = this
  48. let lastIndex = 0
  49. self._.forEach(self.tree, branch => {
  50. lastIndex++
  51. if (self._.find(branch.pages, { _id: entryPath }) !== undefined) {
  52. return false
  53. }
  54. })
  55. self.tree = self._.slice(self.tree, 0, lastIndex)
  56. let branch = self._.last(self.tree)
  57. branch.hasChildren = false
  58. branch.pages.forEach(page => {
  59. page.isActive = false
  60. })
  61. },
  62. mainAction (page) {
  63. let self = this
  64. if (page.isActive) {
  65. self.unfold(page._id)
  66. } else if (page.isDirectory) {
  67. self.fetch(page._id)
  68. } else {
  69. self.goto(page._id)
  70. }
  71. }
  72. },
  73. mounted () {
  74. let basePath = window.location.pathname.slice(0, -4)
  75. if (basePath.length > 1) {
  76. basePath = basePath.slice(1)
  77. }
  78. this.fetch(basePath)
  79. }
  80. }
  81. </script>